How to set up an MCP Server in Claude Code

This guide demonstrates how to set up a MySQL MCP server and connect it to Claude Code, allowing the AI assistant to interact directly with your MySQL database. You will learn how to build the MCP server, register it in the Claude Code configuration file, and test the available database tools.

What is an MCP server?

An MCP (Model Context Protocol) server exposes tools that an AI model can call during a conversation. In this setup, the MySQL MCP server provides database tools such as running queries, creating tables, and inserting data. Claude Code launches the MCP server as a subprocess and communicates with it directly, making the setup simpler than browser-based integrations that require an HTTP proxy.

Overview
Overview

Steps to follow

We assume Claude Code is already installed and configured on your system. You will also need Node.js and npm installed to build the MCP server.

  1. Download and build the MySQL MCP server
  2. Configure the MCP server in Claude Code
  3. Test the database tools

Quick reference

# Install dependencies and build the MCP server
npm install
npm run build

# Claude Code configuration file location
C:\Users\{User}\.claude.json

# MCP server configuration block to add to .claude.json
"mcpServers": {
    "mysql-mcp-server": {
        "command": "node",
        "args": [
            "C:\\path\\to\\mysql-mcp-server\\build\\index.js"
        ],
        "env": {
            "MYSQL_HOST": "your-mysql-host",
            "MYSQL_PORT": "your-mysql-port",
            "MYSQL_USER": "your-mysql-user",
            "MYSQL_PASSWORD": "your-mysql-password",
            "MYSQL_DATABASE": "your-database-name"
        }
    }
}

How to install the MySQL MCP server video

The following video shows how to download, build, and set up the MySQL MCP server step-by-step.

Step 1 - Download and build the MySQL MCP server

Navigate to the MySQL MCP server repository on GitHub and download the repository as a ZIP file by clicking the Code button and selecting Download ZIP (Figure 1).

Download MySQL MCP server from GitHub
Figure 1 - Download the MySQL MCP server from GitHub

Locate the downloaded ZIP file in your Downloads folder and extract it to a directory of your choice. The extracted folder will contain the MCP server source files (Figure 2).

Extract folder
Figure 2 - Extract the downloaded ZIP file

Open a terminal window in the extracted MCP server folder. You can do this by right-clicking inside the folder and selecting Open in Terminal or by navigating to the folder path in an existing terminal (Figure 3).

Open terminal in the extracted MCP server folder
Figure 3 - Open a terminal in the extracted MCP server folder

Run npm install to download and install all dependencies required by the MCP server. Wait for the installation to complete before proceeding (Figure 4).

npm install

Run npm install
Figure 4 - Install the MCP server dependencies

Run npm run build to compile the TypeScript source files into JavaScript. The compiled output will be placed in the build folder. This is the index.js file you will reference in the Claude Code configuration (Figure 5).

npm run build

Run npm run build
Figure 5 - Build the MCP server

Step 2 - Configure the MCP server in Claude Code

The following video shows how to register the MySQL MCP server in the Claude Code configuration file and test the available database tools step-by-step.

Locate the Claude Code configuration file at C:\Users\{User}\.claude.json and open it in a text editor. This file stores all Claude Code settings including registered MCP servers (Figure 6).

Find and open Claude config file in text editor
Figure 6 - Open the Claude Code configuration file

Locate the mcpServers property in the JSON file. If it does not exist yet, you will need to add it. This property is where all MCP server definitions are registered (Figure 7).

Locate mcpServers property
Figure 7 - Locate the mcpServers property in the configuration file

Add the MySQL MCP server entry to the mcpServers block. Replace the path in the args array with the actual path to the index.js file in your build folder, and fill in your MySQL connection details in the env section. Save the file when done (Figure 8).

"mcpServers": {
    "mysql-mcp-server": {
        "command": "node",
        "args": [
            "C:\\path\\to\\mysql-mcp-server\\build\\index.js"
        ],
        "env": {
            "MYSQL_HOST": "your-mysql-host",
            "MYSQL_PORT": "your-mysql-port",
            "MYSQL_USER": "your-mysql-user",
            "MYSQL_PASSWORD": "your-mysql-password",
            "MYSQL_DATABASE": "your-database-name"
        }
    }
}

Modify mcpServers property
Figure 8 - Add the MySQL MCP server configuration

Open Claude Code from a terminal window. Claude Code will read the updated configuration file and automatically connect to the registered MCP server on startup (Figure 9).

Open Claude Code from terminal
Figure 9 - Open Claude Code from the terminal

Step 3 - Test the database tools

Test the query tool by asking Claude Code to retrieve data from your database. Claude Code will use the MCP tool to execute the SQL query and return the results directly in the terminal (Figure 10). If prompted, accept the Tool usage.

Show me all users from the database.

Test the SQL query tool
Figure 10 - Test the SQL query tool

The query results will be displayed in the terminal output, confirming that Claude Code is successfully communicating with the MySQL MCP server and executing database operations (Figure 11).

Query tool results
Figure 11 - Query tool results returned by the MCP server

Test the table creation tool by instructing Claude Code to create a new table in your database (Figure 12).

Create a table called "employees" in the database with columns for id, name, position, and salary.

Test the create table tool
Figure 12 - Test the create table tool

Test the data insertion tool by asking Claude Code to insert records into the table. Provide the data in natural language and it will construct and execute the appropriate INSERT statements (Figure 13).

Insert these three rows into the employees table: Alice - Developer - 850000, Bob - Designer - 720000, Charlie - Manager - 950000.

Test the insert data tool
Figure 13 - Test the data insertion tool

Finally, test a conditional query to confirm that filtering works correctly. This verifies the full pipeline from natural language input through SQL execution to result display in the terminal (Figure 14).

Query the database and show me all employees who earn more than 800000.

Query data with conditions
Figure 14 - Test a conditional query

Final thoughts

You have successfully set up a MySQL MCP server and connected it to Claude Code. The AI assistant can now interact with your MySQL database directly through natural language, executing queries, creating tables, and managing data without requiring any manual SQL input.


More information