mcp-server-prod

mcp-server-prod

A hardened MCP server exposing read-only orders tools to AI agents, with rigorous input validation and parameterized queries to prevent injection attacks.

Category
访问服务器

README

mcp-server-prod

A hardened MCP server — because MCP tool arguments are written by an LLM, from untrusted user text. Exposes read-only "orders" tools to an AI agent, and treats every argument as hostile: validated, parameterized, and served over a read-only connection.

Runs offline. docker compose up runs the security battery with no API key and no network — the standard library only. (The MCP server itself needs pip install mcp.)


The problem

An MCP tool signature like search_orders(status: str) looks safe. But status doesn't come from your code — it comes from a model, interpreting whatever a user typed. That's a network boundary wearing a function signature. The naive server everyone writes first concatenates that string into SQL and calls it a day:

sql = f"SELECT * FROM orders WHERE status = '{status}'"   # ← LLM-controlled

One status = "paid' OR '1'='1" and the agent just dumped your whole table.

Quickstart

docker compose up        # security battery: naive vs prod scorecard (offline)
make demo                # same, without Docker
make test                # the security contract tests (pytest)
make serve               # run the actual MCP server over stdio (needs: pip install mcp)

The scorecard (before → after)

The same five hostile tool-calls, run against the naive server and this one:

attack naive prod
filter bypass — status = paid' OR '1'='1 🔴 LEAK 🟢 SAFE
table exfil — customer = zzz' OR '1'='1 🔴 LEAK 🟢 SAFE
numeric injection — min_total = "0 OR 1=1" 🔴 LEAK 🟢 SAFE
id injection — get_order("1 OR 1=1") 🔴 LEAK 🟢 SAFE
write reaches the DB (read-only?) 🔴 LEAK 🟢 SAFE
safely handled 0 / 5 5 / 5

Meanwhile legitimate queries are unaffected — search_orders(status="paid") returns the 12 paid orders, revenue_summary("paid") returns {count: 12, total: 25451.24}. Hardening didn't cost functionality.

The three defenses

  1. Validate every argument (validation.py) — status must be an enum member, order_id must be an integer, limit is clamped to 100. An agent asking for a million rows gets 100; a bad enum is a structured error, not a silent mis-query.
  2. Parameterize every query (tools.py) — user values are bound, never concatenated. customer = "zzz' OR '1'='1" becomes a literal name that matches nobody, not a bypass.
  3. Open the database read-only — file:...?mode=ro. Defense in depth: even a query that slips through cannot mutate data. The write test raises at the driver.

Wire it into a desktop MCP client

{
  "mcpServers": {
    "orders": { "command": "python", "args": ["-m", "mcp_server_prod.server"] }
  }
}

Drop that into Claude Desktop's MCP config and the search_orders / get_order / revenue_summary tools appear to the agent. (A short screen recording of that flow makes a good demo GIF — the server code and config here are what it records.)

How it's verified

Security is a contract test suite, not a claim: the production tools must reject or safely handle each hostile input, and the naive implementation must demonstrably leak (so the threat is real, not hypothetical). CI also builds the server against the official mcp SDK. All checks run offline; the battery scorecard is computed from real behavior.

9 passed        # pytest
0/5 → 5/5       # security battery
mcp server ok   # builds with the official SDK

Honest limitations

· Synthetic 20-row SQLite dataset — a demonstrator of the access pattern, not a product.
· Scope is read-only retrieval. A write-capable server needs authЗ, per-tool authorization,
  and audit logging (authn/authz) — explicitly out of scope here and called out, not faked.
· The "naive vs prod" contrast is illustrative; it doesn't enumerate every injection class
  (no second-order, stored, or ORM-specific vectors).
· Parameterization + read-only defends the data layer; it is not a full threat model
  (rate limiting, secrets handling, and prompt-injection of the agent itself are separate).

Layout

mcp_server_prod/  db.py · validation.py · tools.py (prod) · naive.py · server.py · demo.py
tests/            test_security.py       # the security contract
Dockerfile · docker-compose.yml · .github/workflows/ci.yml

MIT © 2026 Jigon Yoo

推荐服务器

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

官方
精选