"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var transport_exports = {};
__export(transport_exports, {
  ErrorCodes: () => ErrorCodes,
  StdioTransport: () => StdioTransport
});
module.exports = __toCommonJS(transport_exports);
const ErrorCodes = {
  ParseError: -32700,
  InvalidRequest: -32600,
  MethodNotFound: -32601,
  InvalidParams: -32602,
  InternalError: -32603
};
class StdioTransport {
  constructor() {
    this.buffer = "";
  }
  start(handler) {
    process.stdin.setEncoding("utf8");
    process.stdin.on("data", async (chunk) => {
      this.buffer += chunk;
      const lines = this.buffer.split("\n");
      this.buffer = lines.pop() ?? "";
      for (const line of lines) {
        const trimmed = line.trim();
        if (!trimmed) continue;
        try {
          const msg = JSON.parse(trimmed);
          const result = await handler(msg);
          if ("id" in msg && msg.id !== void 0) {
            this.send({ jsonrpc: "2.0", id: msg.id, result });
          }
        } catch (err) {
          process.stderr.write(`[KiroGraph MCP] Parse error: ${err}
`);
        }
      }
    });
  }
  send(msg) {
    process.stdout.write(JSON.stringify(msg) + "\n");
  }
  sendError(id, code, message) {
    this.send({ jsonrpc: "2.0", id, error: { code, message } });
  }
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  ErrorCodes,
  StdioTransport
});
//# sourceMappingURL=transport.js.map
