Repository navigation
feat(experimental): client-hosted MCP door, browser connect token and schema helper - #947
Merged
Merged
Conversation
ConnectClientMcp admits the connection immediately and keeps it alive the way opencode's client does: a capped 500 ms to 10 s retry schedule that resets only on notifications/initialized, a later factory failure reported through the retry callback, replies fenced to the socket that carried the request, and an asynchronous disposal that closes only its own socket and neither cancels nor joins application handlers. Three loopback-WebSocket proofs cover public admission, manual-schema capture and an attach that mints no ticket. The reviewed public API snapshot pins the experimental marks. Size against the upstream client (one .NET cost per row): - Connector, 38 lines: ClientWebSocket is configured before an asynchronous ConnectAsync, so construction and upgrade are separate entry points with a dispose-and-rethrow on a failed upgrade (about 16 lines); mapping the default platform's PlatformNotSupportedException while keeping a caller factory's synchronous exception costs about 9. - Dispatch, 80 lines: task-fault observation and completion snapshots cost about 20 lines; continuations and disposal can run on different pool threads, so retirement, admission and send acquisition share one lock (about 23). Single-writer serialization reuses the existing socket core. - Terminal adapter, 42 changed lines: keeping the existing constructor while admitting supplied and default sockets costs about 10 lines; applying setup headers with a dispose-and-rethrow when setup fails costs about 20; the disposal-observation callback about 4. The send-deadline proof records the 30-second timer count at physical send entry and asserts after release, so a finite-deadline mutant fails on every runtime without stranding test-owned I/O. The loopback exchange bounds its socket I/O with WaitAsync hang guards rather than a timed CancellationTokenSource.
Delegate through the experimental client's pipeline to the generated token route with the shared ticket sentinel. Preserve ordinary HTTP errors, NoThrow and caller cancellation. Register the generated consumer and add the cancellation identity row and additive API entry. Production size ledger (20 physical C# lines): - XML documentation: 9; explains ticket scope, root credentials, errors and explicit minting, against 12 documentation lines on the generated raw route. - Public signature: 3; the minimum extension door, against the raw route's single-line signature (3x). - Braces: 2; same two method braces as the raw route. - Argument guards: 2; one raw-request guard plus the extension receiver guard required by the public .NET boundary. - Pipeline and MockSeam resolution: 1; the minimum public door, replacing the raw client's constructor-held pipeline. - Raw delegation and fixed sentinel: 2; one call across two physical lines, against one generated pipeline call. - Separator: 1; keeps the two public methods distinct. No row exceeds 3x its generated-route plus minimum-door analogue. Tests add or substantively change 101 physical C# lines; the additive API snapshot is separate. No public subclient, root accessor, DTO or registration is added.
…wait for an upstream registration signal
Blind-Striker
force-pushed
the
feat/529-client-mcp
branch
from
November 17, 2026 06:14
d56bd67 to
c10e1b0
Compare
Merged
7 tasks done
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.
📝 Description
What does this PR do?
It adds the experimental client-hosted MCP door (
OPENCODE001). An application opens a WebSocket to the opencode server and serves its own tools there: the application is the MCP server, and opencode is the MCP client.ConnectClientMcp(onExperimentalClient) returns a caller-ownedClientMcpConnectionthat reconnects on its own.initialize,ping,tools/listandtools/call, following upstream's first-party client (packages/client/src/mcp.tsat the pinned v2.3.0).notifications/initializedresets it.CreateClientMcpConnectTokenAsyncmints the browser connect ticket. It is generated internal-raw HTTP behind a hand-written extension that supplies the fixedx-opencode-ticketsentinel.ClientMcpSchema.FromTypeexports an object input schema from source-generatedJsonTypeInfometadata, with no new dependency.client-runtime.md,protocol-and-generation.md, ADR-0021 and ADR-0031, the README, the CHANGELOG, the glossary and the roadmap.Related Issue(s):
WebSocketException. That affects the PTY doors; this door's tests characterize it.🔄 Type of Change
🎯 Protocol & API Surface
tests/OpenCode.Sdk.Tests/Snapshots/PublicApi.verified.txtis updated in this PR. Everything new carries[Experimental("OPENCODE001")]:ExperimentalClientMcpExtensions.ConnectClientMcp;ExperimentalClientMcpExtensions.CreateClientMcpConnectTokenAsync;ClientMcpConnection,ClientMcpOptions,ClientMcpTool,ClientMcpToolResult,ClientMcpContent,ClientMcpSchema;ClientMcpToolContext, with a publicClientMcpToolContext(string? sessionId)constructor, so handler authors can unit-test their handlers (public ClientMcpToolContext(string? sessionId) { });ExperimentalMcpClientTokenRequest/…Response.dotnet run --file tools/opencode-tool.cs -- generate --verifypassesspec/) is untouchedexternal/was hand-editedGenerator rules, for the generator owners' read. Canon (
protocol-and-generation.md):The generator owners' review found it clean: no defects and no drift from the rules or canon;
generate --verifyis current; no generated name or diagnostic changes.🧪 Testing
attach failed) and location reload (1012,location shut down);opencode serve: the pinned v2.3.0, run from source.net472/netstandard2.0). On .NET Framework, the 1012 case asserts the native close-code limit (net472: a server close with 1012 ends terminal sockets in a transport exception #934).✅ Completion Gate
quality-gates.mdpasses on the head rebased ontomaster: whitespace, format/style, clones, slopwatch, the release build, all test projects, the API snapshots,generate --verify, the fixed point, Extensions and Native AOT.📚 Documentation
README.mdupdateddocs/guide/updated: Client-hosted MCP and Browser handoff, with compiling snippetsCHANGELOG.mdentry added for user-facing changes✅ Code Quality Checklist
🔍 Additional Notes
Review. Three independent full-diff reviews found no correctness blocker; the README blocker they found is fixed here. The concurrency change (handlers deferred off the read loop) had two further independent reads.
Recorded divergence (approved by the maintainer). The frame decoder parses with
MaxDepth = 256, because the responder walks the document recursively when it formats names, and the bound keeps that recursion safe. A depth of 256 is accepted and 257 is refused, and a boundary test pins both. Upstream'sJSON.parsehas no limit. Before this change, System.Text.Json's default of 64 already bounded depth, so the question was which bound to record, not whether to have one.client-runtime.mdrecords it under the client-MCP responder:Deferred live proofs (#942). Two live rows wait for an upstream signal that a client-attached connection is registered:
The server registers the connection only after its handshake ends, and nothing public reports it.
Breaking Changes: none. Everything new is additive and experimental.
Dependencies: none added.