opencode patches SDK 2.4.0 to leave tools/list unchecked and checks each tool itself
Kind: idiosyncrasy · Status: current · Last verified: 2026-11-27 · Clients: opencode · Revisions: 2025-11-25, 2026-07-28
opencode pins @modelcontextprotocol/client, core and server at an exact 2.4.0. package.json and bun.lock register a patch against the client package only. script/upgrade-mcp-sdk.ts rebuilds the patch for each SDK release and names the opencode PR behind each edit.
What the patch changes
- The
tools/listresult schema becomestools: z.array(z.unknown())in the legacy codec and in both 2026-07-28 result shapes. The SDK returns listed tools without validating them. outputSchemais accepted when its root is nottype: "object".- The
x-mcp-headerscan tolerates a listed tool that is not an object. - An input-required request passes its own options to the handler as
mcpReq.origin. opencode uses this to route an elicitation to the caller that started the request. - OAuth metadata discovery URLs no longer carry the server URL's query string.
- A login that asks for
offline_accessno longer addsprompt=consent. RequestOptionsgainsonRequestId, and atimeoutofInfinitydisables the request timer.events/poll,events/stream,events/subscribeandevents/unsubscribesendMcp-Namefromparams.name.
Listed tools are checked in opencode
McpClient.connect calls listTools with cacheMode: "bypass" and checks each returned tool. A tool is skipped with a warning when it is not an object, has no non-empty string name, or has an inputSchema that is not an object or has a type other than "object". Fields of the wrong type on a kept tool are dropped. One malformed tool costs that tool, and the rest of the list survives with their outputSchema intact.
callTool passes its own copy of the tool definition with outputSchema removed. The SDK then skips its output validation, so a result that breaks the server's own schema does not fail the call.
Session recovery moved out of the patch
The 1.29.0 patch recovered an expired session inside the transport. The 2.4.0 patch has no such edit. failure in client.ts maps an SdkHttpError to SessionExpiredError when the transport holds a session id and the status is 404, or 400 with the body Bad Request: Server not initialized. McpConnection.recovering then stops the connection, starts a new one and runs the request once more. Tool calls, prompt gets, resource reads and resource listing go through it. A list-changed refresh that sees the expiry reconnects without a retry.
Sources
- patches/@modelcontextprotocol%2Fclient@2.4.0.patch, commit
5d1f7884,patches/@modelcontextprotocol%2Fclient@2.4.0.patch, 2026-11-27 - package.json and bun.lock, the patch registration, commit
5d1f7884,package.json, 2026-11-27 - script/upgrade-mcp-sdk.ts, the list of edits and the PR behind each, commit
5d1f7884,script/upgrade-mcp-sdk.ts:edits, 2026-11-27 - packages/core/src/mcp/client.ts, tools, commit
5d1f7884,packages/core/src/mcp/client.ts:connect, 2026-11-27 - packages/core/src/mcp/client.ts, failure, commit
5d1f7884,packages/core/src/mcp/client.ts:connect, 2026-11-27 - packages/core/src/mcp/connection.ts, recover and recovering, commit
5d1f7884,packages/core/src/mcp/connection.ts:make, 2026-11-27