Mybatis Mapper2sql

by handsomestWei

309 downloads
Not rated
GitHub

About

Automatically extract SQL statements from MyBatis mapper XML files. Support automatic mocking of SQL parameters, and support automatic connection to the database to execute SQL tests and output results.

Details

Author
handsomestWei
Downloads
309
Categories
Database

- Extracts SQL from MyBatis mapper XML files
- Automatically mocks SQL parameters based on type inference
- Tests extracted SQL by connecting to a real database
- Uses MyBatis’s official parsing engine for deterministic results
- Supports multiple database types

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 Mybatis Mapper2sql
    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

Claude Desktop / Cursor

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

{
    "mcpServers": {
        "mybatis mapper2sql": {
            "mapper2sql": {
                "command": "java",
                "args": [
                    "-DdbType=mysql",
                    "-DjdbcDriver=com.mysql.cj.jdbc.Driver",
                    "-DjdbcDriverJar=/path/to/mysql-connector-java-8.0.33.jar",
                    "-DjdbcUrl=jdbc:mysql://localhost:3306/testdb",
                    "-DuserName=root",
                    "-Dpassword=your_password_here",
                    "-jar",
                    "mapper2sql-mcp-server-1.0.0.jar"
                ],
                "env": {
                    "JAVA_HOME": "/path/to/jdk17",
                    "PATH": "/path/to/jdk17/bin;${PATH}"
                }
            }
        }
    }
}

McpServers

{
    "mapper2sql": {
        "command": "java",
        "args": [
            "-DdbType=mysql",
            "-DjdbcDriver=com.mysql.cj.jdbc.Driver",
            "-DjdbcDriverJar=/path/to/mysql-connector-java-8.0.33.jar",
            "-DjdbcUrl=jdbc:mysql://localhost:3306/testdb",
            "-DuserName=root",
            "-Dpassword=your_password_here",
            "-jar",
            "mapper2sql-mcp-server-1.0.0.jar"
        ],
        "env": {
            "JAVA_HOME": "/path/to/jdk17",
            "PATH": "/path/to/jdk17/bin;${PATH}"
        }
    }
}

将原有的 MyBatis Mapper2SQL 工具,转型为 MCP (Model Context Protocol) 服务,使其能够在 AI 时代继续发挥价值,并与 AI 模型协作提供更强大的 SQL 提取和分析能力。

功能特性



- SQL提取: 从MyBatis mapper XML文件中提取SQL语句
- 参数Mock: 自动生成SQL参数,支持基于resultMap和JDBC连接的类型推断
- SQL测试: 连接数据库执行SQL并记录执行结果

核心优势



1. 确定性解析: 基于 MyBatis 官方解析引擎,结果稳定可靠。
2. AI 协作: 作为 AI 的"专家工具",提供精确的 SQL 解析能力。
3. 服务化: 通过 MCP 协议提供标准化接口。
4. 扩展性: 支持多种数据库类型。

可用工具


本项目提供3个专业工具,满足不同场景的SQL提取需求:

1. parse_mapper


- 功能: 基础 SQL 提取,保留占位符(不进行参数模拟)
- 适用场景: 快速查看 SQL 结构,无需参数 mock
- 参数:
- filePath (string): mapper XML文件或目录路径

2. parse_mapper_and_mock


- 功能: SQL 提取 + 参数自动 mock
- 适用场景: 需要可执行 SQL 进行测试或分析
- 参数:
- filePath (string): mapper XML文件或目录路径

3. parse_mapper_and_run_test


- 功能: SQL 提取 + 参数 mock + 执行测试
- 适用场景: 验证 SQL 在真实数据库中的执行情况
- 参数:
- filePath (string): mapper XML文件或目录路径

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.