Skip to main content
Glama

execute_k6_test_with_options

Run load tests with k6 by specifying test duration and virtual users to simulate traffic and measure system performance.

Instructions

Execute a k6 load test with custom duration and VUs.

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
durationYes
vusYes

Implementation Reference

  • Handler function decorated with @mcp.tool(), defining the tool interface, parameters (schema), and delegating to the helper function.
    @mcp.tool()
    async def execute_k6_test_with_options(script_file: str, duration: str, vus: int) -> str:
        """Execute a k6 load test with custom duration and VUs.
    
        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 actual k6 test execution logic using subprocess, including file validation, command construction, 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?

With no annotations provided, the description carries full burden for behavioral disclosure. It states the tool executes a load test but doesn't mention critical behaviors like whether it's destructive (e.g., impacts system performance), requires specific permissions, has rate limits, or what happens upon execution (e.g., returns results, runs in background). This leaves significant gaps for a mutation tool.

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 core purpose in the first sentence. The parameter explanations are concise and directly relevant. However, the 'Args:' section formatting is slightly redundant with the schema but still earns its place by clarifying semantics.

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

Completeness2/5

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

Given no annotations, no output schema, and a mutation tool (executing tests), the description is incomplete. It lacks information on return values, error handling, prerequisites (e.g., script availability), and behavioral implications. For a tool that likely affects system resources, this is inadequate.

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 effectively adds meaning by explaining all three parameters: 'script_file' as a path to a .js file, 'duration' with format examples, and 'vus' as number of virtual users. This provides clear semantics beyond the bare schema, though it could be more detailed (e.g., constraints on values).

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 custom duration and VUs.' It specifies the verb ('execute'), resource ('k6 load test'), and key customizable parameters. However, it doesn't explicitly differentiate from its sibling 'execute_k6_test' (mentioned in context), which would be needed for a perfect score.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus its sibling 'execute_k6_test' or any alternatives. It mentions custom parameters but doesn't explain scenarios where this tool is preferred over simpler versions or when it should be avoided.

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