-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmcp_server.py
More file actions
37 lines (32 loc) · 1.01 KB
/
mcp_server.py
File metadata and controls
37 lines (32 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from mcp.server.fastmcp import FastMCP
from ai_analyzer_local import analyze_with_llm
from utils.parser import parse_jtl
from prometheus_exporter import start_prometheus_server
import subprocess, time, os
mcp = FastMCP("jmeter-ai-server")
JMETER_PATH = "/usr/bin/jmeter"
RESULT_FILE = "/results/latest.jtl"
@mcp.tool()
def run_test(plan_path: str, threads: int = 5, ramp: int = 2, duration: int = 60):
cmd = [
JMETER_PATH, "-n",
"-t", plan_path,
"-l", RESULT_FILE,
"-Jthreads=" + str(threads),
"-Jramp=" + str(ramp),
"-Jduration=" + str(duration)
]
start_time = time.time()
subprocess.run(cmd, check=True)
elapsed = time.time() - start_time
return {"status": "completed", "runtime_sec": elapsed, "results": RESULT_FILE}
@mcp.tool()
def get_metrics():
return parse_jtl(RESULT_FILE)
@mcp.tool()
def ai_report():
metrics = parse_jtl(RESULT_FILE)
return analyze_with_llm(metrics)
if __name__ == "__main__":
start_prometheus_server()
mcp.run()\n