Repository navigation
feat(client): add connectClientMcp helper for client-hosted MCP tools - #57504
Merged
Merged
Conversation
This was referenced Oct 20, 2026
jlongster
force-pushed
the
client-mcp-helper
branch
from
October 20, 2026 19:29
d4119fc to
19a177f
Compare
jlongster
force-pushed
the
client-mcp-attach
branch
from
October 20, 2026 19:37
9f06040 to
9a90fc2
Compare
jlongster
force-pushed
the
client-mcp-helper
branch
from
October 20, 2026 19:37
19a177f to
246bd2e
Compare
jlongster
force-pushed
the
client-mcp-transport
branch
from
October 22, 2026 18:53
9e8f20c to
3d7233f
Compare
jlongster
force-pushed
the
client-mcp-helper
branch
from
October 22, 2026 19:02
54e272c to
b315124
Compare
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Stack 3/5, based on
client-mcp-attach. Merge in order.Part of the client MCP stack (experimental): a client (TUI/desktop/web) opens a WebSocket to the server, and the server treats that incoming socket as an internal MCP server scoped to a location. Tool calls carry
_meta["ai.opencode/sessionID"]so the client acts on the calling session. MCP has no official WebSocket transport, so this is a custom transport, which the spec allows.This PR
Adds
@opencode/client/mcp, a separate subpath that doesn't import core or server and has no runtime dependencies:connectClientMcp({ url, name, directory?, headers?, tools })opens the WebSocket, serves the tools, and reconnects with backoff (0.5s → 10s, reset once the server sendsnotifications/initialized){ name, description?, inputSchema? (JSON Schema), handler(args, ctx) }.ctx.sessionIDholds the calling session@modelcontextprotocol/server. It only answers what core's attached MCP client uses:initialize(echoes the requested legacy protocol version),ping,tools/listandtools/call. Unknown tools get-32602, unknown methods get-32601, a handler that throws returns anisError: trueresult, and malformed frames are ignoredinputSchemabefore callingUsing a hand-written server instead of the SDK and zod shrinks the minified browser bundle of
@opencode/client/mcpfrom 251 KB (64 KB gzip) to 2.1 KB (1.1 KB gzip). It also keeps them out of every@opencode/clientinstall.@modelcontextprotocol/clientis only a dev dependency.Tests run a Bun WebSocket server acting as the opencode server, and the real MCP SDK client talks to the hand-written server. They cover the handshake, listing, calls with and without a session ID, errors, reconnects and backoff.
Stack
→ 3. feat(client): add connectClientMcp helper for client-hosted MCP tools #57504 feat(client): add connectClientMcp helper for client-hosted MCP tools