FastMCP Orders Server
FastMCP Orders Server
A Model Context Protocol (MCP) server built with FastMCP that exposes a tool for querying customer orders from a PostgreSQL database.
プロジェクト構造
├── mcp_server.py # FastMCP server — stdio transport (default), HTTP optional
├── mcp_client.py # Demo client — connects via stdio, calls the tool
├── .env.example # Template for DB credentials
├── requirements.txt # Python dependencies
├── schema.sql # DDL to create customers + orders tables
├── seed.sql # Sample data for local testing
└── README.md # This fileRelated MCP server: Mock Store MCP Server
前提条件
Python ≥ 3.10
PostgreSQL instance with a database containing the schema described below
データベーススキーマ
サーバーは2つのテーブルを想定しています:
テーブル | カラム |
|
|
|
|
提供されたSQLファイルを実行して作成します:
psql -d orders_db -f schema.sql
psql -d orders_db -f seed.sqlセットアップ
1. 依存関係のインストール
pip install -r requirements.txt2. データベース認証情報の設定
envテンプレートをコピーし、接続詳細を記入してください:
cp .env.example .env
nano .env # edit values to match your PostgreSQL instanceサーバーの実行
Stdioトランスポート(デフォルト)
python mcp_server.pyこれはローカルMCPサーバーの標準モードで、Claude Desktop、MCP Inspector、およびstdio互換のクライアントで動作します。
HTTPトランスポート(オプション — リモートクライアント)
python mcp_server.py --transport http --port 9000クライアントがローカルプロセスではなくリモートHTTPエンドポイントを必要とする場合に便利です。
デモクライアントの実行
バンドルされたクライアントはstdio経由でサーバーに接続し、3つのテストシナリオを実行します:
python mcp_client.py期待される出力(シードデータがロードされた状態):
[TEST 1] Orders for customer_id=1 with min_amount=100.0
Order ID Date Amount (€) Status
--------------------------------------------------------
5 2025-06-15 180.75 € completed
3 2025-03-01 520.00 € shipped
1 2025-01-10 250.00 € completed
→ 3 order(s) found
[TEST 2] Orders for 'carlos@example.com' with min_amount=300.0
Order ID Date Amount (€) Status
--------------------------------------------------------
8 2025-05-10 890.00 € shipped
6 2025-02-01 340.00 € completed
→ 2 order(s) found
[TEST 3] Lookup nonexistent email (expecting error)
⚠ Customer not found (nobody@nowhere.com)MCP Inspectorを使用したテスト
MCP InspectorはMCPサーバーを探索するためのインタラクティブなツールです。
npx @modelcontextprotocol/inspector node mcp_server.jsPythonサーバーの場合:
npx @modelcontextprotocol/inspector python mcp_server.pyインスペクタは
http://localhost:6287でブラウザウィンドウを開きます。UIで、ツールの下にあるget_customer_orders_above_amountを見つけます。
パラメータを入力し(例:
{"customer_id": 1, "min_amount": 100})、Callをクリックします。構造化されたJSONレスポンスを確認します。
ツール仕様
get_customer_orders_above_amount
合計がユーロで最低金額を超える顧客の注文を取得します。
パラメータ | 型 | 必須 | 説明 |
|
| いいえ | 顧客の主キー(両方指定された場合は優先) |
|
| いいえ | 代替検索用のメールアドレス |
|
| いいえ | ユーロでの最低注文金額(含む、デフォルト0.0) |
customer_idまたはcustomer_emailの少なくとも一方を指定する必要があります。
戻り値: list[dict] — 各dictはキーorder_id、order_date、total_amount、statusを持ちます。結果はorder_dateの降順で並べられます。
エラーレスポンスは、"error"キーを持つ単一のdictを含むリストとして返されます(生のスタックトレースはクライアントに漏れません)。
セキュリティに関する注意
ハードコードされた認証情報はありません — すべてのDBパラメータは
python-dotenvを介して読み込まれた環境変数から取得されます。パラメータ化されたクエリのみ — SQLインジェクションは、
$1、$2プレースホルダーを全体で使用することで防止されます。コネクションプーリング —
asyncpgプール(2~10接続)がサーバー起動時に一度作成され、シャットダウン時に閉じられます。
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- -license-quality-maintenanceEnables connection to PostgreSQL databases for EC solution platforms to query and manage e-commerce data including orders, members, and other business information. Provides tools for direct SQL execution, table structure analysis, and specialized e-commerce data retrieval functions.
- Flicense-qualityDmaintenanceEnables AI agents to explore and query a mock e-commerce store's data including customers, products, inventory, and orders through conversational interactions backed by PostgreSQL.
- Flicense-qualityDmaintenanceEnables interaction with the Pagila sample PostgreSQL database through natural language queries and SQL execution, supporting safe SELECT operations and text-to-SQL conversion.
- AlicenseAqualityAmaintenanceEnables read-only interaction with PostgreSQL databases through natural language queries, supporting dynamic connections and secure query validation.31952MIT
Related MCP Connectors
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
Comprehensive PostgreSQL documentation and best practices, including ecosystem tools
Manage Supabase projects end to end across database, auth, storage, realtime, and migrations. Moni…
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/masalinas/poc-ai-mcp-claude-code'
If you have feedback or need assistance with the MCP directory API, please join our Discord server