Back to MCP directory
publicPublicdnsLocal runtime

QAInsights_locust-mcp-server

Locust-MCP-Server是一个基于Model Context Protocol框架的负载测试服务器,支持通过AI开发环境无缝运行Locust性能测试,提供可配置的测试参数和实时执行输出。

article

README

🚀 Locust-MCP-Server

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

🚀 快速开始

创建Locust测试脚本

首先,你需要创建一个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"})

配置MCP服务器

使用你喜欢的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"
      ]
    }
  }
}

启动测试

现在,你可以让LLM运行测试,例如输入运行Locust测试以执行hello.py。Locust MCP服务器将使用以下工具启动测试:

  • run_locust:带有配置选项的测试运行(无头模式、主机、持续时间、用户数和启动率)

✨ 主要特性

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

Locust-MCP-Server

🔧 先决条件

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

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

📦 安装指南

克隆仓库

git clone https://github.com/yourusername/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               # 默认测试持续时间

📚 详细文档

运行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
)

参数详情

| 参数 | 详情 | |------|------| | test_file | Locust测试脚本的路径 | | headless | 无头模式(True)或带UI(False) | | host | 要负载测试的目标主机 | | runtime | 测试持续时间(例如,“30s”、“1m”、“5m”) | | users | 模拟的并发用户数 | | spawn_rate | 用户的启动率 |

🤝 贡献

欢迎贡献!请随意提交拉取请求。

📄 许可证

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

help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client