{"version":3,"file":"mcp-servers.mjs","names":[],"sources":["../../src/commands/mcp-servers.ts"],"sourcesContent":["import { defineCommand } from \"citty\";\nimport { consola } from \"consola\";\nimport { isHarnessId, listHarnesses } from \"../registry.ts\";\nimport { mcpAdd, mcpList, mcpRemove, mcpSync } from \"../tool-operations.ts\";\nimport { formatArgs, report } from \"./output.ts\";\n\nfunction requireHarnessId(id: string): string {\n  if (!isHarnessId(id)) {\n    consola.error(`Unknown harness: ${id}\\nKnown: ${listHarnesses().join(\", \")}`);\n    process.exit(1);\n  }\n  return id;\n}\n\nexport default defineCommand({\n  meta: { description: \"Manage MCP servers across harness configs\" },\n  subCommands: {\n    list: defineCommand({\n      meta: { description: \"List configured MCP servers, normalized\" },\n      args: {\n        id: { type: \"positional\" as const, description: \"Harness id\", required: false },\n        ...formatArgs,\n      },\n      run({ args }) {\n        const id = args.id === undefined ? undefined : requireHarnessId(args.id as string);\n        report(mcpList(id), args);\n      },\n    }),\n    add: defineCommand({\n      meta: { description: \"Add or replace one MCP server in a harness config\" },\n      args: {\n        id: { type: \"positional\" as const, description: \"Harness id\", required: true },\n        name: { type: \"positional\" as const, description: \"Server name\", required: true },\n        command: { type: \"string\" as const, description: \"Binary for a stdio server\" },\n        args: {\n          type: \"string\" as const,\n          description: \"Space-separated arguments for a stdio server\",\n        },\n        env: { type: \"string\" as const, description: \"Comma-separated K=V environment variables\" },\n        url: { type: \"string\" as const, description: \"URL for an http/sse server\" },\n        scope: { type: \"string\" as const, description: \"user (default) or project\" },\n        ...formatArgs,\n      },\n      run({ args }) {\n        const env = args.env\n          ? Object.fromEntries(\n              args.env\n                .split(\",\")\n                .map((pair) => pair.split(/=(.*)/s))\n                .filter((pair) => pair[0])\n                .map((pair) => [pair[0] as string, pair[1] ?? \"\"]),\n            )\n          : undefined;\n        const result = mcpAdd(\n          requireHarnessId(args.id as string),\n          {\n            name: args.name as string,\n            ...(args.command ? { command: args.command } : {}),\n            ...(args.args ? { args: args.args.split(\" \").filter(Boolean) } : {}),\n            ...(env ? { env } : {}),\n            ...(args.url ? { url: args.url } : {}),\n          },\n          args.scope === \"project\" ? \"project\" : \"user\",\n        );\n        report(result, args);\n      },\n    }),\n    sync: defineCommand({\n      meta: {\n        description: \"Reset harness configs to the master list from ~/.config/agntn/mcp.jsonc\",\n      },\n      args: {\n        id: { type: \"positional\" as const, description: \"Harness id\", required: false },\n        ...formatArgs,\n      },\n      run({ args }) {\n        const id = args.id === undefined ? undefined : requireHarnessId(args.id as string);\n        report(mcpSync(id), args);\n      },\n    }),\n    remove: defineCommand({\n      meta: { description: \"Remove one MCP server from a harness config\" },\n      args: {\n        id: { type: \"positional\" as const, description: \"Harness id\", required: true },\n        name: { type: \"positional\" as const, description: \"Server name\", required: true },\n        scope: { type: \"string\" as const, description: \"user (default) or project\" },\n        ...formatArgs,\n      },\n      run({ args }) {\n        report(\n          mcpRemove(\n            requireHarnessId(args.id as string),\n            args.name as string,\n            args.scope === \"project\" ? \"project\" : \"user\",\n          ),\n          args,\n        );\n      },\n    }),\n  },\n});\n"],"mappings":";;;;;;AAMA,SAAS,iBAAiB,IAAoB;CAC5C,IAAI,CAAC,YAAY,EAAE,GAAG;EACpB,QAAQ,MAAM,oBAAoB,GAAG,WAAW,cAAc,CAAC,CAAC,KAAK,IAAI,GAAG;EAC5E,QAAQ,KAAK,CAAC;CAChB;CACA,OAAO;AACT;AAEA,IAAA,sBAAe,cAAc;CAC3B,MAAM,EAAE,aAAa,4CAA4C;CACjE,aAAa;EACX,MAAM,cAAc;GAClB,MAAM,EAAE,aAAa,0CAA0C;GAC/D,MAAM;IACJ,IAAI;KAAE,MAAM;KAAuB,aAAa;KAAc,UAAU;IAAM;IAC9E,GAAG;GACL;GACA,IAAI,EAAE,QAAQ;IACZ,MAAM,KAAK,KAAK,OAAO,KAAA,IAAY,KAAA,IAAY,iBAAiB,KAAK,EAAY;IACjF,OAAO,QAAQ,EAAE,GAAG,IAAI;GAC1B;EACF,CAAC;EACD,KAAK,cAAc;GACj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