This project demonstrates how the Model Context Protocol (MCP) enables communication between different AI agents. It provides a step-by-step example of how agents can work together using MCP.
Model Context Protocol (MCP) is a standardized protocol that allows AI agents to:
- ๐ง Share tools - Agents can expose functionality for others to use
- ๐ Share resources - Agents can provide access to data and files
- ๐ค Communicate seamlessly - Standardized message format for interoperability
- ๐ Work together - Multiple agents can collaborate on complex tasks
โโโ mcp_server.py # MCP Server Agent (provides tools & resources)
โโโ mcp_client.py # MCP Client Agent (uses tools & resources)
โโโ mcp_orchestrator.py # Multi-agent orchestrator
โโโ run_demo.py # Simple demo runner
โโโ README.md # This file
๐ท Server Agent starts up
๐ท Client Agent starts up
๐ท Orchestrator registers both agents
๐ Client asks Server: "What tools do you have?"
๐ Client asks Server: "What resources can you provide?"
โ
Server responds with available capabilities
๐ Client connects to Server
โ
Connection established - agents can now communicate
๐ง Client: "Please use your calculator tool to add 10 + 5"
โ๏ธ Server: Executes calculator tool
๐ค Server: Returns result "15"
๐ Client: "Please give me the user data resource"
๐ Server: Reads and returns user data
๐ค Server: Sends data back to client
Here's what happens when agents communicate:
CLIENT SERVER
| |
| {"method": "tools/list"} |
|------------------------>|
| |
| {"tools": [...]} |
|<------------------------|
| |
| {"method": "tools/call", |
| "params": {...}} |
|------------------------>|
| |
| {"content": [...]} |
|<------------------------|
- Purpose: Perform basic math operations
- Operations: add, subtract, multiply, divide
- Example:
{"operation": "add", "a": 10, "b": 5}
- Purpose: Process text strings
- Operations: uppercase, lowercase, reverse
- Example:
{"text": "hello", "operation": "uppercase"}
- URI:
data/users.json - Content: Sample user data with names and roles
- Access: Any connected client can read this resource
# Run just the server demo
python mcp_server.py
# Run client connecting to server
python mcp_client.py
# Run full multi-agent orchestrator
python mcp_orchestrator.pypython run_demo.py- Client connects to server
- Client uses calculator and text processing tools
- Client reads user data resource
- Multiple specialized servers (math-only, text-only)
- Multiple clients working on shared task
- Coordinated workflow across agents
- Resource sharing between multiple clients
The demo simulates a business scenario:
- Client 1 formats document titles using text processing
- Client 2 calculates sales metrics using math tools
- Both clients access shared user database
- Coordinated result - complete sales report
# Server exposes tools
server.tools = {"calculator": {...}, "text_processor": {...}}
# Client discovers and uses tools
tools = await client.list_tools()
result = await client.use_tool("calculator", {"operation": "add", "a": 5, "b": 3})# Server provides resources
server.resources = {"data/users.json": {...}}
# Client accesses resources
data = await client.read_resource("data/users.json")# Orchestrator manages multiple agents
orchestrator.register_agent("client1", client1)
orchestrator.register_agent("server1", server1)
orchestrator.connect_agents("client1", "server1")After running this demo, you'll understand:
โ
How MCP enables agent-to-agent communication
โ
The request/response pattern in MCP
โ
How agents discover each other's capabilities
โ
How multiple agents can work together on complex tasks
โ
The difference between tools and resources in MCP
โ
How to orchestrate multi-agent workflows
tools/list- Discover available toolstools/call- Execute a tool with parametersresources/list- Discover available resourcesresources/read- Read a specific resource
- Server Agents - Provide tools and resources
- Client Agents - Use tools and resources from servers
- Orchestrator - Manages and coordinates multiple agents
- Synchronous - Request-response pairs
- Asynchronous - Non-blocking operations
- Structured - JSON-based message format
- Typed - Schema validation for tool parameters
To extend this demo:
- Add more specialized tools (file operations, API calls, etc.)
- Implement authentication and security
- Add real network communication (TCP/HTTP)
- Create more complex multi-agent workflows
- Add error handling and retry mechanisms
This demo provides a foundation for understanding MCP and building more sophisticated multi-agent systems.