// src/adapters/codex/structured-output-mcp-server.ts
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";

// src/adapters/codex/structured-output-constants.ts
var STRUCTURED_OUTPUT_MCP_NAME = "posthog_output";
var STRUCTURED_OUTPUT_TOOL_NAME = "create_output";

// src/adapters/codex/structured-output-mcp-server.ts
function die(message) {
  process.stderr.write(`[structured-output-mcp-server] ${message}
`);
  process.exit(1);
}
var schemaEnv = process.env.POSTHOG_OUTPUT_SCHEMA;
if (!schemaEnv) {
  die("POSTHOG_OUTPUT_SCHEMA env var is required");
}
var jsonSchema;
try {
  jsonSchema = JSON.parse(Buffer.from(schemaEnv, "base64").toString("utf-8"));
} catch (err) {
  die(`Failed to parse POSTHOG_OUTPUT_SCHEMA as base64-encoded JSON: ${err}`);
}
var zodType = z.fromJSONSchema(jsonSchema);
if (!(zodType instanceof z.ZodObject)) {
  die(
    `POSTHOG_OUTPUT_SCHEMA must describe a JSON object schema (got ${zodType.constructor.name})`
  );
}
var zodShape = { ...zodType.shape };
var server = new McpServer({
  name: STRUCTURED_OUTPUT_MCP_NAME,
  version: "1.0.0"
});
server.tool(
  STRUCTURED_OUTPUT_TOOL_NAME,
  "Submit the structured output for this task. Call this tool with the required fields to deliver your final result.",
  zodShape,
  async () => {
    return {
      content: [
        {
          type: "text",
          text: "Output submitted successfully."
        }
      ]
    };
  }
);
var transport = new StdioServerTransport();
await server.connect(transport);
//# sourceMappingURL=structured-output-mcp-server.js.map