UNPKG

@chinchillaenterprises/mcp-stripe

Version:

Multi-tenant Stripe MCP server with account management and credential persistence

52 lines (46 loc) 1.44 kB
import { McpError, ErrorCode } from "@modelcontextprotocol/sdk/types.js"; import { z } from "zod"; export function handleError(error: unknown, context: string): never { console.error(`Error in ${context}:`, error); if (error instanceof McpError) { throw error; } if (error instanceof z.ZodError) { throw new McpError( ErrorCode.InvalidParams, `Invalid parameters: ${error.errors.map(e => `${e.path.join('.')}: ${e.message}`).join(', ')}` ); } if (error instanceof Error) { // Check for specific Stripe errors if ('type' in error) { const stripeError = error as any; if (stripeError.type === 'StripeAuthenticationError') { throw new McpError( ErrorCode.InvalidRequest, "Invalid Stripe API key. Please check your credentials." ); } if (stripeError.type === 'StripeAPIError') { throw new McpError( ErrorCode.InternalError, `Stripe API error: ${stripeError.message}` ); } if (stripeError.type === 'StripeInvalidRequestError') { throw new McpError( ErrorCode.InvalidParams, `Invalid request: ${stripeError.message}` ); } } throw new McpError( ErrorCode.InternalError, `${context} failed: ${error.message}` ); } throw new McpError( ErrorCode.InternalError, `${context} failed with unknown error` ); }