k6-mcp-server 是一个用于运行 k6 负载测试的 Model Context Protocol(MCP)服务器实现,能简单集成到 MCP 框架中,支持自定义测试参数,还可通过环境变量配置,提供实时测试输出,助力高效开展负载测试。
在使用 k6-mcp-server 之前,你需要完成一些准备工作,然后按照步骤进行安装和配置,最后就可以启动测试啦。
在开始之前,请确保安装了以下内容:
git clone https://github.com/qainsights/k6-mcp-server.git
uv pip install -r requirements.txt
.env 文件:K6_BIN=/path/to/k6 # 可选:默认为系统PATH中的'k6'
test.js):import http from "k6/http";
import { sleep } from "k6";
export default function () {
http.get("http://test.k6.io");
sleep(1);
}
{
"mcpServers": {
"k6": {
"command": "/path/to/bin/uv",
"args": [
"--directory",
"/path/to/k6-mcp-server",
"run",
"k6_server.py"
]
}
}
}
运行 hello.js 的 k6 测试。k6 MCP 服务器将使用以下工具之一启动测试:execute_k6_test:使用默认选项运行测试(持续时间 30 秒,10 个 VU)execute_k6_test_with_options:使用自定义持续时间和 VU 数量运行测试execute_k6_test(
script_file: str,
duration: str = "30s", # 可选,默认为"30s"
vus: int = 10 # 可选,默认为10
)
execute_k6_test_with_options(
script_file: str,
duration: str,
vus: int
)
欢迎贡献!请随意提交 Pull Request。
该项目在 MIT License 下许可,详情请参阅 LICENSE 文件。