Locust MCP server

Enables natural language control of Locust load testing operations, allowing configuration and execution of performance tests with customizable parameters for users, spawn rate, and test duration.
Back to servers
Setup instructions
Provider
NaveenKumar Namachivayam
Release date
Mar 30, 2025
Language
Python
Stats
4 stars

This server implements the Model Context Protocol (MCP) to run Locust load tests, allowing AI-powered development environments to seamlessly execute performance tests. It works with various MCP clients like Claude Desktop, Cursor, and Windsurf to make load testing more accessible.

Prerequisites

Before installation, ensure you have:

Installation

  1. Clone the repository:
git clone https://github.com/qainsights/locust-mcp-server.git
  1. Install the required dependencies:
uv pip install -r requirements.txt
  1. Set up environment variables (optional) by creating a .env file in the project root:
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

Usage

Creating Test Scripts

First, create a Locust test script (e.g., 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"})

Configuring the MCP Server

Configure the MCP server in your MCP client (Claude Desktop, Cursor, Windsurf, etc.) using the following specification:

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

Running Tests

Once configured, you can ask the LLM to run a test with a natural language command like: run locust test for hello.py.

The server supports the following tool:

  • run_locust: Executes a test with configurable options for headless mode, host, runtime, users, and spawn rate

API Reference

Run Locust Test

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

Parameters:

  • test_file: Path to your Locust test script
  • headless: Run in headless mode (True) or with UI (False)
  • host: Target host to load test
  • runtime: Test duration (e.g., "30s", "1m", "5m")
  • users: Number of concurrent users to simulate
  • spawn_rate: Rate at which users are spawned

Features

The Locust MCP server includes:

  • Simple integration with Model Context Protocol framework
  • Support for both headless and UI modes
  • Configurable test parameters (users, spawn rate, runtime)
  • Real-time test execution output
  • HTTP/HTTPS protocol support
  • Custom task scenarios support

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

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

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

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

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

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

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later