This repository was archived by the owner on May 18, 2026. It is now read-only.
fix: tool-retrieval MCP server crashes on startup (plain-object schema bug)#3
Merged
Merged
Conversation
… schema
setRequestHandler() in @modelcontextprotocol/sdk requires a Zod schema as
its first argument (ListToolsRequestSchema / CallToolRequestSchema), not a
plain object like { method: 'tools/list' }. Passing a plain object caused
the SDK to throw 'Schema is missing a method literal' synchronously during
server construction, so the process exited immediately on every mcp-serve
invocation.
Fixes:
- Use ListToolsRequestSchema and CallToolRequestSchema from the SDK's
types module in both setRequestHandler calls.
- Extract server setup into createMcpServer({ Server, ListToolsRequestSchema,
CallToolRequestSchema }) so it can be unit-tested without a real stdio
transport.
- Remove the module-level startServer() auto-call; export startServer()
explicitly and call it from bin/cli.js so requiring the module in tests
is safe.
Tests added (docs/tool-retrieval-mcp.feature + step-definitions):
- Zod schema validation: asserts setRequestHandler is called with proper
Zod schemas (not plain objects) using a mock Server + safeParse checks.
- list-tools wire protocol: full Client<->Server round-trip via
InMemoryTransport; asserts search_tools appears in the manifest.
- call-tool wire protocol: same in-process transport; asserts a valid
CallToolResult envelope is returned (empty corpus path, no embedder needed).
All 53 scenarios pass (234 steps).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
`opencode-workspace mcp-serve` exited immediately on every invocation with:
```
tool-retrieval-server: fatal error: Schema is missing a method literal
MCP error -32000: Connection closed local mcp startup failed
```
`Server.setRequestHandler()` in `@modelcontextprotocol/sdk` requires a Zod schema as its first argument. The code was passing a plain JavaScript object instead:
```js
// Before — crashes the server on startup
server.setRequestHandler({ method: 'tools/list' }, handler);
server.setRequestHandler({ method: 'tools/call' }, handler);
```
The SDK calls `getObjectShape(schema)` on the first argument. A plain object has no `.shape` or `._zod` property, so `shape?.method` is `undefined` and the SDK throws synchronously — killing the process before it can serve a single request.
Fix
Use the correct Zod schemas exported by the SDK:
```js
const { ListToolsRequestSchema, CallToolRequestSchema } =
await import('@modelcontextprotocol/sdk/types.js');
server.setRequestHandler(ListToolsRequestSchema, handler);
server.setRequestHandler(CallToolRequestSchema, handler);
```
Refactor (enables the new tests)
Tests added
All previously existing 50 scenarios still pass. Three new scenarios cover the layer that was completely untested:
53/53 scenarios pass, 234/234 steps pass.