DB Agent MCP Server
Provides tools for executing SQL queries against MySQL databases, including read-only operations (SELECT, SHOW, DESCRIBE, EXPLAIN) and write operations (INSERT, UPDATE, DELETE, CREATE, DROP, ALTER) with approval requirements for data modifications.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@DB Agent MCP Servershow me the top 10 customers by total purchases"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
DB Agent MCP Server
MySQLデータベースにクエリを実行するMCPサーバーです。
セットアップ
1. 依存関係のインストール
bun install2. 環境変数の設定
.envファイルを作成し、以下の環境変数を設定してください:
# データベース設定(必須)
DB_HOST=localhost
DB_PORT=3306
DB_USER=root
DB_PASS=root
DB_NAME=appdb
# サーバー設定(オプション)
PORT=3000
# 認証設定(オプション)
AUTH_ENABLED=false # 認証を有効にする場合は true
API_KEY=your-secret-api-key # 認証が有効な場合に使用するAPIキー認証について:
AUTH_ENABLED=false(デフォルト): 認証なしで動作します(開発環境向け)AUTH_ENABLED=true: 認証が有効になります。この場合、API_KEYの設定が必須です認証が有効な場合、リクエストには以下のいずれかの方法でAPIキーを含める必要があります:
Authorization: Bearer <API_KEY>ヘッダーAuthorization: ApiKey <API_KEY>ヘッダーX-API-Key: <API_KEY>ヘッダー
3. MySQLデータベースの起動
docker build -t local-mcp-mysql ./docker/mysql
docker run -d \
-p 3306:3306 \
--name mcp-mysql \
-e MYSQL_ROOT_PASSWORD=root \
local-mcp-mysql
docker exec -it mcp-mysql mysql -uroot -proot appdbDockerコンテナの停止・削除
コンテナを停止する場合:
docker stop mcp-mysqlコンテナを停止して削除する場合:
docker stop mcp-mysql
docker rm mcp-mysqlコンテナを停止せずに削除する場合(強制削除):
docker rm -f mcp-mysql4. MCPサーバーの起動
HTTPサーバーとして起動します:
bun run startデフォルトでhttp://localhost:3000/mcpで起動します。ポートを変更する場合は環境変数PORTを設定してください。
PORT=8080 bun run start認証について:
デフォルトでは認証が無効(
AUTH_ENABLED=false)です本番環境では
AUTH_ENABLED=trueとAPI_KEYを設定して認証を有効にしてください
5. MCPクライアントの設定
Cursorの場合
認証が無効な場合(開発環境):
Cursorの設定ファイル(~/.cursor/mcp.json または設定UI)に以下を追加:
{
"mcpServers": {
"db-agent": {
"url": "http://localhost:3000/mcp"
}
}
}認証が有効な場合(本番環境):
headersセクションを使用してAPIキーを指定します。以下のいずれかの方法を使用できます:
方法1: X-API-Keyヘッダーを使用
{
"mcpServers": {
"db-agent": {
"url": "http://localhost:3000/mcp",
"headers": {
"X-API-Key": "your-secret-api-key"
}
}
}
}方法2: Authorizationヘッダーを使用(Bearer形式)
{
"mcpServers": {
"db-agent": {
"url": "http://localhost:3000/mcp",
"headers": {
"Authorization": "Bearer your-secret-api-key"
}
}
}
}方法3: Authorizationヘッダーを使用(ApiKey形式)
{
"mcpServers": {
"db-agent": {
"url": "http://localhost:3000/mcp",
"headers": {
"Authorization": "ApiKey your-secret-api-key"
}
}
}
}Claude Desktopの場合
認証が無効な場合(開発環境):
~/Library/Application Support/Claude/claude_desktop_config.json に以下を追加:
{
"mcpServers": {
"db-agent": {
"url": "http://localhost:3000/mcp"
}
}
}認証が有効な場合(本番環境):
headersセクションを使用してAPIキーを指定します:
{
"mcpServers": {
"db-agent": {
"url": "http://localhost:3000/mcp",
"headers": {
"X-API-Key": "your-secret-api-key"
}
}
}
}または
{
"mcpServers": {
"db-agent": {
"url": "http://localhost:3000/mcp",
"headers": {
"Authorization": "Bearer your-secret-api-key"
}
}
}
}重要: MCPサーバーを起動してから、CursorやClaude Desktopを再起動してください。
Related MCP server: MySQL Database Server
使用方法
MCPクライアントから以下の2つのツールを使用してSQLクエリを実行できます。
run_query_readonly - 読み取り専用クエリ(承認不要)
SELECT、SHOW、DESCRIBE、DESC、EXPLAINクエリを実行します。このツールは承認を求めません。
例:
SELECT * FROM users LIMIT 10;SELECT COUNT(*) FROM sessions;SHOW TABLES;DESCRIBE users;EXPLAIN SELECT * FROM users;
run_query_write - 書き込みクエリ(承認必要)
INSERT、UPDATE、DELETE、CREATE、DROP、ALTERなどの書き込み操作を実行します。このツールはユーザーの承認を求めます。
例:
INSERT INTO users (name, email) VALUES ('John', 'john@example.com');UPDATE users SET name = 'Jane' WHERE id = 1;DELETE FROM sessions WHERE expired_at < NOW();CREATE TABLE products (id INT PRIMARY KEY, name VARCHAR(255));
This server cannot be deployed
Maintenance
Related MCP Connectors
Safe, read-only Postgres and MySQL access for AI agents. Audit log + column-level controls.
Generate, fix, explain and run read-only SQL on PostgreSQL, MySQL and SQL Server
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.
Query 40 databases from Claude, ChatGPT, or Cursor — on any device. Read-only, encrypted, audited.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables secure interaction with MySQL databases, allowing AI assistants to list tables, read data, and execute SQL queries through a controlled interface.-
- AlicenseNot gradedqualityDmaintenanceEnables secure MySQL database operations through natural language with built-in safety features. Supports SELECT queries by default while providing configurable restrictions for INSERT, UPDATE, and DELETE operations.133 npmMIT
- AlicenseBqualityNot gradedmaintenanceEnables secure interaction with MySQL databases through listing tables, reading data, and executing SQL queries with proper error handling and controlled access.1MIT
- FlicenseNot gradedqualityDmaintenanceEnables AI assistants to securely interact with MySQL databases, including listing tables, viewing schemas, and executing read-only SQL queries through natural language.6-