Repository navigation
fix(opencode): write MCP secrets as {env:VAR} in the project opencode.json - #27
Merged
Merged
Conversation
….json
`profile apply opencode` (project scope) wrote MCP servers to
`<project>/opencode.json` with `${VAR}` placeholders already replaced by
the values from `.agent-ctrl/.env`. That file is meant to be committed,
so secrets ended up in the repository working tree.
MCP placeholders are resolved centrally in McpServerAggregator, so the
loader now also keeps the unresolved command, args, env and url. For
project scope the OpenCode adapter renders those with each `${VAR}`
written as OpenCode's `{env:VAR}`, which OpenCode substitutes from its
environment at run time, and warns which variables to export. The
private user-level ~/.config/opencode/opencode.json keeps resolved values.
Closes #24
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.
Closes #24
Problem
profile apply opencode(project scope) wrote MCP servers to<project>/opencode.jsonwith${VAR}placeholders already replaced by the values from.agent-ctrl/.env. The projectopencode.jsonis meant to be committed ("safe to be checked into Git", https://opencode.ai/docs/config/), so secrets ended up in the repository working tree.Change
McpServerAggregatorresolves placeholders centrally. It now also keeps the unresolvedcommand,args,envandurlof each server (unresolvedonMcpLoadedServerandApplyMcpServer, passed through byApplySourceLoaderandProfileScanner).${VAR}written as OpenCode's{env:VAR}. OpenCode substitutes{env:VAR}from its environment at run time (https://opencode.ai/docs/config/; MCP examples at https://opencode.ai/docs/mcp-servers/).-v:OpenCode reads these MCP values from the environment at run time; export them before starting opencode: TOKEN~/.config/opencode/opencode.json, private) keeps the resolved values, unchanged.docs/platforms/OPENCODE.md.Example output (
<project>/opencode.json):Behaviour change
OpenCode does not read
.agent-ctrl/.env. Project-scope MCP servers that use placeholders now need those variables exported in the shell that startsopencode; an unset variable becomes an empty string.Verification
OpenCodeAdapter.test.ts: project scope has no secret, uses{env:VAR}inenvironment,commandandurl, and warns with the variable name (failed before the fix); user scope keeps the resolved value.bun test: 1124 pass, 0 fail.scripts/lint.sh, Prettier (changed files),bun run buildpass.profile apply opencodein a throwaway project with a secret-using server: no secret anywhere in the project tree, placeholders as above, warning shown without-v.Not in this PR
{env:VAR}is not verified.