UNPKG

hubble-mcp-tool

Version:
34 lines (33 loc) 1.06 kB
import { ErrorCode, McpError } from "@modelcontextprotocol/sdk/types.js"; /** * Handles and transforms errors into standardized MCP errors */ export class ErrorHandler { /** * Handles Zod validation errors */ static handleZodError(error) { const message = error.errors .map((e) => `${e.path.join(".")}: ${e.message}`) .join(", "); return new McpError(ErrorCode.InvalidParams, `Invalid arguments: ${message}`); } /** * Handles general errors and converts them to MCP errors if needed */ static handleError(error, context) { if (error instanceof McpError) { return error; } const errorMessage = error instanceof Error ? error.message : "Unknown error"; return new McpError(ErrorCode.InternalError, `${context}: ${errorMessage}`); } /** * Creates an invalid parameters error */ static createInvalidParamsError(message) { return new McpError(ErrorCode.InvalidParams, message); } }