🚀 MyBatis Mapper2SQL MCP Server
This is a MyBatis Mapper XML SQL extraction service based on the Model Context Protocol (MCP). It enables the extraction and analysis of SQL statements from MyBatis mapper XML files, providing powerful support for database operations.
🚀 Quick Start
This project transforms the original MyBatis Mapper2SQL tool into an MCP (Model Context Protocol) service. This allows it to continue to be valuable in the AI era and collaborate with AI models to provide more powerful SQL extraction and analysis capabilities.
Based on spring - ai, it offers a stdio (stdin/stdout) mode for inter - process communication via standard input and output, suitable for integration with command - line tools.
✨ Features
- SQL Extraction: Extract SQL statements from MyBatis mapper XML files.
- Parameter Mocking: Automatically generate SQL parameters, supporting type inference based on resultMap and JDBC connections.
- SQL Testing: Connect to the database, execute SQL, and record the execution results.
🔧 Technical Details
Core Advantages
- Deterministic Parsing: Based on the official MyBatis parsing engine, the results are stable and reliable.
- AI Collaboration: Serves as an "expert tool" for AI, providing accurate SQL parsing capabilities.
- Service - Oriented: Provides standardized interfaces through the MCP protocol.
- Scalability: Supports multiple database types.
Available Tools
This project offers 3 professional tools to meet SQL extraction needs in different scenarios:
1. parse_mapper
- Function: Basic SQL extraction, retaining placeholders (without parameter simulation).
- Applicable Scenarios: Quickly view the SQL structure without the need for parameter mocking.
- Parameters:
filePath(string): Path to the mapper XML file or directory.
2. parse_mapper_and_mock
- Function: SQL extraction + automatic parameter mocking.
- Applicable Scenarios: Require executable SQL for testing or analysis.
- Parameters:
filePath(string): Path to the mapper XML file or directory.
3. parse_mapper_and_run_test
- Function: SQL extraction + parameter mocking + execution testing.
- Applicable Scenarios: Verify the execution of SQL in a real - world database.
- Parameters:
filePath(string): Path to the mapper XML file or directory.
📚 Documentation
Compilation and Execution
Refer to
MCP Client Configuration
[Refer to](/mcp - config - example.json)
💻 Usage Examples
Refer to Local Debugging Instructions for Trae MCP Client
Basic Usage
{
"name": "parse_mapper",
"arguments": {
"filePath": "/path/to/mapper.xml"
}
}
Advanced Usage
SQL Extraction with Parameter Mocking
{
"name": "parse_mapper_and_mock",
"arguments": {
"filePath": "/path/to/mapper.xml"
}
}
SQL Testing
{
"name": "parse_mapper_and_run_test",
"arguments": {
"filePath": "/path/to/mapper.xml"
}
}
📄 References
- [spring - ai weather examples](https://github.com/spring - projects/spring - ai - examples/blob/main/model - context - protocol/weather/starter - stdio - server/README.md)
- modelcontextprotocol quickstart java server









