import type { FrameStore } from "../store/frame-store.js"; export interface MCPRequest { method: string; params?: unknown; } export interface MCPResponse { protocolVersion?: string; capabilities?: unknown; serverInfo?: { name: string; version: string; }; tools?: unknown[]; content?: unknown[]; error?: { message: string; code: string; context?: Record; nextActions?: string[]; }; data?: Record; } export interface ToolCallParams { name: string; arguments: Record; } /** * Options for creating an MCPServer instance. */ export interface MCPServerOptions { /** * FrameStore instance to use for frame persistence. * If not provided, creates a SqliteFrameStore with the given dbPath. */ frameStore?: FrameStore; /** Database path. Only used if frameStore is not provided. */ dbPath?: string; /** Repository root path for policy resolution. */ repoRoot?: string; } /** * MCP Server - handles protocol requests */ export declare class MCPServer { private frameStore; private imageManager; private policy; private repoRoot; private idempotencyCache; /** * Create a new MCPServer instance. * * Supports two construction patterns: * 1. Legacy: MCPServer(dbPath: string, repoRoot?: string) - creates SqliteFrameStore internally * 2. DI: MCPServer(options: MCPServerOptions) - uses provided FrameStore for testing/swapping * * @param dbPathOrOptions - Either a database path string (legacy) or MCPServerOptions object * @param repoRoot - Repository root path (only used with legacy constructor) */ constructor(dbPathOrOptions: string | MCPServerOptions, repoRoot?: string); /** * Handle incoming MCP request */ handleRequest(request: MCPRequest): Promise; /** * Handle initialize request (MCP protocol handshake) */ private handleInitialize; /** * Handle tools/list request * Returns tools sorted by name for deterministic ordering */ private handleToolsList; /** * Handle tools/call request */ private handleToolsCall; /** * Handle mcp_lex_frame_remember tool - create new Frame * * Validates module IDs against policy with alias resolution before creating Frame (THE CRITICAL RULE) */ private handleRemember; /** * Handle validate_remember tool - validate Frame input without storage (dry-run) * * Performs the same validation as handleRemember but returns a structured validation result * without creating or storing a Frame. This enables agents to verify inputs incrementally. */ private handleValidateRemember; /** * Handle mcp_lex_frame_recall tool - search Frames with Atlas Frame */ private handleRecall; /** * Handle get_frame tool - retrieve a specific frame by ID */ private handleGetFrame; /** * Handle mcp_lex_frame_list tool - list recent Frames */ private handleListFrames; /** * Handle mcp_lex_policy_check tool - validate policy file */ private handlePolicyCheck; /** * Handle mcp_lex_frame_timeline tool - show timeline of Frame evolution */ private handleTimeline; /** * Handle mcp_lex_atlas_analyze tool - analyze code structure and dependencies */ private handleCodeAtlas; /** * Handle introspect tool - discover current Lex state */ private handleIntrospect; /** * Abbreviate error code for compact format * Uses a deterministic mapping to avoid collisions * Example: VALIDATION_REQUIRED_FIELD -> VAL_REQ_FIE */ private abbreviateErrorCode; /** * Handle help tool - self-documentation for Lex MCP tools (AX #577) * * Returns structured help including: * - Tool descriptions and required fields * - Executable examples * - Related tools for common workflows * - Common workflow patterns * - Naming convention guidance (AX-014) */ private handleHelp; /** * Get total frame count from database. * Uses FrameStore.getFrameCount() interface method. */ private getFrameCount; /** * Handle get_hints tool - retrieve hint details by hint IDs * * Per AX-012, provides cacheable advice snippets for error recovery. * Agents can fetch hints once and cache them to minimize token usage. */ private handleGetHints; /** * Handle db_stats tool - get database statistics */ private handleDbStats; /** * Handle turncost_calculate tool - calculate turn cost metrics */ private handleTurncostCalculate; /** * Handle contradictions_scan tool - scan for frame contradictions */ private handleContradictionsScan; /** * Close the server and release resources. * Properly closes the FrameStore on shutdown. */ close(): Promise; }