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

在开始之前,请确保已安装以下内容:
git clone https://github.com/qainsights/locust-mcp-server.git
uv pip install -r requirements.txt
.env 文件:LOCUST_HOST=http://localhost:8089 # 测试默认主机
LOCUST_USERS=3 # 默认用户数
LOCUST_SPAWN_RATE=1 # 默认用户生成速率
LOCUST_RUN_TIME=10s # 默认测试持续时间
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"})
{
"mcpServers": {
"locust": {
"command": "/Users/naveenkumar/.local/bin/uv",
"args": [
"--directory",
"/Users/naveenkumar/Gits/locust-mcp-server",
"run",
"locust_server.py"
]
}
}
}
run locust test for hello.py。Locust MCP服务器将使用以下工具启动测试:run_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文件以获取详细信息。 </中文翻译>