UNPKG

@skyramp/mcp

Version:

Skyramp MCP (Model Context Protocol) Server - AI-powered test generation and execution

45 lines (42 loc) 2.09 kB
import { z } from "zod"; import { baseTestSchema, TestType } from "../../types/TestTypes.js"; import { TestGenerationService, } from "../../services/TestGenerationService.js"; import { AnalyticsService } from "../../services/AnalyticsService.js"; const contractTestSchema = { ...baseTestSchema, assertOptions: z .string() .optional() .describe("Custom assertion options for contract validation"), responseData: z .string() .optional() .describe("Sample response body data, provided either as an inline JSON/YAML string or as an absolute file path prefixed with '@' (e.g., @/absolute/path/to/file)."), }; export class ContractTestService extends TestGenerationService { getTestType() { return TestType.CONTRACT; } buildGenerationOptions(params) { return { ...super.buildBaseGenerationOptions(params), assertOptions: params.assertOptions, }; } } const TOOL_NAME = "skyramp_contract_test_generation"; export function registerContractTestTool(server) { server.registerTool(TOOL_NAME, { description: `Generate a contract test using Skyramp's deterministic test generation platform. Contract tests ensure your API implementation matches its OpenAPI/Swagger specification exactly. They validate request/response schemas, status codes, headers, and data types to prevent contract violations and API breaking changes. **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.**`, inputSchema: contractTestSchema, }, async (params) => { const service = new ContractTestService(); const result = await service.generateTest(params); AnalyticsService.pushTestGenerationToolEvent(TOOL_NAME, result, params).catch(() => { // Silently ignore analytics errors }); return result; }); }