completed tools and setup

This commit is contained in:
southseact-3d
2026-02-08 20:02:30 +00:00
parent 39136e863f
commit bd6817f697
5 changed files with 480 additions and 4 deletions

View File

@@ -235,6 +235,69 @@ export namespace Config {
result.compaction = { ...result.compaction, prune: false }
}
// Allow host applications to inject additional MCP servers at runtime.
// This is intentionally env-driven so tools can be loaded only when needed
// (e.g. a Builder feature toggle) without requiring writing config files.
const extraMcpRaw = process.env.OPENCODE_EXTRA_MCP_SERVERS
if (extraMcpRaw && typeof extraMcpRaw === "string") {
try {
const parsed = JSON.parse(extraMcpRaw)
if (Array.isArray(parsed)) {
result.mcp ??= {}
for (const entry of parsed) {
if (!entry || typeof entry !== "object") continue
const name = typeof (entry as any).name === "string" ? (entry as any).name.trim() : ""
if (!name) continue
const enabledFromEntry = (entry as any).enabled
const disabledFromEntry = (entry as any).disabled
const enabled =
typeof enabledFromEntry === "boolean"
? enabledFromEntry
: typeof disabledFromEntry === "boolean"
? !disabledFromEntry
: true
const env = (entry as any).env
const envRecord: Record<string, string> | undefined =
env && typeof env === "object" && !Array.isArray(env) ? (env as Record<string, string>) : undefined
const timeout = (entry as any).timeout
const timeoutMs = Number.isFinite(timeout) ? Math.max(0, Number(timeout)) : undefined
// Accept either { command: 'node', args: [...] } or { command: ['node', ...] }
const commandVal = (entry as any).command
const argsVal = (entry as any).args
const commandParts: string[] = Array.isArray(commandVal)
? commandVal.filter((x: any) => typeof x === "string" && x.length)
: typeof commandVal === "string" && commandVal.trim().length
? [commandVal.trim()]
: []
const argsParts: string[] = Array.isArray(argsVal) ? argsVal.filter((x: any) => typeof x === "string") : []
if (commandParts.length === 0) {
log.warn("Ignoring OPENCODE_EXTRA_MCP_SERVERS entry without command", { name })
continue
}
result.mcp[name] = {
type: "local",
command: [...commandParts, ...argsParts],
env: envRecord,
enabled,
...(timeoutMs !== undefined ? { timeout: timeoutMs } : {}),
}
}
} else {
log.warn("OPENCODE_EXTRA_MCP_SERVERS must be a JSON array; ignoring", { valueType: typeof parsed })
}
} catch (err) {
log.warn("Failed to parse OPENCODE_EXTRA_MCP_SERVERS; ignoring", { error: err instanceof Error ? err.message : String(err) })
}
}
result.plugin = deduplicatePlugins(result.plugin ?? [])
return {