cafe-shop-mcp-agent
Cafe Shop MCP Agent - 詳細ドキュメント
システム概要
Cafe Shop MCP Agent("Bean & Brew")は、Model Context Protocol (MCP) エコシステムの高度な実装です。MCP の streamable-http トランスポートプロトコルを使用して安全に通信する2つのスタンドアロンサービスで構成されています。
このシステムは、AWS Bedrock 上で動作する LangChain ベースの ReAct エージェントを使用して、自然言語のコーヒーショップリクエストを処理し、MCP サーバーを介して PostgreSQL データベースに対してライブ在庫の照会と注文の実行を行います。
Related MCP server: mcp-coffee
1. アーキテクチャ詳細
1.1 クライアントインターフェース(client/)
クライアントは、ユーザー向け API および LangChain エージェントの実行環境として機能します。
フレームワーク: FastAPI
エージェントオーケストレーター: LangGraph + LangChain(
create_agent)LLM エンジン: AWS Bedrock(
ChatBedrock)永続化: スレッドレベルのメモリのための LangGraph AsyncPostgresSaver(チェックポインター)。
ミドルウェア統合:
SummarizationMiddleware: 2000トークンまたは10メッセージを超える履歴を圧縮します。PIIMiddleware: Bedrock に送信する前に、メールアドレスを編集し、クレジットカードをマスクし、電話番号を編集します。HumanInTheLoopMiddleware: 実行前に明示的な人間の承認を得るために、add_orderツール呼び出しをインターセプトします。
1.2 MCP サーバー(mcp_server/)
サーバーは、ドメインロジックとデータ境界を安全に公開します。
フレームワーク: FastMCP(
mcp.server.fastmcp)データベース: PostgreSQL(SQLAlchemy ORM 経由で管理)。
トランスポート: HTTP SSE(
streamable-http)。
2. API 契約とデータフロー
2.1 チャットエンドポイント(クライアント)
POST /api/v1/chat
リクエストペイロード(ChatRequest):
{
"message": "I'd like to order 2 Cappuccinos please.",
"mode": "normal",
"stream": false,
"thread_id": "user-session-id"
}注: mode は normal、structured、または空のままにできます。stream は、レスポンスが SSE か同期 JSON かを決定します。
レスポンスペイロード(ChatResponse - ノーマルモード):
{
"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."
}
}(pending_approval が存在する場合、次のリクエストの message は同じ thread_id で正確に "approve" または "reject" である必要があります)。
2.2 データベーススキーマ(MCP サーバー)
PostgreSQL データベースは、4つの主要テーブルで構成されています:
menu_items:menu_item_id(PK)、name(一意)、price(Numeric)、stock_quantity(int)、is_active(bool)。orders:order_id(UUID PK)、order_sequence_id(BigInt シーケンス)、customer_name(str)、status(str)。order_items:ordersとmenu_itemsをquantity列でリンクするジャンクションテーブル。error_logs:log_id、error_code、message、source。
3. Model Context Protocol (MCP) バインディング
FastMCP サーバーは、以下のコンポーネントを明示的に登録します。クライアントは、セッション初期化中(load_session_context)にこれらを無条件にロードします。
3.1 ツール(@mcp.tool())
ツール名 | 引数 | 戻り値 | 説明 |
| なし |
| アクティブなメニュー項目( |
|
|
| 整数のシーケンス ID を検索して、注文ステータス( |
|
|
| 注文を確定し、シーケンス ID を生成し、在庫 |
3.2 プロンプト(@mcp.prompt())
brew_buddy_system: 役割、目的、制約、出力形式をフォーマットする主要な ReAct エージェントの指示(XML タグ<role>、<instructions>を使用)。order_confirmation(customer_name, items): 温かみのあるフォーマット済みの確認レシートを生成します。
3.3 リソース(@mcp.resource())
menu://items: ライブメニューと価格の読み取り専用テキストダンプ。store://info: 営業時間、所在地、連絡先ポリシーを含む静的文字列。
4. セットアップと実行手順
4.1 前提条件
PostgreSQL がローカルまたは Docker 経由で実行されていること。
AWS Bedrock へのアクセス(AWS 認証情報が設定されていること)。
Python 3.11+ と
uvパッケージマネージャー。
4.2 MCP サーバーを起動する
mcp_server/ に移動し、.env を DB_HOST、DB_USER、DB_PASS などで更新して、以下を実行します:
uv sync
python main.pyこれにより、データベースマイグレーション(create_tables.py)が自動的にトリガーされ、デフォルトのコーヒーメニューがシードされ、FastMCP がポート 8000 で起動します。
4.3 クライアント API を起動する
client/ に移動し、.env を AWS と MCP サーバーの認証情報(MCP_SERVER_URL=http://localhost:8000)で更新して、以下を実行します:
uv sync
python main.pyこれにより、ユーザー向け FastAPI アプリケーションがポート 8080 で起動します。
4.4 ワークフロー例
ユーザーがメニューを尋ねる:
POST /api/v1/chat-> エージェントがmenu://itemsリソースを読み取ります。ユーザーが注文する:
POST /api/v1/chat-> エージェントがadd_orderを呼び出します。HITL ミドルウェアがインターセプトしてpending_approvalを返します。ユーザーが承認する:
POST /api/v1/chat(message: "approve"、同じ thread_id)-> クライアントが LangGraph チェックポインターの状態を再開 -> ツールが MCP サーバー上で実行 -> DB の在庫が減少します。
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
Related MCP Connectors
MCP server for your apps' tools and custom tools, plus hosted AI agents and approval-gated workflows
Hosted MCP for e-commerce: live product catalog, stock, and pricing for AI agents.
Build and run AI workflows, agents, data tables and 1000+ API integrations from any MCP client.
Related MCP Servers
- FlicenseBqualityDmaintenanceAn MCP adapter that maps Coffee Company B2B HTTP APIs to MCP tools, allowing AI agents to query member information, benefits, coupons, and payment statuses. It enables seamless integration for AI assistants to manage coffee-related customer assets and loyalty details through natural language.101-
- FlicenseNot gradedqualityDmaintenanceEnables coffee shop order management via MCP, including menu lookup, order creation, and status tracking.-
- FlicenseAqualityDmaintenanceMCP server that recommends coffee based on preferences (mood, milk, caffeine, temperature) from a static menu; includes tools for listing menu, recommending, and explaining recommendations.3-
- FlicenseNot gradedqualityCmaintenanceEnables natural language queries to a local PostgreSQL database for inventory and order information via MCP tools.-