This project serves as a reference implementation of the Model Context Protocol (MCP), enabling seamless tool calling between Large Language Models (LLMs) and applications. It features a client/server architecture with HTTP APIs, local CLI execution, and integration with AWS Bedrock and Claude 3.7.
The project was developed with the assistance of Claude 3.7, Anthropic's advanced AI assistant. The llm/
directory contains design specifications, implementation plans, and technical decisions, providing insight into the AI-assisted development process.
mcp-example/
├── core/ # Core protocol implementation
│ ├── schema.py # Protocol schema definitions
│ ├── validation.py # Schema validation utilities
│ ├── registry.py # Tool registry
│ └── executor.py # Tool executor
├── tools/ # Tool implementations
│ ├── calculator.py # Calculator tool
│ └── text.py # Text processing tool
├── adapters/ # Interface adapters
│ ├── stdio/ # Command-line interface
│ └── http/ # HTTP client for remote servers
├── server/ # Server implementation
│ ├── app.py # FastAPI server
│ └── main.py # Server runner
├── examples/ # Usage examples
├── tests/ # Test suite
└── llm/ # Implementation documentation
bash
git clone https://github.com/yourusername/mcp-example.git
cd mcp-example
bash
poetry install
bash
python3 -m venv venv
source venv/bin/activate # On Windows, use: venv\Scripts\activate
pip install -e .
# With Poetry
poetry run python -m mcp_example.adapters.stdio.cli
# With venv
python -m mcp_example.adapters.stdio.cli
# With Poetry
poetry run python -m mcp_example.server.main --host 0.0.0.0 --port 8000
# With venv
python -m mcp_example.server.main --host 0.0.0.0 --port 8000
bash
curl -X GET http://localhost:8000/api/functions -H "X-API-Key: test-key"
bash
curl -X POST http://localhost:8000/api/functions/call \
-H "X-API-Key: test-key" \
-H "Content-Type: application/json" \
-d '{"name": "calculator", "parameters": {"operation": "add", "a": 5, "b": 3}}'
GET /api/functions
: List all available functionsPOST /api/functions/call
: Call a functionWebSocket /api/functions/stream
: Stream function resultsfrom mcp_example.adapters.http.client import MCPClient
client = MCPClient(base_url="http://localhost:8000", api_key="test-key")
functions = client.list_functions()
response = client.call_function(name="calculator", parameters={"operation": "add", "a": 5, "b": 3})
print(f"Result: {response.result}")
import asyncio
from mcp_example.adapters.http.client import AsyncMCPClient
async def main():
client = AsyncMCPClient("http://localhost:8000", api_key="test-key")
async for chunk in client.stream_function(name="long_running_operation", parameters={"duration": 5}):
print(f"Progress: {chunk.result}")
await client.close()
asyncio.run(main())
bash
export AWS_ACCESS_KEY_ID="your-access-key"
export AWS_SECRET_ACCESS_KEY="your-secret-key"
export AWS_DEFAULT_REGION="us-west-2"
from mcp_example.adapters.aws.claude import ClaudeAdapter, ClaudeMessage, ClaudeRole
from mcp_example.core.schema import FunctionDefinition
adapter = ClaudeAdapter()
messages = [ClaudeMessage(role=ClaudeRole.USER, content="What's 42 + 7?")]
calculator_function = FunctionDefinition(name="calculator", description="Performs arithmetic operations", parameters={"type": "object", "properties": {"operation": {"type": "string", "enum": ["add", "subtract", "multiply", "divide"], "description": "The operation to perform"}, "a": {"type": "number", "description": "First operand"}, "b": {"type": "number", "description": "Second operand"}}, "required": ["operation", "a", "b"]})
response = adapter.generate(messages, functions=[calculator_function])
function_calls = adapter.extract_function_calls(response)
for call in function_calls:
print(f"Function: {call.name}, Parameters: {call.parameters}")
from mcp_example.core.executor import execute
from mcp_example.tools.proxy import register
register()
result = execute({"name": "proxy", "parameters": {"server_url": "http://remote-server.com", "api_key": "remote-server-key", "function_name": "calculator", "parameters": {"operation": "add", "a": 5, "b": 3}}})
print(f"Result from remote server: {result}")
from mcp_example.core.executor import execute
calc_result = execute({"name": "calculator", "parameters": {"operation": "add", "a": 5, "b": 3}})
text_result = execute({"name": "transform_text", "parameters": {"operation": "append", "text": "The result is: ", "append_text": str(calc_result)}})
print(text_result) # Output: "The result is: 8"
Performs basic arithmetic operations: add, subtract, multiply, divide, power, sqrt, log.
Provides text transformation and analysis: uppercase, lowercase, capitalize, title, reverse, count_chars, count_words, trim, replace.
This project is licensed under the MIT License - see the LICENSE file for details.
A reference implementation of the Model Context Protocol (MCP) enabling seamless tool calling between LLMs and applications. Features client/server architecture with HTTP APIs, local CLI execution, and AWS Bedrock integration in a production-ready, extensible framework.