Skip to content

[FEATURE]: Support file-based secrets in MCP server env configuration #21662

@malikwirin

Description

@malikwirin

Feature hasn't been suggested before.

  • I have verified this feature I'm about to request hasn't been suggested before.

Describe the enhancement you want to request

Problem

OpenCode's MCP server configuration accepts env values as literal strings.
This makes it incompatible with secret managers that expose secrets as files on disk rather than as host environment variables — such as sops-nix, systemd credentials, Docker secrets, or pass.

With file-based secret managers, secrets are decrypted at runtime and written to paths like /run/secrets/my_token. They are never present as environment variables in the OpenCode process itself, so there is currently no way to inject them into MCP server environments.

Proposed Solution

Introduce an env_files key in the MCP server config that maps environment variable names to file paths. OpenCode would read the file contents and set the variable before spawning the MCP server process — no shell involved:

"codeberg": {
  "type": "local",
  "command": "/path/to/forgejo-mcp",
  "args": ["transport", "stdio", "--url", "https://codeberg.org"],
  "env_files": {
    "FORGEJO_ACCESS_TOKEN": "/run/secrets/codeberg_token"
  }
}

Why not use host environment variables?

File-based secret managers like sops-nix or systemd credentials do not populate the host environment. The secrets only exist as files at runtime and are not accessible via process.env in the OpenCode process.

Related

A similar request exists for charmbracelet/crush:
charmbracelet/crush#2334

Alternatives Considered

  • Wrapper shell scripts per MCP server — functional but requires boilerplate outside the config and complicates NixOS/Home Manager module integration
  • Storing secrets as host env vars — not applicable for file-based managers

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)discussionUsed for feature requests, proposals, ideas, etc. Open discussion

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions