A lightweight, asynchronous Model Context Protocol (MCP) implementation in Python built with asyncio.
The Model Context Protocol (MCP) is an open protocol that enables AI assistants to connect with external data sources and tools. Think of it as a standardized way for AI models to interact with your applications, databases, APIs, and services.
📚 Learn more about MCP:
- https://modelcontextprotocol.io/docs/getting-started/intro
- https://en.wikipedia.org/wiki/Model_Context_Protocol
- 🚀 Asynchronous by design - Built on asyncio for high performance
- 🔧 Extensible tool system - Easily add custom tools and services
- 📡 Simple protocol - Clean JSON-based communication over TCP
- 🔌 Client & Server - Complete implementation of both sides
Start the server:
python main.py serverIn another terminal, run the client:
python main.py clientaiomcp/
├── protocol.py # Message types and serialization
├── tool_services.py # Abstract tool service classes
├── tool_manager.py # Tool registration and management
├── server.py # MCP server implementation
├── client.py # MCP client implementation
main.py # Entry point for examples
AioMCP comes with three example tools:
echo- Echo back input textadd- Add two numberssay_hello- Generate greeting messages
from aiomcp.tool_services import ToolService
class CustomToolService(ToolService):
async def execute(self, arguments: dict[str, Any]) -> Any:
# Your tool logic here
return "Result"from aiomcp.tool_manager import ToolManager
from aiomcp.protocol import Tool
tool_manager = ToolManager()
tool_manager.register_tool(
Tool(
name="custom_tool",
description="My custom tool",
parameters={
"type": "object",
"properties": {
"param1": {"type": "string", "description": "First parameter"}
},
"required": ["param1"]
}
),
CustomToolService()
)- 🤖 AI Assistant Integration - Connect LLMs to your tools
- 🔌 Plugin Systems - Dynamic tool discovery and execution
- 🏗 Microservices - Lightweight RPC between services
- 🧪 Testing - Mock external services in tests