DB-Explorer-MCP
Database Explorer MCP
一个用于探索和安全查询关系型数据库的 FastMCP 服务器。本地开发数据库为 SQLite;SQLAlchemy 也通过其驱动程序支持 PostgreSQL 和 MySQL。
架构
MCP 客户端执行自然语言推理并生成 SQL。该服务器暴露数据库工具,验证只读查询,执行它们,并返回结构化结果。
MCP client LLM -> FastMCP tools -> safety layer -> SQLAlchemy -> database服务器不会调用 Anthropic,因此不需要 Anthropic API 密钥。
Related MCP server: nl2sql-mcp
设置
安装 uv,然后从此目录运行:
uv sync
uv run python tests/seed_test_db.py
uv run pytest如果 uv 尚不在 PATH 中,请使用:
py -m uv sync
py -m uv run pytest默认数据库为:
sqlite:///sample.db要使用其他数据库,请在启动服务器前设置 DATABASE_URL。示例:
$env:DATABASE_URL = "sqlite:///C:/data/example.db"
$env:DATABASE_URL = "postgresql+psycopg2://user:password@localhost:5432/example"
$env:DATABASE_URL = "mysql+pymysql://user:password@localhost:3306/example"运行 MCP 服务器
uv run server.py可共享的 VS Code MCP 配置位于 .vscode/mcp.json。它通过 stdio 启动服务器,并可与兼容 MCP 的客户端和 Inspector 一起使用。
对于远程托管,请使用 Streamable HTTP:
$env:MCP_TRANSPORT = "streamable-http"
$env:MCP_HOST = "0.0.0.0"
$env:MCP_PORT = "8000"
uv run server.py远程部署必须提供身份验证,并通过其秘密配置保护 DATABASE_URL。
工具
explore_schema:列出表或检查单个表execute_query:执行一个安全的只读SELECTexplain_query:返回原生执行计划validate_schema:报告缺失的主键和未索引的外键suggest_index:根据表元数据或查询计划建议索引migration_context:为客户端迁移生成提供模式上下文validate_migration:验证提议的UP和DOWN脚本而不执行它们
每次查询执行和解释都经过安全层。变更语句、注释和多个语句都会被拒绝。查询结果默认最多返回 100 行。
测试
uv run pytest测试套件使用临时 SQLite 数据库,不需要外部凭据或正在运行的数据库服务器。
远程部署
有关 FastMCP Horizon 部署步骤、远程数据库要求和身份验证清单,请参阅 DEPLOYMENT.md。
Available Tools
7 toolsexecute_queryB
Execute one validated, read-only SQL SELECT query.
Inputs: sql (required), row_limit. Returns: object
explain_queryA
Return the database execution plan for one safe SELECT query.
Inputs: sql (required). Returns: object
explore_schemaA
Explore database tables, columns, keys, indexes, and sample rows.
Inputs: table_name, include_sample_data. Returns: object
migration_contextB
Return schema context for client-side migration generation.
Inputs: no named parameters. Returns: object
suggest_indexB
Suggest indexes from a query plan or table foreign-key metadata.
Inputs: query, table_name. Returns: object
validate_migrationA
Validate migration scripts without executing them.
Inputs: up_sql (required), down_sql (required). Returns: object
validate_schemaC
Check tables for missing primary keys and unindexed foreign keys.
Inputs: table_name. Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 7 tools
Most tools have distinct purposes: exploring, executing, explaining, validating, and suggesting indexes are clearly separate. The main overlap risk is between explore_schema and migration_context, since both provide schema context, but their intended use cases differ enough to avoid serious confusion.
Six of seven tools follow a clean verb_noun pattern (explore_schema, execute_query, explain_query, validate_schema, suggest_index, validate_migration). migration_context breaks the pattern by being a noun phrase, but the overall naming style remains predictable and readable.
With 7 tools, the server is well-scoped for the stated purpose of database exploration, query execution, and migration validation. Each tool addresses a meaningful workflow step without unnecessary bloat.
The toolset covers the core read-only database workflows: schema inspection, query validation/execution/explanation, structural tenant-focused checks, index suggestions, and migration validation. No obvious dead-end exists for the server's stated purpose.
Maintenance
Related MCP Connectors
Query your org's data in natural language — read-only MCP access to SQL, NoSQL, files & warehouses.
Query your warehouse or a CSV with Claude/ChatGPT over MCP, governed by table-level ACL + audit.
Draxlr's remote MCP server connects AI assistants to your SQL databases and dashboards. Explore schemas, run read-only queries, manage saved queries and dashboards, and export results, all with row-level security so each user sees only their own data.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceAn MCP server that provides safe, read-only access to SQLite databases through MCP. This server is built with the FastMCP framework, which enables LLMs to explore and query SQLite databases with built-in safety features and query validation.107-
- FlicenseNot gradedqualityFmaintenanceA production-ready MCP server that transforms natural language into safe, executable SQL queries with multi-database support and intelligent schema analysis.1-
- AlicenseNot gradedqualityDmaintenanceA read-only MCP server for PostgreSQL that enables safe database introspection and querying via natural language.MIT
- FlicenseAqualityCmaintenanceRead-only Text-to-SQL MCP server for PostgreSQL and MySQL that lets users query databases using natural language, with robust multi-layer safety guarantees against writes.6-