About Mybatis Mapper2sql
Mybatis Mapper2sql is an MCP service for MyBatis developers that extracts SQL from mapper XML and supports parameter mocking and database execution tests. It uses the MyBatis parsing engine and communicates over stdio.
Key features
- 01Extract SQL from mapper XML
- 02Automatically mock SQL parameters
- 03Run SQL tests against a database
- 04Support multiple database types
Use cases
- 01Inspect SQL structure in mapper XML
- 02Generate parameterized SQL for analysis
- 03Verify SQL execution results in a database
MCP support
The service exposes MCP tools over stdio for SQL extraction, parameter mocking, and execution tests.
Configuration
Local server config is the same for every client. Copy it into your client’s MCP config file.
We haven’t collected a package or remote endpoint for this server. Follow the instructions in the project README.
Tools
Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.
Details
From the project READMEMyBatis Mapper2SQL MCP Server
这是一个基于Model Context Protocol (MCP)的MyBatis Mapper XML SQL提取服务。
概述
本项目将原有的 MyBatis Mapper2SQL 工具,转型为 MCP (Model Context Protocol) 服务,使其能够在 AI 时代继续发挥价值,并与 AI 模型协作提供更强大的 SQL 提取和分析能力。
基于spring-ai, 提供stdio(stdin/stdout)模式,通过标准输入输出,进行进程间通信,适用于命令行工具集成。
功能特性
- SQL提取: 从MyBatis mapper XML文件中提取SQL语句
- 参数Mock: 自动生成SQL参数,支持基于resultMap和JDBC连接的类型推断
- SQL测试: 连接数据库执行SQL并记录执行结果
核心优势
- 确定性解析: 基于 MyBatis 官方解析引擎,结果稳定可靠。
- AI 协作: 作为 AI 的"专家工具",提供精确的 SQL 解析能力。
- 服务化: 通过 MCP 协议提供标准化接口。
- 扩展性: 支持多种数据库类型。
可用工具
本项目提供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文件或目录路径
使用说明
编译运行
MCP客户端配置
使用示例
基本SQL提取
{
"name": "parse_mapper",
"arguments": {
"filePath": "/path/to/mapper.xml"
}
}
带参数Mock的SQL提取
{
"name": "parse_mapper_and_mock",
"arguments": {
"filePath": "/path/to/mapper.xml"
}
}
SQL测试
{
"name": "parse_mapper_and_run_test",
"arguments": {
"filePath": "/path/to/mapper.xml"
}
}
参考
Comments
New to MCP?
From what the protocol is to installing your first server, these answers cover most first questions.
An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.