build: separate runtime artifacts and supervise command ownership
This commit is contained in:
+2
-1
@@ -1,3 +1,4 @@
|
||||
import { silentLogger } from "../../dist/logger.js";
|
||||
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
|
||||
|
||||
import { BROWSER_TOOL_CONTRACTS } from "../../dist/contracts/browserToolContracts.js";
|
||||
@@ -22,7 +23,7 @@ if (process.argv[2] === "reversed") {
|
||||
const { createServer } = await import("../../dist/server/createServer.js");
|
||||
const config = parseConfig({});
|
||||
if (!config.ok) throw config.error;
|
||||
const session = createBinarySession(config.value);
|
||||
const session = createBinarySession(config.value, silentLogger, {});
|
||||
const server = createServer(session, session);
|
||||
const client = new Client({ name: "contract-presentation", version: "1" });
|
||||
const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair();
|
||||
|
||||
Vendored
+65
@@ -0,0 +1,65 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import type { ToolAnnotations } from "@modelcontextprotocol/server";
|
||||
import type { CapabilityDescriptor } from "../../src/application/AnalysisProvider.js";
|
||||
import type { ToolKind } from "../../src/contracts/toolContractTypes.js";
|
||||
import type { ToolEffects } from "../../src/contracts/toolEffects.js";
|
||||
|
||||
interface GeneratedTool {
|
||||
readonly name: string;
|
||||
readonly analysisOperation: CapabilityDescriptor["operation"] | null;
|
||||
readonly title: string;
|
||||
readonly description: string;
|
||||
readonly kind: ToolKind;
|
||||
readonly requiresSession: boolean;
|
||||
readonly inputSchema: Readonly<Record<string, unknown>>;
|
||||
readonly outputSchema: Readonly<Record<string, unknown>>;
|
||||
readonly annotations: ToolAnnotations;
|
||||
readonly effects: ToolEffects;
|
||||
}
|
||||
|
||||
interface GeneratedPayload {
|
||||
readonly catalog: readonly GeneratedTool[];
|
||||
}
|
||||
|
||||
const generatedPayload: unknown = JSON.parse(
|
||||
readFileSync(
|
||||
new URL("../../.cache/mcp-tool-catalog.json", import.meta.url),
|
||||
"utf8",
|
||||
),
|
||||
);
|
||||
if (!isGeneratedPayload(generatedPayload))
|
||||
throw new TypeError(
|
||||
"Generated MCP catalog payload is invalid; run npm run mcp-catalog:generate",
|
||||
);
|
||||
|
||||
/** Canonical schemas advertised through the pinned MCP SDK. */
|
||||
export const GENERATED_MCP_TOOL_CATALOG = generatedPayload.catalog;
|
||||
|
||||
function isGeneratedPayload(value: unknown): value is GeneratedPayload {
|
||||
return (
|
||||
isRecord(value) &&
|
||||
Array.isArray(value.catalog) &&
|
||||
value.catalog.every(isGeneratedTool)
|
||||
);
|
||||
}
|
||||
|
||||
function isGeneratedTool(value: unknown): value is GeneratedTool {
|
||||
return (
|
||||
isRecord(value) &&
|
||||
typeof value.name === "string" &&
|
||||
(typeof value.analysisOperation === "string" ||
|
||||
value.analysisOperation === null) &&
|
||||
typeof value.title === "string" &&
|
||||
typeof value.description === "string" &&
|
||||
typeof value.kind === "string" &&
|
||||
typeof value.requiresSession === "boolean" &&
|
||||
isRecord(value.inputSchema) &&
|
||||
isRecord(value.outputSchema) &&
|
||||
isRecord(value.annotations) &&
|
||||
isRecord(value.effects)
|
||||
);
|
||||
}
|
||||
|
||||
function isRecord(value: unknown): value is Readonly<Record<string, unknown>> {
|
||||
return typeof value === "object" && value !== null && !Array.isArray(value);
|
||||
}
|
||||
Reference in New Issue
Block a user