UNPKG

@tanstack/ai-mcp

Version:

Host-side Model Context Protocol client for TanStack AI: discover and run MCP server tools, resources, and prompts in any adapter's chat() loop, with generated end-to-end types.

40 lines (39 loc) • 1.38 kB
import { MCPEventRequestError } from "../errors.js"; import { isRecord } from "./value.js"; import { ProtocolError } from "@modelcontextprotocol/client"; //#region src/events/errors-map.ts var KIND_BY_CODE = { [-32602]: "invalid-params", [-32023]: "not-found", [-32024]: "forbidden", [-32025]: "resource-exhausted", [-32026]: "unsupported", [-32027]: "callback-endpoint" }; function redactData(data) { if (!isRecord(data)) return data; const { secret: _secret, ...rest } = data; return rest; } function looksLikeSecret(text) { return text.includes("whsec_"); } /** * Map a ProtocolError from an `events/*` call to `MCPEventRequestError`. * Other values pass through unchanged. */ function toMCPEventRequestError(err) { if (!(err instanceof ProtocolError)) return err; const kind = KIND_BY_CODE[err.code] ?? "unknown"; const data = redactData(err.data); const reason = isRecord(err.data) && typeof err.data.reason === "string" ? err.data.reason : void 0; const rawMessage = err.message; const message = looksLikeSecret(rawMessage) ? `MCP events request failed (${kind})` : rawMessage; return new MCPEventRequestError(message, err.code, kind, reason, data, err); } function isMethodNotFound(err) { return err instanceof ProtocolError && err.code === -32601; } //#endregion export { isMethodNotFound, toMCPEventRequestError }; //# sourceMappingURL=errors-map.js.map