Repository navigation
Closed as not planned
Description
Description
OpenCode does not pass the env block from mcp.<name>.env in opencode.json to locally spawned MCP server processes.
When configuring a local MCP server (e.g., mcp-searxng) with an env block like:
"mcp": {
"searxng": {
"type": "local",
"command": ["npx", "-y", "mcp-searxng"],
"enabled": true,
"env": {
"SEARXNG_URL": "http://localhost:47820"
}
}
}The child process inherits OpenCode's own environment instead of receiving the configured SEARXNG_URL. This causes the MCP server to start successfully (stdio connection established, tools registered), but fail at runtime when it tries to read process.env.SEARXNG_URL and finds it undefined.
I verified this by:
- Confirming
SEARXNG_URLis present in theopencode.jsonconfig. - Checking
/proc/<opencode_pid>/environ—SEARXNG_URLis not present in OpenCode's own environment. - Checking
/proc/<mcp-searxng_pid>/environ—SEARXNG_URLis not present in the spawned MCP server either. - Manually setting
export SEARXNG_URL=http://localhost:47820before starting OpenCode resolves the issue, confirming the bug is in env propagation, not the MCP server itself.
Plugins
None
OpenCode version
1.16.0
Steps to reproduce
- Configure a local MCP server in
opencode.jsonwith anenvblock:{ "mcp": { "searxng": { "type": "local", "command": ["npx", "-y", "mcp-searxng"], "enabled": true, "env": { "SEARXNG_URL": "http://localhost:47820" } } } } - Ensure the
SEARXNG_URLenvironment variable is not set in your shell before starting OpenCode. - Start OpenCode and try to use the MCP tool (e.g.,
searxng_searxng_web_search). - Observe the error:
⚠️ Configuration Issues: SEARXNG_URL not set... - Check the spawned MCP process environment:
cat /proc/$(pgrep -f mcp-searxng)/environ | tr '\0' '\n' | grep SEARXNG— it will be empty. - Stop OpenCode, run
export SEARXNG_URL=http://localhost:47820, restart OpenCode — the tool now works.
Screenshot and/or share link
N/A
Operating System
WSL Linux (Ubuntu 24.04.4 LTS)
Terminal
Windows Terminal
Metadata
Metadata
Assignees
Labels
No labels
Activity
github-actions commentedon Jun 5, 2026
This issue might be a duplicate of existing issues. Please check:
envconfig not passed to spawned child process (same root cause, same workaround, same behavior)fix(opencode): accept 'env' as alias for 'environment' in MCP local c…
github-actions commentedon Aug 5, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.