披萨订购系统

一个基于FastAPI和MCP服务器的本地披萨订购系统,展示多代理协作的模块化AI架构。

  • by bumbum2403
  • Jupyter Notebook
  • 本地部署
  • 更新于
在 GitHub 查看 bumbum2403/Pizza-AI-A2A-MCP-

使用说明

披萨代理:本地MCP驱动的披萨订购系统

这是一个本地的、支持代理的披萨订购后端,通过FastAPI公开,并将其打包到一个MCP服务器中,Claude Desktop可以直接推理和调用。 这是真的 代理兼容系统 它使用2个单独的MCP服务器:

1.  mcp/delivery_mcp_server.py ( Built with OpenAPI specs)
2. mcp/pizza_mcp_server.py ( Built the standard FastMCP way)

该项目展示了如何通过主机LLM(Claude Desktop)组合多个独立的MCP服务器,每个服务器负责一个域,以解决多步现实任务。

该项目采用模块化、协议驱动的架构,而不是构建一个单一的人工智能系统,其中:

每个域都通过MCP公开其功能

LLM充当智能主机和协调器

代理商之间无需直接打电话即可协作

结果是一个使用本地基础设施的现实的、生产式的人工智能系统。

这个项目展示了什么

  • 具有OpenAPI规范的真正FastAPI后端
  • 自动OpenAPI→ 使用FastMCP进行MCP转换
  • 用于交付调度的第二个独立MCP服务器
  • Claude Desktop充当MCP主机
  • 无需硬编码编排的代理间推理
  • 内存状态管理(无需数据库)
  • 服务器端强制执行确定性业务规则

在本地运行

克隆项目

  git clone https://github.com/bumbum2403/Pizza-AI-A2A-MCP-.git

转到项目目录

  cd Pizza-AI-A2A-MCP-

安装依赖项: 如果在此存储库中看到environment.yml文件,请运行以下命令以创建完全镜像的环境:

  conda env create -f environment.yml

  • 启动FastAPI服务器
  uvicorn app.main:app --reload
  • 启动披萨配送MCP服务器(使用FastAPI服务器启动MCP服务器) 检查参考:这里url(https://gofastmcp.com/integrations/openapi)
  python3 app/mcp/pizza_mcp_server.py
  • 启动计划交付MCP服务器
  python3 app/mcp/delivery_mcp_server.py

系统架构

在较高层次上,该系统由三层组成:

  1. 域API(FastAPI/Python)
  2. MCP服务器(FastMCP/stdio)
  3. MCP主机(克劳德桌面)
┌──────────────────────────┐
│      Claude Desktop      │
│      (MCP Host)          │
│                          │
│  - Decides which agent   │
│    to call               │           
│  - Translates intent     │        MCP over stdio
│    into tool calls       │-------------
│  - Merges responses      │            |
└───────────┬──────────────┘            |
            │                           |       
            │ MCP over stdio            |   
            │                           |
 ┌──────────▼──────────┐     ┌──────────▼──────────┐
 │ Pizza Ordering MCP  │     │ Delivery MCP Server │
 │ (Auto from OpenAPI) │     │ (Custom MCP Server) │
 │                     │     │                     │
 │ - Menu              │     │ - Slot checking     │
 │ - Order creation    │     │ - Scheduling        │
 │ - Order status      │     │ - Time constraints  │
 └──────────┬──────────┘     └──────────┬──────────┘
            │                           │HTTP + 
            │ HTTP                      │ In-memory
            │                           │
 ┌──────────▼──────────┐     ┌──────────▼──────────┐
 │ FastAPI Application │     │ Delivery Logic      │
 │                     │     │ (Python only)       │
 └─────────────────────┘     └─────────────────────┘

披萨订购API(FastAPI):

FastAPI服务器公开了一个具有以下功能的模拟披萨订购系统:

1. Fetch available pizza menu

2. Create pizza orders

3. Retrieve order status
GET    /menu/                 → List pizzas
POST   /orders/               → Create an order
GET    /orders/{order_id}     → Get order status
GET    /health                → Health check

运作原理

将FastAPI与Pydantic模型结合使用

将所有数据存储在内存字典中

自动生成OpenAPI 3.1规范

不需要数据库

OpenAPI模式成为MCP转换的契约。

它是如何建造的

    1. FastMCP loads the OpenAPI spec from /openapi.json
    2. Every API endpoint becomes an MCP Tool
    3. HTTP requests are executed using an internal HTTP client
    4. Transport is stdio, not HTTP

此MCP服务器不包含业务逻辑。 它是一个将API暴露给AI系统的适配器层。

交付MCP服务器(自定义)

交付MCP服务器的存在是为了演示代理之间的协作。 它是一个完全独立的领域,有自己的逻辑和约束。

能力

  • 检查交货位可用性
  • 安排交货
  • 执行业务规则:
  • 停电时间:03:00–07:00
  • 最短交付周期:30分钟

代理到代理(A2A)流程

当用户询问:

“Order a small margherita and check if delivery at 2:00 AM is possible”

Claude Desktop执行以下推理:

Call Pizza MCP → get menu
|
Call Pizza MCP → create order
|
Call Delivery MCP → check slot
|
Merge responses
|
Ask user for confirmation
|
Call Delivery MCP → schedule delivery
|
Call Pizza MCP → fetch order status
|
Present final result

没有服务器直接与另一台服务器通信。 所有协调都发生在主机级别。 Claude Desktop兼具以下两种功能:

- MCP Host
- MCP Client for each server