This MySQL MCP Server implements the Model Context Protocol to provide a bridge between AI assistants and MySQL databases, allowing for data operations via a standardized interface.
To build the server using Maven:
mvn install
The build process will create a JAR file in the target directory that you'll use to run the server.
Add the following configuration to your MCP server config file:
{
"mysql-server": {
"command": "java",
"args": [
"-jar",
"{{ProjectDirectory}}\\target\\mcp-mysql-server-1.0.0.jar"
],
"env": {
"SPRING_DATASOURCE_URL": "jdbc:mysql://username:password@localhost:3306/database"
}
}
}
Make sure to replace the following with your actual database credentials:
username
: Your MySQL usernamepassword
: Your MySQL passwordlocalhost:3306
: Your database host and portdatabase
: Your database nameThe server provides these core capabilities:
Use the query tool to execute SELECT statements:
The listAllTablesName tool displays all tables in your database:
To examine a table's structure, use the getTableSchema tool:
When properly configured, the MCP server integrates with Claude Desktop or Cline, providing a visual interface for database interactions:
The server allows AI assistants to interact with database content directly:
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "mysql-server" '{"command":"java","args":["-jar","{{ProjectDirectory}}\\target\\mcp-mysql-server-1.0.0.jar"],"env":{"SPRING_DATASOURCE_URL":"jdbc:mysql://username:password@localhost:3306/database"}}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"mysql-server": {
"command": "java",
"args": [
"-jar",
"{{ProjectDirectory}}\\target\\mcp-mysql-server-1.0.0.jar"
],
"env": {
"SPRING_DATASOURCE_URL": "jdbc:mysql://username:password@localhost:3306/database"
}
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"mysql-server": {
"command": "java",
"args": [
"-jar",
"{{ProjectDirectory}}\\target\\mcp-mysql-server-1.0.0.jar"
],
"env": {
"SPRING_DATASOURCE_URL": "jdbc:mysql://username:password@localhost:3306/database"
}
}
}
}
3. Restart Claude Desktop for the changes to take effect