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.
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.
- Download and build the MySQL MCP server
- Configure the MCP server in Claude Code
- 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).
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).
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).
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 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
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).
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).
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"
}
}
}
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).
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.
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).
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 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.
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.
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.