dograh/api/mcp_server/ts_validator/src/index.ts
Abhishek 00a1a22b74
feat: refactor node spec and add mcp tools (#244)
* refactor: carve out extraction panel

* refactor: create spec versions for node types

* refactor: create a GenericNode and remove custom nodes

* feat: add python and typescript sdk

* add dograh sdk

* fix: fetch draft workflow definition over published one

* fix: fix routes of SDKs to use code gen

* chore: remove doclink dependency to reduce image size

* chore: format files

* chore: bump pipecat

* feat: let mcp fetch archived workflows on demand

* chore: fix tests

* feat: add sdk documentation

* chore: change banner and add badge
2026-04-21 07:56:16 +05:30

74 lines
2 KiB
TypeScript

// Stdin/stdout dispatch. Reads a single JSON request, routes to
// generate or parse, writes a single JSON response. Exits 0 on request
// success (including validation failures — those are in the JSON), and
// exits 1 only on internal errors (bad input JSON, unhandled exception).
import { generateCode } from "./generate.ts";
import { parseCode } from "./parse.ts";
import type { NodeSpec, WireWorkflow } from "./types.ts";
interface GenerateRequest {
command: "generate";
workflow: WireWorkflow;
specs: NodeSpec[];
workflowName?: string;
}
interface ParseRequest {
command: "parse";
code: string;
specs: NodeSpec[];
}
type Request = GenerateRequest | ParseRequest;
async function readStdin(): Promise<string> {
const chunks: Buffer[] = [];
for await (const chunk of process.stdin) {
chunks.push(chunk as Buffer);
}
return Buffer.concat(chunks).toString("utf-8");
}
function writeResult(payload: unknown): void {
process.stdout.write(JSON.stringify(payload));
}
async function main(): Promise<void> {
const input = await readStdin();
let req: Request;
try {
req = JSON.parse(input) as Request;
} catch (e) {
writeResult({
ok: false,
stage: "internal",
errors: [{ message: `Invalid JSON on stdin: ${(e as Error).message}` }],
});
process.exit(1);
}
if (req.command === "generate") {
writeResult(generateCode(req.workflow, req.specs, { workflowName: req.workflowName }));
return;
}
if (req.command === "parse") {
writeResult(parseCode(req.code, req.specs));
return;
}
writeResult({
ok: false,
stage: "internal",
errors: [{ message: `Unknown command: ${(req as { command?: unknown }).command}` }],
});
process.exit(1);
}
main().catch((err: unknown) => {
writeResult({
ok: false,
stage: "internal",
errors: [{ message: (err as Error).stack ?? String(err) }],
});
process.exit(1);
});