---
id: opencode-checks-listed-tools-itself-on-a-patched-sdk
title: opencode patches SDK 2.4.0 to leave tools/list unchecked and checks each tool itself
kind: idiosyncrasy
summary: opencode applies a bun patch to @modelcontextprotocol/client 2.4.0. The patch stops the SDK validating listed tools, so opencode checks each one and skips only the malformed ones. Session recovery on a 404 is in opencode's own code.
capabilities:
  - tools
  - transports.streamableHttp
clients:
  - opencode
specVersions:
  - 2025-11-25
  - 2026-07-28
sources:
  - url: https://github.com/anomalyco/opencode
    title: patches/@modelcontextprotocol%2Fclient@2.4.0.patch
    commit: 5d1f7884
    path: patches/@modelcontextprotocol%2Fclient@2.4.0.patch
    date: 2026-11-27
  - url: https://github.com/anomalyco/opencode
    title: package.json and bun.lock, the patch registration
    commit: 5d1f7884
    path: package.json
    date: 2026-11-27
  - url: https://github.com/anomalyco/opencode
    title: script/upgrade-mcp-sdk.ts, the list of edits and the PR behind each
    commit: 5d1f7884
    path: script/upgrade-mcp-sdk.ts:edits
    date: 2026-11-27
  - url: https://github.com/anomalyco/opencode
    title: packages/core/src/mcp/client.ts, tools
    commit: 5d1f7884
    path: packages/core/src/mcp/client.ts:connect
    date: 2026-11-27
  - url: https://github.com/anomalyco/opencode
    title: packages/core/src/mcp/client.ts, failure
    commit: 5d1f7884
    path: packages/core/src/mcp/client.ts:connect
    date: 2026-11-27
  - url: https://github.com/anomalyco/opencode
    title: packages/core/src/mcp/connection.ts, recover and recovering
    commit: 5d1f7884
    path: packages/core/src/mcp/connection.ts:make
    date: 2026-11-27
status: current
lastVerified: 2026-11-27
related:
  - opencode-patches-its-sdk-for-session-recovery
  - opencode-retries-tools-list-without-output-schema
canonical: https://canimcp.io/research/opencode-checks-listed-tools-itself-on-a-patched-sdk
last-updated: 2026-11-27
---

> **Alpha: work in progress. canimcp is an alpha, built by one person and changing often. Statuses, notes and probe results may be incomplete or inaccurate, and pages, data and the API can change without notice. Check the cited source before relying on a claim, and send corrections through the [contact page](https://canimcp.io/contact).**

# 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](/clients/opencode.md) · 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/list` result schema becomes `tools: z.array(z.unknown())` in the legacy codec and in both 2026-07-28 result shapes. The SDK returns listed tools without validating them.
- `outputSchema` is accepted when its root is not `type: "object"`.
- The `x-mcp-header` scan 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_access` no longer adds `prompt=consent`.
- `RequestOptions` gains `onRequestId`, and a `timeout` of `Infinity` disables the request timer.
- `events/poll`, `events/stream`, `events/subscribe` and `events/unsubscribe` send `Mcp-Name` from `params.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](https://github.com/anomalyco/opencode), commit `5d1f7884`, `patches/@modelcontextprotocol%2Fclient@2.4.0.patch`, 2026-11-27
- [package.json and bun.lock, the patch registration](https://github.com/anomalyco/opencode), commit `5d1f7884`, `package.json`, 2026-11-27
- [script/upgrade-mcp-sdk.ts, the list of edits and the PR behind each](https://github.com/anomalyco/opencode), commit `5d1f7884`, `script/upgrade-mcp-sdk.ts:edits`, 2026-11-27
- [packages/core/src/mcp/client.ts, tools](https://github.com/anomalyco/opencode), commit `5d1f7884`, `packages/core/src/mcp/client.ts:connect`, 2026-11-27
- [packages/core/src/mcp/client.ts, failure](https://github.com/anomalyco/opencode), commit `5d1f7884`, `packages/core/src/mcp/client.ts:connect`, 2026-11-27
- [packages/core/src/mcp/connection.ts, recover and recovering](https://github.com/anomalyco/opencode), commit `5d1f7884`, `packages/core/src/mcp/connection.ts:make`, 2026-11-27

## Related notes

- [opencode-patches-its-sdk-for-session-recovery](/research/opencode-patches-its-sdk-for-session-recovery.md)
- [opencode-retries-tools-list-without-output-schema](/research/opencode-retries-tools-list-without-output-schema.md)
