MCPcopy Create free account
hub / github.com/MatterAIOrg/OrbCode / addMcpServer

Function addMcpServer

src/mcp/config.ts:236–252  ·  view source on GitHub ↗
(cwd: string, name: string, config: McpServerConfig, scope: McpScope)

Source from the content-addressed store, hash-verified

234
235/** Add (or overwrite) a server in the given scope's config file. */
236export function addMcpServer(cwd: string, name: string, config: McpServerConfig, scope: McpScope): void {
237 if (!/^[A-Za-z0-9_-]+$/.test(name)) {
238 throw new Error(`Invalid server name "${name}". Use only letters, numbers, hyphens, and underscores.`)
239 }
240 if (scope === "project") {
241 const existing = readProjectMcpJson(cwd)
242 existing[name] = config
243 writeProjectMcpJson(cwd, existing)
244 } else {
245 const filePath = settingsPathForScope(cwd, scope)
246 const settings = readFullSettings(filePath)
247 const servers = normalizeServers(settings.mcpServers)
248 servers[name] = config
249 settings.mcpServers = servers
250 writeFullSettings(filePath, settings)
251 }
252}
253
254/** Remove a server from the given scope's config file. Returns true if it
255 * existed and was removed, false if it wasn't found. */

Callers 1

runAddFunction · 0.85

Calls 6

readProjectMcpJsonFunction · 0.85
writeProjectMcpJsonFunction · 0.85
settingsPathForScopeFunction · 0.85
readFullSettingsFunction · 0.85
normalizeServersFunction · 0.85
writeFullSettingsFunction · 0.85

Tested by

no test coverage detected