#!/usr/bin/env node /** * mcp/server.ts -- InferMap MCP server (stdio transport, JSON-RPC 2.0). * * Node-only: uses node:fs, node:path, node:readline. NOT edge-safe. * * Exposes 4 tools (`map`, `inspect`, `validate`, `apply`) wired to the * existing InferMap TS core/node APIs (MapEngine, file/DB providers, * fromConfig). Also exposes resources (Supported Domains, Scorer Pipeline, * Last Mapping Report) and prompts (map-walkthrough, compare-schemas, * domain-mapping) -- byte-parity with the Python sibling at * `packages/python/infermap/infermap/mcp/server.py`. * * Every tool dispatch is wrapped in try/catch so a single failure never * crashes the JSON-RPC loop; errors come back as `{ error: "" }`. * * Mirrors the hand-rolled JSON-RPC pattern in * `packages/typescript/goldenmatch/src/node/mcp/server.ts` (no MCP SDK dep), * extended with resources/prompts methods to match the Python InferMap server. */ interface Tool { readonly name: string; readonly description: string; readonly inputSchema: Readonly>; } declare const TOOLS: readonly Tool[]; /** Reset the cached "last mapping" report (used by tests). */ declare function resetLastMappingReport(): void; /** * Dispatch a single tool call. Never throws -- failures come back as * `{ error: "" }`. Caches the `map` report so the "Last Mapping Report" * resource can serve it. */ declare function handleTool(name: string, rawArgs: Record): Promise; interface Resource { readonly uri: string; readonly name: string; readonly description: string; readonly mimeType: string; } declare function listResources(): Resource[]; declare function readResource(uri: string): string; interface PromptArgument { readonly name: string; readonly description: string; readonly required: boolean; } interface Prompt { readonly name: string; readonly description: string; readonly arguments: readonly PromptArgument[]; } interface PromptMessage { readonly role: "user"; readonly content: { readonly type: "text"; readonly text: string; }; } declare const PROMPTS: readonly Prompt[]; declare function getPrompt(name: string, args?: Record): PromptMessage[]; /** * Start the MCP server reading JSON-RPC messages one per line from stdin and * writing responses to stdout. Intended for Claude Desktop / any MCP client * using stdio transport. * * Unknown methods return a JSON-RPC error. Bad JSON is logged to stderr (via * console.warn) but does not crash the loop. */ declare function startMcpServer(): void; export { PROMPTS, TOOLS, getPrompt, handleTool, listResources, readResource, resetLastMappingReport, startMcpServer };