Skip to content

feat(mcp): add a declarative MCP tool server extension package - #625

Merged
jimhoyd merged 2 commits into
mainfrom
claude/mcp-extension
Sep 24, 2026
Merged

jimhoyd merged 2 commits into
mainfrom
claude/mcp-extension

Conversation

@jimhoyd

@jimhoyd jimhoyd commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Implements the triage decision on #573: a new optional operator-installed extension, @jimhoyd/urlcode-mcp, rather than a core route handler. Follows the packages/forms / packages/store conventions (schema, RuntimeExtension activation, own README/SECURITY.md/package.json).

  • The extension owns JSON-RPC 2.0 framing, protocol version negotiation, request-id handling and initialize/ping/tools/list/tools/call dispatch and error codes. Project YAML declares only bounded tools (name, description, a request.body.schema-shaped input schema, and a trusted project handler) — no JSON-RPC mechanics in project config.
  • Fixes the specific defect the issue's evidence reported: a hand-written implementation that used something other than the actual JSON-RPC request id as the response id. The response id here is always read verbatim from the request's own id field (any JSON-RPC-legal string/integer, or a notification with no id at all getting no response), covered explicitly by a dedicated test.
  • Tool input validation reuses core's bounded validator instead of reinventing it: packages/core/src/body-schema.ts is now also published as the public @jimhoyd/urlcode/body-schema subpath (assertBodySchema, bodySchemaIssues, bodySchemaLine) — the exact code request.body.schema itself runs.
  • Tool handlers are trusted project code, loaded through core's existing loadExtensionHooks/functionFile machinery (the same mechanism forms' onSubmit hook uses), rather than a second dynamic-import/path-resolution implementation.
  • Core's dependency boundary is unchanged: core never imports packages/mcp (scripts/check-core-boundaries.ts passes), and the new package resolves core through the same file:../.. workspace link scripts/check-workspace-links.ts enforces.

Design decisions

  • New package, not a core handler, per the triage decision.
  • Single JSON-RPC POST endpoint per declared "server" — a project can declare multiple named MCP servers, each with its own mount, serverName/serverVersion and bounded tools map (mirrors how store lets one extension serve multiple mounted collections). GET on the mount answers 405 (the MCP spec's own guidance when a server doesn't offer the optional SSE stream).
  • Minimal method surface: initialize, ping, tools/list, tools/call, plus accepting the notifications/initialized notification. Standard JSON-RPC error codes (-32700/-32600/-32601/-32602/-32603).
  • Host-owned error behavior: a thrown tool handler error never reaches the caller as written — it becomes a fixed generic isError: true tool result, and the real error is handed to an optional operator onToolError(error, {server, tool}) callback (best-effort; never affects the response). This is the explicit host-owned-error mechanism the triage decision called for.
  • Deliberately deferred (documented in packages/mcp/README.md "What this does not implement", and to be filed as follow-up issues): the Streamable HTTP transport's optional GET/SSE stream and Mcp-Session-Id resumption, JSON-RPC batching (removed by the 2025-06-18 MCP revision and refused outright here), the resources/prompts primitives, tool outputSchema/structuredContent, and tools/list pagination. This keeps the tool surface minimal ("MCP over HTTP becomes declarative", not a full-featured MCP server) as directed.
  • Distribution stays conservative: like forms and store before their promotion, @jimhoyd/urlcode-mcp ships private: true, workspace-only (no npm, no signed extension-bundles@v… release, no init --with scaffold). It's wired into verify:workspaces, the package-audit budget, and the CI workspace-verify/workspace-integration matrices, but intentionally left out of the signed-bundle composition system and the six-package pack-sources reproducible-build set — expanding those is a separate, larger decision out of this PR's scope.

