debugg-ai-mcp
Version:
MCP Server for debugg ai web browsing
108 lines (107 loc) • 4.01 kB
JavaScript
// index.ts
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
import { DebuggAIServerClient } from "./services/index.js";
import { E2eTestRunner } from "./e2e-agents/e2eRunner.js";
const createE2eTestTool = {
name: "debugg_ai_test_page_changes",
description: "Use DebuggAI to run & and test UI changes that have been made with its User emulation agents",
inputSchema: {
type: "object",
properties: {
description: {
type: "string",
description: "Description of what page (relative url) and features should be tested.",
},
localPort: {
type: "number",
description: "Localhost port number where the app is running. Eg. 3000",
},
filePath: {
type: "string",
description: "Absolute path to the file to test",
},
repoName: {
type: "string",
description: "The name of the current repository",
},
branchName: {
type: "string",
description: "Current branch name",
},
repoPath: {
type: "string",
description: "Local path of the repo root",
},
},
required: ["localPort", "description", "repoPath", "repoName",],
},
};
async function configureTestRunner(client) {
const e2eTestRunner = new E2eTestRunner(client);
return e2eTestRunner;
}
const server = new Server({
name: "DebuggAI MCP Server",
version: "0.1.0",
}, {
capabilities: {
tools: {},
},
});
server.setRequestHandler(CallToolRequestSchema, async (req) => {
console.error("Received CallToolRequest:", req);
const apiKey = process.env.DEBUGGAI_API_KEY;
const testUsername = process.env.TEST_USERNAME_EMAIL;
const testPassword = process.env.TEST_USER_PASSWORD;
if (!apiKey || !testUsername || !testPassword) {
console.error("Missing one or more required environment variables: DEBUGGAI_API_KEY, TEST_USERNAME_EMAIL, TEST_USER_PASSWORD");
process.exit(1);
}
try {
const { name, arguments: args } = req.params;
const client = new DebuggAIServerClient(apiKey);
if (name === "debugg_ai_create_new_e2e_test") {
const { description, localPort, repoName, branchName, repoPath, filePath } = args;
const e2eTestRunner = await configureTestRunner(client);
const test = await e2eTestRunner.createNewE2eTest(localPort, description, repoName, branchName, repoPath, filePath);
const testOutcome = test?.outcome;
const testDetails = test?.conversations?.[0]?.messages?.map((message) => message.content);
return {
content: [
{
type: "text",
text: JSON.stringify({ testOutcome, testDetails }, null, 2),
},
],
};
}
throw new Error(`Tool not found: ${name}`);
}
catch (err) {
return {
content: [
{
type: "text",
text: JSON.stringify({ error: err instanceof Error ? err.message : String(err) }),
},
],
};
}
});
server.setRequestHandler(ListToolsRequestSchema, async () => {
return {
tools: [createE2eTestTool],
};
});
async function main() {
console.error("Starting DebuggAI MCP server...");
const transport = new StdioServerTransport();
await server.connect(transport);
console.error("DebuggAI MCP Server running on stdio");
}
main().catch((err) => {
console.error("Fatal error in main():", err);
process.exit(1);
});