cafe-shop-mcp-agent

cafe-shop-mcp-agent

Enables natural language interaction with a coffee shop's inventory and order system, allowing users to check menu items, place orders, and track order status via MCP tools.

Category
访问服务器

README

Cafe Shop MCP Agent - Exhaustive Documentation

System Overview

The Cafe Shop MCP Agent ("Bean & Brew") is an advanced implementation of the Model Context Protocol (MCP) ecosystem. It consists of two standalone services that communicate securely using the MCP streamable-http transport protocol.

The system uses a LangChain-based ReAct agent running on AWS Bedrock to process natural language coffee shop requests, querying live inventory and executing orders against a PostgreSQL database through the MCP server.


1. Architecture Deep-Dive

1.1 The Client Interface (client/)

The Client acts as the user-facing API and the LangChain Agent execution environment.

  • Framework: FastAPI
  • Agent Orchestrator: LangGraph + LangChain (create_agent)
  • LLM Engine: AWS Bedrock (ChatBedrock)
  • Persistence: LangGraph AsyncPostgresSaver (Checkpointer) for thread-level memory.
  • Middleware Integration:
    • SummarizationMiddleware: Compresses history beyond 2000 tokens or 10 messages.
    • PIIMiddleware: Redacts emails, masks credit cards, and redacts phone numbers before sending to Bedrock.
    • HumanInTheLoopMiddleware: Intercepts the add_order tool call for explicit human approval before execution.

1.2 The MCP Server (mcp_server/)

The Server exposes domain logic and data boundaries securely.

  • Framework: FastMCP (mcp.server.fastmcp)
  • Database: PostgreSQL (managed via SQLAlchemy ORM).
  • Transport: HTTP SSE (streamable-http).

2. API Contract & Data Flow

2.1 Chat Endpoint (Client)

POST /api/v1/chat

Request Payload (ChatRequest):

{
  "message": "I'd like to order 2 Cappuccinos please.",
  "mode": "normal", 
  "stream": false,
  "thread_id": "user-session-id"
}

Note: mode can be normal, structured, or left empty. stream dictates whether response is SSE or synchronous JSON.

Response Payload (ChatResponse - Normal Mode):

{
  "message": "I have set up your order for 2 Cappuccinos. Before I finalize it, do you approve?",
  "structured_output": null,
  "stream_chunks": null,
  "pending_approval": {
    "tool": "add_order",
    "args": {"customer_name": "Guest", "items": [{"item_name": "Cappuccino", "quantity": 2}]},
    "description": "Tool add_order requires approval."
  }
}

(If pending_approval is present, the next request's message must be exactly "approve" or "reject" with the same thread_id).

2.2 Database Schema (MCP Server)

The PostgreSQL database consists of 4 main tables:

  1. menu_items: menu_item_id (PK), name (unique), price (Numeric), stock_quantity (int), is_active (bool).
  2. orders: order_id (UUID PK), order_sequence_id (BigInt Seq), customer_name (str), status (str).
  3. order_items: Junction table linking orders and menu_items with a quantity column.
  4. error_logs: log_id, error_code, message, source.

3. Model Context Protocol (MCP) Bindings

The FastMCP server explicitly registers the following components. The Client loads these unconditionally during session initialization (load_session_context).

3.1 Tools (@mcp.tool())

Tool Name Arguments Returns Description
check_menu None Dict[str, List[Dict]] Fetches active menu items (name, price, description) and current stock_quantity.
check_order_status order_sequence_id (int) Dict Returns order status (PENDING, PROCESSED) by looking up the integer sequence ID.
add_order customer_name (str), items (List) Dict Places order, generates sequence ID, and reduces inventory stock_quantity. Intercepted by HITL on the client side.

3.2 Prompts (@mcp.prompt())

  • brew_buddy_system: The primary ReAct agent instructions formatting role, objectives, constraints, and output format (using XML tags <role>, <instructions>).
  • order_confirmation(customer_name, items): Generates a warm, formatted confirmation receipt.

3.3 Resources (@mcp.resource())

  • menu://items: Read-only text dump of the live menu and prices.
  • store://info: Static string containing store hours, location, and contact policies.

4. Setup and Execution Steps

4.1 Prerequisites

  • PostgreSQL running locally or via Docker.
  • AWS Bedrock access (AWS credentials configured).
  • Python 3.11+ and uv package manager.

4.2 Start the MCP Server

Navigate to mcp_server/, update your .env with DB_HOST, DB_USER, DB_PASS, etc., and run:

uv sync
python main.py

This automatically triggers database migrations (create_tables.py) and seeds the default coffee menu, starting FastMCP on port 8000.

4.3 Start the Client API

Navigate to client/, update your .env with AWS and MCP Server credentials (MCP_SERVER_URL=http://localhost:8000), and run:

uv sync
python main.py

This starts the user-facing FastAPI application on port 8080.

4.4 Example Workflow

  1. User asks for menu: POST /api/v1/chat -> Agent reads menu://items resource.
  2. User places order: POST /api/v1/chat -> Agent calls add_order. HITL middleware interrupts and returns pending_approval.
  3. User approves: POST /api/v1/chat (message: "approve", same thread_id) -> Client resumes LangGraph checkpointer state -> Tool executes on MCP Server -> DB stock reduced.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选