MCP Commerce Server
MCP Commerce Server (PostgreSQL + Hugging Face)
This project provides a deployment-ready MCP server that can be invoked from a LangGraph orchestration flow.
It accepts natural-language input, uses an open-source Hugging Face model to derive query intent, and safely fetches data from PostgreSQL.
What is implemented
MCP tools:
query_commerce(query, user_context?, limit?)get_product_price(product_name, limit?)get_user_orders(user_id?, email?, limit?)calculate_two_numbers(a, b, operation?)where operation supports add/subtract
PostgreSQL schema for:
Product prices (
products)Users (
users)Orders (
orders,order_items)
Hugging Face model integration (open-source text-to-text model default:
google/flan-t5-base)SQL-injection-safe query layer (no model SQL execution; only parameterized, pre-approved SQL templates)
OpenTelemetry tracing and structured logging for MCP tool flow, intent parsing, DB connection, and query execution
Docker + docker-compose setup for deployment
Why this is SQL-injection safe
LLM output is treated as intent only, not executable SQL.
The server maps intent to a fixed set of SQL templates.
All runtime values are passed as query parameters via psycopg (
%splaceholders).limitis bounded server-side to prevent abuse.
Project structure
.
├── db/init.sql
├── docker-compose.yml
├── Dockerfile
├── examples/langgraph_client.py
├── pyproject.toml
├── requirements.txt
└── src/mcp_commerce_server
├── config.py
├── db.py
├── hf_intent.py
├── main.py
├── query_service.py
└── server.py1. Local development setup
Create and activate a virtual environment:
python -m venv .venv source .venv/bin/activateInstall dependencies:
pip install -r requirements.txtCreate env file:
cp .env.example .envStart PostgreSQL and seed schema:
Option A: Use your own DB and run
db/init.sql.Option B: Use docker-compose (recommended below).
2. Run with docker-compose (deployment-ready local)
Ensure
.envexists and hasHF_API_KEY.Start services:
docker compose up --buildMCP server is exposed at:
http://localhost:8000/mcp(streamable-http transport)
3. Run MCP server directly (stdio for local MCP clients)
python -m mcp_commerce_server.mainSet MCP_TRANSPORT=stdio in .env for this mode.
4. LangGraph orchestration usage
See
examples/langgraph_client.pyfor end-to-end invocation.The example now connects to two MCP servers:
commerceatMCP_COMMERCE_URL(defaulthttp://localhost:8000/mcp)knowledgeatMCP_KNOWLEDGE_URL(defaulthttp://localhost:8001/mcp)
It sends different prompts so the model routes to different tools (commerce query tools,
calculate_two_numbers, and knowledge tools).
5. Environment variables
Variable | Description | Required |
| PostgreSQL host | Yes |
| PostgreSQL port | Yes |
| Database name | Yes |
| Database user | Yes |
| Database password | Yes |
| Hugging Face API key | Yes (for model inference) |
| Open-source HF model id | No ( |
|
| No ( |
| HTTP host for streamable MCP | No ( |
| HTTP port for streamable MCP | No ( |
| Python logging level | No ( |
| OpenTelemetry service name | No ( |
6. Deployment steps (production-oriented)
Build image:
docker build -t commerce-mcp-server:latest .Push image to your registry:
docker tag commerce-mcp-server:latest <registry>/<namespace>/commerce-mcp-server:latest docker push <registry>/<namespace>/commerce-mcp-server:latestProvision managed PostgreSQL (AWS RDS / Azure Database / Cloud SQL).
Apply
db/init.sqlonce (or convert to migration pipeline).Deploy container to your platform (Kubernetes, ECS, App Service, Cloud Run, etc.) with:
MCP_TRANSPORT=streamable-httpDB connection variables
HF_API_KEYsecret
Expose HTTP endpoint and allow only trusted callers (VPC/ingress ACL, auth gateway, or service mesh policy).
Configure LangGraph to call deployed MCP URL.
7. Hardening recommendations before go-live
Use DB least-privilege user (read-only if writes are unnecessary).
Add request auth in front of MCP endpoint (API gateway/JWT/mTLS).
Add query logging + tracing.
Add circuit breakers/timeouts for HF and DB.
Add schema migrations (Alembic/Flyway/liquibase) for controlled releases.
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/vikramjt/mcp_demo'
If you have feedback or need assistance with the MCP directory API, please join our Discord server