UNPKG

ai-debug-local-mcp

Version:

🎯 ENHANCED AI GUIDANCE v4.1.2: Dramatically improved tool descriptions help AI users choose the right tools instead of 'close enough' options. Ultra-fast keyboard automation (10x speed), universal recording, multi-ecosystem debugging support, and compreh

121 lines • 3.85 kB
import { Tool } from '@modelcontextprotocol/sdk/types.js'; import { ResourceManager } from '../utils/resource-manager.js'; import { SessionResourceManager } from '../utils/session-resource-manager.js'; /** * Base interface for all tool handlers */ export interface ToolHandler { /** * Array of tools this handler provides */ tools: Tool[]; /** * Handle a tool request * @param toolName The name of the tool to execute * @param args The arguments passed to the tool * @param sessions Active debugging sessions * @returns Promise with the tool result */ handle(toolName: string, args: any, sessions: Map<string, any>): Promise<any>; /** * Optional initialization method */ initialize?(): Promise<void>; } export interface BaseHandlerOptions { resourceManager?: ResourceManager; sessionResourceManager?: SessionResourceManager; } /** * Base class with common functionality for tool handlers */ export declare abstract class BaseToolHandler implements ToolHandler { abstract tools: Tool[]; abstract handle(toolName: string, args: any, sessions: Map<string, any>): Promise<any>; /** * Helper to get a session or throw if not found */ protected getSession(sessionId: string, sessions: Map<string, any>): any; /** * Helper to create a text response */ protected createTextResponse(text: string): { content: { type: string; text: string; }[]; }; /** * Helper to create an error response */ protected createErrorResponse(error: any): { content: { type: string; text: string; }[]; isError: boolean; }; } /** * Enhanced BaseHandler with resource management - solves the audit finding: * "20+ handlers use sessions.get() but NO handlers call cleanup directly" */ export declare class BaseHandler extends BaseToolHandler { protected resourceManager: ResourceManager; protected sessionResourceManager: SessionResourceManager; protected handlerName: string; tools: Tool[]; handle(toolName: string, args: any, sessions: Map<string, any>): Promise<any>; constructor(options?: BaseHandlerOptions); /** * Track a resource for automatic cleanup */ protected trackResource(resourceType: 'page' | 'browser' | 'context', sessionId: string, resource: any): void; /** * Get session with resource tracking - replaces the problematic sessions.get() pattern */ protected getSessionWithTracking(sessionId: string, sessions: Map<string, any>): any; /** * Cleanup resources for this handler */ protected cleanupResources(sessionId?: string): Promise<void>; /** * Get resource count for this handler */ protected getResourceCount(): number; /** * Get resource statistics for this handler */ protected getResourceStats(): any; /** * Get session resource statistics */ protected getSessionStats(): any; /** * Check if session is active */ protected isSessionActive(sessionId: string): boolean; /** * Create a new session with resource tracking */ protected createTrackedSession(sessionId: string): Promise<any>; /** * Execute with resource cleanup on error */ protected executeWithCleanup<T>(sessionId: string, operation: () => Promise<T>, sessions: Map<string, any>): Promise<T>; /** * Get handler name for debugging */ getHandlerName(): string; /** * Get resource management status */ getResourceManagementStatus(): { handlerName: string; resourceCount: number; sessionCount: number; resourceStats: any; sessionStats: any; }; } //# sourceMappingURL=base-handler.d.ts.map