About MySQL MCP Server
MySQL MCP Server connects MCP clients to MySQL databases for table inspection, data reads, and SQL execution. It also documents access to MySQL running in WSL.
Key features
- 01List database tables
- 02Read up to 100 rows from a table
- 03Run SELECT and SHOW TABLES queries
- 04Run INSERT, UPDATE, and DELETE statements
- 05Document WSL connectivity
Use cases
- 01Inspect tables in a MySQL database
- 02Read table data for further processing
- 03Execute database queries or updates through MCP
MCP support
The MCP server exposes table listing and reading as resources, and provides a tool for executing SQL queries.
Configuration
Local server config is the same for every client. Copy it into your client’s MCP config file.
Tools
Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.
Details
From the project READMEMySQL MCP Server
このプロジェクトは、MCP (Model Context Protocol) を使用してMySQLデータベースとやり取りするためのサーバーを提供します。WSL環境でMySQLデータベースにアクセスするためのインターフェースを提供します。
機能
- MySQLデータベース内のテーブル一覧の取得
- テーブルからのデータ読み取り(最大100行)
- SQLクエリの実行(SELECT、SHOW TABLES、INSERT、UPDATE、DELETEなど)
プロジェクト構造
src/mysql_mcp_server/
├── __init__.py # パッケージ初期化
├── config/ # 設定関連モジュール
│ ├── __init__.py
│ └── settings.py # データベース設定
├── database/ # データベース操作モジュール
│ ├── __init__.py
│ ├── connection.py # DB接続処理
│ └── errors.py # エラークラス
├── tools/ # ツールモジュール
│ ├── __init__.py
│ └── sql_tools.py # SQL実行ツール
└── server.py # MCPサーバーメイン
インストールと実行
前提条件
- Python 3.11以上
- MySQLサーバー(ローカルまたはリモート)
- 仮想環境(virtualenv)
- Docker(Dockerを使用する場合)
セットアップ
-
リポジトリをクローン:
git clone <repository-url> cd mysql_mcp_server -
仮想環境を作成し、アクティベート:
python -m venv .venv source .venv/bin/activate # Linuxの場合 -
依存関係をインストール:
pip install -r requirements.txt . -
セットアップスクリプトを実行して、実行スクリプトに実行権限を付与:
chmod +x setup.sh ./setup.sh
実行方法
以下のいずれかの方法でサーバーを実行できます:
1. 直接実行
./run_direct.sh
2. モジュールとして実行
./run_module.sh
3. Dockerコンテナで実行
# Dockerイメージをビルド
docker build -t mysql-mcp-server:latest .
# コンテナを実行
./run_docker.sh
環境変数
サーバーは以下の環境変数を使用してMySQLに接続します:
MYSQL_HOST: MySQLサーバーのホスト(デフォルト:host.docker.internal)MYSQL_PORT: MySQLサーバーのポート(デフォルト:13306)MYSQL_USER: MySQLユーザー名MYSQL_PASSWORD: MySQLパスワードMYSQL_DATABASE: 使用するデータベース名
MCPプロトコル
このサーバーはMCP(Model Control Protocol)を実装しており、以下のエンドポイントを提供します:
list_resources: データベース内のテーブル一覧を取得read_resource: 特定のテーブルからデータを読み取りlist_tools: 利用可能なツール(SQLクエリの実行)を一覧表示call_tool: SQLクエリを実行
WSL連携
WSL(Windows Subsystem for Linux)環境内のMySQLサーバーに接続する場合:
- WSL内のMySQLサーバーが起動していることを確認
- WSL内のMySQLがリモート接続を許可するように設定されていることを確認
/etc/mysql/mysql.conf.d/mysqld.cnfファイルでbind-addressを0.0.0.0に変更- 使用するMySQLユーザーにリモートからのアクセス権限を付与
- Windows側のファイアウォールがMySQLポート(デフォルト13306)への接続を許可していることを確認
開発
Noxセッション
このプロジェクトは、テスト、フォーマット、リントのためのNoxセッションを提供しています。
-
Noxをインストール:
pip install nox -
全てのテストを実行:
nox -s test -
コードをフォーマット:
nox -s format -
リントチェックを実行:
nox -s lint
直接テストを実行
pytest tests/
コードカバレッジを確認
pytest --cov=src.mysql_mcp_server tests/
ライセンス
このプロジェクトはMITライセンスの下で公開されています。
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.