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.
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();
}-
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
-
Write your test script
Use the example above or create your own test scriptscript.js. -
Run your test
Use your custom k6 binary to run the script:./k6 run script.js
Creates a new MCP client instance.
Parameters:
config.endpoint(string): MCP server endpoint URLconfig.timeout(number): Connection timeout in seconds used for connection and tool callconfig.isSSE(boolean): Use Server-Sent Events transportconfig.headers(object, optional): Custom HTTP headers
Returns: MCPClient instance
Calls a tool on the MCP server.
Parameters:
toolName(string): Name of the tool to callargs(object): Arguments to pass to the tool
Returns: Tool response as a string
Closes the MCP client connection.
| 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. |
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). |
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
If you wish to contribute to this project, please start by reading the Contributing Guidelines.