Skip to content

infobip/xk6-infobip-mcp

Repository files navigation

xk6-infobip-mcp

k6 extension for Model Context Protocol (MCP) integration

This k6 extension enables performance testing of MCP (Model Context Protocol) servers by providing a JavaScript API for creating MCP clients, calling tools, and managing connections. It is ideal for load testing MCP-based applications and validating MCP server performance under various conditions.

Originally developed to load test Infobip MCP Servers, this extension works with any MCP-compliant server implementation.

Example

import mcp from "k6/x/infobip_mcp";

export const options = {
  vus: 10,
  duration: '30s',
};

export default function () {
  // Create MCP client
  const client = mcp.NewClient({
    endpoint: "https://your-mcp-server.com/mcp",
    timeout: 30,
    isSSE: false,
    headers: {
      "Authorization": "Bearer your-token",
      "Content-Type": "application/json"
    }
  });

  // Call a tool on the MCP server
  const result = client.callTool("your_tool_name", {
    param1: "value1",
    param2: 42
  });

  console.log("Tool response:", result);

  // Clean up connection
  client.closeConnection();
}

Quick Start

  1. Build a custom k6 binary with xk6-infobip-mcp
    Use xk6 to build k6 with this extension:

    go install go.k6.io/xk6/cmd/xk6@latest
    xk6 build --with github.com/infobip/xk6-infobip-mcp
  2. Write your test script
    Use the example above or create your own test script script.js.

  3. Run your test
    Use your custom k6 binary to run the script:

    ./k6 run script.js

API Reference

NewClient(config)

Creates a new MCP client instance.

Parameters:

  • config.endpoint (string): MCP server endpoint URL
  • config.timeout (number): Connection timeout in seconds used for connection and tool call
  • config.isSSE (boolean): Use Server-Sent Events transport
  • config.headers (object, optional): Custom HTTP headers

Returns: MCPClient instance

MCPClient.callTool(toolName, args)

Calls a tool on the MCP server.

Parameters:

  • toolName (string): Name of the tool to call
  • args (object): Arguments to pass to the tool

Returns: Tool response as a string

MCPClient.closeConnection()

Closes the MCP client connection.

Metrics

MCP-Specific Metrics

Metric Name Type Description
mcp_call_duration Trend Duration of individual MCP tool calls in milliseconds. Use this to analyze response times and identify slow operations.
mcp_calls Counter Total number of MCP tool calls made during the test. Helps track the volume of operations executed.
mcp_success Rate Success rate of MCP operations in percentage. A high rate indicates reliable server performance.
mcp_errors Rate Error rate of MCP operations in percentage. Monitor this to identify reliability issues with your MCP server.

HTTP Metrics

Since MCP communication happens over HTTP, standard k6 HTTP metrics are also collected:

Metric Name Type Description
http_req_duration Trend Duration of HTTP requests to the MCP server in milliseconds. Includes connection time, sending, waiting, and receiving.
http_reqs Counter Total number of HTTP requests made to the MCP server. Each MCP operation typically results in one or more HTTP requests.
http_req_failed Rate Rate of failed HTTP requests in percentage (status codes ≥ 400). Note: Some specific status codes may not be considered failures (e.g., 404 for DELETE, 405 for GET).

Metric Tags

All metrics include the following tags for detailed analysis:

  • method: HTTP method used (GET, POST, etc.)
  • url: The MCP server endpoint URL
  • status: HTTP response status code

Contribute

If you wish to contribute to this project, please start by reading the Contributing Guidelines.

About

k6 extension for Model Context Protocol (MCP) integration

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •