Mysql Mcp Server For Java

by 6000fish

2 stars
355 downloads
Not rated
GitHub

About

Mysql Mcp Server For Java is a ready-to-run MySQL database server implementation for the Model Context Protocol (MCP), built with the MCP Java SDK. It allows MCP clients (e.g., Claude Code, Codex) to connect to a MySQL database and perform SQL operations through natural language.

Details

Author
6000fish
GitHub stars
2
Downloads
355
Categories
Database

- Built with the MCP Java SDK for custom MCP servers.
- Uses stdio transport for local Agent integration.
- Exposes seven MySQL tools: query, execute, list_databases, list_tables, describe_table, explain_query, get_table_status.
- Ready-to-run jar with no additional project setup.
- Verified compatibility with Claude Code and Codex clients.

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name Mysql Mcp Server For Java
    Command (node, npx, python, etc.)

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

Build the jar with mvn package -pl mcp-server-collection/mcp-server-mysql -am -DskipTests. Then configure your MCP client’s mcpServers entry with "type": "stdio", the java command pointing to the generated jar, and environment variables MYSQL_HOST, MYSQL_PORT, MYSQL_DATABASE, MYSQL_USERNAME, MYSQL_PASSWORD. Restart the client and the server tools become available.

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "mysql mcp server for java": {
            "mysql": {
                "type": "stdio",
                "command": "java",
                "args": [
                    "-jar",
                    "/absolute/path/to/mcp-java/mcp-server-collection/mcp-server-mysql/target/mcp-server-mysql-0.1.1.jar"
                ],
                "env": {
                    "MYSQL_HOST": "localhost",
                    "MYSQL_PORT": "3306",
                    "MYSQL_DATABASE": "mcp_demo",
                    "MYSQL_USERNAME": "root",
                    "MYSQL_PASSWORD": "your_password"
                }
            }
        }
    }
}

McpServers

{
    "mysql": {
        "type": "stdio",
        "command": "java",
        "args": [
            "-jar",
            "/absolute/path/to/mcp-java/mcp-server-collection/mcp-server-mysql/target/mcp-server-mysql-0.1.1.jar"
        ],
        "env": {
            "MYSQL_HOST": "localhost",
            "MYSQL_PORT": "3306",
            "MYSQL_DATABASE": "mcp_demo",
            "MYSQL_USERNAME": "root",
            "MYSQL_PASSWORD": "your_password"
        }
    }
}

MCP Java SDK

Maven Central
Release
CI
Java
License

> Java SDK for building custom Model Context Protocol (MCP) servers quickly, with runnable MySQL and Redis server examples.

MCP.so listings: MySQL MCP Server for Java · Redis MCP Server for Java

Why this project

- Build custom MCP servers in Java with a small SDK.
- Use stdio for local Agent integration and SSE for HTTP-based integrations.
- Define tools, resources, and prompts with either Java code or annotations.
- Start from copyable examples instead of wiring JSON-RPC by hand.
- Use MySQL and Redis servers as ready-to-run examples for real data sources.

5-minute paths

| Goal | Start here | Requires external service |
|------|------------|---------------------------|
| Run the fastest SDK demo | mcp-examples/quick-start | No |
| Copy a custom server template | mcp-examples/custom-server-template | No |
| Build inside Spring Boot | mcp-examples/spring-boot-example | No |
| Connect Redis to an Agent | docs/redis-server.md | Redis |
| Connect MySQL to an Agent | docs/mysql-server.md | MySQL |

Full walkthrough: 5-Minute Quick Start.

Install from Maven Central

Core SDK:

<dependency>
    <groupId>io.github.6000fish</groupId>
    <artifactId>mcp-sdk</artifactId>
    <version>0.1.1</version>
</dependency>

Spring Boot starter:

<dependency>
    <groupId>io.github.6000fish</groupId>
    <artifactId>mcp-spring-boot-starter</artifactId>
    <version>0.1.1</version>
</dependency>

Fastest SDK demo

Build the no-database quick-start server:

mvn package -pl mcp-examples/quick-start -am -DskipTests

Add the runnable jar to your MCP Agent configuration:

{
  "mcpServers": {
    "quick-start": {
      "type": "stdio",
      "command": "java",
      "args": [
        "-jar",
        "/absolute/path/to/mcp-java/mcp-examples/quick-start/target/quick-start-0.1.1.jar"
      ]
    }
  }
}

Restart the Agent and ask:

