Migrate MCP server to SDK v2 and fix the bundle that never booted
The plugin ships dist/mcp/server.js as its MCP entry point, and that bundle
could not start at all: it threw "TypeError: ... is not a constructor" while
loading and never answered a request. MCP defaults to off, so enabling it
produced no seal_cli tool and no visible error.
Root cause: src/server.ts is circularly entangled with the CLI command graph
(server -> cli/runner -> cli/commands/mcp -> server, and
server -> cli/runner -> cli/commands/http -> http/routes -> server). When
bun build --target=node flattened that cycle together with zod's own
core <-> classic cycle, zod's class initialisers landed after the top-level
z.lazy() call the SDK makes at import time, leaving ZodLazy undefined.
Not fixable by changing targets: --target=bun, --compile, and dropping
--minify all fail the same way. Only removing the cycles fixes it.
- Moved tokenizeCommand / normalizeCliArgs to a leaf module (src/cli/tokenize.ts)
and made the mcp command import the server lazily, removing both cycles.
- Added a test that boots the packaged bundle over stdio and completes a
handshake; the existing tests exercise source, not the shipped artifact,
which is why this went unnoticed. Verified it fails on the old bundle.
- Committed the rebuilt dist/mcp/server.js, since the previously committed
artifact is the broken one.
Also migrated the monolithic @modelcontextprotocol/sdk v1 to the v2 split
packages (@modelcontextprotocol/server for the server,
@modelcontextprotocol/client for tests):
- Low-level Server + setRequestHandler -> high-level McpServer + registerTool;
hand-written JSON Schema -> z.strictObject (still emits
additionalProperties: false).
- Added the title and annotations clients could not previously see:
readOnlyHint false, destructiveHint true, idempotentHint false,
openWorldHint true. seal_cli is a passthrough that can reach mutating verbs,
so it must not be advertised as safe to auto-run or safe to retry; the
description now names the command families needing user confirmation.
- startServer uses serveStdio, which owns protocol-era negotiation
(2025-era clients keep working) and teardown.
- .mcp.json uses the ZCode-native ${ZCODE_PLUGIN_ROOT}; verified in ZCode's
resolver that CLAUDE_PLUGIN_ROOT and ZCODE_PLUGIN_ROOT are the same alias.
Dropping the v1 SDK removes express, hono, cors and ajv from the dependency
graph (bun.lock -149 lines).
This commit is contained in:
1 parent
ac779cad88
commit
524259c67c
11 files changed
+530
-549
No files matched your search
@@ -1,4 +1,3 @@
|
||||
import { startServer } from "../../server.js";
|
||||
import { printJson } from "../printer.js";
|
||||
import type { ParsedArgs } from "../types.js";
|
||||
|
||||
@@ -8,7 +7,8 @@ export async function handleMcpCommand(action: string | undefined, args: ParsedA
|
||||
return;
|
||||
}
|
||||
|
||||
await startServer();
|
||||
const { startServer } = await import("../../server.js");
|
||||
startServer();
|
||||
}
|
||||
|
||||
export function printMcpConfig() {
|
||||
|
||||
Reference in new issue
Block a user