Skip to main content
Glama

execute_k6_test

Run load tests to evaluate system performance by executing k6 scripts with configurable duration and virtual user simulation.

Instructions

Execute a k6 load test.

Args: script_file: Path to the k6 test script (.js) duration: Duration of the test (e.g., "30s", "1m", "5m") vus: Number of virtual users to simulate

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
script_fileYes
durationNo30s
vusNo

Implementation Reference

  • The handler function for the 'execute_k6_test' MCP tool, decorated with @mcp.tool() for automatic registration and handling tool execution by delegating to the run_k6_script helper.
    async def execute_k6_test(script_file: str, duration: str = "30s", vus: int = 10) -> str:
        """Execute a k6 load test.
    
        Args:
            script_file: Path to the k6 test script (.js)
            duration: Duration of the test (e.g., "30s", "1m", "5m")
            vus: Number of virtual users to simulate
        """
        return await run_k6_script(script_file, duration, vus)
  • Supporting utility function that implements the core logic for running k6 tests via subprocess, including file validation, command construction, execution, and error handling.
    async def run_k6_script(script_file: str, duration: str = "30s", vus: int = 10) -> str:
        """Run a k6 load test script.
    
        Args:
            script_file: Path to the k6 test script (.js)
            duration: Duration of the test (e.g., "30s", "1m", "5m")
            vus: Number of virtual users to simulate
    
        Returns:
            str: k6 execution output
        """
        try:
            # Convert to absolute path
            script_file_path = Path(script_file).resolve()
            
            # Validate file exists and is a .js file
            if not script_file_path.exists():
                return f"Error: Script file not found: {script_file}"
            if not script_file_path.suffix == '.js':
                return f"Error: Invalid file type. Expected .js file: {script_file}"
    
            # Get k6 binary path from environment
            k6_bin = os.getenv('K6_BIN', 'k6')
            
            # Print the k6 binary path for debugging
            print(f"k6 binary path: {k6_bin}")
    
            # Build command
            cmd = [str(Path(k6_bin).resolve())]
            cmd.extend(['run'])
            cmd.extend(['-d', duration])
            cmd.extend(['-u', str(vus)])
            cmd.extend([str(script_file_path)])
    
            # Print the full command for debugging
            print(f"Executing command: {' '.join(cmd)}")
            
            # Run the command and capture output
            result = subprocess.run(cmd, capture_output=True, text=True)
            
            # Print output for debugging
            print(f"\nCommand output:")
            print(f"Return code: {result.returncode}")
            print(f"Stdout: {result.stdout}")
            print(f"Stderr: {result.stderr}")
    
            if result.returncode != 0:
                return f"Error executing k6 test:\n{result.stderr}"
            
            return result.stdout
    
        except Exception as e:
            return f"Unexpected error: {str(e)}"
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It states the tool executes a load test, implying a potentially resource-intensive operation, but does not disclose behavioral traits such as permissions needed, rate limits, whether it runs synchronously/asynchronously, or what happens on failure. This is a significant gap for a tool with mutation-like behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded with the main purpose, followed by parameter explanations in a structured 'Args:' section. Every sentence earns its place by clarifying parameters, though it could be slightly more concise by integrating the parameter details more seamlessly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of executing a load test (a mutation-like operation), no annotations, and no output schema, the description is incomplete. It covers the basic purpose and parameters but lacks critical context such as return values, error handling, or execution behavior. This is adequate as a minimum but has clear gaps for safe agent use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It provides clear semantics for all three parameters: 'script_file' as a path to a .js file, 'duration' with examples of time formats, and 'vus' as the number of virtual users. This adds substantial value beyond the bare schema, though it could include more details like valid ranges or constraints.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Execute a k6 load test' with a specific verb ('execute') and resource ('k6 load test'). It distinguishes from the sibling tool 'execute_k6_test_with_options' by being the basic version, though this distinction is implied rather than explicit. The purpose is not vague or tautological.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage by specifying parameters for a basic load test, but does not explicitly state when to use this tool versus the sibling 'execute_k6_test_with_options'. No exclusions or alternatives are mentioned, leaving the agent to infer that this is for simpler tests without additional options.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/QAInsights/k6-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server