Locust Mcp Server

Locust Mcp Server

🚀 Locust-MCP-Server

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

🚀 快速开始

在使用 Locust-MCP-Server 前,请确保你已完成以下操作:

  1. 确保安装了 Python 3.13 或更高版本以及 uv 包管理器(安装指南)。
  2. 克隆仓库:
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               # 用户默认spawn率
LOCUST_RUN_TIME=10s               # 默认测试持续时间

完成上述准备工作后,你就可以开始进行 Locust 负载测试了:

  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 运行测试,例如:运行 Locust 测试以分析 hello.py。Locust MCP 服务器将使用以下工具启动测试:
  • run_locust:带有配置选项的测试运行器(无头模式、主机、持续时间、用户数和 spawn 率)

✨ 主要特性

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

📦 安装指南

  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               # 用户默认spawn率
LOCUST_RUN_TIME=10s               # 默认测试持续时间

💻 使用示例

基础用法

创建一个 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"})

高级用法

使用 run_locust API 启动测试:

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

📚 详细文档

📝 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:用户的 spawn 率。

✨ 使用场景

  • 通过 LLM 驱动的结果分析。
  • 借助 LLM 进行有效调试。

🤝 贡献

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

📄 许可证

此项目在 MIT 许可证下,详细信息请参阅 LICENSE 文件。

  • 0 关注
  • 0 收藏,20 浏览
  • system 提出于 2025-10-06 09:24

相似服务问题

相关AI产品