FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix(mcp): pass configured server env block to child process (#49983) by omid-io · Pull Request #49998 · anomalyco/opencode · GitHub

fix(mcp): pass configured server env block to child process (#49983) - #49998

Open
omid-io wants to merge 1 commit into
anomalyco:devfrom
omid-io:fix/mcp-server-env-passthrough
Open

omid-io wants to merge 1 commit into
anomalyco:devfrom
omid-io:fix/mcp-server-env-passthrough

Conversation

omid-io commented Sep 19, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #49983

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When configuring a local MCP server in opencode.jsonc with an env block (the standard key used by Claude Desktop, Cursor, and OpenCode's own LSP config), the environment variables were not being passed to the spawned child process.

Root causes:

  1. Local schema in packages/core/src/v1/config/mcp.ts and packages/core/src/config/mcp.ts only accepted environment, causing Effect Schema's decode with onExcessProperty: "ignore" to strip env.
  2. ConfigV2Compat.lower in packages/opencode/src/config/v2-compat.ts similarly omitted env from the intermediate Server schema.
  3. connectLocal in packages/opencode/src/mcp/index.ts only spread ...mcp.environment when constructing StdioClientTransport.

Fix:

  • Added env as an optional string record in V1 and V2 Local MCP schemas and Server in v2-compat.ts.
  • Forwarded env in migrateMcp.
  • Merged both ...mcp.environment and ...mcp.env into the child process environment in connectLocal.

How did you verify your code works?

  • Added unit tests in packages/opencode/test/config/v2-compat.test.ts verifying env preservation in both flat and enveloped MCP configs.
  • Added an end-to-end unit test in packages/opencode/test/mcp/lifecycle.test.ts verifying that TEST_MCP_ENV_VAR configured via env is received by the spawned child process MCP server.
  • Ran test suites:
    • bun test test/config/v2-compat.test.ts (37/37 pass)
    • bun test test/mcp/lifecycle.test.ts (22/22 pass)
    • bun test test/mcp (62/62 pass across 10 files)
    • bun test packages/core/test/config/config.test.ts (15/15 pass)
  • Ran oxlint with 0 errors.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] MCP server env block from opencode.jsonc not passed to child process

1 participant


Back | FazBrowse Home | New Git URL