MCP Commerce Server

MCP Commerce Server

Enables natural-language querying of e-commerce data (products, users, orders) from a PostgreSQL database, using a Hugging Face model for safe intent extraction and parameterized SQL execution.

Category
访问服务器

README

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?)
  • 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)
  • Docker + docker-compose setup for deployment

Why this is SQL-injection safe

  1. LLM output is treated as intent only, not executable SQL.
  2. The server maps intent to a fixed set of SQL templates.
  3. All runtime values are passed as query parameters via psycopg (%s placeholders).
  4. limit is 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.py

1. Local development setup

  1. Create and activate a virtual environment:
    python -m venv .venv
    source .venv/bin/activate
    
  2. Install dependencies:
    pip install -r requirements.txt
    
  3. Create env file:
    cp .env.example .env
    
  4. Start 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)

  1. Ensure .env exists and has HF_API_KEY.
  2. Start services:
    docker compose up --build
    
  3. MCP 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.main

Set MCP_TRANSPORT=stdio in .env for this mode.

4. LangGraph orchestration usage

  • See examples/langgraph_client.py for end-to-end invocation.
  • Configure your LangGraph runtime to connect to:
    • transport: streamable_http
    • url: http://<host>:8000/mcp

5. Environment variables

Variable Description Required
POSTGRES_HOST PostgreSQL host Yes
POSTGRES_PORT PostgreSQL port Yes
POSTGRES_DB Database name Yes
POSTGRES_USER Database user Yes
POSTGRES_PASSWORD Database password Yes
HF_API_KEY Hugging Face API key Yes (for model inference)
HF_MODEL_ID Open-source HF model id No (google/flan-t5-base)
MCP_TRANSPORT stdio or streamable-http No (stdio)
MCP_HOST HTTP host for streamable MCP No (0.0.0.0)
MCP_PORT HTTP port for streamable MCP No (8000)

6. Deployment steps (production-oriented)

  1. Build image:
    docker build -t commerce-mcp-server:latest .
    
  2. Push image to your registry:
    docker tag commerce-mcp-server:latest <registry>/<namespace>/commerce-mcp-server:latest
    docker push <registry>/<namespace>/commerce-mcp-server:latest
    
  3. Provision managed PostgreSQL (AWS RDS / Azure Database / Cloud SQL).
  4. Apply db/init.sql once (or convert to migration pipeline).
  5. Deploy container to your platform (Kubernetes, ECS, App Service, Cloud Run, etc.) with:
    • MCP_TRANSPORT=streamable-http
    • DB connection variables
    • HF_API_KEY secret
  6. Expose HTTP endpoint and allow only trusted callers (VPC/ingress ACL, auth gateway, or service mesh policy).
  7. Configure LangGraph to call deployed MCP URL.

7. Hardening recommendations before go-live

  1. Use DB least-privilege user (read-only if writes are unnecessary).
  2. Add request auth in front of MCP endpoint (API gateway/JWT/mTLS).
  3. Add query logging + tracing.
  4. Add circuit breakers/timeouts for HF and DB.
  5. Add schema migrations (Alembic/Flyway/liquibase) for controlled releases.

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选