0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Azure Database for MySQL MCP Server (Preview)

Posted at

はじめに

4月に発表された Azure Database for PostgreSQL MCP Server (Preview) に続いて、Azure Database for MySQL MCP Server (Preview) が 日本時間6月5日に発表されました。
https://techcommunity.microsoft.com/blog/adformysql/model-context-protocol-mcp-server-for-azure-database-for-mysql/4418075
image.png
内容としては、前述の for PostgreSQL と殆ど同じですが、jsonでdatabaseを指定しなくなっています。また、クローンするリポジトリがAzure MySQL全体になっています。

注意点

本記事は、Azure Database for MySQL MCP Server リポジトリ の2025年6月5日の情報を基に作成しています。閲覧日時によっては、記事の情報がリポジトリと乖離したり、手順通りに実行できなくなる可能性があります。最新情報は随時 Azure Database for MySQL Blog にて確認してください。

必要なもの

・Python 3.10 以降
・Azure Database for MySQL フレキシブルサーバー
・MCPクライアントアプリケーション ( VSCode や Claude Desktop)

インストール手順

:one: リポジトリのクローン

git clone https://github.com/Azure/azure-mysql.git
cd azure-mysql
cd azure-mysql-mcp

:two: 仮想環境の構築

Windows cmd:

python -m venv azure-mysql-mcp-venv
.\azure-mysql-mcp-venv\Scripts\activate.bat

Windows PowerShell:

python -m venv azure-mysql-mcp-venv
.\azure-mysql-mcp-venv\Scripts\Activate.ps1

MacOS and Linux:

python -m venv azure-mysql-mcp-venv
source ./azure-mysql-mcp-venv/bin/activate 

:three: 依存関係のインストール

pip install mcp
pip install mysql-connector-python
pip install azure-mgmt-mysqlflexibleservers
pip install azure-identity

Claude DesktopでMCPサーバーを使用する方法

:one: Claude Desktop にて ファイル → 設定 → 開発者を選択し、「構成を編集」をクリック
:two: claude_desktop_config.json の編集で、以下のコードを必要事項を記入しつつ追加

{
    "mcpServers": {
        "azure-mysql-mcp": {
            "command": "<path to the virtual environment>\\azure-mysql-mcp-venv\\Scripts\\python",
            "args": [
                "<path to azure_mysql_mcp.py file>\\azure_mysql_mcp.py"
            ],
            "env": {
                "MYSQLHOST": "<Fully qualified name of your Azure Database for MySQL instance>",
                "MYSQLUSER": "<Your Azure Database for MySQL username>",
                "MYSQLPASSWORD": "<Your Azure Database for MySQL password>"
            }
        }        
    }
}

:three: Claude Desktop を再起動

VSCodeでMCP Serverを使用する方法

:one: VSCode の Setting にて、"MCP"と検索し、"Edit in setting.json"をクリックする
:two: "setting.json" の "mcp" セクションに以下のコードを必要情報を記入しつつ追加

{
    "mcp": {
        "inputs": [],
        "servers": {
            "azure-mysql-mcp": {
                "command": "<path to the virtual environment>\\azure-mysql-mcp-venv\\Scripts\\python",
                "args": [
                    "<path to azure_mysql_mcp.py file>\\azure_mysql_mcp.py"
                ],
                "env": {
                    "MYSQLHOST": "<Fully qualified name of your Azure Database for MySQL instance>",
                    "MYSQLUSER": "<Your Azure Database for MySQL username>",
                    "MYSQLPASSWORD": "<Your Azure Database for MySQL password>"
                }
            }
        }
    }
}

:three: VSCode の Copilot チャットウィンドウを開き、Agent モードに変更する。
:four: スパナアイコンをクリックし、tools に "MCP Server: azure-mysql-mcp" が含まれていることを確認する

Microsoft Entra Authentication を使用してログインする場合

Claude Desktop の場合は claude_desktop_config.json、VSCodeの場合は setting.json のコードを以下のコードに必要事項を記入しつつ書き換える

"azure-mysql-mcp": {
    "command": "<path to the virtual environment>\\azure-mysql-mcp-venv\\Scripts\\python",
    "args": [
        "<path to azure_mysql_mcp.py file>\\azure_mysql_mcp.py"
    ],
    "env": {
        "MYSQLHOST": "<Fully qualified name of your Azure Database for MySQL instance>",
        "MYSQLUSER": "<Your Microsoft Entra ID username or the resource name of your Azure resource with a system-assigned identity or the identity name>",
        "AZURE_USE_AAD": "True",
        "AZURE_SUBSCRIPTION_ID": "<Your Azure subscription ID>",
        "AZURE_RESOURCE_GROUP": "<Your Resource Group that contains the Azure Database for MySQL instance>"
    }
}

検証

Claude Desktopを用いて、MCP Serverを利用します。
Azure Database for MySQLに、sample_storeというデータベースを作成するよう依頼すると、以下のようなSQLコードを生成し、実際にデータベースを作成してくれました。

{
  `s`: `CREATE TABLE customers (
    customer_id INT PRIMARY KEY AUTO_INCREMENT,
    first_name VARCHAR(50) NOT NULL,
    last_name VARCHAR(50) NOT NULL,
    email VARCHAR(100) UNIQUE NOT NULL,
    phone VARCHAR(20),
    address VARCHAR(200),
    city VARCHAR(50),
    state VARCHAR(50),
    zip_code VARCHAR(10),
    created_date DATE DEFAULT (CURRENT_DATE)
)`,
  `database`: `sample_store`
}

