Skip to main content

A bridge server that connects Model Context Protocol (MCP) with Agent-to-Agent (A2A) protocol

Project description

A2A MCP Server

License

A middleware server that bridges the Model Context Protocol (MCP) with the Agent-to-Agent (A2A) protocol, enabling MCP-compatible AI assistants (like Claude) to seamlessly interact with A2A agents.

Overview

This project serves as an integration layer between two cutting-edge AI agent protocols:

  • Model Context Protocol (MCP): Developed by Anthropic, MCP allows AI assistants to connect to external tools and data sources. It standardizes how AI applications and large language models connect to external resources in a secure, composable way.

  • Agent-to-Agent Protocol (A2A): Developed by Google, A2A enables communication and interoperability between different AI agents through a standardized JSON-RPC interface.

By bridging these protocols, this server allows MCP clients (like Claude) to discover, register, communicate with, and manage tasks on A2A agents through a unified interface.

Features

  • Agent Management

    • Register A2A agents with the bridge server
    • List all registered agents
    • Unregister agents when no longer needed
  • Communication

    • Send messages to A2A agents and receive responses
    • Stream responses from A2A agents in real-time
  • Task Management

    • Track which A2A agent handles which task
    • Retrieve task results using task IDs
    • Cancel running tasks
  • Transport Support

    • Multiple transport types: stdio, streamable-http, SSE
    • Configure transport type using MCP_TRANSPORT environment variable

Installation

Prerequisites

  • Python 3.11+
  • FastMCP library (2.3.4+)
  • A2A client library

Setup

  1. Clone the repository:

    git clone https://github.com/yourusername/a2a-mcp-server.git
    cd a2a-mcp-server
    
  2. Set up a virtual environment:

    python -m venv .venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
    
  3. Install dependencies:

    pip install -r requirements.txt
    
  4. Configure environment variables (optional):

    export MCP_HOST="0.0.0.0"  # Host for the MCP server
    export MCP_PORT="8000"     # Port for the MCP server
    export MCP_TRANSPORT="streamable-http"  # Transport type: stdio, streamable-http, or sse
    
  5. Run the server:

    python a2a_mcp_server.py
    

Available MCP Tools

The server exposes the following MCP tools for integration with LLMs like Claude:

Agent Management

  • register_agent: Register an A2A agent with the bridge server

    {
      "name": "register_agent",
      "arguments": {
        "url": "http://localhost:41242"
      }
    }
    
  • list_agents: Get a list of all registered agents

    {
      "name": "list_agents",
      "arguments": {}
    }
    
  • unregister_agent: Remove an A2A agent from the bridge server

    {
      "name": "unregister_agent",
      "arguments": {
        "url": "http://localhost:41242"
      }
    }
    

Message Processing

  • send_message: Send a message to an agent and get a task_id for the response

    {
      "name": "send_message",
      "arguments": {
        "agent_url": "http://localhost:41242",
        "message": "What's the exchange rate from USD to EUR?",
        "session_id": "optional-session-id"
      }
    }
    
  • send_message_stream: Send a message and stream the response

    {
      "name": "send_message_stream",
      "arguments": {
        "agent_url": "http://localhost:41242",
        "message": "Tell me a story about AI agents.",
        "session_id": "optional-session-id"
      }
    }
    

Task Management

  • get_task_result: Retrieve a task's result using its ID

    {
      "name": "get_task_result",
      "arguments": {
        "task_id": "b30f3297-e7ab-4dd9-8ff1-877bd7cfb6b1",
        "history_length": null
      }
    }
    
  • cancel_task: Cancel a running task

    {
      "name": "cancel_task",
      "arguments": {
        "task_id": "b30f3297-e7ab-4dd9-8ff1-877bd7cfb6b1"
      }
    }
    

Usage Examples

Basic Workflow

1. Client registers an A2A agent
   ↓
2. Client sends a message to the agent (gets task_id)
   ↓
3. Client retrieves the task result using task_id

Example with Claude as the MCP Client

User: Register an agent at http://localhost:41242

Claude uses: register_agent(url="http://localhost:41242")
Claude: Successfully registered agent: ReimbursementAgent

