Skip to content

Commit 6737be5

Browse files
jorgenclawclaude
andcommitted
fix(opencode): resolve MCP env placeholders and unbreak the bash tool for local models
container.json's mcpServers.<name>.env can reference `${VAR_NAME}` placeholders so secrets aren't duplicated into the DB-persisted config — the real value lives in the container's own process env instead. Nothing ever resolved these; every provider passed the env map straight through to the MCP subprocess, so it received the literal unexpanded string as its credential. Proton mail auth was failing with "no such user" — not a signed-out account, just proton-mcp logging in with the literal text "${PROTON_BRIDGE_PASSWORD}". Resolve placeholders in agent-runner's index.ts, the one point every provider's mcpServers config flows through before spawn. OpenCode's bash tool schema requires a `description` field that local/Ollama models (Qwen here) don't reliably emit, failing every bash call with a Zod validation error before the command runs. Confirmed against upstream (anomalyco/opencode#13146, #24003) — both closed NOT_PLANNED, since OpenCode's maintainers consider the schema correct and the gap model-specific, so no version bump fixes it. Added container/opencode-notes.md to the opencode provider's instructions set so the model is explicitly told to always include it. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01KmVSSumuigQ8QyLM4z8Nym
1 parent 42f2120 commit 6737be5

4 files changed

Lines changed: 46 additions & 1 deletion

File tree

‎container/agent-runner/src/index.ts‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,34 @@ import './providers/index.js';
3636
import { createProvider, type ProviderName } from './providers/factory.js';
3737
import { runPollLoop } from './poll-loop.js';
3838

39+
/**
40+
* container.json's mcpServers.<name>.env can reference the container's own
41+
* process env via `${VAR_NAME}` placeholders (e.g. Proton Bridge auth, kept
42+
* out of the DB-persisted config so the plaintext secret isn't duplicated
43+
* there). Nothing downstream resolves these — providers pass the env map
44+
* straight through to the MCP subprocess — so without this step the
45+
* subprocess receives the literal, unexpanded string as its credential.
46+
* Resolve here, the single point every provider's mcpServers config flows
47+
* through before spawn.
48+
*/
49+
function resolveEnvPlaceholders(env: Record<string, string>): Record<string, string> {
50+
const resolved: Record<string, string> = {};
51+
for (const [key, value] of Object.entries(env)) {
52+
const match = /^\$\{([A-Z0-9_]+)\}$/.exec(value);
53+
if (!match) {
54+
resolved[key] = value;
55+
continue;
56+
}
57+
const resolvedValue = process.env[match[1]];
58+
if (resolvedValue === undefined) {
59+
log(`Warning: MCP env placeholder ${value} has no matching process env var — leaving unset`);
60+
continue;
61+
}
62+
resolved[key] = resolvedValue;
63+
}
64+
return resolved;
65+
}
66+
3967
function log(msg: string): void {
4068
console.error(`[agent-runner] ${msg}`);
4169
}
@@ -93,7 +121,7 @@ async function main(): Promise<void> {
93121
};
94122

95123
for (const [name, serverConfig] of Object.entries(config.mcpServers)) {
96-
mcpServers[name] = serverConfig;
124+
mcpServers[name] = { ...serverConfig, env: resolveEnvPlaceholders(serverConfig.env) };
97125
log(`Additional MCP server: ${name} (${serverConfig.command})`);
98126
}
99127

‎container/agent-runner/src/providers/opencode.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ function buildOpenCodeConfig(options: ProviderOptions): Record<string, unknown>
238238
// by OpenCode, so point at the concrete files, not at composed CLAUDE.md.
239239
const instructions = [
240240
'/app/CLAUDE.md',
241+
'/app/opencode-notes.md',
241242
'/workspace/agent/.claude-fragments/*.md',
242243
'/workspace/agent/CLAUDE.local.md',
243244
];

‎container/opencode-notes.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## bash tool: `description` is required
2+
3+
The `bash` tool's schema requires a `description` parameter (a short, 5-10 word summary of what the command does) alongside `command` — even though it is not always shown to you as required. Omitting it fails the call with a schema validation error before the command ever runs.
4+
5+
Correct: `bash(command="ls -la", description="List current directory files")`
6+
Wrong: `bash(command="ls -la")` — fails with `description: Invalid input: expected string, received undefined`
7+
8+
Always include `description` on every `bash` call.

‎src/container-runner.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,14 @@ export function buildMounts(
337337
mounts.push({ hostPath: sharedClaudeMd, containerPath: '/app/CLAUDE.md', readonly: true });
338338
}
339339

340+
// OpenCode-specific tool notes — read-only, pulled into the instructions
341+
// array unconditionally by the opencode provider (container path is fixed;
342+
// harmless no-op for other providers since nothing references it there).
343+
const opencodeNotes = path.join(process.cwd(), 'container', 'opencode-notes.md');
344+
if (defaultSurfaces && fs.existsSync(opencodeNotes)) {
345+
mounts.push({ hostPath: opencodeNotes, containerPath: '/app/opencode-notes.md', readonly: true });
346+
}
347+
340348
// Per-group .claude-shared at /home/node/.claude (Claude state, settings,
341349
// skill symlinks)
342350
if (defaultSurfaces) {

0 commit comments

Comments
 (0)