Repository navigation
Conversation
- A server's scope decides who shares a running instance: session (the default), space (sessions in one space) or app (every session). An instance is keyed by its scope and everything its connection is made from, so sessions resolving different settings never share one. - Exposure stays each session's own; sessions sharing an instance can declare different tools. - Each drain leases its session's instances. An instance no session uses closes at once; one no drain holds closes after an idle timeout (10 minutes, Harness option mcpIdleTimeout). - space servers start in the space's folder and are sent it as root on a local sandbox; app servers start where the app started, with no roots. - A session's servers keep their config order across exchanges, so a restarted server no longer moves its tools to the end. - Docs: sharing a server, and idle close. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… interrupts - An instance key includes the server's name, so two entries with the same settings are two instances and a renamed server never closes the instance its new name uses. - Leases count each instance once per session, so an alias can no longer drive a count negative and keep a server from idling out. - Reconcile updates every membership and lease count in one step and closes unused instances on their own, so an interrupted exchange cannot leave a shared instance holding a session it no longer has. - An instance that starts with no drain holding it still gets an idle timer. - Keys are canonical JSON, so the same env or headers in another order share an instance. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Every MCP failure is a Schema.TaggedError with the message the model reads, turned into a tool result only at the edge: - UnavailableError: disabled, shut down, not connected, needs sign-in, or a tool no longer offered. - ToolCallError: a tool call or resource request failed on the server. - ResourceError: unusable resource-tool arguments, or a server without resources. - ValueError: an env or headers value that does not resolve. - OutputError: output that could not be saved. Connect attempts fail with ConnectError. The text the model sees is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
codework run reads mcp.json next to the user settings, starts a stdio MCP server written against the wire protocol, declares its tool to a fake OpenAI-compatible provider with the server's schema, returns the call's result to the model, and stops the server when the CLI exits. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
mcp.json accepts every exposure Pi does: direct, hidden, codemode and deferred, with codemode-deferred read as codemode, so entries copied from Pi stay valid. Until codemode and tool_search exist, codemode and deferred tools are not declared and a session is warned once that they cannot be reached. Resource tools are declared when a server with resources is direct, and reach every server with resources that is not hidden. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Summary
Stacked on #81. Decides who shares a running MCP server and how long it lives. Until now every session ran its own servers until the process exited.
Scopes (
scopeinmcp.json, defaultsession)sessionspaceappsessionandspaceservers start inhostDir, elsehostCwd, and get no roots. MCP stays host-only.cwd,roots). Sessions that resolve different settings for a server, for example through different project files, never share it.Lifetime
runner/execute.ts, next to the mount).Harness.layeroptionmcpIdleTimeout. The next exchange that needs it starts it again.rehomeorabsorb, a session's next exchange resolves a different key and drops the old instance; an archived env's instances idle out.Also
Review fixes (Codex, gpt-6.1-sol high)
env/headersin another order share an instance.twin, a server withmine's exact settings. It runs as its own process, and everything still idles out.Tagged errors
Every MCP failure is now a
Schema.TaggedError(UnavailableError,ToolCallError,ResourceError,ValueError,OutputError; connect attempts useConnectError), as opencode does. The tool adapter turnserror.messageinto model text only at the edge. The model-facing text is unchanged, and no artifact moved.Pi's exposure values
mcp.jsonaccepts every exposure Pi does (direct,hidden,codemode,deferred, andcodemode-deferredas an alias), so entries copied from Pi stay valid.tool_searchexist,codemode/deferredtools aren't declared, and the session is warned once with Pi's wording.direct, and reach every server with resources that isn't hidden.directfor now, and flips tocodemode(Pi's default) with the codemode work.CLI end-to-end
packages/codework/test/cli.mcp.test.tsspawns the realcodework runwithmcp.json, a fake OpenAI-compatible provider and a hand-written stdio MCP server. It checks that:Artifact:
cli.mcp.json.Test plan
test/mcp.session.test.tsgets a new scope test, through the full harness with real stdio servers. Sessions A and B share a space and C is in another, each calling asession, aspaceand anappserver:session: three processesspace: A and B share one, C has its ownapp: one process for all threemcp.session.scopes.json, stable across runs.vp checkandvp run typecheck🤖 Generated with Claude Code