编码API

AWS Agent 自动更新工具链

This post shows how to keep the AWS Agent Registry current automatically. Using AWS CloudTrail, Amazon EventBridge, AWS Lambda, and AgentCore Identity, an event-driven pipeline det

返回指南列表

AWS Agent 自动更新工具链

AWS Agent 自动更新工具链利用 AWS CloudTrail、Amazon EventBridge、AWS Lambda 和 AgentCore Identity,实现 AWS Agent Registry 的动态更新。该方案专为企业团队优化 Cursor 等 AI 编程工具的路径,让 MCP 服务器工具及架构模式实时同步,避免 stale metadata 导致的查询失败或依赖错误。

适用于开发 AgentCore MCP 服务器、维护多账号 Agent 治理及希望用 Cursor 高效调用 AWS 工具的工程师。决策时,可根据当前 Cursor 订阅档位和计划集成数量,选择单账号快速起步还是多账号事件转发。官方示例代码已开源,部署后可直接验证最新工具列表与 Cursor API 匹配度。

此工具链直接支持 AWS Agent Registry 作为 Cursor 等工具的中转源头,确保每次 AgentCore 更新后,Cursor 客户端立即获取准确架构,避免手动维护的低效。

架构概述

AWS Agent 自动更新工具链采用事件驱动管道,由五种 AWS 服务组成:

  • AWS CloudTrail 捕获 AgentCore 的 UpdateAgentRuntime API 调用,作为管理事件。
  • Amazon EventBridge 路由匹配事件至 Lambda 函数,支持跨账号转发。
  • AWS Lambda 查询 MCP 服务器工具列表,与 Registry 比对差异后更新记录。
  • AWS Agent Registry 作为中央事实来源,存储 MCP 服务器记录及工具 Schema。
  • AgentCore Identity 通过 OAuth 交换,避免 Lambda 存储密钥。

架构同时支持单账号和多账号部署。单账号模式下,所有组件位于同一账户;多账号模式下,MCP 服务器账号(Account B)的事件经跨账号转发至 Registry 账号(Account A)。

下图展示完整事件流:CloudTrail 捕获更新后,EventBridge 触发 Lambda 查询并同步。

该方案适用于 Cursor 等 IDE 中转路径优化,让工程师无需手动更新 Registry 即可保持数据 freshness。

工作原理

部署后,管道按以下流程运行:

1. 触发:开发人员在 MCP 服务器账号更新 AgentCore,调用 UpdateAgentRuntime API,CloudTrail 记录事件。

2. 路由:EventBridge 捕获事件并转发至 Registry 账号的事件总线。

3. 解析:Lambda 从事件中提取 runtime ARN,构建 MCP 服务器调用 URL。

4. 认证:通过 AgentCore Identity 生成安全 OAuth bearer token。

5. 获取:Lambda 调用 MCP 服务器的 initialize 方法启动会话,再执行 tools/list 获取最新工具列表。

6. 同步:Lambda 查找匹配的 Registry 记录,比较 Schema 差异,更新记录(若有变化)。

此流程假设 Registry 账号已预注册 MCP 服务器记录,仅更新现有记录。单账号部署时跳过跨账号转发步骤。

技术实现

事件捕获与路由

CloudTrail 记录 UpdateAgentRuntime 事件,延迟约 5–15 分钟。跨账号模式下,EventBridge 规则匹配 source: aws.bedrock-agentcore 且 detail-type: API Call via AWS CloudTrail、detail.eventName: UpdateAgentRuntime。

规则目标直接调用 Lambda 函数,传入完整 CloudTrail 事件 JSON。

提取 MCP 服务器 URL

Lambda 解析 runtime ARN,从账户 ID 和区域动态构建 URL:


def _extract_mcp_url(event):

 detail = event.get("detail", {})

 runtime_arn = detail.get("responseElements", {}).get("agentRuntimeArn", "")

 if not runtime_arn:

 return None, None

 arn_parts = runtime_arn.split(":")

 account_id = arn_parts[4] if len(arn_parts) > 4 else None

 region = detail.get("awsRegion", "us-west-2")

 encoded_arn = runtime_arn.replace(":", "%3A").replace("/", "%2F")

 mcp_url = f""

 return mcp_url, account_id

安全认证

使用 AgentCore Identity 两步流程:先获取 workload access token,再交换为 OAuth bearer token。


def get_bearer_token(account_id=None):

 # ...(完整代码逻辑,通过 CREDENTIAL_PROVIDER_XX 获取 token,避免存储密钥)

 pass

查询 MCP 服务器

Lambda 先调用 initialize(设置协议版本等),获取 session_id,再执行 tools/list 获取工具数组。


def call_tools_list(mcp_url, token):

 # 初始化会话...

 init_payload = { ... }

 # tools/list...

 return _parse_sse_json(list_resp.text)

匹配与更新

Lambda 查询 Registry 记录(通过 ARN 匹配),若 Schema 变更则更新(记录状态 revert 至 DRAFT)。

优势与适用场景

此工具链显著提升 AWS Agent Registry 鲜活性,减少 stale metadata 导致的 Cursor 调用失败。企业团队可将其绑定到 Cursor Pro 或 Business 订阅中,实现自动工具发现。

与手动维护相比,事件驱动方式支持动态扩展至数百个 MCP 服务器。

延伸阅读

风险与边界

此方案依赖 AWS 管理服务,可能产生 Lambda 执行、EventBridge 事件及 Registry 存储费用。跨账号模式需额外 IAM 权限设置,初期可能涉及 5–15 分钟延迟。AgentCore Identity 配置错误可能导致认证失败。非法律意见声明:本文内容基于 AWS 2026-11-11 公开博客及官方示例,仅供参考,不构成任何法律或技术保证。请根据实际环境及最新 AWS 文档验证,开发者需自行承担所有配置风险与潜在服务成本。

English summary

This post demonstrates an event-driven pipeline using AWS CloudTrail, EventBridge, Lambda, and AgentCore Identity to keep the AWS Agent Registry current automatically. The architecture captures runtime updates via UpdateAgentRuntime API calls and syncs tool schemas to the central registry, preventing stale metadata that breaks Cursor or other IDE integrations. It supports both single-account and multi-account setups, with secure OAuth token exchange via AgentCore Identity. Engineers managing MCP servers across accounts can deploy it to ensure Cursor always receives the latest tool list without manual intervention. The sample code is available in the official AWS repo for immediate testing. Limitations include no automatic new record creation and a 5-15 minute event delivery delay, but it significantly improves registry freshness for enterprise AI agent workflows.