FlowSphere MCP服务器
](https://github.com/ymoud/flowsphere-mcp/releases)     
用于FlowSphere代码生成的模型上下文协议(MCP)服务器
变换 FlowSphere 配置文件转换为生产就绪测试代码 python, JavaScript,以及 C.
______________________________________________________________________
它做什么
从FlowSphere JSON配置生成独立的可执行测试代码:
- python -pytest,行为/BDD
- JavaScript -杰斯特、摩卡、黄瓜/BDD
- C -xUnit、NUnit、SpecFlow/BDD
例子: 一个20行的JSON配置变成了400多行工作测试代码,其中包含完整的HTTP执行、变量替换、条件和验证。
______________________________________________________________________
✨ 快速开始
选项1:与Claude Code CLI一起使用(推荐)
# 1. Install dependencies
cd C:\dev\GitHub\flowsphere-mcp-server
pip install -r requirements.txt
# 2. Add MCP server to Claude Code
claude mcp add --transport stdio flowsphere-mcp python "C:\dev\GitHub\flowsphere-mcp-server\src\flowsphere_mcp\server.py"
# 3. Restart Claude Code
claude
# 4. Verify connection
/mcp
# Should show: flowsphere-mcp ✓ Connected现在让Claude生成测试:
"Generate Python pytest code from tests/fixtures/simple_config.json"
"Create JavaScript Jest tests from this FlowSphere config"
"Generate C# xUnit tests with namespace MyApp.Tests"选项2:直接使用Python API
import json
from flowsphere_mcp.generators.python_generator import PythonPytestGenerator
# Load your FlowSphere config
with open('tests/fixtures/simple_config.json') as f:
config = json.load(f)
# Generate Python pytest code
generator = PythonPytestGenerator()
code = generator.generate(config)
# Save to file
with open('test_api.py', 'w') as f:
f.write(code)
print("✅ Generated test_api.py")______________________________________________________________________
📦 安装和设置
先决条件
- Python 3.10+
- 点 (Python包管理器)
再进行
cd C:\dev\GitHub\flowsphere-mcp-server
pip install -r requirements.txt配置MCP服务器(Claude Code CLI)
# Add the server
claude mcp add --transport stdio flowsphere-mcp python "C:\path\to\flowsphere-mcp-server\src\flowsphere_mcp\server.py"
# Verify configuration
claude mcp list
# Get server details
claude mcp get flowsphere-mcp
# Restart Claude Code to connect
claude配置已保存到: %USERPROFILE%\.claude.json
MCP连接故障排除
如果服务器显示“连接失败”:
- 验证Python包:
pip install -r requirements.txt- 检查服务器路径:
claude mcp get flowsphere-mcp路径应使用反斜杠: C:\path\to\...
- 如果需要,请重新添加服务器:
claude mcp remove flowsphere-mcp -s local
claude mcp add --transport stdio flowsphere-mcp python "C:\correct\path\src\flowsphere_mcp\server.py"- 重新启动Claude代码 获取更改
______________________________________________________________________
🚀 用法
所有8个支持的生成器
| 语言 | 框架 | MCP工具 | 输出 |
|---|---|---|---|
| Python | pytest | generate_python_pytest | 单个测试文件 |
| Python | 行为(BDD) | generate_python_behave | 功能+步骤 |
| JavaScript | 恶作剧 | generate_javascript_jest | 测试+包.json |
| JavaScript | Mocha | generate_javascript_mocha | 测试+包.json |
| JavaScript | 黄瓜(BDD) | generate_javascript_cucumber | 功能+步骤 |
| C# | xUnit | generate_csharp_xunit 测试+.csproj。 | |
| C# | NUnit | generate_csharp_nunit 测试+.csproj。 | |
| C# | 规范流(BDD) | generate_csharp_specflow | 功能+步骤 |
示例:Python pytest
# Via MCP tool
result = mcp_server.call_tool("generate_python_pytest", {
"config": your_flowsphere_config,
"test_class_name": "APITests" # Optional
})
# Generated output includes:
# - Complete APISequence class with all 18 FlowSphere features
# - Test class with all test methods
# - Variable substitution, conditions, validations
# - Dependencies list and usage instructions运行生成的测试:
pip install pytest requests jsonpath-ng
pytest test_api.py -v示例:JavaScript Jest
// Via MCP tool
result = mcp_server.call_tool("generate_javascript_jest", {
"config": your_flowsphere_config
})
// Returns:
// - result.code: Complete Jest test file
// - result.package_json: NPM dependencies
// - result.usage_instructions: How to run运行生成的测试:
npm install
npm test示例:C#xUnit
// Via MCP tool
result = mcp_server.call_tool("generate_csharp_xunit", {
"config": your_flowsphere_config,
"namespace": "MyApp.Tests" // Optional
})
// Returns:
// - result.code: Complete xUnit test file
// - result.csproj: Project file with NuGet packages
// - result.usage_instructions: How to run运行生成的测试:
dotnet test配置示例
看 测试/夹具/ 对于5种FlowSphere配置示例:
simple_config.json-基本GET请求auth_flow_config.json-通过令牌提取进行身份验证conditional_config.json-有条件执行validation_config.json-响应验证full_features_config.json-全部18个功能
了解更多关于FlowSphere的信息: https://github.com/ymoud/flowsphere
______________________________________________________________________
🧪 测试生成的代码
Python pytest
# Install dependencies
pip install pytest requests jsonpath-ng
# Run tests
pytest generated_test.py -v
# Run with debug output
pytest generated_test.py -v -sPython行为(BDD)
# Install dependencies
pip install behave requests jsonpath-ng
# Organize files
mkdir -p features/steps
mv *.feature features/
mv *_steps.py features/steps/
# Run tests
behave -vJavaScript恶作剧
# Install dependencies (from generated package.json)
npm install
# Run tests
npm test
# Run with coverage
npm test -- --coverageJavaScript Mocha
# Install dependencies
npm install --save-dev mocha chai axios jsonpath-plus uuid
# Run tests
npx mocha test_file.test.jsJavaScript黄瓜
# Install dependencies
npm install --save-dev @cucumber/cucumber axios jsonpath-plus chai
# Organize files
mkdir -p features/step_definitions
mv *.feature features/
mv *_steps.js features/step_definitions/
# Run tests
npx cucumber-jsC# x单元
# Create project
dotnet new xunit -n MyTests
# Add packages (from generated .csproj)
dotnet add package xunit
dotnet add package Newtonsoft.Json
# Run tests
dotnet testC#NUnit
# Create project
dotnet new nunit -n MyTests
# Add packages
dotnet add package NUnit
dotnet add package Newtonsoft.Json
# Run tests
dotnet testC#规范流
# Create project
dotnet new classlib -n MyTests
# Add packages
dotnet add package SpecFlow
dotnet add package SpecFlow.NUnit
# Organize files
mkdir Features StepDefinitions
mv *.feature Features/
mv *Steps.cs StepDefinitions/
# Run tests
dotnet test______________________________________________________________________
🔧 可用的MCP工具
服务器暴露 11个MCP工具 对于AI代理:
架构和文档工具
1. get_flowsphere_schema
获取完整的FlowSphere配置模式文档。
退货: 包含所有属性、类型、默认值和示例的全面模式
2. get_flowsphere_features
获取所有18个FlowSphere功能的详细文档。
退货: 功能描述、实施说明、示例
3. get_feature_checklist
获取必须在生成的代码中实现的所有功能的清单。
退货: 18项功能检查表
Python生成器
4. generate_python_pytest
生成生产就绪的Python pytest代码。
参数:
config(必填):FlowSphere配置对象test_class_name(可选):自定义测试类名generate_report(可选):生成综合生成报告save_report_to(可选):保存报告的文件路径
退货:
status:“成功”或“错误”code:生成的Python pytest代码config_json:单独的配置文件内容config_filename:“config.json”dependencies:pip包列表usage_instructions:如何运行测试generation_report:可选详细报告(如果generate_report=true)
5. generate_python_behave
生成Python行为/BDD测试(Gherkin+步骤定义)。
参数:
config(必填):FlowSphere配置对象feature_name(可选):自定义要素文件名generate_report(可选):生成综合生成报告save_report_to(可选):保存报告的文件路径
退货:
code:组合Gherkin特征+步长定义config_json:单独的配置文件内容dependencies:pip包列表(行为、请求、jsonpath ng)note:文件组织说明generation_report:可选详细报告
JavaScript生成器
6. generate_javascript_jest
生成JavaScript Jest测试。
参数:
config(必填):FlowSphere配置对象test_class_name(可选):自定义测试类名generate_report(可选):生成综合生成报告save_report_to(可选):保存报告的文件路径
退货:
code:生成的Jest测试文件config_json:单独的配置文件内容package_json:完整的package.jsondependencies:npm包列表usage_instructions:如何运行测试generation_report:可选详细报告
7. generate_javascript_mocha
使用Chai断言生成JavaScript Mocha测试。
参数:
config(必填):FlowSphere配置对象test_class_name(可选):自定义测试类名generate_report(可选):生成综合生成报告save_report_to(可选):保存报告的文件路径
退货:
code:生成的Mocha测试文件config_json:单独的配置文件内容package_json:完整的package.jsondependencies:npm包列表(mocha、chai、axios、jsonpath plus)generation_report:可选详细报告
8. generate_javascript_cucumber
生成JavaScript Cucumber/BDD测试(Gherkin+步骤定义)。
参数:
config(必填):FlowSphere配置对象feature_name(可选):自定义要素文件名generate_report(可选):生成综合生成报告save_report_to(可选):保存报告的文件路径
退货:
feature:小黄瓜特征文件内容steps:步骤定义文件内容config_json:单独的配置文件内容package_json:完整的package.jsondependencies:npm包列表(@cucumber/cucumber,axios,chai)note:文件组织说明generation_report:可选详细报告
C#生成器
9. generate_csharp_xunit
生成C#xUnit测试。
参数:
config(必填):FlowSphere配置对象test_class_name(可选):自定义测试类名namespace(可选):自定义命名空间(默认:FlowSphere.Tests)generate_report(可选):生成综合生成报告save_report_to(可选):保存报告的文件路径
退货:
code:生成的xUnit测试文件config_json:单独的配置文件内容csproj:使用NuGet包完成.csproj文件dependencies:NuGet包列表(xunit、Newtonsoft.Json)usage_instructions:如何运行测试generation_report:可选详细报告
10. generate_csharp_nunit
使用约束模型断言生成C#NUnit测试。
参数:
config(必填):FlowSphere配置对象test_class_name(可选):自定义测试类名namespace(可选):自定义命名空间(默认:FlowSphere.Tests)generate_report(可选):生成综合生成报告save_report_to(可选):保存报告的文件路径
退货:
code:生成的NUnit测试文件config_json:单独的配置文件内容csproj:使用NuGet包完成.csproj文件dependencies:NuGet包列表(NUnit、Newtonsoft.Json)usage_instructions:如何运行测试generation_report:可选详细报告
11. generate_csharp_specflow
生成C#SpecFlow/BDD测试(Gherkin+步骤定义)。
参数:
config(必填):FlowSphere配置对象feature_name(可选):自定义要素文件名step_class_name(可选):自定义步骤定义类名namespace(可选):自定义命名空间(默认:FlowSphere.Tests)generate_report(可选):生成综合生成报告save_report_to(可选):保存报告的文件路径
退货:
feature:小黄瓜特征文件内容steps:C#步骤定义文件内容config_json:单独的配置文件内容csproj:使用NuGet包完成.csproj文件dependencies:NuGet包列表(SpecFlow、NUnit)note:文件组织说明generation_report:可选详细报告
📊 生成报告
所有代码生成工具都支持可选的综合报告,包括:
- 配置分析 -大小、节点数、检测到的特征
- 令牌使用分析 -输入/输出令牌,实时跟踪
- 成本估算 -GPT-4定价参考,节省计算
- 优化建议 -上下文感知提示
- 规模预测 -每日/每周/每月成本估算
示例用法:
result = mcp_server.call_tool("generate_python_pytest", {
"config": your_config,
"generate_report": True,
"save_report_to": "reports/generation_report.md"
})
# Access the report
print(result['generation_report']) # Full markdown report
print(result['report_path']) # File path if saved______________________________________________________________________
✅ 完整的功能覆盖
所有发电机支持 全部18个FlowSphere功能:
HTTP执行
- ✅ GET、POST、PUT、DELETE、PATCH请求
- ✅ 自定义标头(根据请求和默认值)
- ✅ 请求正文(JSON)
- ✅ 超时配置
变量替换(4种类型)
- ✅
{{ .vars.key }}-全局变量 - ✅
{{ .responses.nodeId.field }}-响应参考 - ✅
{{ .input.variableName }}-用户输入 - ✅
{{ $guid }},{{ $timestamp }}-动态占位符
状态评估(8名操作员)
- ✅
equals,notEquals - ✅
contains,notContains - ✅
greaterThan,lessThan - ✅
greaterThanOrEqual,lessThanOrEqual - ✅ 多种条件下的AND逻辑
- ✅ 条件中的变量替换
响应验证
- ✅ HTTP状态码验证
- ✅ 使用所有运算符进行JSONPath字段验证
- ✅ 跳过默认验证标志
高级功能
- ✅ 带变量存储的字段提取(JSONPath)
- ✅ 用户提示(
promptMessage) - ✅ 浏览器启动(
launchBrowser) - ✅ 跳过默认标题标志
- ✅ 调试模式(
enableDebug)
______________________________________________________________________
📂 项目结构
flowsphere-mcp-server/
├── src/flowsphere_mcp/
│ ├── server.py # MCP server (11 tools)
│ ├── schema/
│ │ ├── config_schema.py # FlowSphere schema docs
│ │ └── features.py # 18 features documentation
│ ├── templates/
│ │ ├── python/ # pytest, behave templates
│ │ ├── javascript/ # Jest, Mocha, Cucumber templates
│ │ └── csharp/ # xUnit, NUnit, SpecFlow templates
│ ├── generators/
│ │ ├── base_generator.py # Base generator class
│ │ ├── python_generator.py # Python pytest generator
│ │ ├── behave_generator.py # Python behave generator
│ │ ├── javascript_generator.py # JS Jest/Mocha/Cucumber generators
│ │ └── csharp_generator.py # C# xUnit/NUnit/SpecFlow generators
│ └── utils/
│ └── report_generator.py # Generation report builder
├── tests/
│ ├── fixtures/ # 5 sample FlowSphere configs
│ ├── test_*_generator.py # Generator tests (153 tests total)
│ └── generated_code/ # Example outputs
├── requirements.txt
├── ROADMAP.md
└── README.md______________________________________________________________________
🗺️ 开发阶段
- ✅ 第一阶段 -架构提供程序
- ✅ 第2阶段 -Python pytest生成器(31个测试)
- ✅ 第三期 -Python行为/BDD生成器(34个测试)
- ✅ 阶段4 -JavaScript生成器(Jest、Mocha、Cucumber)(46次测试)
- ✅ 阶段5 -C#生成器(xUnit、NUnit、SpecFlow)(39次测试)
- ✅ 第7.1阶段 -令牌优化(配置文件加载)-每代保存3000个令牌
- 🔄 第7阶段 -令牌效率和性能优化(正在进行中)
- 📋 第6阶段 -出版与发行(PyPI、Smithery)
当前状态: 153项测试通过,100%覆盖,8台发电机可投入生产
______________________________________________________________________
❓ 故障排除
MCP服务器无法连接
症状: 服务器在中显示“连接失败” /mcp 输出
解决:
- 验证是否安装了Python包:
pip install -r requirements.txt - 检查配置中的服务器路径:
claude mcp get flowsphere-mcp - 确保Windows上的路径使用反斜杠:
C:\path\to\... - 重新添加服务器:
claude mcp remove flowsphere-mcp -s local然后claude mcp add... - 重新启动Claude代码:退出
/exit那么claude
生成的Python测试失败
解决:
# Install dependencies
pip install pytest requests jsonpath-ng behave
# Verify Python version
python --version # Should be 3.10+
# Check config file is in correct location
ls config.json # Should be in same directory as test file生成的JavaScript测试失败
解决:
# Install dependencies from generated package.json
npm install
# Verify Node.js version
node --version # Should be 16+
# Check config file location
ls config.json # Should be in same directory as test file生成的C#测试失败
解决:
# Restore packages
dotnet restore
# Verify .NET SDK version
dotnet --version # Should be 6.0+
# Check config file location
dir config.json # Should be in project root or Configuration/ folder生成的代码中存在导入错误
解决方案: 所有生成的代码都需要 config.json 从文件加载。确保:
- 保存
config_json从MCP响应到名为的文件config.json - 将其放置在与测试相同的目录中(或
configuration/子目录) - 看
noteMCP响应中的特定放置指令字段
______________________________________________________________________
🆘 支持和后续步骤
快速链接
- FlowSphere文档: https://github.com/ymoud/flowsphere
- 示例配置: 测试/夹具/
- 路线图: ROADMAP.md
后续步骤
- 尝试快速启动 -使用Claude Code CLI在5分钟内运行
- 生成您的第一个测试 -使用中的示例配置之一
tests/fixtures/ - 运行生成的代码 -看到它与真实的API协同工作
- 自定义配置 -尝试不同的FlowSphere功能
- 与CI/CD集成 -将生成的测试添加到您的管道中
运行单元测试
验证一切正常:
# Run all tests (153 tests)
pytest tests/ -v
# Run specific generator tests
pytest tests/test_python_generator.py -v # 31 tests
pytest tests/test_behave_generator.py -v # 34 tests
pytest tests/test_javascript_generator.py -v # 30 tests
pytest tests/test_mocha_generator.py -v # 8 tests
pytest tests/test_cucumber_generator.py -v # 8 tests
pytest tests/test_xunit_generator.py -v # 12 tests
pytest tests/test_nunit_generator.py -v # 14 tests
pytest tests/test_specflow_generator.py -v # 13 tests______________________________________________________________________
📄 许可证
MIT许可证-请参阅 许可证 详见
______________________________________________________________________
内置❤️ FlowSphere社区
