This project automates the transition from legacy OpenAPI specs to the Model Context Protocol (MCP). Instead of manually writing tools, I built a system that generates them dynamically.
- Legacy System: A Mock
FastAPIbackend (simulating the pizza database). - The Bridge (
generate_mcp.py): A Python script that parsesopenapi.jsonand auto-generates a fully compliant MCP server (server.py). This ensures scalability—if the menu changes, the AI tools update automatically. - Agent Swarm:
- Ordering Agent: Uses Gemini 1.5 to interact with the generated MCP server.
- Scheduling Agent: Receives order context (ETA) and uses a simulated Calendar MCP to block time for a "Pizza Study Break.
- Install Dependencies:
pip install fastapi uvicorn mcp google-genai python-dotenv
- Start the Backend:
uvicorn backend:app --port 8000
- Generate the MCP Server:
python backend.py generate_spec # Creates json python generate_mcp.py # Creates server.py
- Run the Multi-Agent Workflow:
python main_flow.py
- Why Mock Data? As per the prompt requirements, I focused on the MCP transformation logic rather than building a complex SQL backend.
- Security: API Keys are managed via
.env(not committed). - Robustness: The generator sanitizes function names to prevent Python syntax errors during the JSON-to-MCP conversion.
graph TD
User[User] -->|Natural Language| Agent1[Ordering Agent]
Agent1 -->|Tools| MCPServer[Generated MCP Server]
MCPServer -->|API Calls| Backend[Legacy FastAPI Backend]
Agent1 -->|Order Context| Agent2[Scheduling Agent]
Agent2 -->|Tools| Calendar[Calendar MCP]
subgraph "The Innovation Layer"
OpenAPI[OpenAPI Spec] -->|Parsed by| Generator[generate_mcp.py]
Generator -->|Writes Code| MCPServer
end