Use the quick-start MCP server to greet Alice and get the current time.

The demo exposes greet, current_time, calculate, text_transform, and resource server://info.

Build your own MCP server

For a copyable annotation-based template:

mvn package -pl mcp-examples/custom-server-template -am -DskipTests

Configure the generated jar:

{
  "mcpServers": {
    "custom-template": {
      "type": "stdio",
      "command": "java",
      "args": [
        "-jar",
        "/absolute/path/to/mcp-java/mcp-examples/custom-server-template/target/custom-server-template-0.1.1.jar"
      ]
    }
  }
}

Then edit CustomMcpServer.java and add your own @McpTool, @McpResource, or @McpPrompt methods.

Minimal SDK API example:

McpServer server = DefaultMcpServer.builder()
        .name("my-server")
        .version("1.0.0")
        .build();

server.tool("greet", "Greet someone", arguments -> {
String name = (String) arguments.getOrDefault("name", "World");
return ToolCallResult.success("Hello, " + name + "!");
});

server.start(new StdioTransport());

Annotation example:

@McpServer(name = "my-server", version = "1.0.0")
public class MyServer {

@McpTool(name = "hello", description = "Say hello")
public String hello(@Param(name = "name") String name) {
return "Hello, " + name + "!";
}
}

Ready-to-use servers

Build the currently published ready-to-use server modules:

mvn package -pl mcp-server-collection/mcp-server-mysql -am -DskipTests
mvn package -pl mcp-server-collection/mcp-server-redis -am -DskipTests

MySQL server config:

{
  "mcpServers": {
    "mysql": {
      "type": "stdio",
      "command": "java",
      "args": [
        "-jar",
        "/absolute/path/to/mcp-java/mcp-server-collection/mcp-server-mysql/target/mcp-server-mysql-0.1.1.jar"
      ],
      "env": {
        "MYSQL_HOST": "localhost",
        "MYSQL_PORT": "3306",
        "MYSQL_DATABASE": "mcp_demo",
        "MYSQL_USERNAME": "my_user",
        "MYSQL_PASSWORD": "your_password"
      }
    }
  }
}

Redis server config:

{
  "mcpServers": {
    "redis": {
      "type": "stdio",
      "command": "java",
      "args": [
        "-jar",
        "/absolute/path/to/mcp-java/mcp-server-collection/mcp-server-redis/target/mcp-server-redis-0.1.1.jar"
      ],
      "env": {
        "REDIS_HOST": "localhost",
        "REDIS_PORT": "6379",
        "REDIS_PASSWORD": ""
      }
    }
  }
}

Before connecting real data, read the Security Guide. Keep credentials in local Agent configuration or environment variables only.

Available server tools

| Server | Description | Tools |
|--------|-------------|-------|
| MySQL | Database operations | query, execute, list_databases, list_tables, describe_table, explain_query, get_table_status |
| Redis | Cache operations | get, set, del, keys, type, ttl, hget, hset, hgetall, lrange, llen, scard, smembers, info, dbsize |

Documentation

User documentation:

- 5-Minute Quick Start
- MySQL Server Guide
- Redis Server Guide
- Security Guide
- Troubleshooting
- Changelog

Maintainer documentation:

- Release Guide
- MCP Directory Submission Materials

Compatibility

The stdio servers are designed for mainstream MCP clients and Agents:

- Claude Code: verified with MySQL and Redis stdio servers.
- Codex: verified with MySQL stdio server, including tools/list, tools/call, and client _meta fields.
- Other MCP clients such as opencode, OpenClaw, Gemini-related tooling: use the same stdio JSON-RPC flow and should use the documented config shape.

Compatibility safeguards include required inputSchema on tools, tolerant request parsing for client extension fields such as _meta, omitted null fields in stdio responses, and logging to stderr so stdout stays reserved for MCP JSON-RPC messages.

Project structure

mcp-java/
├── mcp-sdk/                      # Core SDK
├── mcp-spring-boot-starter/      # Spring Boot integration
├── mcp-server-collection/        # Ready-to-use server implementations
└── mcp-examples/                 # SDK examples and templates

Build from source

git clone https://github.com/6000fish/mcp-java.git
cd mcp-java
mvn clean install

Community

- Contributing Guide
- Security Policy
- Code of Conduct
- Changelog

Maintainers

Release instructions are in docs/release.md. Do not commit Maven Central credentials, GPG passphrases, private keys, or settings.xml.

License

MIT

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.