springboot-test-mcp

springboot-test-mcp

A Spring Boot REST API testing server that supports functional testing with assertions, database queries, and performance testing with configurable concurrency and stress testing.

Category
访问服务器

README

Spring Boot Test MCP Server

一个 MCP (Model Context Protocol) 服务器,为 Claude Code 提供 Spring Boot REST API 的功能测试性能测试能力。

核心功能

🧪 功能测试

  • call_api — 调用 REST API,获取完整响应
  • assert_response — 多维度断言(状态码、JSON 字段、响应时间等)
  • run_functional_tests — 批量执行测试用例,支持 setup/teardown SQL
  • query_database — 查询 Oracle 数据库验证数据正确性
  • execute_dml — 准备/清理测试数据

🔥 性能测试

  • run_perf_test — 可配置并发数和时长的负载测试
  • run_stress_test — 逐步增加压力的阶梯压测,定位性能拐点

📋 辅助工具

  • discover_api_endpoints — 自动发现 Spring Boot API 端点(Actuator 或源码扫描)
  • get_test_report — 获取测试报告
  • check_config — 检查配置和连接状态
  • reset_test_session — 重置测试会话

快速开始

1. 安装依赖

cd springboot-test-mcp
pip install -e .

或直接安装:

pip install httpx "mcp[cli]>=1.6.0" oracledb python-dotenv jmespath

2. 配置环境变量

复制 .env.example.env,填入你的配置:

TARGET_BASE_URL=http://localhost:8080
ORACLE_HOST=localhost
ORACLE_PORT=1521
ORACLE_SERVICE=ORCL
ORACLE_USER=your_user
ORACLE_PASSWORD=your_password

3. 配置 Claude Code

在项目根目录创建 .claude/settings.json

{
  "mcpServers": {
    "springboot-test": {
      "command": "python",
      "args": ["/absolute/path/to/springboot-test-mcp/main.py"]
    }
  }
}

或在 Claude Code 中运行:

claude mcp add springboot-test -- python /absolute/path/to/springboot-test-mcp/main.py

4. 启动被测服务后使用

在 Claude Code 中:

# 检查配置
> check_config

# 发现 API
> discover_api_endpoints

# 功能测试
> call_api(method="GET", path="/api/users")
> run_functional_tests(test_cases=[{
    "name": "创建用户",
    "method": "POST",
    "path": "/api/users",
    "body": {"name": "Alice", "email": "alice@test.com"},
    "assertions": [
      {"target": "status_code", "operator": "eq", "expected": 201},
      {"target": "json_path", "json_path": "name", "operator": "eq", "expected": "Alice"}
    ]
  }])

# 性能测试
> run_perf_test(name="用户列表压测", method="GET", path="/api/users",
                concurrency=50, duration_seconds=30)

# 阶梯压测
> run_stress_test(name="用户API压测", method="GET", path="/api/users",
                  max_concurrency=200, step_size=50, step_duration_seconds=30)

# 数据库验证
> query_database(sql="SELECT * FROM users WHERE name='Alice'")

项目结构

springboot-test-mcp/
├── main.py                  # 入口
├── server.py                # MCP Tool 定义(所有工具)
├── config.py                # 配置管理
├── core/
│   ├── __init__.py          # HTTP 客户端(httpx)
│   ├── assertion_engine.py  # 断言引擎
│   ├── test_runner.py       # 功能测试执行器
│   └── perf_engine.py       # 性能测试引擎(asyncio 并发)
├── db/
│   ├── __init__.py          # Oracle 连接器(oracledb thin mode)
│   └── oracle_connector.py  # 别名
├── discovery/
│   └── __init__.py          # API 发现(Actuator + 源码扫描)
├── models/
│   └── __init__.py          # 数据模型
├── .env.example             # 环境变量模板
└── claude_desktop_config.json  # Claude 配置参考

支持的断言

target 说明 示例
status_code HTTP 状态码 {"target": "status_code", "operator": "eq", "expected": 200}
json_path JSON 字段(JMESPath) {"target": "json_path", "json_path": "data.name", "operator": "eq", "expected": "Alice"}
response_time 响应时间(ms) {"target": "response_time", "operator": "lt", "expected": 500}
body 完整响应体 {"target": "body", "operator": "contains", "expected": "success"}
header 响应头 {"target": "header", "operator": "contains", "expected": "application/json"}
operator 说明
eq / neq 等于 / 不等于
gt / lt / gte / lte 大于 / 小于 / 大于等于 / 小于等于
contains / not_contains 包含 / 不包含
matches 正则匹配
exists / not_exists 存在 / 不存在

性能测试指标

  • 总请求数、成功/失败数
  • 错误率 (%)
  • 吞吐量 (req/s)
  • 延迟分布:Avg / Min / Max / Median / P90 / P95 / P99
  • 状态码分布
  • 阶梯压测自动识别性能拐点

技术栈

  • MCP SDK: mcp[cli] (Python FastMCP)
  • HTTP Client: httpx (异步)
  • Oracle: oracledb (thin mode,无需 Oracle Client)
  • JSON Path: jmespath
  • 并发: asyncio (性能测试)

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选