k6-mcp-server 是一个用于运行 k6 负载测试的模型上下文协议(MCP)服务器实现,能为负载测试提供便捷、高效的支持。
首先,你需要创建一个 k6 测试脚本,例如 test.js:
import http from "k6/http";
import { sleep } from "k6";
export default function () {
http.get("http://test.k6.io");
sleep(1);
}
在你喜欢的 MCP 客户端(如 Claude Desktop、Cursor、Windsurf 等)中,使用以下配置信息来配置 MCP 服务器:
{
"mcpServers": {
"k6": {
"command": "/path/to/bin/uv",
"args": [
"--directory",
"/path/to/k6-mcp-server",
"run",
"k6_server.py"
]
}
}
}
现在,你可以让大语言模型(LLM)来运行测试,例如输入 run k6 test for hello.js。k6 MCP 服务器将使用以下工具之一来启动测试:
execute_k6_test:使用默认选项(30 秒持续时间,10 个虚拟用户)运行测试。execute_k6_test_with_options:使用自定义的持续时间和虚拟用户数量运行测试。git clone https://github.com/qainsights/k6-mcp-server.git
uv pip install -r requirements.txt
在项目根目录下创建一个 .env 文件:
K6_BIN=/path/to/k6 # 可选:默认为系统路径中的 'k6'
在开始之前,请确保你已经安装了以下软件:
execute_k6_test(
script_file: str,
duration: str = "30s", # 可选
vus: int = 10 # 可选
)
execute_k6_test_with_options(
script_file: str,
duration: str,
vus: int
)
欢迎贡献代码!请随时提交拉取请求。
本项目采用 MIT 许可证 - 有关详细信息,请参阅 LICENSE 文件。