The MCP2ANP Bridge Server enables MCP clients to access ANP (Agent Network Protocol) agents as local tools through protocol conversion. It bridges ANP's crawler-style interaction paradigm into MCP tool-based interactions, allowing MCP clients like Claude Desktop and IDEs to interact with ANP agents without modification.
Core Capabilities:
DID Authentication: Configure and manage local DID documents and private keys for secure authentication with ANP services
Fetch ANP Documents: Retrieve and parse ANP documents from URLs (the sole entry point to the ANP ecosystem), extracting content, type information, and discoverable links
Invoke OpenRPC Methods: Execute JSON-RPC 2.0 methods on OpenRPC endpoints exposed by ANP agents for structured remote procedure calls
Key Features:
Operates entirely locally without requiring remote servers
Supports complete multi-step workflows like hotel booking, travel planning, and agent discovery
Provides three core tools:
anp.setAuth
,anp.fetchDoc
, andanp.invokeOpenRPC
Provides local DID (Decentralized Identifier) authentication management using local DID documents and private keys for secure ANP agent interactions.
MCP2ANP
MCP to ANP Bridge Server - 让任何支持 MCP 的应用,像"本地工具"一样访问 ANP 智能体
概述
MCP2ANP 是一个 MCP 桥接服务器,将 ANP (Agent Network Protocol) 的"爬虫式"交互范式转换为 MCP (Model Control Protocol) 工具,使 Claude Desktop、Cursor、各类 IDE 等 MCP 客户端无需改造即可访问 ANP 智能体。
核心特性
🔧 两个核心工具:
anp.fetchDoc
、anp.invokeOpenRPC
🔐 DID 认证支持: 本地 DID 文档和私钥管理
🌐 协议适配: ANP 爬虫式交互 ↔ MCP 工具式交互
🚀 双模式支持: 本地 stdio 模式 + 远程 HTTP API 模式
📊 结构化日志: 完整的操作追踪和调试信息
🧪 全面测试: 单元测试和集成测试覆盖
运行模式
本地模式(stdio): 通过标准输入输出与 MCP 客户端通信,适用于 Claude Desktop 等桌面应用
远程模式(HTTP): 通过 FastAPI 提供 HTTP API,支持远程调用,使用 API Key 进行鉴权
详见 远程服务器文档
架构设计
快速开始
安装
启动服务器
本地模式(stdio):
远程模式(HTTP API):
详细的远程模式使用方法请参见 远程服务器文档
运行官方 Demo(推荐)
项目提供了基于 MCP 官方 SDK 的完整客户端演示脚本,能够从启动服务器到调用所有工具一次跑通。推荐使用下列命令直接体验:
该脚本会通过 stdio 启动
mcp2anp.server
,依次演示anp.setAuth
、anp.fetchDoc
与anp.invokeOpenRPC
。如需与真实 ANP 服务联调,请确保本地或远程 JSON-RPC 端点可达。
Claude code中添加此mcp server
助于:下面的路径需要更改为你自己路径
在mcp2anp目录安装
在其他目录安装
基本使用
设置认证(可选):
{ "didDocumentPath": "docs/did_public/public-did-doc.json", "didPrivateKeyPath": "docs/did_public/public-private-key.pem" }注:如果不调用setAuth,系统会自动使用docs/did_public/中的公共DID凭证
获取 ANP 文档:
{ "url": "https://agent-connect.ai/agents/travel/mcp/agents/amap/ad.json" }调用 OpenRPC 方法:
{ "endpoint": "https://example.com/rpc", "method": "searchLocations", "params": { "query": "北京天安门", "city": "北京" } }
工具说明
注意:
anp.setAuth
工具已移除。系统现在自动使用环境变量或默认的公共 DID 凭证进行认证。
anp.fetchDoc
获取并解析 ANP 文档,提取可跟进的链接。这是访问 ANP 生态中 URL 的唯一入口。
输入:
url
: 要获取的 ANP 文档 URL
输出:
contentType
: 内容类型text
: 原始文本内容json
: 解析的 JSON 内容(如适用)links
: 可跟进的链接列表
anp.invokeOpenRPC
调用 OpenRPC 端点的 JSON-RPC 2.0 方法。
输入:
endpoint
: OpenRPC 端点 URLmethod
: 要调用的方法名params
: 方法参数(可选)id
: 请求 ID(可选)
输出:
result
: 方法返回结果raw
: 原始 JSON-RPC 响应
项目结构
开发
环境准备
运行测试
代码质量
使用示例
官方 MCP 客户端 Demo(examples/mcp_client_demo.py
)
examples/mcp_client_demo.py
通过 MCP 官方 SDK 的 stdio_client
启动 mcp2anp.server
并串联所有工具,是最快速了解桥接工作方式的脚本:
脚本会自动:
列出
mcp2anp
暴露的工具使用
docs/did_public/
内的公共凭证调用anp.setAuth
访问
anp.fetchDoc
并展示返回的链接调用
anp.invokeOpenRPC
的echo
和getStatus
方法验证回路
如需与真实环境交互,可将脚本中的测试 URL 替换为目标 ANP 服务地址。
完整的酒店预订工作流
配置
环境变量
ANP_LOG_LEVEL
: 日志级别 (DEBUG, INFO, WARNING, ERROR)ANP_TIMEOUT
: HTTP 请求超时时间(秒)ANP_MAX_RETRIES
: 最大重试次数
命令行选项
--log-level
: 设置日志级别--reload
: 启用热重载(开发模式)
安全注意事项
⚠️ DID 私钥保护: 不要将私钥文件提交到版本控制
🔒 本地运行: 服务器仅在本地运行,不暴露到网络
🛡️ 输入验证: 所有工具输入都经过 Pydantic 验证
📝 审计日志: 所有操作都有详细的结构化日志
贡献
Fork 本仓库
创建功能分支 (
git checkout -b feature/amazing-feature
)提交更改 (
git commit -m 'Add amazing feature'
)推送到分支 (
git push origin feature/amazing-feature
)打开 Pull Request
提交规范
使用 Google Python 编码规范
确保所有测试通过:
uv run pytest
运行代码检查:
uv run ruff mcp2anp/ tests/
保持 ≥90% 测试覆盖率
许可证
本项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情。
相关项目
Agent Connect - ANP 协议实现
MCP SDK - MCP Python SDK
支持
local-only server
The server can only run on the client's local machine because it depends on local resources.
Enables MCP clients like Claude Desktop to interact with ANP (Agent Network Protocol) agents through three core tools: authentication setup, document fetching, and OpenRPC method invocation. Converts ANP's crawler-style interaction paradigm into MCP-compatible tools for seamless agent communication.