SQG MCP Server - Spring Boot project initialization tools
npm install sqg-mcp-server这是一个 Model Context Protocol (MCP) 服务器,专门提供 Spring Boot 项目初始化相关的工具。
``bash`
npm install -g sqg-mcp-server
`bash`
git clone https://github.com/sqg/sqg-mcp-server.git
cd sqg-mcp-server
npm install
npm run build
1. get-init-project-metadata - 获取 Spring Boot 项目初始化的可配置参数和依赖信息
2. init-project - 初始化 Spring Boot 项目
3. generate-db-code - 根据数据库表结构生成 Java 实体类、Mapper 接口、XML 映射文件和 Service 层代码
1. 找到 Claude Desktop 的配置文件:
- Windows: %APPDATA%\Claude\claude_desktop_config.json~/Library/Application Support/Claude/claude_desktop_config.json
- macOS:
2. 添加服务器配置(推荐使用 npx 方式):
#### 方式一:使用 npx(推荐,无需安装)
`json`
{
"mcpServers": {
"sqg-mcp-server": {
"command": "npx",
"args": ["-y", "sqg-mcp-server"],
"env": {}
}
}
}
#### 方式二:全局安装后使用
`json`
{
"mcpServers": {
"sqg-mcp-server": {
"command": "sqg-mcp-server",
"env": {}
}
}
}
#### 方式三:从源码安装
`json`
{
"mcpServers": {
"sqg-mcp-server": {
"command": "node",
"args": ["你的项目路径/dist/index.js"],
"env": {}
}
}
}
3. 重启 Claude Desktop
| 方式 | 优点 | 缺点 | 适用场景 |
|------|------|------|----------|
| npx | 无需安装,自动获取最新版本 | 首次启动稍慢 | 推荐给普通用户 |
| 全局安装 | 启动快速,离线可用 | 需要手动更新版本 | 频繁使用者 |
| 源码安装 | 可自定义修改 | 需要手动构建和维护 | 开发者 |
如果全局安装,可以直接运行:
`bash`
sqg-mcp-server
你可以使用我们提供的测试脚本:
`bash`
npm test
或者手动与服务器交互。服务器通过标准输入输出进行 JSON-RPC 通信。
获取所有可用的配置参数和依赖信息:
`json`
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "get-init-project-metadata",
"arguments": {}
}
}
获取特定 Spring Boot 版本的配置参数:
`json`
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "get-init-project-metadata",
"arguments": {
"bootVersion": "2.7.0"
}
}
}
`json`
{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "init-project",
"arguments": {
"artifactId": "my-spring-app",
"name": "My Spring Application",
"groupId": "com.example",
"packageName": "com.example.myapp",
"targetDirectory": "./my-project"
}
}
}
更多使用示例请参考:
- get-init-project-metadata 工具使用指南
- init-project 工具使用示例
- generate-db-code 工具使用示例
`bash安装依赖
npm install
或者使用开发模式(自动构建并运行):
`bash
npm run dev
`项目结构
`
mcp-server-demo/
├── src/
│ └── index.ts # 主要的 MCP server 代码
├── dist/ # 编译后的 JavaScript 文件
├── package.json # 项目配置和依赖
├── tsconfig.json # TypeScript 配置
└── README.md # 项目说明
`代码说明
$3
1. Server 实例: 使用
@modelcontextprotocol/sdk 创建的 MCP server
2. 工具定义: 定义了 init-project 工具及其输入模式
3. 请求处理器:
- ListToolsRequestSchema - 处理工具列表请求
- CallToolRequestSchema - 处理工具调用请求
4. 传输层: 使用 StdioServerTransport 进行标准输入输出通信$3
#### Init-Project 工具
`typescript
{
name: "init-project",
description: "初始化 Spring Boot 项目",
inputSchema: {
type: "object",
properties: {
language: { type: "string", description: "编程语言", default: "java" },
datasource: { type: "string", description: "数据源类型", default: "double" },
bootVersion: { type: "string", description: "Spring Boot 版本", default: "2.6.6" },
groupId: { type: "string", description: "Maven Group ID", default: "com.sqg" },
artifactId: { type: "string", description: "Maven Artifact ID", default: "example" },
// ... 更多参数
},
required: []
}
}
`#### Generate-DB-Code 工具
`typescript
{
name: "generate-db-code",
description: "根据数据库表结构生成 Java 实体类、Mapper 接口、XML 映射文件和 Service 层代码",
inputSchema: {
type: "object",
properties: {
configFile: { type: "string", description: "配置文件路径", default: "" },
tables: { type: "string", description: "要生成的表名,多个表名用逗号分隔", default: "" },
outputDir: { type: "string", description: "输出目录路径", default: "./generated" },
dbUrl: { type: "string", description: "数据库连接URL", default: "" },
username: { type: "string", description: "数据库用户名", default: "" },
password: { type: "string", description: "数据库密码", default: "" }
},
required: []
}
}
`
依赖说明
-
@modelcontextprotocol/sdk: MCP 官方 TypeScript SDK
- typescript: TypeScript 编译器
- @types/node`: Node.js 类型定义MIT