#!/usr/bin/env node /** * MCP 数据库万能连接器 - 主服务器 * 通过 Model Context Protocol 让 Claude Desktop 连接数据库 */ import { Server } from '@modelcontextprotocol/sdk/server/index.js'; import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js'; import type { DbAdapter, DbConfig } from '../types/adapter.js'; import type { AppConfig } from '../types/http.js'; import { SchemaCacheConfig } from '../core/database-service.js'; import type { QueryAnalyzer } from '../core/query-analyzer.js'; import type { ProfileManager } from '../core/profile-manager.js'; /** * 数据库 MCP 服务器类 */ export declare class DatabaseMCPServer { private server; private adapter; private config; private databaseService; private cacheConfig; private appConfig; private queryAnalyzer; private profileManager; private activeProfile; private planHistory; constructor(config?: DbConfig, cacheConfig?: Partial); /** * v2.16: set app-level config (for metrics, etc.). Optional; defaults are used if not set. */ setAppConfig(appConfig: AppConfig): void; /** * v2.17: set the QueryAnalyzer. Optional; when not set, query-experience tools * will return a "queryAnalyzer disabled" error. */ setQueryAnalyzer(qa: QueryAnalyzer | null): void; /** * v2.18: set the ProfileManager. Optional; when not set, profile tools * return a "profileManager not configured" error. */ setProfileManager(pm: ProfileManager | null): void; /** * v3.1: set the PlanHistory (optional). When set, index-advisor tools * (explain_query_with_advice, compare_query_plans, list_query_plans) become available. */ setPlanHistory(ph: any): void; /** * v3.2: configure all optional dependencies from a loaded AppConfig. * Constructs and wires QueryAnalyzer, ProfileManager, PlanHistory when their * respective env flags are enabled. Idempotent — safe to call multiple times. */ configureFromAppConfig(appConfig: AppConfig): Promise; /** v2.18: get the active profile name (null if none). */ getActiveProfile(): string | null; /** * v5.0.0: 激活 profile 并建立完整连接(复用 ProfileManager.loadProfile 已建立的 * adapter + service,不重复 createPool)。供 use_profile dispatch 和 MCP 启动时 * .db-profile 自动激活共用。 * * 必须在 profileManager 设置过之后才能用(否则 throw)。 * * @returns true 表示成功,this.adapter / this.config / this.databaseService / this.activeProfile 全部更新; * false 表示 profile 配置缺失(不应该发生)。 */ private activateProfile; /** * v3.2: set the current MCP session id. stdio uses 'stdio-default'; SSE/Streamable HTTP * sets this from the transport's sessionId (in mcp-sse.ts). */ setSessionId(id: string): void; /** * v3.3.1: detect Claude Code client by clientInfo.name. Claude Code reports * names like "claude-code", "Claude Code", "claude-code-ai", depending on * version. We match case-insensitively on the substring "claude-code". * This is the heuristic the user agreed to in v3.3.1 brainstorming. */ /** * v3.2: handle use_tool_group meta-tool — REMOVED in v4.0 (G4) * v3.2: handle use_tool_schema meta-tool — REMOVED in v4.0 (G2) */ /** * 设置 MCP 协议处理器 */ private setupHandlers; /** * 设置数据库适配器 */ setAdapter(adapter: DbAdapter): void; /** * 获取 MCP Server 实例(用于 SSE/HTTP 传输) */ getServer(): Server; /** * 连接数据库(不启动传输层) */ connectDatabase(): Promise; /** * 使用指定的传输层连接 MCP 服务器 */ connect(transport: Transport): Promise; /** * 启动服务器(使用 stdio 传输,用于 Claude Desktop) */ start(): Promise; /** * 停止服务器 */ stop(): Promise; } //# sourceMappingURL=mcp-server.d.ts.map