MCPcopy Index your code
hub / github.com/anomalyco/opencode / addMcpToConfig

Function addMcpToConfig

packages/opencode/src/cli/cmd/mcp.ts:412–427  ·  view source on GitHub ↗
(name: string, mcpConfig: ConfigMCPV1.Info, configPath: string)

Source from the content-addressed store, hash-verified

410}
411
412async function addMcpToConfig(name: string, mcpConfig: ConfigMCPV1.Info, configPath: string) {
413 let text = "{}"
414 if (await Filesystem.exists(configPath)) {
415 text = await Filesystem.readText(configPath)
416 }
417
418 // Use jsonc-parser to modify while preserving comments
419 const edits = modify(text, ["mcp", name], mcpConfig, {
420 formattingOptions: { tabSize: 2, insertSpaces: true },
421 })
422 const result = applyEdits(text, edits)
423
424 await Filesystem.write(configPath, result)
425
426 return configPath
427}
428
429export const McpAddCommand = effectCmd({
430 command: "add [name]",

Callers 1

mcp.tsFile · 0.85

Calls 2

writeMethod · 0.80
existsMethod · 0.45

Tested by

no test coverage detected