@skyramp/mcp
Version:
Skyramp MCP (Model Context Protocol) Server - AI-powered test generation and execution
61 lines (57 loc) • 3.09 kB
JavaScript
import { z } from "zod";
import { baseTestSchema, baseTraceSchema, TestType, codeRefactoringSchema, } from "../../types/TestTypes.js";
import { TestGenerationService, } from "../../services/TestGenerationService.js";
import { AnalyticsService } from "../../services/AnalyticsService.js";
const integrationTestSchema = z
.object({
...baseTestSchema,
chainingKey: z
.string()
.optional()
.describe("JSON path of POST response that will be used for chaining. Example: If asked to use item_id to chain the requests, please ensure chainingKey is set to item_id."),
trace: baseTraceSchema.shape.trace.optional(),
include: baseTraceSchema.shape.include.optional(),
exclude: baseTraceSchema.shape.exclude.optional(),
scenarioFile: z
.string()
.describe("Path to the scenario file to be used for test generation. This file is generated by the skyramp_scenario_test_generation tool.")
.optional(),
...codeRefactoringSchema.shape,
...baseTestSchema,
endpointURL: baseTestSchema.endpointURL.default(""),
})
.omit({ method: true }).shape;
export class IntegrationTestService extends TestGenerationService {
getTestType() {
return TestType.INTEGRATION;
}
buildGenerationOptions(params) {
return {
...super.buildBaseGenerationOptions(params),
responseData: params.responseData,
playwrightInput: params.playwrightInput,
scenarioFile: params.scenarioFile,
};
}
async handleApiAnalysis(params, generateOptions) {
return null;
}
}
const TOOL_NAME = "skyramp_integration_test_generation";
export function registerIntegrationTestTool(server) {
server.registerTool(TOOL_NAME, {
description: `Generate an integration test using Skyramp's deterministic test generation platform.
Integration tests validate that multiple services, components, or modules work together correctly. They test complex user workflows, service interactions, data flow between systems, and ensure that integrated components function as expected in realistic scenarios.
**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 scenarioFile or trace parameter:**
If \`scenarioFile\` or \`trace\` parameter is provided, DO NOT pass \`apiSchema\` or \`endpointURL\` parameters. The scenario/trace file already contains all necessary endpoint and schema information. Passing both will cause test generation to fail.`,
inputSchema: integrationTestSchema,
}, async (params) => {
const service = new IntegrationTestService();
const result = await service.generateTest(params);
AnalyticsService.pushTestGenerationToolEvent(TOOL_NAME, result, params).catch(() => {
// Silently ignore analytics errors
});
return result;
});
}