Skip to content

docs: how we measure the context cost, and the SDK's dead $schema header - #133

Merged
VickyXAI merged 2 commits into
mainfrom
docs/schema-overhead
Sep 2, 2026
Merged

docs: how we measure the context cost, and the SDK's dead $schema header#133
VickyXAI merged 2 commits into
mainfrom
docs/schema-overhead

Conversation

@VickyXAI

@VickyXAI VickyXAI commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

The measurement method and the ecosystem finding behind 0.45.0 lived only in a session scratch directory — a temporary path that disappears. The wrapper is a technique other MCP authors can copy, and the verification recipe is what keeps the claim checkable a year from now.

What the doc covers

  • What each profile costs, and how to reproduce it against this server or any other stdio MCP server. Includes the gotcha that measuring a published package must be done from outside this checkout, or npx resolves to the local build.
  • The $schema finding. The SDK's zod→JSON-Schema conversion stamps "$schema": "http://json-schema.org/draft-07/schema#" onto every tool, on both the zod v3 and v4 branches, and exposes no way to suppress it. ~15 tokens per tool that the author never wrote and cannot see in their source.
  • The fix, copyable. Wrapping tools/list through the public setRequestHandler only — no forking, no node_modules patching, no private-field access — plus the two properties that make it safe to ship: never load-bearing, and no-ops when there is nothing to wrap. Links to the shipped files.
  • How far "dead weight" can be defended. No SDK code path reads it; its bundled ajv validator never receives inputSchema; compiling all 20 schemas with and without it gives identical verdicts on 100/100 pairs. Closed-source clients were not instrumented, and the doc says so rather than overclaiming.
  • The ensure_ascii footgun. Python's json.dumps escapes non-ASCII by default, which inflated the first published figures by 565 tokens (4.4%) and forced a retraction. Includes the diagnostic fingerprint: description totals agreeing to the token while grand totals diverge, and pure-ASCII tools showing a delta of exactly zero.

Also

README's context-cost card now links to this doc rather than to a section heading, so the "how we measure it" promise leads somewhere that explains it.

Caveats are stated in the doc rather than omitted: $schema was a 2% win and descriptions are the remaining ~54%; schemas are prompt-cached so the dollar cost is roughly a tenth of the context cost; o200k_base is a proxy that under-counts.

Verification

431/431 tests pass; sync-brand-numbers --check clean. Docs-only otherwise — no version bump, so this does not trigger a release.

🤖 Generated with Claude Code

https://claude.ai/code/session_01WUL3ExR4Nz7uebxKaKwjDi

VickyXAI and others added 2 commits September 2, 2026 12:46
The measurement method and the ecosystem finding behind 0.45.0 existed only in
a session scratch directory, which is a temporary path. The wrapper is a
technique other MCP authors can copy and the verification recipe is what keeps
the claim checkable a year from now, so it belongs in the repo.

Covers: what each profile costs and how to reproduce it against any stdio MCP
server; why the SDK stamps a draft-07 $schema header onto every zod-defined
tool and how to strip it through public API only; how far "it is dead weight"
can actually be defended (no SDK code path reads it, its bundled ajv validator
never receives inputSchema, and compiling with and without it gives identical
verdicts on 100/100 pairs — closed-source clients were not instrumented, and
the doc says so); and the ensure_ascii footgun that inflated the first
published figures by 4.4% and forced a retraction.

README's card now links here instead of to a section heading.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WUL3ExR4Nz7uebxKaKwjDi
@VickyXAI
VickyXAI merged commit 8d7aba6 into main Sep 2, 2026
1 check passed
@VickyXAI
VickyXAI deleted the docs/schema-overhead branch September 2, 2026 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant