MCP Database Server
MCP データベースサーバー
柱: プロトコル、相互運用性 & API
ステータス: 月1 - 必須
LLMクライアントにスキーマ、安全なクエリ、ストアドプロシージャを公開するためのPython製MCPサーバー。
問題
LLMは、広範な認証情報を付与したり破壊的なSQLを実行する自由を与えずに、企業データベースを照会する必要がある。
Related MCP server: DB Insights MCP Server
MVP
FastMCPを使用したMCPサーバー
許可されたスキーマの一覧表示
読み取り専用クエリ
ストアドプロシージャの許可リスト
呼び出しの監査
アーキテクチャ
MCPサーバー(
mcp.server.MCPServer、@mcp.tool()で登録されたツール)スキーマレジストリ(テーブル/カラムの許可リスト、
db.py)読み取り専用オーソライザー(
sqlite3.Connection.set_authorizer、security.py)監査ロガー(各ツール呼び出しのインメモリトレイル、
audit.py)
図
flowchart LR
A0[MCP client] --> A1[MCP server: list_tables / describe_table / run_readonly_query]
A1 --> A2[SQLite authorizer: allowlist + read-only]
A2 --> A3[SQLite: invoices]
A1 --> A4[Audit log]スタック
Python
mcp(Model Context Protocol公式SDK)SQLite(stdlibの
sqlite3、アクセス制御にset_authorizerを使用)unittest
Docker Compose
実行方法
MCP公式SDKによる実際の実装。アクセス制御はSQLに対する正規表現(回避が容易)を使用せず、SQLite自体のset_authorizerを使用する。これは、行が実行される前に、読み取られる各テーブル/カラムと各ステートメントタイプを承認または拒否する。MCPサーバーを実行するには:
python3.12 -m venv .venv && source .venv/bin/activate
pip install -e .
python -m mcp_database_server # sobe o servidor MCP via stdio
python -m unittest discover -s testsテスト
test_security.py: オーソライザーがINSERT/UPDATE/DELETE/DROP/ALTER、ATTACH、許可リスト外のテーブル(例:sqlite_master)、およびスタックされたステートメント(SELECT 1; DROP TABLE ...)をブロックする。test_server.py: 各ツールのロジックを直接呼び出し(プロトコルなし)、すべての呼び出しが監査イベントを生成することを含む。test_integration.py:python -m mcp_database_serverを実際のサブプロセスとして起動し、mcp.client.stdio+ClientSession経由で通信する - サーバーがMCPを話すことを証明する。Python関数が動作するだけではない。
リスクと決定事項
SQLインジェクションと過剰な権限: 正規表現ではなく、ドライバーレベルで
set_authorizerを使用して解決。単一のSQLite接続はスレッドセーフではない。MCPサーバーは各ツール呼び出しをワーカースレッドにディスパッチするため、
ServerState.lockがアクセスを直列化する(実装中に発見・修正された実際のバグで、test_integration.pyでカバー)。MCPツールは、スタックトレースを漏らす代わりに、LLMクライアントに明確なメッセージ付きの
ValueErrorを返す。
次のステップ
実際のデータがある場合、SQLAlchemy経由でSQLiteをPostgreSQLに置き換える。
クライアントごとの認証/許可リストを追加する(現在は、接続されたMCPクライアントはすべてツールにアクセスできる)。
監査ログをプロセス外に永続化する(現在はインメモリのみ)。
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceProvides secure, read-only access to Microsoft SQL Server with multi-layer protection, enabling safe query execution, schema discovery, and SQL script analysis through natural language.1
- FlicenseNot gradedqualityCmaintenanceEnables AI assistants to query SQL databases safely with read-only access, allowing schema discovery and SELECT queries while blocking writes and DDL operations.
- AlicenseNot gradedqualityBmaintenanceEnables LLM clients to query SQL databases via natural language with read-only, AST-validated, and capped queries, ensuring safety guarantees.2MIT
- AlicenseNot gradedqualityBmaintenanceProvides read-only access to databases for MCP-compatible AI tools, allowing schema exploration and SELECT queries without exposing credentials or risking data changes.923MIT
Related MCP Connectors
Query PostgreSQL databases in plain English — LLM-generated, safety-validated SQL.
Runtime permission, approval, and audit layer for AI agent tool execution.
Read-only access to your VortexIQ store data: audits, KPIs, alerts, Brand DNA, reports, Ask VIQ.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/oliverhubtech-source/mcp-database-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server