MCPcopy
hub / github.com/coder/mux / addServer

Method addServer

src/node/services/mcpConfigService.ts:244–300  ·  view source on GitHub ↗
(
    name: string,
    input: {
      transport?: MCPServerTransport;
      command?: string;
      url?: string;
      headers?: Record<string, MCPHeaderValue>;
    }
  )

Source from the content-addressed store, hash-verified

242 }
243
244 async addServer(
245 name: string,
246 input: {
247 transport?: MCPServerTransport;
248 command?: string;
249 url?: string;
250 headers?: Record<string, MCPHeaderValue>;
251 }
252 ): Promise<Result<void>> {
253 if (!name.trim()) {
254 return Err("Server name is required");
255 }
256
257 const transport: MCPServerTransport = input.transport ?? "stdio";
258
259 if (transport === "stdio") {
260 if (!input.command?.trim()) {
261 return Err("Command is required");
262 }
263 } else {
264 if (!input.url?.trim()) {
265 return Err("URL is required");
266 }
267 }
268
269 const cfg = await this.getGlobalConfig();
270 const existing = cfg.servers[name];
271
272 const base = {
273 disabled: existing?.disabled ?? false,
274 toolAllowlist: existing?.toolAllowlist,
275 };
276
277 const next: MCPServerInfo =
278 transport === "stdio"
279 ? {
280 transport: "stdio",
281 command: input.command!,
282 ...base,
283 }
284 : {
285 transport,
286 url: input.url!,
287 headers: input.headers,
288 ...base,
289 };
290
291 cfg.servers[name] = next;
292
293 try {
294 await this.saveGlobalConfig(cfg);
295 return Ok(undefined);
296 } catch (error) {
297 log.error("Failed to save MCP server", { name, error });
298 return Err(getErrorMessage(error));
299 }
300 }
301

Callers 3

routerFunction · 0.80

Calls 5

getGlobalConfigMethod · 0.95
saveGlobalConfigMethod · 0.95
ErrFunction · 0.90
OkFunction · 0.90
getErrorMessageFunction · 0.90

Tested by

no test coverage detected