FastMCP Orders Server
Enables querying customer orders from a PostgreSQL database by customer ID or email, with optional minimum amount filtering.
README
FastMCP Orders Server
A Model Context Protocol (MCP) server built with FastMCP that exposes a tool for querying customer orders from a PostgreSQL database.
Project Structure
├── 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 file
Prerequisites
- Python ≥ 3.10
- PostgreSQL instance with a database containing the schema described below
Database Schema
The server expects two tables:
| Table | Columns |
|---|---|
customers |
id (PK), name (text), email (text, unique) |
orders |
id (PK), customer_id (FK→customers), order_date, total_amount (numeric, €), status |
Run the provided SQL files to create them:
psql -d orders_db -f schema.sql
psql -d orders_db -f seed.sql
Setup
1. Install dependencies
pip install -r requirements.txt
2. Configure database credentials
Copy the env template and fill in your connection details:
cp .env.example .env
nano .env # edit values to match your PostgreSQL instance
Running the Server
Stdio transport (default)
python mcp_server.py
This is the standard mode for local MCP servers and works with Claude Desktop, the MCP Inspector, and any stdio-compatible client.
HTTP transport (optional — remote clients)
python mcp_server.py --transport http --port 9000
Useful when clients need a remote HTTP endpoint instead of a local process.
Running the Demo Client
The bundled client connects to the server via stdio and runs three test scenarios:
python mcp_client.py
Expected output (with seed data loaded):
[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)
Testing with the MCP Inspector
The MCP Inspector is an interactive tool for exploring MCP servers.
npx @modelcontextprotocol/inspector node mcp_server.js
For Python servers:
npx @modelcontextprotocol/inspector python mcp_server.py
- The inspector opens a browser window on
http://localhost:6287. - In the UI, locate get_customer_orders_above_amount under Tools.
- Fill in parameters (e.g.,
{"customer_id": 1, "min_amount": 100}) and click Call. - Inspect the structured JSON response.
Tool Specification
get_customer_orders_above_amount
Retrieve a customer's orders whose total exceeds a minimum amount in euros.
| Parameter | Type | Required | Description |
|---|---|---|---|
customer_id |
int | None |
No | Primary key of the customer (takes precedence if both given) |
customer_email |
str | None |
No | Email address for alternative lookup |
min_amount |
float |
No | Minimum order value in € (inclusive, default 0.0) |
At least one of customer_id or customer_email must be provided.
Returns: list[dict] — each dict has keys order_id, order_date, total_amount, status. Results are ordered by order_date descending.
Error responses are returned as a list containing a single dict with an "error" key (no raw stack traces leak to the client).
Security Notes
- No hardcoded credentials — all DB parameters come from environment variables loaded via
python-dotenv. - Parameterized queries only — SQL injection is prevented by using
$1,$2placeholders throughout. - Connection pooling — an
asyncpgpool (2–10 connections) is created once at server startup and closed at shutdown.
Claude code configurations
If you want disable the autocompact to hav emore context window space use this parameter in your claude settings.json
"DISABLE_AUTO_COMPACT": "true"
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.
E2B
Using MCP to run code via e2b.