Skip to content

Local MCP servers inherit OPENCODE_SERVER_PASSWORD #52427

Closed as not planned
Closed as not planned

Description

@phetzy

Description

When opencode serve runs with OPENCODE_SERVER_PASSWORD (and optionally OPENCODE_SERVER_USERNAME) set, every local (type: "local") MCP server it starts receives both variables in its environment.

connectLocal in packages/opencode/src/mcp/index.ts (v1.18.32, 545f51d) builds the server's environment as:

env: {
  ...process.env,
  ...(cmd === "opencode" ? { BUN_BE_BUN: "1" } : {}),
  ...mcp.environment,
},

So any MCP server, including a third-party one from npm, can read the Basic Auth credential and call the opencode HTTP API with full access: send prompts, answer permission requests, read sessions. The password exists to keep other local processes out of the server, and the MCP server is exactly such a process.

Steps to reproduce

  1. Configure a local MCP server whose command prints its environment, for example ["sh", "-c", "env > /tmp/mcp-env; cat"].
  2. Run OPENCODE_SERVER_PASSWORD=secret opencode serve.
  3. Open a session so the MCP server starts.
  4. /tmp/mcp-env contains OPENCODE_SERVER_PASSWORD=secret.

Observed on opencode 1.18.32, macOS.

Expected

The server's own credentials are not passed to child processes it starts for tools. Removing OPENCODE_SERVER_PASSWORD and OPENCODE_SERVER_USERNAME from the inherited environment before mcp.environment is applied would keep an explicit per-server setting possible. The same likely applies to other children started with ...process.env (LSP servers, formatters, shell tools); those may deserve the same treatment.

A fork already does this: Kilo Code strips KILO_SERVER_PASSWORD and KILO_SERVER_USERNAME in packages/*/src/kilocode/process/env.ts.

Activity

  1. github-actions commented on Oct 1, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

  2. phetzy commented on Oct 1, 2026

    @phetzy
    Author

    Neither of the issues above was fixed. #14567 was closed automatically after 60 days without activity, and #31778 was closed while a later comment confirmed it still reproduced. On 1.18.32, connectLocal in packages/opencode/src/mcp/index.ts still builds the local MCP server environment as { ...process.env, ...mcp.environment }, so this report stands.

  3. thdxr commented on Oct 11, 2026

    @thdxr
    Member

    Thanks for the report! OpenCode 2.0 is now out and development is focused on V2, so we're closing issues filed against OpenCode 1. Please upgrade (opencode upgrade --major, details: https://anoma.ly/notes/opencode-2-0), and if this is still relevant on 2.0, reopen this issue or open a new one with your 2.0 version.

    — from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions