24 lines
618 B
TypeScript
24 lines
618 B
TypeScript
export class McpHttpError extends Error {
|
|
readonly status: number;
|
|
readonly code: string;
|
|
readonly headers: Record<string, string>;
|
|
|
|
constructor(status: number, code: string, message: string, headers: Record<string, string> = {}) {
|
|
super(message);
|
|
this.name = "McpHttpError";
|
|
this.status = status;
|
|
this.code = code;
|
|
this.headers = headers;
|
|
}
|
|
}
|
|
|
|
export function toToolError(error: unknown): string {
|
|
if (error instanceof McpHttpError) {
|
|
return `${error.code}: ${error.message}`;
|
|
}
|
|
if (error instanceof Error) {
|
|
return error.message;
|
|
}
|
|
return "Unknown MCP tool error.";
|
|
}
|