UNPKG

sfcc-dev-mcp

Version:

MCP server for Salesforce B2C Commerce Cloud development assistance including logs, debugging, and development tools

132 lines 4.65 kB
import { Logger } from '../../utils/logger.js'; import { SFCCConfig } from '../../types/types.js'; export interface HandlerContext { logger: Logger; config: SFCCConfig; capabilities: { canAccessLogs: boolean; canAccessOCAPI: boolean; }; } export interface ToolExecutionResult { content: Array<{ type: 'text'; text: string; }>; isError?: boolean; } export interface ToolArguments { [key: string]: any; } /** * Generic tool specification interface * Defines the contract for declarative tool configuration */ export interface GenericToolSpec<TArgs = ToolArguments, TResult = any> { /** Optional validation function for tool arguments */ validate?: (args: TArgs, toolName: string) => void; /** Optional function to apply default values to arguments */ defaults?: (args: TArgs) => Partial<TArgs>; /** Main execution function for the tool */ exec: (args: TArgs, context: ToolExecutionContext) => Promise<TResult>; /** Function to generate log message for the tool execution */ logMessage: (args: TArgs) => string; } /** * Context provided to tool execution functions * Allows tools to access clients and other resources */ export interface ToolExecutionContext { /** Handler context with configuration and capabilities */ handlerContext: HandlerContext; /** Logger instance for the handler */ logger: any; /** Additional context data that can be provided by concrete handlers */ [key: string]: any; } export declare class HandlerError extends Error { readonly toolName: string; readonly code: string; readonly details?: any | undefined; constructor(message: string, toolName: string, code?: string, details?: any | undefined); } export declare abstract class BaseToolHandler<TToolName extends string = string> { protected context: HandlerContext; protected logger: Logger; private _isInitialized; constructor(context: HandlerContext, subLoggerName: string); /** * Abstract method to get tool configuration * Each concrete handler implements this with their specific config */ protected abstract getToolConfig(): Record<TToolName, GenericToolSpec>; /** * Abstract method to get tool name set for O(1) lookup * Each concrete handler implements this with their specific tool set */ protected abstract getToolNameSet(): Set<string>; /** * Abstract method to create execution context * Each concrete handler can provide specialized context */ protected abstract createExecutionContext(): Promise<ToolExecutionContext>; /** * Check if this handler can handle the given tool */ canHandle(toolName: string): boolean; /** * Config-driven tool execution * Handles validation, defaults, execution, and logging uniformly */ handle(toolName: string, args: ToolArguments, startTime: number): Promise<ToolExecutionResult>; /** * Generic tool dispatch using configuration * Handles validation, defaults, and execution */ private dispatchTool; /** * Apply default values to arguments */ private applyDefaults; /** * Create validated arguments with defaults applied */ private createValidatedArgs; /** * Initialize the handler (lazy initialization) */ protected initialize(): Promise<void>; /** * Override this method for custom initialization logic */ protected onInitialize(): Promise<void>; /** * Clean up resources when handler is destroyed */ dispose(): Promise<void>; /** * Override this method for custom cleanup logic */ protected onDispose(): Promise<void>; /** * Validate required arguments */ protected validateArgs(args: ToolArguments, required: string[], toolName: string): void; /** * Create a standardized response */ protected createResponse(data: any, stringify?: boolean): ToolExecutionResult; /** * Create an error response */ protected createErrorResponse(error: Error, toolName: string): ToolExecutionResult; /** * Execute a tool operation with standardized logging and error handling */ protected executeWithLogging(toolName: string, startTime: number, operation: () => Promise<any>, logMessage?: string): Promise<ToolExecutionResult>; /** * @deprecated Use executeWithLogging instead */ protected wrap(toolName: string, startTime: number, fn: () => Promise<any>, logMessage?: string): Promise<ToolExecutionResult>; } //# sourceMappingURL=base-handler.d.ts.map