Skip to main content
Glama
DB-Explorer-MCP

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:执行一个安全的只读 SELECT

  • explain_query:返回原生执行计划

  • validate_schema:报告缺失的主键和未索引的外键

  • suggest_index:根据表元数据或查询计划建议索引

  • migration_context:为客户端迁移生成提供模式上下文

  • validate_migration:验证提议的 UP 和 DOWN 脚本而不执行它们

每次查询执行和解释都经过安全层。变更语句、注释和多个语句都会被拒绝。查询结果默认最多返回 100 行。

测试

uv run pytest

测试套件使用临时 SQLite 数据库,不需要外部凭据或正在运行的数据库服务器。

远程部署

有关 FastMCP Horizon 部署步骤、远程数据库要求和身份验证清单,请参阅 DEPLOYMENT.md。

Available Tools

7 tools
execute_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

    A3.5/5.0

    Scored across 7 tools

    Disambiguation4/5

    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.

    Naming Consistency4/5

    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.

    Tool Count5/5

    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.

    Completeness5/5

    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

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      D
      maintenance
      An 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
      -
    • F
      license
      Not graded
      quality
      F
      maintenance
      A production-ready MCP server that transforms natural language into safe, executable SQL queries with multi-database support and intelligent schema analysis.
      1
      -
    • A
      license
      Not graded
      quality
      D
      maintenance
      A read-only MCP server for PostgreSQL that enables safe database introspection and querying via natural language.
      MIT
    • F
      license
      A
      quality
      C
      maintenance
      Read-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
      -