chore: integrate canonical Evidence changes for MCP error delivery
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { parseMcpToolError } from "../../fixtures/mcpToolError.js";
|
||||
import { parseEvidence } from "../../../src/domain/evidence.js";
|
||||
import type { CallToolResult } from "@modelcontextprotocol/server";
|
||||
import {
|
||||
jsonValueSchema,
|
||||
@@ -40,35 +41,7 @@ export const closeEnhancedToolResources = async (): Promise<void> => {
|
||||
);
|
||||
};
|
||||
|
||||
export const jsonResult = (result: CallToolResult): JsonValue => {
|
||||
if (result.isError === true)
|
||||
return jsonValueSchema.parse(parseMcpToolError(result));
|
||||
if (result.structuredContent === undefined)
|
||||
throw new Error("Tool result omitted structured content");
|
||||
const structured = jsonValueSchema.safeParse(result.structuredContent);
|
||||
if (!structured.success)
|
||||
throw new Error("Tool structured result was not JSON");
|
||||
if (
|
||||
typeof structured.data === "object" &&
|
||||
structured.data !== null &&
|
||||
!Array.isArray(structured.data) &&
|
||||
"normalized_result" in structured.data
|
||||
) {
|
||||
return structured.data.normalized_result ?? null;
|
||||
}
|
||||
if (
|
||||
typeof structured.data === "object" &&
|
||||
structured.data !== null &&
|
||||
!Array.isArray(structured.data) &&
|
||||
"evidence_id" in structured.data &&
|
||||
"result" in structured.data
|
||||
)
|
||||
return structured.data.result ?? null;
|
||||
const text = result.content.find((item) => item.type === "text");
|
||||
if (text?.type !== "text")
|
||||
throw new Error("Tool result omitted text content");
|
||||
const decoded: unknown = JSON.parse(text.text);
|
||||
const parsed = jsonValueSchema.safeParse(decoded);
|
||||
if (!parsed.success) throw new Error("Tool result was not JSON");
|
||||
return parsed.data;
|
||||
};
|
||||
export const jsonResult = (result: CallToolResult): JsonValue =>
|
||||
result.isError === true
|
||||
? jsonValueSchema.parse(parseMcpToolError(result))
|
||||
: parseEvidence(result.structuredContent).normalized_result;
|
||||
|
||||
Reference in New Issue
Block a user