sqg-mcp-server
v1.0.7
Published
SQG MCP Server - Spring Boot project initialization tools
Downloads
22
Maintainers
Readme
SQG MCP Server
这是一个 Model Context Protocol (MCP) 服务器,专门提供 Spring Boot 项目初始化相关的工具。
安装
通过 npm 安装(推荐)
npm install -g sqg-mcp-server从源码安装
git clone https://github.com/sqg/sqg-mcp-server.git
cd sqg-mcp-server
npm install
npm run build功能特性
- get-init-project-metadata - 获取 Spring Boot 项目初始化的可配置参数和依赖信息
- init-project - 初始化 Spring Boot 项目
- generate-db-code - 根据数据库表结构生成 Java 实体类、Mapper 接口、XML 映射文件和 Service 层代码
使用方法
在 Claude Desktop 中使用
找到 Claude Desktop 的配置文件:
- Windows:
%APPDATA%\Claude\claude_desktop_config.json - macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
- Windows:
添加服务器配置(推荐使用 npx 方式):
方式一:使用 npx(推荐,无需安装)
{
"mcpServers": {
"sqg-mcp-server": {
"command": "npx",
"args": ["-y", "sqg-mcp-server"],
"env": {}
}
}
}方式二:全局安装后使用
{
"mcpServers": {
"sqg-mcp-server": {
"command": "sqg-mcp-server",
"env": {}
}
}
}方式三:从源码安装
{
"mcpServers": {
"sqg-mcp-server": {
"command": "node",
"args": ["你的项目路径/dist/index.js"],
"env": {}
}
}
}- 重启 Claude Desktop
使用方式对比
| 方式 | 优点 | 缺点 | 适用场景 | |------|------|------|----------| | npx | 无需安装,自动获取最新版本 | 首次启动稍慢 | 推荐给普通用户 | | 全局安装 | 启动快速,离线可用 | 需要手动更新版本 | 频繁使用者 | | 源码安装 | 可自定义修改 | 需要手动构建和维护 | 开发者 |
命令行使用
如果全局安装,可以直接运行:
sqg-mcp-server手动测试
你可以使用我们提供的测试脚本:
npm test或者手动与服务器交互。服务器通过标准输入输出进行 JSON-RPC 通信。
工具使用示例
get-init-project-metadata 工具
获取所有可用的配置参数和依赖信息:
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "get-init-project-metadata",
"arguments": {}
}
}获取特定 Spring Boot 版本的配置参数:
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "get-init-project-metadata",
"arguments": {
"bootVersion": "2.7.0"
}
}
}init-project 工具
{
"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"
}
}
}更多使用示例请参考:
安装和运行
# 安装依赖
npm install
# 构建项目
npm run build
# 启动服务器
npm start
# 运行测试
npm test或者使用开发模式(自动构建并运行):
npm run dev项目结构
mcp-server-demo/
├── src/
│ └── index.ts # 主要的 MCP server 代码
├── dist/ # 编译后的 JavaScript 文件
├── package.json # 项目配置和依赖
├── tsconfig.json # TypeScript 配置
└── README.md # 项目说明代码说明
主要组件
- Server 实例: 使用
@modelcontextprotocol/sdk创建的 MCP server - 工具定义: 定义了 init-project 工具及其输入模式
- 请求处理器:
ListToolsRequestSchema- 处理工具列表请求CallToolRequestSchema- 处理工具调用请求
- 传输层: 使用
StdioServerTransport进行标准输入输出通信
工具示例
Init-Project 工具
{
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 工具
{
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 SDKtypescript: TypeScript 编译器@types/node: Node.js 类型定义
许可证
MIT
