@skyramp/mcp
Version:
Skyramp MCP (Model Context Protocol) Server - AI-powered test generation and execution
110 lines (105 loc) • 5.11 kB
JavaScript
import { SkyrampClient } from "@skyramp/skyramp";
import { closeProxyTerminal } from "../utils/proxy-terminal.js";
import { z } from "zod";
import { PLAYWRIGHT_OUTPUT_FILE_FIELD_NAME, TELEMETRY_entrypoint_FIELD_NAME, TRACE_OUTPUT_FILE_FIELD_NAME, validatePath, } from "../utils/utils.js";
import { logger } from "../utils/logger.js";
export function registerTraceStopTool(server) {
server.registerTool("skyramp_stop_trace_collection", {
description: `Stop trace collection and save captured data using Skyramp's comprehensive tracing capabilities.
Stopping trace collection finalizes the monitoring process and exports all captured data to specified files. This includes API calls, service communications, user interactions, and network traffic that occurred during the collection period.
INTEGRATION WITH TEST GENERATION:
The generated trace and Playwright files can be used as inputs for:
- Integration test generation (using trace files)
- Load test generation (using trace files)
- E2E test generation (using both trace and Playwright files)
- UI test generation (using Playwright files)
For detailed documentation visit: https://www.skyramp.dev/docs/load-test/advanced-generation#end-trace-collection`,
inputSchema: {
traceOutputFile: z
.string()
.describe("MUST be absolute path to save the trace output file (e.g., /path/to/skyramp-traces.json). This file will contain the collected trace data"),
playwright: z
.boolean()
.describe("Whether Playwright was used for trace collection. Must match the setting used when starting trace collection"),
playwrightOutput: z
.string()
.describe("MUST be absolute path to save the Playwright output file (e.g., /path/to/playwright.zip). Only used when playwright is true"),
prompt: z
.string()
.describe("The prompt user provided to stop trace collection"),
},
annotations: {
keywords: ["stop trace", "collect generated trace"],
},
}, async (params) => {
logger.info("Stopping trace collection", {
traceOutputFile: params.traceOutputFile,
playwright: params.playwright,
playwrightOutput: params.playwrightOutput,
prompt: params.prompt,
});
const client = new SkyrampClient();
try {
const stopTraceOptions = {
output: params.traceOutputFile ?? "skyramp-traces.json",
workerContainerName: "skyramp-trace-worker",
playwright: params.playwright ?? false,
playwrightOutput: params.playwrightOutput ?? "playwright.zip",
entrypoint: TELEMETRY_entrypoint_FIELD_NAME,
};
let errList = {
content: [],
isError: true,
};
if (stopTraceOptions.output === "" &&
stopTraceOptions.playwrightOutput === "") {
errList.content.push({
type: "text",
text: "Error: Either trace output file or playwright output file is required.",
});
}
logger.debug("Trace collection stop options", {
playwright: stopTraceOptions.playwright,
});
if (!stopTraceOptions.playwright) {
logger.info("Playwright disabled for trace collection");
stopTraceOptions.playwrightOutput = "";
}
let err = validatePath(stopTraceOptions.output, TRACE_OUTPUT_FILE_FIELD_NAME);
if (err && err.content) {
errList.content.push(err.content[0]);
}
err = validatePath(stopTraceOptions.playwrightOutput, PLAYWRIGHT_OUTPUT_FILE_FIELD_NAME);
if (err && err.content) {
errList.content.push(err.content[0]);
}
// If error is not empty, return error
if (errList.content.length > 0) {
return errList;
}
await closeProxyTerminal();
const result = await client.traceCollect(stopTraceOptions);
return {
content: [
{
type: "text",
text: `Trace collection is stopped: ${result}. Trace is generated to given output file
**IMPORTANT: GO THROUGH THE TRACE AND LET THE USER KNOW THE ENDPOINT DOMAINS CAPTURED AND MAKE SURE USER WANTS TO INCLUDE THEN FOR INTEGRATION/E2E/LOAD TEST GENERATION.
UI TESTS CAN BE GENERATED USING PLAYWRIGHT FILES ONLY.**`,
},
],
};
}
catch (error) {
return {
content: [
{
type: "text",
text: `Trace generation result: ${error.message}`,
},
],
isError: true,
};
}
});
}