mcp-ai-agent-guidelines
Version:
A comprehensive Model Context Protocol server providing advanced tools, resources, and prompts for implementing AI agent best practices
141 lines • 4.19 kB
TypeScript
/**
* Centralized error handling utilities with typed errors for improved debugging and resilience
*/
import { type ErrorCode } from "./error-codes.js";
/**
* Structured context payload for McpToolError instances.
*/
export interface McpToolErrorContext {
[key: string]: unknown;
}
/**
* MCP-aware error with standardized codes, retry hints, and response formatting.
* @public
*/
export declare class McpToolError extends Error {
readonly code: ErrorCode;
readonly context: McpToolErrorContext;
readonly timestamp: Date;
readonly cause?: Error;
constructor(code: ErrorCode, message?: string, context?: McpToolErrorContext, cause?: Error);
/**
* Determines if this error is safe to retry based on its code category.
*/
isRetryable(): boolean;
/**
* Formats the error into an MCP-compatible response payload.
*/
toResponse(): {
isError: true;
content: Array<{
type: "text";
text: string;
}>;
};
}
/**
* Session error for session-related issues
*/
export declare class SessionError extends Error {
readonly code: string;
readonly context?: Record<string, unknown>;
readonly timestamp: Date;
constructor(message: string, context?: Record<string, unknown>);
}
/**
* Phase error for design phase workflow issues
*/
export declare class PhaseError extends Error {
readonly code: string;
readonly context?: Record<string, unknown>;
readonly timestamp: Date;
constructor(message: string, context?: Record<string, unknown>);
}
/**
* Generation error for artifact generation failures
*/
export declare class GenerationError extends Error {
readonly code: string;
readonly context?: Record<string, unknown>;
readonly timestamp: Date;
constructor(message: string, context?: Record<string, unknown>);
}
/**
* Consistency error for consistency enforcement failures
*/
export declare class ConsistencyError extends Error {
readonly code: string;
readonly context?: Record<string, unknown>;
readonly timestamp: Date;
constructor(message: string, context?: Record<string, unknown>);
}
/**
* Unknown error for unrecognized error types
*/
export declare class UnknownError extends Error {
readonly code: string;
readonly context?: Record<string, unknown>;
readonly timestamp: Date;
constructor(message: string, context?: Record<string, unknown>);
}
/**
* Type representing errors with standard structure
*/
export interface StandardError extends Error {
code: string;
context?: Record<string, unknown>;
timestamp: Date;
}
/**
* Centralized error reporter for consistent error handling
*/
export declare class ErrorReporter {
/**
* Report and log an error, optionally rethrowing it
*/
static report(error: Error | unknown, context?: Record<string, unknown>, options?: {
rethrow?: boolean;
defaultMessage?: string;
}): StandardError;
/**
* Report a non-critical error as a warning
*/
static warn(error: Error | unknown, context?: Record<string, unknown>, defaultMessage?: string): void;
/**
* Convert any error to a StandardError
*/
private static toStandardError;
/**
* Extract error message from various error types
*/
private static extractMessage;
/**
* Create a safe error response for API returns
*/
static createErrorResponse(error: Error | unknown, context?: Record<string, unknown>): {
success: false;
error: {
message: string;
code: string;
timestamp: string;
context?: Record<string, unknown>;
};
};
/**
* Create a full error response with standard fields
*/
static createFullErrorResponse<T = unknown>(error: Error | unknown, baseResponse: {
sessionId: string;
status?: string;
recommendations?: string[];
artifacts?: T[];
}): {
success: false;
sessionId: string;
status: string;
message: string;
recommendations: string[];
artifacts: T[];
};
}
//# sourceMappingURL=errors.d.ts.map