fix(opencode): accept 'env' as alias for 'environment' in MCP local config#31317
Open
sulthonzh wants to merge 2 commits into
Open
fix(opencode): accept 'env' as alias for 'environment' in MCP local config#31317sulthonzh wants to merge 2 commits into
sulthonzh wants to merge 2 commits into
Conversation
When an MCP server process dies or the HTTP transport drops, the client was left in connected state with stale tool definitions. No reconnect was attempted, so tools permanently vanished for the session. Register an onclose handler on each MCP client that: - Detects unexpected transport closure (not intentional disconnect) - Marks the server as failed and clears cached defs - Re-creates the client via createAndStore() using the original config - Publishes ToolsChanged event so the UI updates Guard all intentional close paths (disconnect, finalizer, closeClient) by deleting s.clients[name] BEFORE calling client.close(), so the onclose handler sees s.clients[name] !== client and returns early. Fixes anomalyco#17099
…onfig Users writing 'env' in opencode.json MCP config (matching MCP spec convention) had their variables silently dropped because the schema only accepted 'environment'. This caused MCP servers to start but fail at runtime when reading process.env. Add 'env' as an optional field in ConfigMCPV1.Local schema. In connectLocal(), spread mcp.env after mcp.environment so env takes precedence when both are present. Fixes anomalyco#30892 Closes anomalyco#26332
a28f4d0 to
f061bf5
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.
Issue for this PR
Closes #30892
Closes #26332
Type of change
What does this PR do?
Users configuring MCP servers with
"env": { "KEY": "value" }in opencode.json had their variables silently dropped because the schema only accepted"environment". The MCP spec and most documentation examples useenv, so this is a common user error that produces no warning.The schema now accepts both
envandenvironmentas optional fields on local MCP config. InconnectLocal(),mcp.envis spread aftermcp.environmentsoenvtakes precedence when both are present.How did you verify your code works?
env field in local MCP config is passed to spawned process— configures a local MCP withenvfield, verifies the transport receives the env vars in its options"env": { "MY_VAR": "test" }in opencode.json MCP config, start OpenCode, verify the spawned process hasMY_VARin its environmentScreenshots / recordings
N/A — no UI changes.
Checklist