Database MCP Server
データベースMCPサーバー
さまざまなデータベース システムに接続して対話するためのツールを提供するモデル コンテキスト プロトコル (MCP) サーバー。
特徴
マルチデータベースのサポート: SQLite、PostgreSQL、MySQL/MariaDB、SQL Server データベースに接続します
統合インターフェース: サポートされているすべてのデータベース タイプでデータベース操作を行うための共通ツール
データベース固有の拡張機能: 必要に応じて、データベース固有の機能のための特定のツール
スキーマ管理: テーブルとインデックスの作成、変更、削除
クエリ実行: 生のSQLクエリを実行するか、構造化クエリツールを使用する
トランザクションサポート: トランザクションの開始、コミット、ロールバック
Related MCP server: MCP TapData Server
インストール
前提条件
Python 3.8以上
必要な Python パッケージ (pip で自動的にインストールされます):
SQLアルケミー
使用するデータベースに応じて、さまざまなデータベース ドライバーがあります。
SQLite (Python に含まれています)
PostgreSQL:
psycopg2-binaryMySQL/MariaDB:
mysql-connector-pythonSQL サーバー:
pyodbc
ソースからのインストール
# Clone the repository
git clone <repository-url>
# Install the package
pip install -e .構成
サーバーは、環境変数、構成ファイル、または実行時に接続の詳細を提供することで構成できます。
環境変数
DB_CONFIG_PATH: JSON設定ファイルへのパスDB_CONNECTIONS: 接続IDのカンマ区切りリスト、または接続の詳細を含むJSON文字列
設定ファイルの形式
{
"connections": {
"sqlite_conn": {
"type": "sqlite",
"db_path": "/path/to/database.db"
},
"postgres_conn": {
"type": "postgres",
"host": "localhost",
"port": 5432,
"database": "mydatabase",
"user": "myuser",
"password": "mypassword"
}
}
}使用法
サーバーの実行
クロードのMCPサーバーとして
# Run with default settings
python -m db_mcp_server
# Specify a configuration file
python -m db_mcp_server --config /path/to/config.json
# Set logging level
python -m db_mcp_server --log-level DEBUGスタンドアロン Web サーバーとして (任意の LLM 用)
# Run as a web server
python -m db_mcp_server.web_server
# Specify host and port
python -m db_mcp_server.web_server --host 0.0.0.0 --port 8000
# Specify configuration file and logging level
python -m db_mcp_server.web_server --config /path/to/config.json --log-level DEBUG利用可能なMCPツール
接続管理
add_connection: 新しいデータベース接続を追加するtest_connection: データベース接続をテストするlist_connections: すべてのデータベース接続を一覧表示するremove_connection: データベース接続を削除する
クエリ実行
execute_query: SQLクエリを実行するget_records: テーブルからレコードを取得するinsert_record: テーブルにレコードを挿入するupdate_record: テーブル内のレコードを更新するdelete_record: テーブルからレコードを削除する
スキーマ管理
list_tables: データベース内のすべてのテーブルを一覧表示するget_table_schema: テーブルのスキーマを取得するcreate_table: 新しいテーブルを作成するdrop_table: テーブルを削除するcreate_index: テーブルにインデックスを作成するdrop_index: インデックスを削除するalter_table: テーブル構造を変更する
トランザクション管理
begin_transaction: トランザクションを開始するcommit_transaction: トランザクションをコミットするrollback_transaction: トランザクションをロールバックする
例
接続を追加する
{
"connection_id": "my_sqlite_db",
"type": "sqlite",
"db_path": "/path/to/database.db"
}クエリを実行する
{
"connection_id": "my_sqlite_db",
"query": "SELECT * FROM users WHERE age > ?",
"params": [21]
}テーブルを作成する
{
"connection_id": "my_sqlite_db",
"table": "users",
"columns": [
{
"name": "id",
"type": "INTEGER",
"primary_key": true,
"nullable": false
},
{
"name": "name",
"type": "TEXT",
"nullable": false
},
{
"name": "email",
"type": "TEXT",
"nullable": true
}
]
}レコードを挿入
{
"connection_id": "my_sqlite_db",
"table": "users",
"data": {
"name": "John Doe",
"email": "john@example.com"
}
}発達
テストの実行
# Run all tests
python -m unittest discover
# Run specific test file
python -m unittest tests.test_sqlite他のLLMからの接続
スタンドアロンのウェブサーバーとして実行する場合、他のLLM(Llama 3など)はHTTP経由でデータベースMCPサーバーに接続できます。サーバーは以下のエンドポイントを公開します。
エンドポイント
/list_tools- GET または POST: 利用可能なすべてのツールとその説明および入力スキーマのリストを返します。/call_tool- POST: 特定のデータベースツールを実行する
例: 別の LLM からの呼び出し
このサーバーを他のLLMと併用するには、LLMにサーバーへのHTTPリクエストを生成させます。Llama 3のようなLLMのプロンプトの構造例を以下に示します。
You can interact with a database by making HTTP requests to a database service at http://localhost:8000.
The service provides the following endpoints:
1. To get a list of available tools:
Make a POST request to: http://localhost:8000/list_tools
2. To execute a database tool:
Make a POST request to: http://localhost:8000/call_tool
with a JSON body like:
{
"name": "tool_name",
"arguments": {
"param1": "value1",
"param2": "value2"
}
}
For example, to execute a SQL query, you would make a request like:
POST http://localhost:8000/call_tool
Content-Type: application/json
{
"name": "execute_query",
"arguments": {
"connection_id": "my_db",
"query": "SELECT * FROM users"
}
}クライアント統合用のサンプル Python コード
import requests
import json
# Base URL of the database MCP server
BASE_URL = "http://localhost:8000"
# List available tools
def list_tools():
response = requests.post(f"{BASE_URL}/list_tools")
return response.json()
# Execute a database tool
def call_tool(tool_name, arguments):
payload = {
"name": tool_name,
"arguments": arguments
}
response = requests.post(f"{BASE_URL}/call_tool", json=payload)
return response.json()
# Example: List tables in a database
def list_tables(connection_id):
return call_tool("list_tables", {"connection_id": connection_id})
# Example: Execute a SQL query
def execute_query(connection_id, query, params=None):
return call_tool("execute_query", {
"connection_id": connection_id,
"query": query,
"params": params
})
# Example: Add a new connection
def add_connection(connection_id, db_type, **kwargs):
args = {"connection_id": connection_id, "type": db_type}
args.update(kwargs)
return call_tool("add_connection", args)ライセンス
This server cannot be deployed
Maintenance
Related MCP Connectors
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
Model Context Protocol server for Studex tools, notifications, and profile integrations
A Model Context Protocol server for Wix AI tools
Model Context Protocol server for the Apideck Unified API. Connect any MCP-compatible agent framework to 100+ accounting systems, HRIS platforms, file storage providers, and more through one integration. More information https://www.apideck.com/mcp-server
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceA Model Context Protocol (MCP) implementation for connecting to and working with various database systems.16 npm21MIT

MCP TapData Serverofficial
FlicenseNot gradedqualityDmaintenanceA Model Context Protocol server that enables Large Language Models to access and interact with database connections, including viewing schemas and performing CRUD operations on connected databases.-- AlicenseBqualityCmaintenanceA Model Context Protocol server that enables SQL operations (SELECT, INSERT, UPDATE, DELETE) and table management through a standardized interface with SQLite databases.743 npm1ISC
- FlicenseCqualityDmaintenanceA Model Context Protocol server that provides a standardized interface for interacting with SQL databases through the MCP protocol.38 npm4-