run_locust
Execute load testing with Locust by configuring users, spawn rate, runtime, and host. Input a test file to simulate and analyze performance under specific conditions.
Instructions
Run Locust with the given configuration.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| headless | No | ||
| host | No | http://localhost:8089 | |
| runtime | No | 30s | |
| spawn_rate | No | ||
| test_file | Yes | ||
| users | No |
Implementation Reference
- locust_server.py:14-52 (handler)The main handler function for the 'run_locust' tool, decorated with @mcp.tool. It runs Locust via subprocess with configurable parameters like users, spawn rate, runtime, and headless mode.@mcp.tool(name="run_locust", description="Run Locust with the given configuration.") async def run_locust(test_file: str, host: str = os.getenv("LOCUST_HOST", "http://localhost:8089"), users: int = int(os.getenv("LOCUST_USERS", "100")), spawn_rate: int = int(os.getenv("LOCUST_SPAWN_RATE", "10")), runtime: str = os.getenv("LOCUST_RUNTIME", "30s"), headless: bool = os.getenv("LOCUST_HEADLESS", "true").lower() == "true") -> Any: """ Run Locust with the given configuration. Args: test_file: Path to the Locust test file host: Target host URL to load test users: Number of concurrent users to simulate spawn_rate: Rate at which users are spawned per second runtime: Duration of the test (e.g., "30s", "1m", "5m") headless: Whether to run in headless mode (no web UI) """ locust_bin = os.getenv("LOCUST_BIN", "locust") cmd = [locust_bin, "-f", test_file, "--host", host] if headless: cmd.extend(["--headless"]) cmd.extend(["-u", str(users)]) cmd.extend(["-r", str(spawn_rate)]) cmd.extend(["-t", runtime]) try: result = subprocess.run(cmd, capture_output=True, text=True, check=True) return { "status": "success", "output": result.stdout, "error": result.stderr } except subprocess.CalledProcessError as e: return { "status": "error", "output": e.stdout, "error": e.stderr }
- locust_server.py:14-14 (registration)The @mcp.tool decorator registers the 'run_locust' function as an MCP tool.@mcp.tool(name="run_locust", description="Run Locust with the given configuration.")