GeezerVison is showing github.com — feat(core): add runtime MCP controls by opencode-agent[bot] · Pull Request #37308 · anomalyco/opencode
Conversation
opencode-agent
Bot
commented
Jul 16, 2026
•
edited by rekram1-node
Loading
Uh oh!
There was an error while loading. Please reload this page.
Summary
- add or replace Location-scoped MCP servers at runtime from a full local or remote config
- connect, disconnect, and remove known MCP servers without persisting runtime state to config; remove deletes the entry and disposes its integration registration while keeping credential rows so re-adding the same server needs no re-auth
- preserve OAuth integration registration and credential-driven reconnects for dynamically added remote servers
- clear cached tools, prompts, and resources and publish lifecycle events when replacing or disconnecting a server
- serialize all lifecycle operations (startup, add, connect, disconnect, credential reconnect) per server with a
KeyedMutex<ServerName>; different servers stay concurrent
- route connection callbacks through the same lock with a single staleness guard (
whenLive) so late SDK callbacks and refreshes cannot commit state from a replaced connection
- settle a new entry's startup deferred even when
add fails or is interrupted, so readers awaiting startup can never hang
- fix
whenAllReady capturing a single-use Map iterator: the second query call skipped startup waiting entirely and never saw entries created by add
- store each remote server's integration registration on its entry and dispose it when
add replaces the server, instead of appending a permanent remove transform
This provides the core runtime operations used by V1 ACP while intentionally leaving protocol/server endpoints for a separate change.
Known trade-offs (reviewed, deliberately retained)
connect() shows the prior status during the handshake; no pending status or StatusChanged is published at connect/add admission time (UX nit)
- init-time registration is not batched (N remote servers cause N registry reloads at startup), and replacing a remote server materializes twice (dispose + re-register);
State.batch would coalesce
whenLive tool/prompt refreshes perform network I/O while holding the per-server lock — intentional; holding the lock through commit is what makes the staleness check sound (bounded by catalog timeout)
disconnect() sets status disabled without mutating config.disabled — mirrors V1 semantics; config disabled is only the startup default
- lock hold during connect is bounded by the startup timeout; a disconnect waits behind an in-flight connect
- the concurrency test is a probabilistic smoke test, not a deterministic race reproducer
- an interrupted
add() can leave the old entry stopped with a stale status until the next lifecycle op for that name (recoverable; making the section uninterruptible was judged not worth the complexity)
- disposed integration registrations leave a no-op finalizer in the root scope (idempotent, tiny)
- the register/dispose integration path has no direct test coverage (the test layer's Integration mock dies on use); correctness was traced through
State semantics in review
- the initial startup fork carries no staleness guard: verified empirically that forked fibers acquire their per-server lock synchronously inside
fork() during layer construction, before the Service object exists, so no runtime operation can win that race
Tests
bun test test/mcp.test.ts (packages/core), including a lifecycle-race smoke test and NotFoundError coverage
bun typecheck (packages/core)
- scoped oxlint and Effect pattern scan
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Jul 18, 2026
This was referenced Jul 18, 2026
paperview
added a commit
to paperview/opencode_ex
that referenced
this pull request
Jul 18, 2026
Additions supporting the sync_server chatbot bridge against our
patched opencode daemon (paperview/opencode:paperview-stable):
- New OpencodeEx.MCP module: `status/2`, `add/4`, `disconnect/2`,
`connect/2`. Wraps the runtime MCP endpoints introduced in
anomalyco/opencode#37308. Accepts `directory:` keyword for
workspace-scoped operations (`?directory=...`).
- `OpencodeEx.Session.create/2` accepts `directory:` for scoping the
session to a specific instance. Runtime MCP entries added with the
same directory become visible to that session's tool registry.
- `OpencodeEx.Session.prompt/4` accepts `tool_choice:` ("auto" |
"required" | "none"). Serialized as `toolChoice` on the request
body. Silently ignored by stock upstream (unknown field on legacy
endpoint); honored on our patched fork via
anomalyco/opencode#37678.
Backward-compatible: default paths and bodies unchanged when the new
options are unset.
Uh oh!
There was an error while loading. Please reload this page.
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|