L

Locust AI性能测试服务器

@QAInsights/locust-mcp-server
1 Stars 89 次浏览 QAInsights 更新于 2026-08-23

一种集成了Locust负载测试功能与人工智能驱动的开发环境的服务器,允许用户通过自然语言命令运行性能测试。

MCP 服务配置

复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用

{
  "mcpServers": {
    "locust": {
      "args": [
        "--directory",
        "/Users/naveenkumar/Gits/locust-mcp-server",
        "run",
        "locust_server.py"
      ],
      "command": "/Users/naveenkumar/.local/bin/uv"
    }
  }
}

该服务需要配置环境变量:LOCUST_HOST、LOCUST_RUN_TIME、LOCUST_SPAWN_RATE、LOCUST_USERS

服务介绍

🚀 ⚡️ locust-mcp-server

一个用于运行 Locust 负载测试的 Model Context Protocol (MCP) 服务器实现。该服务器能够无缝集成 Locust 负载测试功能与 AI 驱动的开发环境。

✨ 特性

  • 简单集成到 Model Context Protocol 框架
  • 支持无头模式和 UI 模式
  • 可配置的测试参数(用户数、生成速率、运行时间)
  • 易于使用的 API 以运行 Locust 负载测试
  • 实时测试执行输出
  • 开箱即支持 HTTP/HTTPS 协议
  • 支持自定义任务场景

Locust-MCP-Server

🔧 前提条件

开始之前,请确保已安装以下软件:

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

📦 安装

  1. 克隆仓库:
git clone https://github.com/yourusername/locust-mcp-server.git
  1. 安装所需的依赖项:
uv pip install -r requirements.txt
  1. 设置环境变量(可选):
    在项目根目录下创建 .env 文件:
LOCUST_HOST=http://localhost:8089  # Default host for your tests
LOCUST_USERS=3                     # Default number of users
LOCUST_SPAWN_RATE=1               # Default user spawn rate
LOCUST_RUN_TIME=10s               # Default test duration

🚀 快速入门

  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: 用户生成速率

🤝 贡献

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

📄 许可证

该项目采用 MIT 许可证 - 详情请参阅 LICENSE 文件。