Skip to content

Commit 8533634

Browse files
committed
upd 使用spring-ai实现stdio模式
1 parent f62fa2b commit 8533634

25 files changed

+878
-1524
lines changed

Dockerfile

Lines changed: 0 additions & 24 deletions
This file was deleted.

README.md

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
本项目将原有的 [MyBatis Mapper2SQL](https://github.com/handsomestWei/mybatis-mapper2sql) 工具,转型为 MCP (Model Context Protocol) 服务,使其能够在 AI 时代继续发挥价值,并与 AI 模型协作提供更强大的 SQL 提取和分析能力。
88

9-
基于[modelcontextprotocol java sdk](https://github.com/modelcontextprotocol/java-sdk), 提供stdio(stdin/stdout)模式,通过标准输入输出,进行进程间通信,适用于命令行工具集成。
9+
基于spring-ai, 提供stdio(stdin/stdout)模式,通过标准输入输出,进行进程间通信,适用于命令行工具集成。
1010

1111
## 功能特性
1212

@@ -25,23 +25,22 @@
2525
本项目提供3个专业工具,满足不同场景的SQL提取需求:
2626

2727
#### 1. parse_mapper
28-
- **功能**: 基础 SQL 提取,保留占位符
28+
- **功能**: 基础 SQL 提取,保留占位符(不进行参数模拟)
2929
- **适用场景**: 快速查看 SQL 结构,无需参数 mock
3030
- **参数:**
31-
- `file_path` (string): mapper XML文件或目录路径
31+
- `filePath` (string): mapper XML文件或目录路径
3232

33-
#### 2. parse_mapper_with_mock
33+
#### 2. parse_mapper_and_mock
3434
- **功能**: SQL 提取 + 参数自动 mock
3535
- **适用场景**: 需要可执行 SQL 进行测试或分析
3636
- **参数:**
37-
- `file_path` (string): mapper XML文件或目录路径
38-
- `use_jdbc_connection` (boolean, 可选): 是否使用JDBC连接进行类型推断
37+
- `filePath` (string): mapper XML文件或目录路径
3938

40-
#### 3. parse_mapper_with_test
39+
#### 3. parse_mapper_and_run_test
4140
- **功能**: SQL 提取 + 参数 mock + 执行测试
4241
- **适用场景**: 验证 SQL 在真实数据库中的执行情况
4342
- **参数:**
44-
- `file_path` (string): mapper XML文件或目录路径
43+
- `filePath` (string): mapper XML文件或目录路径
4544

4645
## 使用说明
4746

@@ -52,34 +51,38 @@
5251
[参考](/mcp-config-example.json)
5352

5453
## 使用示例
54+
参考[本地使用Trae MCP客户端调试说明](/doc/本地使用Trae%20MCP客户端调试说明.md)
5555

5656
### 基本SQL提取
5757
```json
5858
{
5959
"name": "parse_mapper",
6060
"arguments": {
61-
"file_path": "/path/to/mapper.xml"
61+
"filePath": "/path/to/mapper.xml"
6262
}
6363
}
6464
```
6565

6666
### 带参数Mock的SQL提取
6767
```json
6868
{
69-
"name": "parse_mapper_with_mock",
69+
"name": "parse_mapper_and_mock",
7070
"arguments": {
71-
"file_path": "/path/to/mapper.xml",
72-
"use_jdbc_connection": false
71+
"filePath": "/path/to/mapper.xml"
7372
}
7473
}
7574
```
7675

7776
### SQL测试
7877
```json
7978
{
80-
"name": "parse_mapper_with_test",
79+
"name": "parse_mapper_and_run_test",
8180
"arguments": {
82-
"file_path": "/path/to/mapper.xml"
81+
"filePath": "/path/to/mapper.xml"
8382
}
8483
}
8584
```
85+
86+
## 参考
87+
+ [spring-ai weather examples](https://github.com/spring-projects/spring-ai-examples/blob/main/model-context-protocol/weather/starter-stdio-server/README.md)
88+
+ [modelcontextprotocol quickstart java server](https://modelcontextprotocol.io/quickstart/server#java)

doc/1-添加MCP服务.jpg

85.2 KB
Loading

doc/2-创建智能体.jpg

48.3 KB
Loading

doc/3-使用该智能体对话.jpg

30.6 KB
Loading
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# 本地使用Trae MCP客户端调试说明
2+
3+
本文档介绍如何在本地使用Trae MCP客户端来调试和测试MyBatis Mapper2SQL MCP服务。
4+
5+
## 准备工作
6+
7+
1. 确保已编译并打包项目:
8+
```bash
9+
mvn clean package -DskipTests
10+
```
11+
12+
2. 确保生成了可执行的JAR文件:`target/mapper2sql-mcp-server-1.0.0.jar`
13+
14+
## 配置步骤
15+
16+
### 步骤1:添加MCP服务
17+
18+
![添加MCP服务](1-添加MCP服务.jpg)
19+
20+
### 步骤2:创建智能体
21+
22+
![创建智能体](2-创建智能体.jpg)
23+
24+
### 步骤3:使用智能体对话
25+
26+
![使用智能体对话](3-使用该智能体对话.jpg)

docker-compose.yml

Lines changed: 0 additions & 21 deletions
This file was deleted.

libs/mapper2sql-1.2.0.jar

529 Bytes
Binary file not shown.

mcp-config-example.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"mapper2sql-mcp-server-1.0.0.jar"
1414
],
1515
"env": {
16-
"JAVA_HOME": "/path/to/jdk17"
16+
"JAVA_HOME": "/path/to/jdk17",
17+
"PATH": "/path/to/jdk17/bin;${PATH}"
1718
}
1819
}
1920
}

mcp-registry.json

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "1.0.0",
44
"description": "Extract SQL from MyBatis mapper XML files with parameter mocking and testing capabilities",
55
"author": "handsomestWei",
6-
"license": "MIT",
6+
"license": "Apache License 2.0",
77
"repository": {
88
"type": "git",
99
"url": "https://github.com/handsomestWei/mybatis-mapper2sql-mcp-server"
@@ -20,81 +20,76 @@
2020
"tools": [
2121
{
2222
"name": "parse_mapper",
23-
"description": "Parse MyBatis mapper XML files and extract SQL statements with placeholders",
23+
"description": "Parse MyBatis mapper XML files and extract SQL statements with placeholders (no parameter mocking)",
2424
"inputSchema": {
2525
"type": "object",
2626
"properties": {
27-
"file_path": {
27+
"filePath": {
2828
"type": "string",
2929
"description": "Path to mapper XML file or directory"
3030
}
3131
},
3232
"required": [
33-
"file_path"
33+
"filePath"
3434
]
3535
}
3636
},
3737
{
38-
"name": "parse_mapper_with_mock",
39-
"description": "Parse MyBatis mapper XML files and extract SQL statements with parameter mocking",
38+
"name": "parse_mapper_and_mock",
39+
"description": "Parse MyBatis mapper XML files and extract SQL statements and mock parameters",
4040
"inputSchema": {
4141
"type": "object",
4242
"properties": {
43-
"file_path": {
43+
"filePath": {
4444
"type": "string",
4545
"description": "Path to mapper XML file or directory"
46-
},
47-
"use_jdbc_connection": {
48-
"type": "boolean",
49-
"description": "Whether to use JDBC connection for type inference (default: false)"
5046
}
5147
},
5248
"required": [
53-
"file_path"
49+
"filePath"
5450
]
5551
}
5652
},
5753
{
58-
"name": "parse_mapper_with_test",
54+
"name": "parse_mapper_and_run_test",
5955
"description": "Parse MyBatis mapper XML files, extract SQL statements with parameter mocking, and test execution",
6056
"inputSchema": {
6157
"type": "object",
6258
"properties": {
63-
"file_path": {
59+
"filePath": {
6460
"type": "string",
6561
"description": "Path to mapper XML file or directory"
6662
}
6763
},
6864
"required": [
69-
"file_path"
65+
"filePath"
7066
]
7167
}
7268
}
7369
],
7470
"examples": [
7571
{
7672
"name": "Basic SQL Extraction",
77-
"description": "Extract SQL from a MyBatis mapper XML file",
73+
"description": "Extract SQL from a MyBatis mapper XML file with placeholders",
7874
"tool": "parse_mapper",
7975
"arguments": {
80-
"file_path": "/path/to/UserMapper.xml"
76+
"filePath": "/path/to/UserMapper.xml"
8177
}
8278
},
8379
{
8480
"name": "SQL Extraction with Parameter Mocking",
8581
"description": "Extract SQL with automatically mocked parameters",
86-
"tool": "parse_mapper_with_mock",
82+
"tool": "parse_mapper_and_mock",
8783
"arguments": {
88-
"file_path": "/path/to/UserMapper.xml",
89-
"use_jdbc_connection": true
84+
"filePath": "/path/to/UserMapper.xml"
9085
}
9186
},
9287
{
9388
"name": "SQL Testing",
9489
"description": "Extract SQL, mock parameters, and test execution",
95-
"tool": "parse_mapper_with_test",
90+
"tool": "parse_mapper_and_run_test",
9691
"arguments": {
97-
"file_path": "/path/to/UserMapper.xml"
92+
"filePath": "/path/to/UserMapper.xml"
9893
}
9994
}
10095
],

0 commit comments

Comments
 (0)