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:テーブルの一覧表示または1つのテーブルの調査

  • execute_query:安全な読み取り専用SELECTを1回実行

  • 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
      -