User: Ask the agent what it can do

Claude uses: send_message(agent_url="http://localhost:41242", message="What can you do?")
Claude: I've sent your message. Here's the task_id: b30f3297-e7ab-4dd9-8ff1-877bd7cfb6b1

User: Get the answer to my question

Claude uses: get_task_result(task_id="b30f3297-e7ab-4dd9-8ff1-877bd7cfb6b1")
Claude: The agent replied: "I can help you process reimbursement requests. Just tell me what you need to be reimbursed for, including the date, amount, and purpose."

Architecture

The A2A MCP server consists of several key components:

  1. FastMCP Server: Exposes tools to MCP clients
  2. A2A Client: Communicates with registered A2A agents
  3. Task Manager: Handles task forwarding and management
  4. Agent Card Fetcher: Retrieves information about A2A agents

Communication Flow

MCP Client → FastMCP Server → A2A Client → A2A Agent
                   ↑                ↓
                   └──── Response ──┘

Task ID Management

When sending a message to an A2A agent, the server:

  1. Generates a unique task_id
  2. Maps this ID to the agent's URL in the task_agent_mapping dictionary
  3. Returns the task_id to the MCP client
  4. Uses this mapping to route task retrieval and cancellation requests

Error Handling

The server provides detailed error messages for common issues:

  • Agent not registered
  • Task ID not found
  • Connection errors to agents
  • Parsing errors in responses

Troubleshooting

Agent Registration Issues

If an agent can't be registered:

  • Verify the agent URL is correct and accessible
  • Check if the agent has a proper agent card at /.well-known/agent.json

Message Delivery Problems

If messages aren't being delivered:

  • Ensure the agent is registered (use list_agents)
  • Verify the agent is running and accessible

Task Result Retrieval Issues

If you can't retrieve a task result:

  • Make sure you're using the correct task_id
  • Check if too much time has passed (some agents might discard old tasks)

Development

Adding New Tool Methods

To add new capabilities to the server, add methods decorated with @mcp.tool() in the a2a_mcp_server.py file.

Custom Task Manager

The server uses a custom A2AServerTaskManager class that extends InMemoryTaskManager. You can customize its behavior by modifying this class.

Project Structure

a2a-mcp-server/
├── a2a_mcp_server.py      # Main server implementation
├── common/                # A2A protocol code (from google/A2A)
│   ├── client/            # A2A client implementation
│   ├── server/            # A2A server implementation
│   ├── types.py           # Common type definitions
│   └── utils/             # Utility functions
├── .gitignore             # Git ignore file
├── pyproject.toml         # Project metadata and dependencies
├── README.md              # This file
└── requirements.txt       # Project dependencies

License

This project is licensed under the Apache License, Version 2.0 - see the LICENSE file for details.

The code in the common/ directory is from the Google A2A project and is also licensed under the Apache License, Version 2.0.

Acknowledgments

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

a2a_mcp_server-0.1.0.tar.gz (23.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

a2a_mcp_server-0.1.0-py3-none-any.whl (20.1 kB view details)

Uploaded Python 3

File details

Details for the file a2a_mcp_server-0.1.0.tar.gz.

File metadata

  • Download URL: a2a_mcp_server-0.1.0.tar.gz
  • Upload date:
  • Size: 23.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for a2a_mcp_server-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4fc70ff0228f0ef19844df6a14329b6f8a9d46c91dc0c98c082921f37218b6b0
MD5 2d34b712614019f37aa3e6d8cf0593f6
BLAKE2b-256 a10aaaf270d138d313d71236fdc904d9dc29f99d79c4645b4142f80baddd005b

See more details on using hashes here.

File details

Details for the file a2a_mcp_server-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: a2a_mcp_server-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 20.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for a2a_mcp_server-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 944f49b7f4d5fec0581a5e49413fae46f8fc143ce72c13754eeb296cd9183718
MD5 9f5c79812683cc897f239bc2fdebf680
BLAKE2b-256 b6dffad4eb08118e348d2b81ace3445c7545a6adb473369a636eda52f9441f01

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page