Skip to main content
Glama
manifullstackdeveloper

Amazon Bedrock AgentCore MCP Gateway

README.md
# MCP Server POC for Amazon Bedrock AgentCore

This POC demonstrates deployment and management of Model Context Protocol (MCP) servers on Amazon Bedrock AgentCore using the Gateway method.

## Overview

The Model Context Protocol (MCP) provides a standardized interface for AI applications to access tools, resources, and enterprise data sources. This solution implements:

- **Gateway Method**: Wraps existing Lambda functions or REST APIs as MCP tools, handling protocol translation automatically
- **MCP Server**: Direct implementation using FastMCP framework

## Architecture

```
┌─────────────────┐
│  Bedrock        │
│  AgentCore      │
└────────┬────────┘
         │
         ▼
┌─────────────────┐
│  MCP Gateway     │  ← Protocol Translation
│  (Lambda)        │
└────────┬────────┘
         │
    ┌────┴────┐
    ▼         ▼
┌────────┐ ┌────────┐
│Lambda  │ │ REST   │
│Functions│ │ APIs   │
└────────┘ └────────┘
```

## Components

1. **MCP Gateway** (`gateway/`): Translates MCP protocol to Lambda/REST API calls
2. **MCP Server** (`server/`): Direct MCP server implementation using FastMCP
3. **Example Tools** (`tools/`): Sample Lambda functions and REST APIs
4. **Infrastructure** (`infrastructure/`): AWS SAM templates for deployment

## Prerequisites

- Python 3.11+
- AWS CLI configured
- AWS SAM CLI installed
- Docker (for local testing)

## Quick Start

### 1. Install Dependencies

```bash
pip install -r requirements.txt
```

### 2. Deploy Infrastructure

**Option A: Using AWS SAM (Recommended for beginners)**
```bash
cd infrastructure
sam build
sam deploy --guided
```

**Option B: Using Terraform**
```bash
cd terraform
cp terraform.tfvars.example terraform.tfvars
# Edit terraform.tfvars with your values
terraform init
terraform plan
terraform apply
```

See `TERRAFORM_QUICKSTART.md` for detailed Terraform deployment guide with Python dependencies layer configuration.

### 3. Test MCP Gateway

```bash
python test_gateway.py
```

## Project Structure

```
mcp_1/
├── gateway/              # MCP Gateway implementation
│   ├── __init__.py
│   ├── gateway.py       # Main gateway handler
│   └── protocol.py      # MCP protocol translation
├── server/               # Direct MCP server
│   ├── __init__.py
│   └── mcp_server.py    # FastMCP server
├── tools/                # Example tools
│   ├── lambda_functions/ # Lambda functions as MCP tools
│   └── rest_apis/        # REST API endpoints
├── infrastructure/       # AWS SAM deployment
│   ├── template.yaml     # SAM template
│   └── README.md         # SAM deployment guide
├── terraform/            # Terraform deployment
│   ├── main.tf           # Main Terraform configuration
│   ├── variables.tf     # Variable definitions
│   ├── outputs.tf        # Output values
│   ├── versions.tf       # Provider versions
│   ├── README.md         # Terraform deployment guide
│   └── Makefile          # Helper commands
├── TERRAFORM_QUICKSTART.md  # Quick Terraform deployment guide
├── QUICKSTART.md         # Local development quick start
├── tests/                # Test files
├── requirements.txt      # Python dependencies
└── README.md            # This file
```

## Gateway Method

The Gateway method automatically:
- Translates MCP tool calls to Lambda invocations
- Translates MCP tool calls to REST API requests
- Handles authentication and error handling
- Provides unified interface for multiple backends

## Example Usage

### Registering a Lambda Function as MCP Tool

```python
from gateway.gateway import MCPGateway

gateway = MCPGateway()
gateway.register_lambda_tool(
    name="weather_lookup",
    lambda_arn="arn:aws:lambda:us-east-1:123456789:function:WeatherFunction",
    description="Get weather information for a location"
)
```

### Registering a REST API as MCP Tool

```python
gateway.register_rest_tool(
    name="stock_price",
    endpoint="https://api.example.com/stock",
    method="GET",
    description="Get stock price information"
)
```

## Testing

Run the test suite:

```bash
pytest tests/
```

Test the gateway locally:

```bash
python -m gateway.gateway
```

## Deployment

- **Terraform**: See `TERRAFORM_QUICKSTART.md` for quick Terraform deployment (includes Python dependencies layer)
- **SAM**: See `DEPLOYMENT.md` for detailed SAM deployment instructions
- **Terraform Details**: See `terraform/README.md` for comprehensive Terraform guide

## License

MIT