{"version":3,"file":"mcp.mjs","names":[],"sources":["../../src/commands/mcp.ts"],"sourcesContent":["import { defineCommand } from \"citty\";\nimport { consola, LogLevels } from \"consola\";\nimport { exitOnClosedPipe } from \"./output.ts\";\n\nexport default defineCommand({\n  meta: {\n    name: \"mcp\",\n    description: \"Run the harnesses MCP server over stdio\",\n  },\n  /**\n   * The server and the SDK load here, because citty resolves every subcommand\n   * to print `harnesses --help` and to look for an alias of an unknown command.\n   *\n   * stdout carries the JSON-RPC frames. consola's default reporter sends\n   * anything at log level or below to that same descriptor, and `DEBUG` in the\n   * environment raises the level on import, so one stray line would corrupt\n   * the stream. Warnings and errors still reach stderr.\n   *\n   * The SDK's stdio transport never watches for the end of stdin, so a client\n   * that exits would leave an in-flight `harnesses_run` going until its own\n   * deadline. Closing the server aborts every pending request signal, which\n   * stops each run's process group the same way a cancellation does, and the\n   * process then exits once that cleanup has nothing left to wait for. A\n   * write to a stdout the client already closed means the same, so it closes\n   * the server too instead of exiting past that cleanup.\n   */\n  async run() {\n    consola.level = LogLevels.warn;\n\n    const [{ createMcpServer }, { StdioServerTransport }] = await Promise.all([\n      import(\"../mcp.ts\"),\n      import(\"@modelcontextprotocol/sdk/server/stdio.js\"),\n    ]);\n    const server = createMcpServer();\n    await server.connect(new StdioServerTransport());\n    process.stdin.once(\"end\", () => void server.close());\n    process.stdout\n      .off(\"error\", exitOnClosedPipe)\n      .on(\"error\", (error: Readonly<NodeJS.ErrnoException>) => {\n        if (error.code !== \"EPIPE\") throw error;\n        void server.close();\n      });\n  },\n});\n"],"mappings":";;;;AAIA,IAAA,cAAe,cAAc;CAC3B,MAAM;EACJ,MAAM;EACN,aAAa;CACf;CAkBA,MAAM,MAAM;EACV,QAAQ,QAAQ,UAAU;EAE1B,MAAM,CAAC,EAAE,mBAAmB,EAAE,0BAA0B,MAAM,QAAQ,IAAI,CACxE,OAAO,eACP,OAAO,4CACT,CAAC;EACD,MAAM,SAAS,gBAAgB;EAC/B,MAAM,OAAO,QAAQ,IAAI,qBAAqB,CAAC;EAC/C,QAAQ,MAAM,KAAK,aAAa,KAAK,OAAO,MAAM,CAAC;EACnD,QAAQ,OACL,IAAI,SAAS,gBAAgB,CAAC,CAC9B,GAAG,UAAU,UAA2C;GACvD,IAAI,MAAM,SAAS,SAAS,MAAM;GAClC,OAAY,MAAM;EACpB,CAAC;CACL;AACF,CAAC"}