Skip to main content
Glama
errorHandling.ts1.23 kB
import type { ToolNames } from "../features/tools/index.js"; import type { ILogger } from "./logger.js"; /** * Standard API error response structure compatible with MCP SDK */ interface ErrorResponse { [key: string]: unknown; isError: true; content: Array<{ type: "text"; text: string; }>; } /** * Handles API errors consistently across the application */ export function handleToolError( error: unknown, logger: ILogger, toolName: ToolNames, referenceComment?: string, ): ErrorResponse { const formattedError = error instanceof Error ? error : new Error(error === null ? "Null error received" : String(error)); const logData: Record<string, unknown> = { error: formattedError.message, message: "Tool execution failed", toolName, }; if (referenceComment) { logData.referenceComment = referenceComment; } if (formattedError.stack) { logData.stack = formattedError.stack; } logger.sendLog({ data: logData, level: "error", logger: "ErrorHandling", }); const errorMessage = `${toolName}: ${formattedError}${referenceComment ? `. ${referenceComment}` : ""}`; return { content: [ { text: errorMessage, type: "text" as const, }, ], isError: true, }; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/8beeeaaat/touchdesigner-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server