/** * MCP Server Setup * * Configures and starts the Model Context Protocol server * with all tool handlers registered. This is the main integration * point that ties all components together. * * Features: * - stdio transport for local MCP communication * - All 10 tools registered (search_code, search_docs, search_by_path, * get_index_status, get_config, get_file_summary, create_index, reindex_project, reindex_file, delete_index) * - Lazy initialization of shared components * - Graceful shutdown on SIGINT/SIGTERM * - Proper error handling and logging * - Strategy orchestrator for configurable indexing strategies */ import { Server } from '@modelcontextprotocol/sdk/server/index.js'; /** * Progress token type (string or number per MCP spec) */ type ProgressToken = string | number; /** * Options for tool execution including MCP progress support */ interface ExecuteToolOptions { /** Server instance for sending notifications */ server: Server; /** Progress token from request _meta (if client requested progress) */ progressToken?: ProgressToken; } import { StrategyOrchestrator } from './engines/index.js'; import { Config } from './storage/config.js'; /** * All registered MCP tools * * Each tool has: * - name: Unique identifier for the tool * - description: Human-readable description * - inputSchema: JSON Schema for input validation * - requiresConfirmation: Whether user confirmation is needed */ declare const tools: { name: string; description: string; inputSchema: { type: "object"; properties: {}; required: string[]; }; requiresConfirmation: boolean; }[]; /** * Tool name type for type-safe tool lookup */ type ToolName = 'create_index' | 'search_code' | 'search_docs' | 'search_by_path' | 'get_index_status' | 'get_config' | 'get_file_summary' | 'reindex_project' | 'reindex_file' | 'delete_index'; /** * Server context containing shared state */ interface ServerContext { /** Current working directory */ cwd: string; /** Detected project path (cached after first detection) */ projectPath: string | null; /** Strategy orchestrator for indexing strategies */ orchestrator: StrategyOrchestrator | null; /** Loaded configuration (cached) */ config: Config | null; } /** * Create initial server context */ declare function createServerContext(): ServerContext; /** * Get the current strategy orchestrator * * Returns null if: * - No index exists yet * - Orchestrator hasn't been initialized * * @param context - Server context * @returns StrategyOrchestrator or null */ declare function getOrchestrator(context: ServerContext): StrategyOrchestrator | null; /** * Set the strategy orchestrator * * @param context - Server context * @param orchestrator - StrategyOrchestrator instance or null */ declare function setOrchestrator(context: ServerContext, orchestrator: StrategyOrchestrator | null): void; /** * Get the cached configuration * * @param context - Server context * @returns Config or null */ declare function getConfig(context: ServerContext): Config | null; /** * Set the cached configuration * * @param context - Server context * @param config - Config instance or null */ declare function setConfig(context: ServerContext, config: Config | null): void; /** * Initialize the strategy orchestrator for a project * * Creates all dependencies and starts the indexing strategy based on config. * This should only be called when an index exists for the project. * * @param context - Server context to update * @param projectPath - Absolute path to the project root * @param indexPath - Absolute path to the index directory * @param config - Project configuration * @returns The created StrategyOrchestrator or null if initialization fails */ declare function initializeOrchestrator(context: ServerContext, projectPath: string, indexPath: string, config: Config): Promise; /** * Initialize orchestrator if an index exists for the project * * Called on server startup to set up indexing strategy for existing indexes. * * @param context - Server context * @param projectPath - Absolute path to the project root */ declare function maybeInitializeOrchestrator(context: ServerContext, projectPath: string): Promise; /** * Get the project path, detecting it if not already cached * * BUG #22 FIX: Validates cached path still exists before returning it. * This handles cases where the project directory was moved/deleted * during a long-running MCP server session. */ declare function getProjectPath(context: ServerContext): Promise; /** * Execute a tool by name with the given arguments */ declare function executeTool(toolName: string, args: Record, serverContext: ServerContext, options: ExecuteToolOptions): Promise<{ content: Array<{ type: 'text'; text: string; }>; }>; /** * Create and configure the MCP server */ export declare function createServer(): { server: Server; context: ServerContext; }; /** * Graceful shutdown handler * * Runs all registered cleanup handlers (FileWatcher, LanceDB, IntegrityEngine, etc.) * before closing the MCP server connection. * * @param signal - Optional signal name that triggered shutdown (SIGTERM, SIGINT, etc.) */ declare function shutdown(signal?: string): Promise; /** * Start the MCP server with stdio transport */ export declare function startServer(): Promise; export { tools, executeTool, shutdown, createServerContext, getProjectPath, getOrchestrator, setOrchestrator, getConfig, setConfig, initializeOrchestrator, maybeInitializeOrchestrator, type ServerContext, type ToolName, }; //# sourceMappingURL=server.d.ts.map