CI wiring

  • package.json: verify:workspaces and verify:workspace-integration now include @jimhoyd/urlcode-mcp.
  • scripts/ci-plan.ts: mcp added to the workspace package matrix, dependency maps and path-classification regexes (no other package depends on it; it depends only on core).
  • .github/workflows/ci.yml: the workspace-integration job's build step now builds @jimhoyd/urlcode-mcp too.
  • scripts/package-audit.ts: budget entry for the new package (measured well under budget: ~13.7 KB packed / ~44 KB unpacked vs. a 45 KB / 140 KB budget).
  • test/ci-release.test.ts: updated to match the above.

Tests

  • packages/mcp/test/mcp.test.ts: 11 focused interoperability tests — a real HTTP round trip via startServer, covering initialize (protocol negotiation, exact request-id fidelity across every JSON-RPC-legal id shape), notifications/initialized (202, no body), tools/list, tools/call (success, schema-validation -32602 with structured issues, unknown-tool -32602, a thrown handler becoming a generic isError result while the real error reaches onToolError), protocol-level failures (-32700 parse error, -32600 invalid envelope/batching, -32601 unknown method), and transport-level rules (content-type, method, size, sub-path).
  • npm run typecheck, npm run build, npm run lint, npm run check (docs + code) all pass at the root.
  • npm run verify in packages/mcp passes (typecheck, build, test).
  • npm run audit:packages passes for all seven workspace packages.
  • Ran the full test/extensions.test.ts, test/http-policy.test.ts and test/ci-release.test.ts suites directly (34 + N + 23 tests, all passing) to confirm the new body-schema export and CI-plan changes don't regress existing extension/body-schema/CI-classification behavior.

What's left

Refs #573

🤖 Generated with Claude Code

Adds @jimhoyd/urlcode-mcp, a new optional operator-installed extension
following the packages/forms and packages/store conventions: the extension
owns JSON-RPC 2.0 framing, protocol version negotiation, exact request-id
round-tripping, and initialize/ping/tools-list/tools-call dispatch, while
project YAML declares only bounded tools (name, description, a
request.body.schema-shaped input schema, and a trusted project handler).

Fixes the specific defect the evidence in #573 reported (a hand-written
232-line JSON-RPC implementation that used something other than the actual
client-supplied JSON-RPC id as the response id): the response id is always
read verbatim from the request's own id field, of every JSON-RPC-legal
shape, and a message with no id (a notification) never gets a response.

Tool input validation reuses core's bounded body-schema validator instead of
reimplementing it: packages/core/src/body-schema.ts is now also published as
the public @jimhoyd/urlcode/body-schema subpath (assertBodySchema,
bodySchemaIssues, bodySchemaLine), the same code request.body.schema itself
runs. Tool handlers are trusted project code loaded via core's existing
loadExtensionHooks/functionFile machinery, matching forms' onSubmit hook.

Core's dependency boundary is preserved (core never imports packages/mcp);
the new package resolves core through the same file:../.. workspace link
scripts/check-workspace-links.ts enforces. mcp is wired into
verify:workspaces, the package-audit budget, and the CI workspace-verify/
workspace-integration matrices (scripts/ci-plan.ts, .github/workflows/ci.yml),
but is deliberately left out of the signed extension-bundles/init --with
composition system and the six-package pack-sources reproducible-build set:
like forms and store initially, it ships private and workspace-only.

Deferred (documented in packages/mcp/README.md "What this does not
implement" and tracked as follow-up issues): the Streamable HTTP transport's
optional GET/SSE stream and Mcp-Session-Id resumption, JSON-RPC batching
(removed by the 2025-06-18 MCP revision and refused outright here),
resources/prompts primitives, tool outputSchema/structuredContent, and
tools/list pagination.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts:
#	llms-full.txt
#	package.json
#	scripts/ci-plan.ts
#	test/ci-release.test.ts
@jimhoyd
jimhoyd merged commit 60978ac into main Sep 24, 2026
22 checks passed
@jimhoyd
jimhoyd deleted the claude/mcp-extension branch September 24, 2026 03:54
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