@skyramp/mcp
Version:
Skyramp MCP (Model Context Protocol) Server - AI-powered test generation and execution
86 lines (81 loc) • 3.91 kB
JavaScript
import { z } from "zod";
import { baseTestSchema, baseTraceSchema, TestType, } from "../../types/TestTypes.js";
import { TestGenerationService, } from "../../services/TestGenerationService.js";
import { AnalyticsService } from "../../services/AnalyticsService.js";
const loadTestSchema = {
...baseTestSchema,
loadCount: z
.string()
.default("")
.describe("Total string of iteration to be executed for the test. DO NOT ASSUME VALUE"),
loadDuration: z
.string()
.default("5")
.describe("Duration of the load test in seconds (default: 5)"),
loadNumThreads: z
.string()
.default("1")
.describe("Number of concurrent threads/users for the load test (default: 1)"),
loadRampupDuration: z
.string()
.default("")
.describe("Time in seconds to gradually increase load to target level. DO NOT ASSUME VALUE"),
loadRampupInterval: z
.string()
.default("")
.describe("Interval in seconds between ramping up threads. DO NOT ASSUME VALUE"),
loadTargetRPS: z
.string()
.default("")
.describe("Target requests per second for the load test. DO NOT ASSUME VALUE"),
trace: baseTraceSchema.shape.trace.default(""),
include: baseTraceSchema.shape.include,
exclude: baseTraceSchema.shape.exclude,
endpointURL: baseTestSchema.endpointURL.default(""),
};
export class LoadTestService extends TestGenerationService {
getTestType() {
return TestType.LOAD;
}
buildGenerationOptions(params) {
return {
...super.buildBaseGenerationOptions(params),
loadCount: params.loadCount,
loadDuration: params.loadDuration,
loadNumThreads: params.loadNumThreads,
loadRampupDuration: params.loadRampupDuration,
loadRampupInterval: params.loadRampupInterval,
loadTargetRPS: params.loadTargetRPS,
};
}
async handleApiAnalysis(params, generateOptions) {
return null;
}
}
const TOOL_NAME = "skyramp_load_test_generation";
export function registerLoadTestTool(server) {
server.registerTool(TOOL_NAME, {
description: `Generate a load test using Skyramp's deterministic test generation platform.
Load tests evaluate your application's performance, scalability, and stability under various traffic conditions. They simulate multiple concurrent users, measure response times, identify performance bottlenecks, and ensure your system can handle expected traffic volumes.
***IMPORTANT***
- At any given time you can provide duration of the test or test execution count
- IF THE USER DOES NOT PROVIDE LOAD PARAMETERS, THEN USE DEFAULT VALUES FOR LOAD TESTS:
- loadDuration: "5" (5 seconds)
- loadNumThreads: "1" (1 thread)
- Other load parameters should remain empty unless explicitly specified by the user
**IMPORTANT: If an apiSchema parameter (OpenAPI/Swagger file path or URL) is provided, DO NOT attempt to read or analyze the file contents. These files can be very large. Simply pass the path/URL to the tool - the backend will handle reading and processing the schema file.**
**CRITICAL - When using trace parameter:**
If \`trace\` parameter is provided (path to a trace file), DO NOT pass \`apiSchema\` or \`endpointURL\` parameters. The trace file already contains all necessary endpoint and schema information. Passing both will cause test generation to fail.`,
inputSchema: loadTestSchema,
_meta: {
keywords: ["load test", "performance test"],
},
}, async (params) => {
const service = new LoadTestService();
const result = await service.generateTest(params);
AnalyticsService.pushTestGenerationToolEvent(TOOL_NAME, result, params).catch(() => {
// Silently ignore analytics errors
});
return result;
});
}