{
  `s`: `INSERT INTO customers (first_name, last_name, email, phone, address, city, state, zip_code) VALUES
('John', 'Smith', 'john.smith@email.com', '555-0101', '123 Main St', 'New York', 'NY', '10001'),
('Sarah', 'Johnson', 'sarah.johnson@email.com', '555-0102', '456 Oak Ave', 'Los Angeles', 'CA', '90210'),
('Michael', 'Brown', 'michael.brown@email.com', '555-0103', '789 Pine Rd', 'Chicago', 'IL', '60601'),
('Emily', 'Davis', 'emily.davis@email.com', '555-0104', '321 Elm St', 'Houston', 'TX', '77001'),
('David', 'Wilson', 'david.wilson@email.com', '555-0105', '654 Maple Dr', 'Phoenix', 'AZ', '85001')`,
  `database`: `sample_store`
}
{
  `s`: `CREATE TABLE products (
    product_id INT PRIMARY KEY AUTO_INCREMENT,
    product_name VARCHAR(100) NOT NULL,
    category VARCHAR(50),
    price DECIMAL(10,2) NOT NULL,
    stock_quantity INT DEFAULT 0,
    description TEXT,
    created_date DATE DEFAULT (CURRENT_DATE)
)`,
  `database`: `sample_store`
}

{
  `s`: `INSERT INTO products (product_name, category, price, stock_quantity, description) VALUES
('Wireless Headphones', 'Electronics', 79.99, 50, 'High-quality wireless headphones with noise cancellation'),
('Coffee Maker', 'Appliances', 129.99, 25, 'Programmable coffee maker with 12-cup capacity'),
('Running Shoes', 'Sports', 89.99, 75, 'Comfortable running shoes for all terrains'),
('Laptop Stand', 'Office', 34.99, 40, 'Adjustable aluminum laptop stand for ergonomic use'),
('Water Bottle', 'Sports', 19.99, 100, 'Insulated stainless steel water bottle, 32oz'),
('Desk Lamp', 'Office', 45.99, 30, 'LED desk lamp with adjustable brightness and color temperature'),
('Yoga Mat', 'Sports', 29.99, 60, 'Non-slip yoga mat with carrying strap'),
('Bluetooth Speaker', 'Electronics', 59.99, 35, 'Portable Bluetooth speaker with excellent sound quality')`,
  `database`: `sample_store`
}
{
  `s`: `CREATE TABLE orders (
    order_id INT PRIMARY KEY AUTO_INCREMENT,
    customer_id INT,
    order_date DATE DEFAULT (CURRENT_DATE),
    total_amount DECIMAL(10,2),
    status VARCHAR(20) DEFAULT 'pending',
    FOREIGN KEY (customer_id) REFERENCES customers(customer_id)
)`,
  `database`: `sample_store`
}

{
  `s`: `INSERT INTO orders (customer_id, order_date, total_amount, status) VALUES
(1, '2024-12-01', 159.98, 'completed'),
(2, '2024-12-02', 79.99, 'completed'),
(3, '2024-12-03', 89.99, 'shipped'),
(4, '2024-12-04', 104.98, 'pending'),
(5, '2024-12-05', 45.99, 'completed'),
(1, '2024-12-06', 29.99, 'shipped'),
(3, '2024-12-07', 209.98, 'pending')`,
  `database`: `sample_store`
}
{
  `s`: `CREATE TABLE order_items (
    order_item_id INT PRIMARY KEY AUTO_INCREMENT,
    order_id INT,
    product_id INT,
    quantity INT NOT NULL,
    unit_price DECIMAL(10,2) NOT NULL,
    FOREIGN KEY (order_id) REFERENCES orders(order_id),
    FOREIGN KEY (product_id) REFERENCES products(product_id)
)`,
  `database`: `sample_store`
}

{
  `s`: `INSERT INTO order_items (order_id, product_id, quantity, unit_price) VALUES
(1, 1, 1, 79.99),
(1, 1, 1, 79.99),
(2, 1, 1, 79.99),
(3, 3, 1, 89.99),
(4, 4, 2, 34.99),
(4, 5, 2, 19.99),
(5, 6, 1, 45.99),
(6, 7, 1, 29.99),
(7, 2, 1, 129.99),
(7, 1, 1, 79.99)`,
  `database`: `sample_store`
}

このサンプルデータベースのスキーマをたずねると、以下のドキュメントを生成しました。
https://claude.ai/public/artifacts/6f9b55e2-5579-4e55-8240-db3115786bad
image.png
image.png

また、可視化するようたずねると、Reactを使用してデータの可視化を行います。
https://claude.ai/public/artifacts/9c7b8cf1-e2b7-4a7d-92a3-6ba515185188

image.png
image.png

まとめ

これらの基本的な動作であれば、かなり素早くデータ操作やデータ参照を行ってくれます。Azure MCP Server が 先月(2025/05) Azure Database for PostgreSQL と 統合された ことを踏まえると、Azure Database for MySQL MCP Server のプレビューもその布石かもしれません。
Azure MCP Server も公開以降機能を拡充しつつあるので、今後どのようになっていくのか楽しみです。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?