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

Function runAdd

src/commands/mcp.ts:203–267  ·  view source on GitHub ↗

`orbcode mcp add` — build a server config from flags and write it.

(args: string[])

Source from the content-addressed store, hash-verified

201
202/** `orbcode mcp add` — build a server config from flags and write it. */
203function runAdd(args: string[]): number {
204 let parsed
205 try {
206 parsed = parseAddFlags(args)
207 } catch (error) {
208 console.error((error as Error).message)
209 return 1
210 }
211 const { scope, transport, env, headers, oauth, positional } = parsed
212
213 if (positional.length === 0) {
214 console.error("Missing server name. Usage: orbcode mcp add <name> <command> [args...]")
215 return 1
216 }
217 const [name, ...rest] = positional
218
219 let config: McpServerConfig
220 if (transport === "http" || transport === "sse") {
221 if (rest.length === 0) {
222 console.error(`Missing URL for ${transport} transport. Usage: orbcode mcp add -t ${transport} <name> <url>`)
223 return 1
224 }
225 const url = rest[0]!
226 const cfg: McpHttpServerConfig | McpSseServerConfig = { type: transport, url }
227 if (Object.keys(headers).length > 0) cfg.headers = headers
228 if (oauth !== false) cfg.oauth = oauth
229 config = cfg
230 } else {
231 // stdio
232 if (rest.length === 0) {
233 console.error("Missing command for stdio transport. Usage: orbcode mcp add <name> <command> [args...]")
234 return 1
235 }
236 const [command, ...cmdArgs] = rest
237 const cfg: McpStdioServerConfig = { type: "stdio", command: command! }
238 if (cmdArgs.length > 0) cfg.args = cmdArgs
239 if (Object.keys(env).length > 0) cfg.env = env
240 config = cfg
241 }
242
243 let detail: string
244 if (transport === "http" || transport === "sse") {
245 const cfg = config as McpHttpServerConfig | McpSseServerConfig
246 detail = `${transport} ${cfg.url}`
247 } else {
248 const cfg = config as McpStdioServerConfig
249 detail = `stdio ${cfg.command}${cfg.args?.length ? " " + cfg.args.join(" ") : ""}`
250 }
251
252 try {
253 addMcpServer(process.cwd(), name!, config, scope)
254 } catch (error) {
255 console.error((error as Error).message)
256 return 1
257 }
258
259 const filePath = configPathForScope(process.cwd(), scope)
260 console.log(`Added ${transport === "http" || transport === "sse" ? transport.toUpperCase() : "stdio"} MCP server ${name}`)

Callers 1

runMcpCommandFunction · 0.85

Calls 3

parseAddFlagsFunction · 0.85
addMcpServerFunction · 0.85
configPathForScopeFunction · 0.85

Tested by

no test coverage detected