Skip to content

Run the authoring MCP server on the official MCP SDK (#846, stdio) - #850

Merged
jimhoyd merged 8 commits into
mainfrom
claude/mcp-sdk-846
Sep 28, 2026
Merged

jimhoyd merged 8 commits into
mainfrom
claude/mcp-sdk-846

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 28, 2026

Copy link
Copy Markdown
Collaborator

Problem and change

First stage of #846: the local authoring MCP server (urlcode mcp, packages/core/src/mcp.ts) now uses the official MCP TypeScript SDK, @modelcontextprotocol/server 2.1.0 (MIT, the current stable v2 line). The handwritten protocol code is deleted: line framing, JSON-RPC parsing, lifecycle state, protocolVersion negotiation and ping.

URLCode keeps:

  • its tool catalog and schemas;
  • Ajv argument validation, with the messages that name the bad argument;
  • its dispatch;
  • its 1 MiB bounds.

The application HTTP server in packages/mcp is the second stage and is untouched here.

Glue the SDK needed (why mcp.ts is 230 lines, not shorter)

Three behaviours needed URLCode-side glue, found by tests:

  1. The stdio transport closes on stdin end and rejects later replies. A client that sends its requests and closes stdin, like the [Request]: Prove an embedded upstream auth provider in one local URLCode application #843 proof's MCP check and most test helpers, lost every reply that wasn't instant. Input now reaches the transport through a pipe the server ends only after every received call has answered.
  2. String chunks spin forever. StdioServerTransport retries this._buffer.subarray is not a function endlessly when a Readable yields strings, which pins a CPU core. Real stdin yields Buffers; serveMcp accepts any Readable, so chunks are normalized to Buffers. Worth reporting upstream.
  3. Concurrent dispatch. The SDK runs tools/call requests concurrently. create_route followed by run_validate then raced over the same file, and parallel compiles hit the compiler's capacity guard. Calls now run one at a time in arrival order, which is what the old server did.

Net: mcp.ts goes from 222 to 230 lines (+49/−45). Protocol ownership moved upstream, but owned lines did not shrink. The saving is in maintaining the protocol, not in lines.

Behaviour changes (no compatibility kept, per #841)

  • Requests sent before initialize are answered instead of refused with -32002; a second initialize is accepted.
  • Malformed JSON, batches, {} and invalid UTF-8 lines are ignored and the session continues; they no longer get -32700/-32600 replies.
  • An input message over 1 MiB ends the session with no reply (the old server sent an error first).
  • A tool result over 1 MiB is an isError result naming the limit (was a -32603 error).
  • Supported protocol revisions are whatever the pinned SDK supports (currently 2025-11-25 back to 2024-11-05, the same set as before).
  • Replies may come out of order across concurrent requests; tool calls themselves stay ordered. Test helpers now sort by id (byReplyId).
  • serverInfo.version still comes from one literal that release:bump rewrites; its regex now targets new Server({name:'urlcode',version:…}).

Legacy tool-name aliases (recipes_show and others) and the deprecated target argument alias are not removed here, to keep this reviewable. They are candidates for deletion under the no-compatibility decision.

Verification

  • New test/mcp-sdk-client.test.ts uses the official @modelcontextprotocol/client 2.1.0 (dev dependency) to spawn urlcode mcp over stdio. It checks:
    • init, list and call, with structuredContent;
    • -32602 for bad arguments, an unknown tool and authoring tools without the flag, each naming the problem;
    • an isError tool failure;
    • a client-side cancelled run_validate rejecting while the session keeps working.
  • test/mcp.test.ts: the three tests pinning handwritten framing are rewritten to the new rules (malformed frames ignored, oversized ends the session, a message split across bytes inside a UTF-8 character still parses).
  • npm run verify: exit 0, core npm test 1,100/1,100, workspace suites, audit:packages, test:addons, test:proof (its MCP runner check goes through the new server). npm run test:package passes.
  • Footprint: +3 runtime packages (@modelcontextprotocol/server, @modelcontextprotocol/core, zod), about 15.7 MiB installed (server 6.3, core 1.3, zod 8.0). Importing the SDK costs about 36 ms; importing dist/mcp.js takes about 165 ms. better-auth in the proof site already brings zod 4, so a site using it shares one copy.
  • Not run on Windows.

Compatibility and security

  • No YAML, schema, CLI flag or tool-surface change. Protocol edge behaviour changed as listed above.

  • Authority is unchanged: tool gating (--host-file, --allow-authoring, --policy), runner environments and project confinement are URLCode code paths the SDK does not touch.

  • New runtime dependencies are pinned exactly; the SDK's optional validators and HTTP pieces are not imported.

  • Changes match the documented portable contract; docs/examples are updated where needed.

  • Relevant tests and package checks pass, or limitations are explained above.

  • No credentials, customer data or private project material are included.

  • Runtime/starter changes remain aligned where applicable.

🤖 Generated with Claude Code

jimhoyd and others added 8 commits September 28, 2026 08:57
Adds proofs/private-requests: a packed-consumer site where Better Auth
1.7.6 on node:sqlite owns accounts, sessions and its tables, an operator
adapter mounts its native handler and turns its verified session into
the request principal and #840's request-bound `identity` capability,
and ordinary function routes implement owner-private requests and one
reviewer-only approval with parameterized SQL.

The adapter refuses before serving on a missing secret, an uninitialized
schema, an origin or basePath mismatch, telemetry left on, or a disabled
rate limiter; forwards only an exact allowlist of Better Auth paths
(disabledPaths misses parametric routes); and supplies the admitted client
address for throttling in a header it always overwrites.

test/private-requests.integration.ts (npm run test:proof) packs this
checkout, installs it into a copy of the site, and exercises setup,
explicit policy approval, provider/target refusals, declarative fixtures
with audit ready, and the HTTP flow including foreign-owner and reviewer
denial, malformed input, concurrent approval, cancellation, sign-out,
revocation and throttling.

Core: explain/report state that an extension mount's subpaths are
provider-defined and not inspected, and list the capabilities a
registration declares on the routes it protects.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tion

verify:workspaces and the workspace-integration job now run
npm run test:proof after test:addons. The proof packs the already-built
core with --ignore-scripts, like the other packaging tests, so prepare
never rebuilds dist under another test. Changes under proofs/ or to the
proof's test are high-impact, so they select that job on a pull request.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t a shell

On Windows the proof's behavior passed but teardown did not: separate
t.after hooks run in registration order, so the temp site was removed
while the served runtime still held its SQLite files (EBUSY), the
server-stop hook never ran, and the live child kept the test process
alive until the job timeout. One unwind stack now attempts every
closer, newest first. npm runs through npm_execpath under this Node, so
Windows needs no shell (DEP0190).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…thoring (#834)

bootstrap, context, explain, review, plan-feature and mcp accept the
operator's --policy. A verified policy pins the host file to its reviewed
projectSha256, so no PROJECT_SHA256 export is needed; bootstrap and
context repeat it in their emitted commands and drop it from
prerequisites. The MCP server verifies it once at startup and its
run_validate/run_test/run_audit runners forward the same file, and
run_tests uses its grants. No tool argument can name, create or change
a policy; an edited project still invalidates it until the operator
reviews and replaces the file.

An empty, unparseable or missing policy file is now named (#847).
bootstrap no longer offers the site's data/ directory for serving, and its
serving hint says operator code, credentials and data stay outside the
project.

The #843 proof now runs its connected MCP workflow: run_validate and
run_test pass on the packed site with only the operator's flags.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…text-834

# Conflicts:
#	proofs/private-requests/README.md
#	test/private-requests.integration.ts
Describe what the SDK now owns (lifecycle, framing, version negotiation,
JSON-RPC errors) and what URLCode keeps (tools, argument validation,
in-order calls, the 1 MiB bounds), and how malformed input, oversized
messages, closing stdin and client cancellation behave.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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