返回市场
群集-MCP服务器

群集-MCP服务器

作者:QAInsights10 星标更新:2025-04-07

项目介绍

🚀 ⚡️ locust-mcp-server

一个用于运行Locust负载测试的模型上下文协议(MCP)服务器实现。此服务器能够无缝集成Locust负载测试能力与AI驱动的开发环境。

✨ 特性

  • 与模型上下文协议框架简单集成
  • 支持无头模式和UI模式
  • 可配置的测试参数(用户数、生成速率、运行时间)
  • 运行Locust负载测试的易用API
  • 实时测试执行输出
  • 内置支持HTTP/HTTPS协议
  • 自定义任务场景支持

Locust-MCP-Server

🔧 先决条件

在开始之前,请确保已安装以下内容:

  • Python 3.13 或更高版本
  • uv 包管理器 (安装指南)

📦 安装

  1. 克隆仓库:
git clone https://github.com/qainsights/locust-mcp-server.git
  1. 安装所需依赖:
uv pip install -r requirements.txt
  1. 设置环境变量(可选): 在项目根目录创建一个 .env 文件:
LOCUST_HOST=http://localhost:8089  # 测试默认主机
LOCUST_USERS=3                     # 默认用户数
LOCUST_SPAWN_RATE=1               # 默认用户生成速率
LOCUST_RUN_TIME=10s               # 默认测试持续时间

🚀 快速开始

  1. 创建一个Locust测试脚本(例如,hello.py):
from locust import HttpUser, task, between

class QuickstartUser(HttpUser):
    wait_time = between(1, 5)

    @task
    def hello_world(self):
        self.client.get("/hello")
        self.client.get("/world")

    @task(3)
    def view_items(self):
        for item_id in range(10):
            self.client.get(f"/item?id={item_id}", name="/item")
            time.sleep(1)

    def on_start(self):
        self.client.post("/login", json={"username":"foo", "password":"bar"})
  1. 使用以下规格在您喜欢的MCP客户端(如Claude Desktop、Cursor、Windsurf等)中配置MCP服务器:
{
  "mcpServers": {
    "locust": {
      "command": "/Users/naveenkumar/.local/bin/uv",
      "args": [
        "--directory",
        "/Users/naveenkumar/Gits/locust-mcp-server",
        "run",
        "locust_server.py"
      ]
    }
  }
}
  1. 现在请求LLM运行测试,例如 run locust test for hello.py。Locust MCP服务器将使用以下工具启动测试:
  • run_locust: 使用可配置选项运行测试,包括无头模式、目标主机、运行时间、用户数和生成速率

📝 API参考

运行Locust测试

run_locust(
    test_file: str,
    headless: bool = True,
    host: str = "http://localhost:8089",
    runtime: str = "10s",
    users: int = 3,
    spawn_rate: int = 1
)

参数:

  • test_file: 指向您的Locust测试脚本的路径
  • headless: 在无头模式下运行(True)或带UI模式(False)
  • host: 负载测试的目标主机
  • runtime: 测试持续时间(例如,“30s”,“1m”,“5m”)
  • users: 模拟的同时用户数
  • spawn_rate: 用户生成速率

✨ 使用案例

  • 基于LLM的结果分析
  • 带有LLM的帮助进行有效调试

🤝 贡献

欢迎贡献!请随时提交Pull Request。

📄 许可证

本项目采用MIT许可证 - 查看LICENSE文件以获取详细信息。 </中文翻译>