Initial Commit

This commit is contained in:
2026-05-27 23:29:53 +01:00
commit fbc70f96e6
10000 changed files with 1102152 additions and 0 deletions

View File

@@ -0,0 +1,64 @@
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";
}
}