Content
# A2A-to-MCP Translator Agent (MCPGatewayAgent)
This project (`@Adapter`) implements an A2A (Agent-to-Agent) proxy, serving as a universal gateway connecting the A2A protocol and MCP (Model Context Protocol) services.
For detailed design, please refer to [DESIGN.md](DESIGN.md).
## Features
- Receives tasks sent via the A2A protocol that are intended to invoke downstream MCP services.
- Parses the MCP service target (URL) and MCP operation instructions (method name, parameters) specified in the task.
- Sends requests to the target MCP service that comply with the MCP JSON-RPC specification (typically via HTTP POST).
- Receives responses from the MCP service.
- Converts the MCP response (success or error) back to the A2A `TaskResult` format and returns it to the caller.
## Environment Setup
1. **Conda Environment**: It is recommended to create and activate a virtual environment with Python >= 3.12 using Conda (e.g., `adapter_env`).
```bash
conda create --name adapter_env python=3.12 -y
conda activate adapter_env
```
2. **Install Dependencies**: Refer to the `pyproject.toml` file. Core dependencies include `httpx`, `pydantic`, `uvicorn`, `starlette`, etc. Development dependencies include `pytest`, `ruff`, `mypy`.
```bash
pip install -e .[dev] # (if the project is configured for editable installation and includes the dev dependency group)
# Alternatively, install core and development dependencies separately
```
3. **PYTHONPATH Setup**: To ensure this project can correctly import the local `@A2A/samples/python/common/` and `@python-sdk/src/mcp/` modules, you need to add the respective paths of these two projects to the `PYTHONPATH` environment variable. For specific methods, please refer to `DESIGN.md` or the development environment configuration instructions.
It is recommended to create a `.env` file in the root directory of this project and add the following content (please replace with your actual paths):
```env
PYTHONPATH=/path/to/A2A/samples/python:/path/to/python-sdk/src:${PYTHONPATH}
```
Then load this `.env` file in your IDE (such as VS Code) or before running scripts (e.g., using `python-dotenv`).
## Running the Agent
```bash
python src/translator/__main__.py --host <your_host> --port <your_port>
```
By default, you can run `python src/translator/__main__.py` (the host defaults to `localhost`, and the port defaults to `8000`, please refer to the configuration in `__main__.py` for details).
## Running Examples
Please refer to the instructions in `examples/README.md` to run end-to-end examples, including a sample MCP service and an A2A client that calls this Agent.
## Development
- **Code Style and Checks**: Use Ruff for linting and formatting. Configuration can be found in `pyproject.toml`.
- **Type Checking**: Use MyPy. Configuration can be found in `pyproject.toml`.
- **Testing**: Use Pytest. Test files are located in the `tests/` directory.
```bash
pytest
```