A2A代理服务

一个用于调用MCP Hello Server的A2A(Agent-to-Agent)代理服务,支持单人或多人问候功能。

  • by metabuildwe
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 metabuildwe/a2a-mcp-hello-py

使用说明

A2A MCP Hello Agent

调用MCP Hello Server的Agent-to-Agent(A2A)代理。

结构

a2a-mcp-hello-py/
├── src/
│   ├── __init__.py         # 패키지 초기화
│   ├── mcp_client.py       # MCP 클라이언트 (MCP 서버 호출)
│   ├── agent.py            # 에이전트 로직
│   ├── agent_executor.py   # A2A Agent Executor
│   └── server.py           # A2A 서버 메인
├── .env                    # 환경 변수 설정
├── .env.example            # 환경 변수 예시
├── requirements.txt        # 의존성
├── pyproject.toml          # 프로젝트 메타데이터
└── README.md               # 이 파일

安装

# 가상 환경 생성
python3 -m venv venv
source venv/bin/activate

# 의존성 설치
pip install -r requirements.txt

设置环境变量

.env 创建或修改文件:

# .env 파일 내용
MCP_SERVER_URL=https://mcp-hello-py-666155174404.asia-northeast3.run.app/mcp
HOST=0.0.0.0
PORT=9999

执行

python src/server.py

# 또는
python3 src/server.py

A2A代理卡

运行服务器后验证Agent卡:

curl http://localhost:9999/.well-known/agent.json

测试(Postman)

Headers设置(所有请求都必需)

标题 值
Content-Type application/json
Accept application/json, text/event-stream

1.验证Agent卡

  • 方法: GET
  • 统一资源定位符: http://localhost:9999/.well-known/agent.json

2.发送消息

  • 方法: POST
  • 统一资源定位符: http://localhost:9999/
  • 身体 (原始JSON):
{
  "jsonrpc": "2.0",
  "id": "1",
  "method": "message/send",
  "params": {
    "message": {
      "role": "user",
      "parts": [{"kind": "text", "text": "김철수에게 인사해줘"}],
      "messageId": "msg-001"
    }
  }
}

3.向大家问好

{
  "jsonrpc": "2.0",
  "id": "2",
  "method": "message/send",
  "params": {
    "message": {
      "role": "user",
      "parts": [{"kind": "text", "text": "김철수, 이영희, 박민수에게 인사해줘"}],
      "messageId": "msg-002"
    }
  }
}

部署Cloud Run时

只更改URL进行相同的测试:

  • https://a2a-mcp-hello-py-xxxxxx.asia-northeast3.run.app/

体系结构

┌─────────────┐       ┌─────────────────┐       ┌─────────────────┐
│  A2A Client │ ───▶  │  A2A MCP Hello  │ ───▶  │  MCP Hello      │
│  (Inspector)│       │  Agent (Python) │       │  Server (Cloud  │
│             │ ◀───  │                 │ ◀───  │  Run)           │
└─────────────┘       └─────────────────┘       └─────────────────┘
     A2A                    HTTP                     MCP
   Protocol                                       Protocol

主要功能

  • 你好:向一个人问好
  • 说你好:向大家问好

参考