# MCP Gateway POC - Project Summary
## Overview
This POC demonstrates a **Model Context Protocol (MCP) Gateway** for Amazon Bedrock AgentCore that enables deployment and management of MCP servers. The gateway method wraps existing Lambda functions or REST APIs as MCP tools, handling protocol translation automatically.
## Architecture
```
┌──────────────────────┐
│ Bedrock AgentCore │
└──────────┬───────────┘
│
│ MCP Protocol (JSON-RPC)
▼
┌──────────────────────┐
│ API Gateway │
│ (AWS) │
└──────────┬───────────┘
│
▼
┌──────────────────────┐
│ MCP Gateway Lambda │
│ - Protocol Handler │
│ - Tool Registry │
│ - Translation Layer │
└──────────┬───────────┘
│
┌──────┴──────┐
▼ ▼
┌─────────┐ ┌──────────┐
│ Lambda │ │ REST │
│Functions│ │ APIs │
└─────────┘ └──────────┘
```
## Components
### 1. Gateway Module (`gateway/`)
- **gateway.py**: Main gateway implementation with tool registry
- **protocol.py**: MCP protocol translation and message handling
- **lambda_handler.py**: AWS Lambda handler for API Gateway integration
### 2. Server Module (`server/`)
- **mcp_server.py**: Direct MCP server using FastMCP framework
### 3. Tools Module (`tools/`)
- **lambda_functions/**: Example Lambda functions
- `weather_tool.py`: Weather lookup
- `calculator_tool.py`: Mathematical operations
- `data_lookup_tool.py`: Data retrieval
- **rest_apis/**: Example REST API server
- `rest_server.py`: FastAPI server with example endpoints
### 4. Infrastructure (`infrastructure/`)
- **template.yaml**: AWS SAM template for deployment
- **README.md**: Deployment instructions
### 5. Scripts (`scripts/`)
- **register_tools.py**: Tool registration utility
### 6. Examples (`examples/`)
- **example_usage.py**: Usage examples and demonstrations
## Key Features
✅ **Protocol Translation**: Automatic translation between MCP and Lambda/REST
✅ **Tool Registry**: Dynamic tool registration and management
✅ **Multiple Backends**: Support for both Lambda and REST APIs
✅ **Error Handling**: Comprehensive error handling and logging
✅ **AWS Integration**: Ready for AWS deployment
✅ **Example Tools**: Pre-built example tools for testing
## File Structure
```
mcp_1/
├── gateway/ # MCP Gateway implementation
│ ├── __init__.py
│ ├── gateway.py # Main gateway class
│ ├── protocol.py # Protocol handler
│ └── lambda_handler.py # AWS Lambda handler
├── server/ # Direct MCP server
│ ├── __init__.py
│ └── mcp_server.py # FastMCP server
├── tools/ # Example tools
│ ├── lambda_functions/ # Lambda function examples
│ └── rest_apis/ # REST API examples
├── infrastructure/ # AWS deployment
│ ├── template.yaml # SAM template
│ └── README.md
├── scripts/ # Utility scripts
│ └── register_tools.py
├── examples/ # Usage examples
│ └── example_usage.py
├── test_gateway.py # Test script
├── requirements.txt # Python dependencies
├── config.example.json # Configuration example
├── README.md # Main documentation
├── QUICKSTART.md # Quick start guide
├── DEPLOYMENT.md # Deployment guide
└── PROJECT_SUMMARY.md # This file
```
## Usage Flow
1. **Deploy Infrastructure**: Deploy Lambda functions and API Gateway
2. **Register Tools**: Register Lambda functions/REST APIs as MCP tools
3. **Connect AgentCore**: Configure Bedrock AgentCore to use MCP Gateway
4. **Use Tools**: AgentCore can now call tools via MCP protocol
## MCP Protocol Support
The gateway implements:
- `initialize`: Server initialization
- `tools/list`: List available tools
- `tools/call`: Execute a tool
## Example Tool Registration
```python
# Register Lambda function
gateway.register_lambda_tool(
name="weather_lookup",
lambda_arn="arn:aws:lambda:...",
description="Get weather information",
input_schema={...}
)
# Register REST API
gateway.register_rest_tool(
name="stock_price",
endpoint="https://api.example.com/stock",
description="Get stock price",
input_schema={...}
)
```
## Testing
- **Local Testing**: `python test_gateway.py`
- **Example Usage**: `python examples/example_usage.py`
- **REST API**: `python -m tools.rest_apis.rest_server`
- **SAM Local**: `sam local start-api`
## Deployment
1. Build: `sam build`
2. Deploy: `sam deploy --guided`
3. Register: `python scripts/register_tools.py`
## Next Steps
1. **Production Hardening**:
- Add authentication (OAuth/IAM)
- Implement rate limiting
- Add monitoring and alerting
- Persist tool registry (DynamoDB)
2. **Enhanced Features**:
- Tool versioning
- Tool discovery
- Batch tool execution
- Streaming responses
3. **Integration**:
- Connect to Bedrock AgentCore
- Add more example tools
- Create CI/CD pipeline
## Dependencies
- **mcp**: MCP framework
- **boto3**: AWS SDK
- **fastapi**: REST API framework
- **httpx**: HTTP client
- **pydantic**: Data validation
## License
MIT
## Author
AWS Architect - GAAB POC