@debugg-ai/debugg-ai-mcp 1.0.21 → 1.0.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/config/index.js +21 -5
- package/dist/handlers/liveSessionHandlers.js +2 -5
- package/dist/handlers/testPageChangesHandler.js +1 -16
- package/dist/services/index.js +29 -0
- package/package.json +1 -1
- package/dist/e2e-agents/e2eRunner.js +0 -145
- package/dist/e2e-agents/recordingHandler.js +0 -57
- package/dist/e2e-agents/resultsFormatter.js +0 -102
package/dist/config/index.js
CHANGED
|
@@ -2,10 +2,26 @@
|
|
|
2
2
|
* Centralized configuration management for DebuggAI MCP Server
|
|
3
3
|
*/
|
|
4
4
|
import { z } from 'zod';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
import { readFileSync } from 'fs';
|
|
6
|
+
import { fileURLToPath } from 'url';
|
|
7
|
+
import { dirname, join } from 'path';
|
|
8
|
+
function findPackageVersion() {
|
|
9
|
+
const __dir = dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
let dir = __dir;
|
|
11
|
+
while (true) {
|
|
12
|
+
try {
|
|
13
|
+
const pkg = JSON.parse(readFileSync(join(dir, 'package.json'), 'utf-8'));
|
|
14
|
+
if (pkg.name === '@debugg-ai/debugg-ai-mcp')
|
|
15
|
+
return pkg.version;
|
|
16
|
+
}
|
|
17
|
+
catch { /* keep walking */ }
|
|
18
|
+
const parent = dirname(dir);
|
|
19
|
+
if (parent === dir)
|
|
20
|
+
return 'unknown';
|
|
21
|
+
dir = parent;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
const _version = findPackageVersion();
|
|
9
25
|
const configSchema = z.object({
|
|
10
26
|
server: z.object({
|
|
11
27
|
name: z.string().default('DebuggAI MCP Server'),
|
|
@@ -32,7 +48,7 @@ export function loadConfig() {
|
|
|
32
48
|
const rawConfig = {
|
|
33
49
|
server: {
|
|
34
50
|
name: 'DebuggAI MCP Server',
|
|
35
|
-
version:
|
|
51
|
+
version: _version,
|
|
36
52
|
},
|
|
37
53
|
api: {
|
|
38
54
|
// Priority: DEBUGGAI_API_TOKEN → DEBUGGAI_JWT_TOKEN → DEBUGGAI_API_KEY
|
|
@@ -76,12 +76,9 @@ export async function startLiveSessionHandler(input, context, progressCallback)
|
|
|
76
76
|
if (!session) {
|
|
77
77
|
throw new Error('Failed to start browser session: No session returned');
|
|
78
78
|
}
|
|
79
|
-
// If we need a tunnel, create it now using the
|
|
79
|
+
// If we need a tunnel, create it now using the account ngrok auth token
|
|
80
80
|
if (isLocalhost && tunnelId) {
|
|
81
|
-
const tunnelAuthToken =
|
|
82
|
-
if (!tunnelAuthToken) {
|
|
83
|
-
throw new Error('No tunnel key provided by backend - tunnels not available for localhost URLs');
|
|
84
|
-
}
|
|
81
|
+
const tunnelAuthToken = await client.getNgrokAuthToken();
|
|
85
82
|
logger.info(`Creating tunnel with backend-provided key for ${input.url} -> ${sessionUrl}`);
|
|
86
83
|
// Create the tunnel using the original localhost URL and the generated tunnel ID
|
|
87
84
|
const port = extractLocalhostPort(input.url);
|
|
@@ -50,22 +50,7 @@ export async function testPageChangesHandler(input, context, progressCallback) {
|
|
|
50
50
|
const { v4: uuidv4 } = await import('uuid');
|
|
51
51
|
tunnelId = uuidv4();
|
|
52
52
|
const tunnelPublicUrl = `https://${tunnelId}.ngrok.debugg.ai`;
|
|
53
|
-
|
|
54
|
-
const session = await client.browserSessions.startSession({
|
|
55
|
-
url: tunnelPublicUrl,
|
|
56
|
-
originalUrl: targetUrlRaw,
|
|
57
|
-
localPort: port,
|
|
58
|
-
sessionName: `Tunnel provisioning for ${targetUrlRaw}`,
|
|
59
|
-
monitorConsole: false,
|
|
60
|
-
monitorNetwork: false,
|
|
61
|
-
takeScreenshots: false,
|
|
62
|
-
isLocalhost: true,
|
|
63
|
-
tunnelId,
|
|
64
|
-
});
|
|
65
|
-
const tunnelAuthToken = session.tunnelKey;
|
|
66
|
-
if (!tunnelAuthToken) {
|
|
67
|
-
throw new Error('Browser sessions service did not return a tunnel auth token');
|
|
68
|
-
}
|
|
53
|
+
const tunnelAuthToken = await client.getNgrokAuthToken();
|
|
69
54
|
const tunnelResult = await tunnelManager.processUrl(targetUrlRaw, tunnelAuthToken, tunnelId);
|
|
70
55
|
targetUrl = tunnelResult.url;
|
|
71
56
|
logger.info(`Tunnel ready: ${targetUrl}`);
|
package/dist/services/index.js
CHANGED
|
@@ -38,6 +38,8 @@ export class DebuggAIServerClient {
|
|
|
38
38
|
e2es;
|
|
39
39
|
browserSessions;
|
|
40
40
|
workflows;
|
|
41
|
+
// Cached ngrok auth token — stable per account, fetched once per server session
|
|
42
|
+
_ngrokAuthToken;
|
|
41
43
|
constructor(userApiKey) {
|
|
42
44
|
this.userApiKey = userApiKey;
|
|
43
45
|
// Note: init() is async and should be called separately
|
|
@@ -50,6 +52,33 @@ export class DebuggAIServerClient {
|
|
|
50
52
|
this.browserSessions = createBrowserSessionsService(this.tx);
|
|
51
53
|
this.workflows = createWorkflowsService(this.tx);
|
|
52
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Returns the ngrok auth token for this account.
|
|
57
|
+
* The token is stable per account — fetched once via a minimal e2e test creation
|
|
58
|
+
* and cached for the lifetime of this server session.
|
|
59
|
+
*/
|
|
60
|
+
async getNgrokAuthToken() {
|
|
61
|
+
if (this._ngrokAuthToken)
|
|
62
|
+
return this._ngrokAuthToken;
|
|
63
|
+
if (!this.tx)
|
|
64
|
+
throw new Error('Client not initialized — call init() first');
|
|
65
|
+
// The e2e-tests POST returns tunnel_key (stable per account) at creation time.
|
|
66
|
+
// We create a minimal probe test, extract the key, then delete the test.
|
|
67
|
+
const created = await this.tx.post('api/v1/e2e-tests/', {
|
|
68
|
+
description: '_mcp_tunnel_probe',
|
|
69
|
+
repoName: '_mcp',
|
|
70
|
+
branchName: 'main',
|
|
71
|
+
});
|
|
72
|
+
const token = created?.tunnelKey;
|
|
73
|
+
if (!token)
|
|
74
|
+
throw new Error('Backend did not return a tunnel auth token');
|
|
75
|
+
// Clean up the probe test
|
|
76
|
+
if (created?.uuid) {
|
|
77
|
+
this.tx.delete(`api/v1/e2e-tests/${created.uuid}/`).catch(() => { });
|
|
78
|
+
}
|
|
79
|
+
this._ngrokAuthToken = token;
|
|
80
|
+
return token;
|
|
81
|
+
}
|
|
53
82
|
}
|
|
54
83
|
/**
|
|
55
84
|
* Create and initialize a service client
|
package/package.json
CHANGED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
2
|
-
import { createRequire } from 'module';
|
|
3
|
-
const require = createRequire(import.meta.url);
|
|
4
|
-
let ngrokModule = null;
|
|
5
|
-
async function getNgrok() {
|
|
6
|
-
if (!ngrokModule) {
|
|
7
|
-
try {
|
|
8
|
-
ngrokModule = require('ngrok');
|
|
9
|
-
}
|
|
10
|
-
catch (error) {
|
|
11
|
-
throw new Error(`Failed to load ngrok module: ${error}`);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return ngrokModule;
|
|
15
|
-
}
|
|
16
|
-
async function startTunnel(authToken, localPort, domain) {
|
|
17
|
-
try {
|
|
18
|
-
const ngrok = await getNgrok();
|
|
19
|
-
if (process.env.DOCKER_CONTAINER === "true") {
|
|
20
|
-
const url = await ngrok.connect({ proto: 'http', addr: `host.docker.internal:${localPort}`, hostname: domain, authtoken: authToken });
|
|
21
|
-
return url;
|
|
22
|
-
}
|
|
23
|
-
else {
|
|
24
|
-
const url = await ngrok.connect({ proto: 'http', addr: localPort, hostname: domain, authtoken: authToken });
|
|
25
|
-
return url;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
catch (err) {
|
|
29
|
-
console.error('Error starting ngrok tunnel:', err);
|
|
30
|
-
throw err;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
async function stopTunnel(url) {
|
|
34
|
-
try {
|
|
35
|
-
const ngrok = await getNgrok();
|
|
36
|
-
if (url) {
|
|
37
|
-
await ngrok.disconnect(url);
|
|
38
|
-
}
|
|
39
|
-
else {
|
|
40
|
-
await ngrok.disconnect();
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
catch (err) {
|
|
44
|
-
console.error('Error stopping ngrok tunnel:', err);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
const POLL_INTERVAL_MS = 1500;
|
|
48
|
-
const TIMEOUT_MS = 900_000; // 15 minutes
|
|
49
|
-
export class E2eTestRunner {
|
|
50
|
-
client;
|
|
51
|
-
constructor(client) {
|
|
52
|
-
this.client = client;
|
|
53
|
-
}
|
|
54
|
-
async setup() {
|
|
55
|
-
await this.configureNgrok();
|
|
56
|
-
}
|
|
57
|
-
async configureNgrok() {
|
|
58
|
-
// ngrok binary is downloaded automatically by the ngrok package
|
|
59
|
-
}
|
|
60
|
-
async startTunnel(authToken, port, url) {
|
|
61
|
-
await startTunnel(authToken, port, url);
|
|
62
|
-
console.error(`Tunnel started at: ${url}`);
|
|
63
|
-
return url;
|
|
64
|
-
}
|
|
65
|
-
/**
|
|
66
|
-
* Create a new E2E test and run it.
|
|
67
|
-
*/
|
|
68
|
-
async createNewE2eTest(testPort, testDescription, repoName, branchName, repoPath, filePath) {
|
|
69
|
-
console.error(`Creating new E2E test with description: ${testDescription}`);
|
|
70
|
-
const key = uuidv4();
|
|
71
|
-
const e2eTest = await this.client.e2es?.createE2eTest(testDescription, { filePath: filePath ?? "", repoName, branchName, repoPath, key });
|
|
72
|
-
console.error("E2E test creation response:", JSON.stringify(e2eTest, null, 2));
|
|
73
|
-
const authToken = e2eTest?.tunnelKey;
|
|
74
|
-
if (!authToken) {
|
|
75
|
-
console.error("Failed to get auth token. E2E test response:", e2eTest);
|
|
76
|
-
console.error("Available keys in response:", e2eTest ? Object.keys(e2eTest) : 'null response');
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
await startTunnel(authToken, testPort, `${key}.ngrok.debugg.ai`);
|
|
80
|
-
console.error(`E2E test created - ${e2eTest}`);
|
|
81
|
-
if (!e2eTest) {
|
|
82
|
-
console.error("Failed to create E2E test.");
|
|
83
|
-
return null;
|
|
84
|
-
}
|
|
85
|
-
if (!e2eTest.curRun) {
|
|
86
|
-
console.error("Failed to create E2E test run.");
|
|
87
|
-
return null;
|
|
88
|
-
}
|
|
89
|
-
return e2eTest.curRun;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Poll an E2E run until it completes or times out.
|
|
93
|
-
*
|
|
94
|
-
* Uses a safe async loop — no setInterval race conditions.
|
|
95
|
-
* The tunnel is stopped in a finally block so cleanup always runs
|
|
96
|
-
* regardless of how the loop exits (completion, timeout, or error).
|
|
97
|
-
*
|
|
98
|
-
* onUpdate is called on every poll tick so progress notifications
|
|
99
|
-
* fire at a steady cadence and keep the MCP connection alive.
|
|
100
|
-
*/
|
|
101
|
-
async handleE2eRun(e2eRun, onUpdate) {
|
|
102
|
-
const tunnelUrl = `https://${e2eRun.key}.ngrok.debugg.ai`;
|
|
103
|
-
const startTime = Date.now();
|
|
104
|
-
let updatedRun = e2eRun;
|
|
105
|
-
console.error(`🔧 Handling E2E run - ${e2eRun.uuid}`);
|
|
106
|
-
console.error(`🌐 Tunnel: ${tunnelUrl}`);
|
|
107
|
-
try {
|
|
108
|
-
while (true) {
|
|
109
|
-
if (Date.now() - startTime >= TIMEOUT_MS) {
|
|
110
|
-
console.error('⏰ E2E test timed out after 15 minutes');
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
await this._sleep(POLL_INTERVAL_MS);
|
|
114
|
-
try {
|
|
115
|
-
const latestRun = await this.client.e2es?.getE2eRun(e2eRun.uuid);
|
|
116
|
-
if (latestRun) {
|
|
117
|
-
updatedRun = latestRun;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
catch (pollError) {
|
|
121
|
-
console.error(`⚠️ Poll error (continuing): ${pollError}`);
|
|
122
|
-
}
|
|
123
|
-
console.error(`📡 Polled E2E run status: ${updatedRun.status}`);
|
|
124
|
-
// Always fire onUpdate — keeps MCP progress notifications alive
|
|
125
|
-
// even when the run is loading or the poll returned null
|
|
126
|
-
await onUpdate(updatedRun);
|
|
127
|
-
if (updatedRun.status === 'completed') {
|
|
128
|
-
break;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
finally {
|
|
133
|
-
await this._stopTunnel(tunnelUrl);
|
|
134
|
-
}
|
|
135
|
-
return updatedRun;
|
|
136
|
-
}
|
|
137
|
-
// Overridable in tests
|
|
138
|
-
async _sleep(ms) {
|
|
139
|
-
return new Promise(resolve => setTimeout(resolve, ms));
|
|
140
|
-
}
|
|
141
|
-
async _stopTunnel(url) {
|
|
142
|
-
await stopTunnel(url);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
export default E2eTestRunner;
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import * as fs from "fs";
|
|
2
|
-
import * as http from "http";
|
|
3
|
-
import * as https from "https";
|
|
4
|
-
import * as path from "path";
|
|
5
|
-
import { URL } from "url";
|
|
6
|
-
export async function fetchAndOpenGif(projectRoot, recordingUrl, testName, testId) {
|
|
7
|
-
const cacheDir = path.join(projectRoot, ".debugg-ai", "e2e-runs");
|
|
8
|
-
console.error('....downloading gif....');
|
|
9
|
-
console.error('cacheDir', cacheDir);
|
|
10
|
-
console.error('testId', testId);
|
|
11
|
-
console.error('recordingUrl', recordingUrl);
|
|
12
|
-
let localUrl = recordingUrl.replace('localhost', 'localhost:8002');
|
|
13
|
-
console.error('localUrl', localUrl);
|
|
14
|
-
await fs.promises.mkdir(cacheDir, { recursive: true });
|
|
15
|
-
const filePath = path.join(cacheDir, `${testName.replace(/[^a-zA-Z0-9]/g, '-')}-${testId.slice(0, 4)}.gif`);
|
|
16
|
-
const fileUrl = new URL(localUrl);
|
|
17
|
-
const file = fs.createWriteStream(filePath);
|
|
18
|
-
console.error(`⬇️ Downloading test recording...`);
|
|
19
|
-
await new Promise((resolve, reject) => {
|
|
20
|
-
console.error('fetching gif', fileUrl);
|
|
21
|
-
if (fileUrl.protocol === 'https:') {
|
|
22
|
-
https.get(localUrl, (response) => {
|
|
23
|
-
if (response.statusCode !== 200) {
|
|
24
|
-
reject(new Error(`Failed to download file: ${response.statusCode}`));
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
response.pipe(file);
|
|
28
|
-
file.on("finish", () => {
|
|
29
|
-
file.close();
|
|
30
|
-
resolve();
|
|
31
|
-
});
|
|
32
|
-
}).on("error", (err) => {
|
|
33
|
-
fs.unlinkSync(filePath);
|
|
34
|
-
reject(err);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
http.get(localUrl, (response) => {
|
|
39
|
-
if (response.statusCode !== 200) {
|
|
40
|
-
reject(new Error(`Failed to download file: ${response.statusCode}`));
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
response.pipe(file);
|
|
44
|
-
file.on("finish", () => {
|
|
45
|
-
file.close();
|
|
46
|
-
resolve();
|
|
47
|
-
});
|
|
48
|
-
}).on("error", (err) => {
|
|
49
|
-
fs.unlinkSync(filePath);
|
|
50
|
-
reject(err);
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
console.error(`📂 Opening test recording`);
|
|
55
|
-
// const fileUri = vscode.Uri.file(filePath);
|
|
56
|
-
// await vscode.commands.executeCommand('vscode.open', fileUri);
|
|
57
|
-
}
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
export class RunResultFormatter {
|
|
2
|
-
steps = [];
|
|
3
|
-
passed(result) {
|
|
4
|
-
return result.status === "completed" && result.outcome === "pass";
|
|
5
|
-
}
|
|
6
|
-
formatFailures(result) {
|
|
7
|
-
if (this.passed(result) || !result.outcome)
|
|
8
|
-
return "";
|
|
9
|
-
return "\n\n❌ Failures:" + "\n" + `> ${result.outcome}`;
|
|
10
|
-
}
|
|
11
|
-
formatStepsAsMarkdown() {
|
|
12
|
-
if (this.steps.length === 0)
|
|
13
|
-
return "";
|
|
14
|
-
return ("\n\n" +
|
|
15
|
-
this.steps
|
|
16
|
-
.map((s, idx) => {
|
|
17
|
-
const num = `Step ${idx + 1}:`;
|
|
18
|
-
const label = s.label.padEnd(30);
|
|
19
|
-
const icon = "✅ Success";
|
|
20
|
-
// s.status === "pending"
|
|
21
|
-
// ? chalk.yellow("⏳ Pending")
|
|
22
|
-
// : s.status === "success"
|
|
23
|
-
// ? chalk.green("✅ Success")
|
|
24
|
-
// : chalk.red("❌ Failed");
|
|
25
|
-
return `${num} ${label} ${icon}`;
|
|
26
|
-
})
|
|
27
|
-
.join("\n\n"));
|
|
28
|
-
}
|
|
29
|
-
updateStep(label, status) {
|
|
30
|
-
const existing = this.steps.find((s) => s.label === label);
|
|
31
|
-
if (existing) {
|
|
32
|
-
existing.status = status;
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
this.steps.push({ label, status });
|
|
36
|
-
}
|
|
37
|
-
console.error('updating step. steps ->', this.steps);
|
|
38
|
-
// Clear terminal and redraw
|
|
39
|
-
console.error("\x1Bc"); // ANSI clear screen
|
|
40
|
-
console.error("🧪 E2E Test Progress" +
|
|
41
|
-
`\r\n${this.steps
|
|
42
|
-
.map((s, i) => {
|
|
43
|
-
const icon = s.status === "pending"
|
|
44
|
-
? "⏳"
|
|
45
|
-
: s.status === "success"
|
|
46
|
-
? "✅"
|
|
47
|
-
: "❌";
|
|
48
|
-
return `${`Step ${i + 1}:`} ${s.label.padEnd(30)} ${icon}`;
|
|
49
|
-
})
|
|
50
|
-
.join("\r\n")}`);
|
|
51
|
-
}
|
|
52
|
-
formatTerminalBox(result) {
|
|
53
|
-
const header = this.passed(result)
|
|
54
|
-
? "✅ Test Passed"
|
|
55
|
-
: "❌ Test Failed";
|
|
56
|
-
const body = [
|
|
57
|
-
"Test: " + result.test?.name,
|
|
58
|
-
"Description: " + (result.test?.description ?? "None"),
|
|
59
|
-
"Duration: " + `${result.metrics?.executionTime ?? 0}s`,
|
|
60
|
-
"Status: " + result.status,
|
|
61
|
-
"Outcome: " + result.outcome,
|
|
62
|
-
this.formatStepsAsMarkdown(),
|
|
63
|
-
this.passed(result) ? "" : this.formatFailures(result),
|
|
64
|
-
]
|
|
65
|
-
.filter(Boolean)
|
|
66
|
-
.join("\n");
|
|
67
|
-
return `${header}\n${body}`;
|
|
68
|
-
}
|
|
69
|
-
formatMarkdownSummary(result) {
|
|
70
|
-
return [
|
|
71
|
-
`🧪 **Test Name:** ${result.test?.name ?? "Unknown"}`,
|
|
72
|
-
`📄 **Description:** ${result.test?.description ?? "None"}`,
|
|
73
|
-
`⏱ **Duration:** ${result.metrics?.executionTime ?? 0}s`,
|
|
74
|
-
`🔎 **Status:** ${result.status}`,
|
|
75
|
-
`📊 **Outcome:** ${result.outcome}`,
|
|
76
|
-
this.formatStepsAsMarkdown(),
|
|
77
|
-
this.formatFailures(result),
|
|
78
|
-
]
|
|
79
|
-
.filter(Boolean)
|
|
80
|
-
.join("\n")
|
|
81
|
-
.trim();
|
|
82
|
-
}
|
|
83
|
-
/*
|
|
84
|
-
Terminal uses different formatting than markdown.
|
|
85
|
-
*/
|
|
86
|
-
terminalSummary(result) {
|
|
87
|
-
return [
|
|
88
|
-
`🧪 Test Name: ${result.test?.name ?? "Unknown"}`,
|
|
89
|
-
`📄 Description: ${result.test?.description ?? "None"}`,
|
|
90
|
-
`⏱ Duration: ${result.metrics?.executionTime ?? 0}s`,
|
|
91
|
-
`🔎 Status: ${result.status}`,
|
|
92
|
-
`📊 Outcome: ${result.outcome}`,
|
|
93
|
-
this.formatFailures(result),
|
|
94
|
-
]
|
|
95
|
-
.filter(Boolean)
|
|
96
|
-
.join("\r\n")
|
|
97
|
-
.trim();
|
|
98
|
-
}
|
|
99
|
-
appendToTestRun(result) {
|
|
100
|
-
console.error(this.terminalSummary(result));
|
|
101
|
-
}
|
|
102
|
-
}
|