返回资讯中心
外部精选
软件工程
#开发者实时流

MCP服务器实验:严格schema拒绝全部10次错误调用,宽松schema零拦截

来源标题:Show HN: Strict MCP schemas rejected 10/10 bad calls; loose schemas: 0/10

一项MCP服务器实验对比了两种工具schema设计:严格schema成功拒绝10/10次错误调用,宽松schema则0/10拦截。该实验通过同一笔记存储暴露两套schema,测试模型实际调用工具时的表现。项目纯用Python标准库实现,无需第三方依赖。

Hacker News 最新ranadhir192026/11/24 · 今天10 分钟阅读

以下正文同步自 Hacker News 最新,版权归原站所有,已转换为易读排版。

Companion lab for The Architect's AI Workshop, Agent Series Ep. 1 — "Build an MCP Server a Model Can Actually Use."

A language model never sees your server code. It sees tool names, descriptions and JSON schemas — and nothing else. So an MCP server is a user interface for a language model, and this lab measures what that means: it exposes one notes store through two schema designs and grades what happens when models try to use each one.

Listed in the HOL Registry — owner-verified listing (catalogue PR merged 2026-11-04).

The server has no dependencies beyond Python itself — the server, the client and the harness are pure standard library (JSON-RPC 2.0 over stdio). Tested with Python 3.12.

git clone https://github.com/ranadhir19/mcp-server-lab.git cd mcp-server-lab python3 validate.py # self-check: must end with OVERALL: PASS (5/5 stages)

That is the whole install: nothing to build, no package to install. (In fact the only command in this lab that needs a third-party package is the optional model-trial runner — see "Run it".)

An MCP client launches the server over stdio. Point the client at notes_server.py with --schema v2 to get the strict design: six tools (create_note, get_note, update_note, delete_note, list_notes, search_notes), required fields enforced, additionalProperties: false, and structured errors instead of silent failures. For any client that takes the standard mcpServers JSON (Claude Desktop, Claude Code, Cursor and others):

{ "mcpServers": { "notes-strict": { "command": "python3", "args": ["/absolute/path/to/mcp-server-lab/notes_server.py", "--schema", "v2"] } } }

Replace /absolute/path/to/mcp-server-lab with the directory you cloned into. With Claude Code, the same registration is one command:

claude mcp add notes-strict -- python3 /absolute/path/to/mcp-server-lab/notes_server.py --schema v2

Then ask the model to list, create, search, update or delete notes. Two things to know: the store starts from the same six seeded notes (n1–n6) on every launch, and state is in memory only — it resets when the server restarts, which is deliberate for a teaching lab. (--schema v1 swaps in the deliberately loose design, so you can watch the same client's calls fail against it.)

python3 validate.py # 5 stages, must end with OVERALL: PASS python3 audit.py # deterministic audits -> audit_results.json python3 run_trials.py --chooser oracle # harness plumbing check only

Model trials (optional; needs pip install llama-cpp-python and a GGUF instruct model):

python3 run_trials.py --chooser llm --model path/to/model.gguf
--out trials_model.json

The experiment, and its criterion — stated before any run

Question. Does schema redesign (v1 → v2) change how often models pick the wrong tool, produce malformed calls, and complete the task?

Pre-stated success criterion. Pooled across the models tested, v2 counts as a win only if wrong-tool calls fall by at least 30% relative to v1 and task completion rises. Anything less and the honest conclusion is the other one: that description quality is not the lever — granularity or model capability is — and that is what gets reported. The criterion lives here, in writing, before the trials run; it does not move afterwards.

Method notes. Single-shot selection (one call per task, no retries), temperature 0, fresh seeded store per task, results inspected through the protocol itself. Models tested are small, locally run open models — the point is the comparison between schema versions on identical tasks, not a leaderboard. Small models are also where schema quality should matter most: a frontier model can often guess its way past a bad description; a small one cannot.

Run audit.py yourself: the loose v1 schema silently accepts all 10 adversarial calls (and three of them mutate the store); the strict v2 schema rejects all 10. Across the 16 ground-truth task calls, v1 returns roughly 5.5 times as many result bytes as v2. The lexical confusability proxy, interestingly, scores v2 worse — its longer descriptions share more vocabulary. Words are not meaning; that proxy is kept in the lab as a standing warning against cheap metrics.

正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。

打开原文
去社区讨论 →