Skip to main content
Glama
MySQL MCP Server

MySQL MCP Server

テストPyPI - ダウンロード 鍛冶屋のバッジ

MySQL MCP サーバー

MySQLデータベースとの安全なやり取りを可能にするモデルコンテキストプロトコル(MCP)実装。このサーバーコンポーネントは、AIアプリケーション(ホスト/クライアント)とMySQLデータベース間の通信を容易にし、制御されたインターフェースを通じてデータベースの探索と分析をより安全かつ構造化します。

注: MySQL MCP サーバーは、スタンドアロン サーバーとして使用するように設計されているのではなく、AI アプリケーションと MySQL データベース間の通信プロトコル実装として設計されています。

特徴

  • 利用可能な MySQL テーブルをリソースとして一覧表示する

  • 表の内容を読む

  • 適切なエラー処理でSQLクエリを実行する

  • 環境変数による安全なデータベースアクセス

  • 包括的なログ記録

Related MCP server: PostgreSQL MCP Server

インストール

手動インストール

pip install mysql-mcp-server

Smithery経由でインストール

Smithery経由で Claude Desktop 用の MySQL MCP Server を自動的にインストールするには:

npx -y @smithery/cli install mysql-mcp-server --client claude

構成

次の環境変数を設定します。

MYSQL_HOST=localhost     # Database host
MYSQL_PORT=3306         # Optional: Database port (defaults to 3306 if not specified)
MYSQL_USER=your_username
MYSQL_PASSWORD=your_password
MYSQL_DATABASE=your_database

使用法

クロード・デスクトップ

これをclaude_desktop_config.jsonに追加します:

{
  "mcpServers": {
    "mysql": {
      "command": "uv",
      "args": [
        "--directory", 
        "path/to/mysql_mcp_server",
        "run",
        "mysql_mcp_server"
      ],
      "env": {
        "MYSQL_HOST": "localhost",
        "MYSQL_PORT": "3306",
        "MYSQL_USER": "your_username",
        "MYSQL_PASSWORD": "your_password",
        "MYSQL_DATABASE": "your_database"
      }
    }
  }
}

Visual Studio Codeを使用

mcp.jsonに以下を追加します:

{
  "servers": {
      "mysql": {
            "type": "stdio",
            "command": "uvx",
            "args": [
                "--from",
                "mysql-mcp-server",
                "mysql_mcp_server"
            ],
      "env": {
        "MYSQL_HOST": "localhost",
        "MYSQL_PORT": "3306",
        "MYSQL_USER": "your_username",
        "MYSQL_PASSWORD": "your_password",
        "MYSQL_DATABASE": "your_database"
      }
  }
}

注: これを動作させるには uv をインストールする必要があります

MCP Inspectorによるデバッグ

MySQL MCP Server はスタンドアロンで実行したり、Python を使用してコマンドラインから直接実行したりすることを目的としていませんが、MCP Inspector を使用してデバッグすることができます。

MCP インスペクターは、MCP 実装をテストおよびデバッグするための便利な方法を提供します。

# Install dependencies
pip install -r requirements.txt
# Use the MCP Inspector for debugging (do not run directly with Python)

MySQL MCP サーバーは、Claude Desktop などの AI アプリケーションと統合されるように設計されており、スタンドアロンの Python プログラムとして直接実行しないでください。

発達

# Clone the repository
git clone https://github.com/yourusername/mysql_mcp_server.git
cd mysql_mcp_server
# Create virtual environment
python -m venv venv
source venv/bin/activate  # or `venv\Scripts\activate` on Windows
# Install development dependencies
pip install -r requirements-dev.txt
# Run tests
pytest

セキュリティに関する考慮事項

  • 環境変数や資格情報をコミットしないでください

  • 必要最小限の権限を持つデータベースユーザーを使用する

  • 本番環境での使用にクエリホワイトリストを実装することを検討する

  • すべてのデータベース操作を監視して記録する

セキュリティのベストプラクティス

このMCP実装は、データベースアクセスを必要とします。セキュリティのため、

  1. 最小限の権限を持つ専用のMySQLユーザーを作成する

  2. ルート認証情報や管理者アカウントは使用しないでください

  3. 必要な操作のみにデータベースアクセスを制限する

  4. 監査目的でログを有効にする

  5. データベースアクセスの定期的なセキュリティレビュー

詳細な手順については、 MySQL セキュリティ構成ガイドを参照してください。

  • 制限付きMySQLユーザーの作成

  • 適切な権限の設定

  • データベースアクセスの監視

  • セキュリティのベストプラクティス

⚠️ 重要: データベース アクセスを構成するときは、常に最小権限の原則に従ってください。

ライセンス

MIT ライセンス - 詳細については LICENSE ファイルを参照してください。

貢献

  1. リポジトリをフォークする

  2. 機能ブランチを作成します( git checkout -b feature/amazing-feature )

  3. 変更をコミットします ( git commit -m 'Add some amazing feature' )

  4. ブランチにプッシュする ( git push origin feature/amazing-feature )

  5. プルリクエストを開く

Available Tools

3 tools
execute_sqlA
Destructive

Execute a SQL statement against the MySQL server. Use for SELECT, DML (INSERT/UPDATE/DELETE), SHOW, DESCRIBE, and ad-hoc queries. Supports cross-database queries using database.table notation. Single statements only — use fully qualified names instead of USE statements.

Inputs: query (required).

get_schema_infoA
Read-only

Get column metadata for a table or all tables in the configured database: column names, data types, nullability, default values, and comments. Call this before querying an unfamiliar table. Omit table_name to see all tables at once. Accepts bare table names (uses MYSQL_DATABASE) or database.table for cross-database lookups.

Inputs: table_name.

get_table_sampleA
Read-only

Fetch a small sample of rows from a table to understand its data format and content. Use alongside get_schema_info before writing complex queries. Accepts bare table names (uses MYSQL_DATABASE) or database.table for cross-database lookups.

Inputs: table_name (required), limit.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.3/5.0

    Scored across 3 tools

    Disambiguation5/5

    Each tool has a distinct and clear purpose: executing SQL, retrieving schema metadata, and fetching sample data. No overlap in functionality.

    Naming Consistency5/5

    All tool names follow a consistent verb_noun pattern in snake_case (execute_sql, get_schema_info, get_table_sample), making them predictable.

    Tool Count5/5

    Three tools is appropriate for the server's scope—covering query execution, schema inspection, and data sampling. Not too few or excessive.

    Completeness4/5

    Covers core database interaction needs (query, schema, sample). Minor gaps like database listing or DDL support exist but are acceptable for the stated purpose.

    Maintenance

    ActivityMaintained
    ResponsivenessUsually handled

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables secure interaction with MySQL databases, allowing AI assistants to list tables, read data, and execute SQL queries through a controlled interface.
      -
    • A
      license
      Not graded
      quality
      Not graded
      maintenance
      Provides AI assistants with safe, controlled access to PostgreSQL databases with read-only defaults, granular permissions, query safety features, and schema introspection capabilities.
      1
      -
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI assistants to safely query and explore SQL Server and PostgreSQL databases with read-only access, supporting schema discovery, relationship exploration, and query execution.
      33 npm
      3
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables AI assistants to query and interact with MySQL, PostgreSQL, and SQLite databases through saved connections, supporting read-only exploration and optional write operations with safety controls.
      MIT