AI Practices AI实践 8h ago Updated 2h ago 更新于 2小时前 46

How we built an MCP bridge to give our AgentCore-hosted AI agent access to local MCP tools 我们如何构建 MCP 桥接,让 AgentCore 托管的 AI 智能体访问本地 MCP 工具

Anthropic's MCP protocol lacks a transport mechanism for remote clients connecting to local servers, creating a gap for cloud-hosted agents needing local tool access AWS built an MCP bridge using WebSocket tunneling and native messaging to connect cloud-hosted Strands agents on AgentCore with local MCP servers The architecture uses four components: AgentCore runtime (cloud), browser extension (bidirectional relay), MCP Bridge (FastMCP proxy on local machine), and local MCP server Authentication 提出MCP桥接方案解决云端Agent调用本地MCP工具的连接问题,填补MCP协议在远程客户端-本地服务器场景的空白 采用WebSocket+原生消息传递的双层隧道架构,通过浏览器扩展作为双向中继实现消息格式转换 基于Amazon Bedrock AgentCore和Strands Agent构建生产级AI助手,一年内已支持超过41,000次对话 工具发现机制支持动态注册,MCP服务器新增工具后Agent无需代码修改即可自动识别 安全设计确保用户凭证不离开本地机器,通过预签名WebSocket URL实现5分钟有效期的临时授权

62
Hot 热度
70
Quality 质量
65
Impact 影响力

Analysis 深度分析

TL;DR

  • Anthropic's MCP protocol lacks a transport mechanism for remote clients connecting to local servers, creating a gap for cloud-hosted agents needing local tool access
  • AWS built an MCP bridge using WebSocket tunneling and native messaging to connect cloud-hosted Strands agents on AgentCore with local MCP servers
  • The architecture uses four components: AgentCore runtime (cloud), browser extension (bidirectional relay), MCP Bridge (FastMCP proxy on local machine), and local MCP server
  • Authentication uses presigned WebSocket URLs generated locally with AWS credentials, ensuring no credentials leave the user's machine
  • The solution enables financial analysts to use centrally deployed AI agents that can directly read and act on local Excel files and browser context

Why It Matters

This architecture solves a critical gap in the MCP ecosystem where cloud-hosted AI agents cannot natively access local tools and data, which is essential for enterprise workflows involving local files like spreadsheets. It demonstrates a production-grade pattern (41,000+ conversations) that other organizations can replicate for secure, self-hosted AI agent deployments on AWS.

Technical Details

  • MCP Bridge Architecture: Uses a FastMCP proxy running locally that translates between native messaging envelope format and raw MCP JSON-RPC, with stdio transport for local server communication
  • Message Flow: Three-layer wrapping/unwrapping—AgentCore sends JSON envelope over WebSocket to browser extension, which relays via native messaging to the bridge, which unwraps and forwards JSON-RPC to the MCP server over stdio
  • WebSocket Authentication: Presigned SigV4-signed WebSocket URLs generated locally using the user's AWS credentials and the bedrock-agentcore SDK, scoped to the deployed runtime ARN with 5-minute validity and automatic reconnection
  • Strands Agent Integration: Agent performs standard MCP initialization handshake (initialize request → capabilities response → notifications/initialized), then calls tools/list on each user message and wraps schemas into Strands AgentTool objects with stream() methods
  • Request-Response Correlation: Each JSON-RPC request gets a unique ID registered against an asyncio.Future keyed by (session_id, jsonrpc_id) for proper response matching

Industry Insight

  • The MCP protocol's current transport limitations (stdio and streamable HTTP only) create a market opportunity for bridge solutions enabling hybrid cloud-local AI agent deployments
  • Enterprises should consider self-hosted patterns on AWS Bedrock AgentCore for sensitive workflows, keeping credentials local while leveraging cloud compute for AI processing
  • The presigned URL authentication pattern demonstrated here provides a secure template for other cloud-to-local communication scenarios without exposing credentials to browsers or networks

TL;DR

  • 提出MCP桥接方案解决云端Agent调用本地MCP工具的连接问题,填补MCP协议在远程客户端-本地服务器场景的空白
  • 采用WebSocket+原生消息传递的双层隧道架构,通过浏览器扩展作为双向中继实现消息格式转换
  • 基于Amazon Bedrock AgentCore和Strands Agent构建生产级AI助手,一年内已支持超过41,000次对话
  • 工具发现机制支持动态注册,MCP服务器新增工具后Agent无需代码修改即可自动识别
  • 安全设计确保用户凭证不离开本地机器,通过预签名WebSocket URL实现5分钟有效期的临时授权

为什么值得看

本文提供了云端AI Agent与本地工具集成的完整技术方案,对需要访问用户本地数据(如Excel、数据库)的企业级AI应用具有重要参考价值。其桥接架构和安全设计为MCP协议在远程场景的落地提供了可复用的工程实践。

技术解析

  • MCP协议架构:MCP采用客户端-服务器架构,支持stdio(本地进程通信)和streamable HTTP(远程通信)两种传输机制,但缺少远程客户端连接本地服务器的标准方案。本文通过隧道技术填补这一空白。
  • 四组件架构:系统由AgentCore运行时(云端托管Strands Agent作为MCP客户端)、浏览器扩展(聊天界面+双向中继)、MCP Bridge(本地FastMCP代理,负责消息格式转换)和MCP服务器(本地运行,通过stdio通信)组成。
  • 消息传递流程:Agent发送的JSON-RPC请求经WebSocket传递到浏览器扩展,扩展通过原生消息传递转发给MCP Bridge,Bridge解包后通过stdio发送给本地MCP服务器,响应沿原路径返回。每跳剥离一层包装。
  • WebSocket连接与安全:浏览器扩展通过预签名URL建立WebSocket连接,使用用户本地AWS凭证和bedrock-agentcore SDK生成SigV4签名的wss:// URL(有效期5分钟)。凭证永不离开用户机器,断连后自动重新请求签名URL并重连。
  • 工具发现与请求关联:Agent每次消息时调用tools/list获取工具列表,包装为Strands AgentTool。每个JSON-RPC请求分配唯一ID,通过asyncio.Future以(session_id, jsonrpc_id)为键进行请求-响应关联。

行业启示

  • 云端Agent+本地工具的混合架构将成为企业AI应用的重要趋势,特别是在金融、数据分析等需要访问本地文件的场景,该方案提供了可落地的技术路径。
  • MCP协议的标准化推动了AI工具生态发展,但远程调用场景仍需额外的桥接层解决传输协议差异,开发者需关注协议演进与适配方案。
  • 安全设计方面,凭证不出本地、预签名URL临时授权等机制为云端Agent访问本地资源提供了可借鉴的安全实践,平衡了功能与安全风险。

Disclaimer: The above content is generated by AI and is for reference only. 免责声明:以上内容由 AI 生成,仅供参考。

Agent Agent Open Source 开源 LLM 大模型 Deployment 部署