65 lines
1.8 KiB
TypeScript
65 lines
1.8 KiB
TypeScript
import { defineCodes, SuaveplanError } from "@suaveplan/error";
|
|
|
|
/**
|
|
* Stable error-code registry for `@suaveplan/mcp`.
|
|
*
|
|
* Codes follow the pattern `MCP.<DOMAIN>` and resolve through
|
|
* `@suaveplan/error`'s `defineCodes` registry, giving callers a
|
|
* fully-qualified string such as `"MCP.UNAUTHORIZED"`.
|
|
*/
|
|
export const MCP_CODES = defineCodes("MCP", [
|
|
"PROTOCOL_INVALID",
|
|
"METHOD_NOT_FOUND",
|
|
"INVALID_PARAMS",
|
|
"INTERNAL_ERROR",
|
|
"UNAUTHORIZED",
|
|
"REQUEST_CANCELLED",
|
|
"TIMEOUT",
|
|
"TRANSPORT_CLOSED",
|
|
"TRANSPORT_ERROR",
|
|
"NOT_INITIALIZED",
|
|
"ALREADY_CONNECTED",
|
|
"DUPLICATE_REGISTRATION",
|
|
"NOT_FOUND",
|
|
"PROTOCOL_VERSION_MISMATCH",
|
|
"HANDLER_FAILED",
|
|
] as const);
|
|
|
|
export type MCPCode = (typeof MCP_CODES)[keyof typeof MCP_CODES];
|
|
|
|
/** Base typed error for `@suaveplan/mcp`. */
|
|
export class MCPError extends SuaveplanError<MCPCode> {
|
|
public constructor(
|
|
code: MCPCode,
|
|
message: string,
|
|
options?: { cause?: Error; context?: Record<string, unknown> }
|
|
) {
|
|
super(code, message, options);
|
|
this.name = "MCPError";
|
|
}
|
|
}
|
|
|
|
/** Transport-layer failures: `TRANSPORT_CLOSED` / `TRANSPORT_ERROR`. */
|
|
export class MCPTransportError extends MCPError {
|
|
public constructor(
|
|
code: MCPCode,
|
|
message: string,
|
|
options?: { cause?: Error; context?: Record<string, unknown> }
|
|
) {
|
|
super(code, message, options);
|
|
this.name = "MCPTransportError";
|
|
}
|
|
}
|
|
|
|
/** Protocol-layer failures: `PROTOCOL_INVALID` / `PROTOCOL_VERSION_MISMATCH`. */
|
|
export class MCPProtocolError extends MCPError {
|
|
public constructor(
|
|
code: MCPCode,
|
|
message: string,
|
|
options?: { cause?: Error; context?: Record<string, unknown> }
|
|
) {
|
|
super(code, message, options);
|
|
this.name = "MCPProtocolError";
|
|
}
|
|
}
|