browsertrack 0.0.1 → 0.1.0
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/README.md +143 -0
- package/dist/chunk-6A7FFDIB.js +221 -0
- package/dist/chunk-6A7FFDIB.js.map +1 -0
- package/dist/chunk-ANMR5WBH.js +659 -0
- package/dist/chunk-ANMR5WBH.js.map +1 -0
- package/dist/chunk-BSKNG4V7.js +1199 -0
- package/dist/chunk-BSKNG4V7.js.map +1 -0
- package/dist/chunk-X7C5CHBO.js +2080 -0
- package/dist/chunk-X7C5CHBO.js.map +1 -0
- package/dist/chunk-ZLNGOOH2.js +554 -0
- package/dist/chunk-ZLNGOOH2.js.map +1 -0
- package/dist/cli/index.js +2829 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/client/index.cjs +2218 -0
- package/dist/client/index.d.ts +197 -0
- package/dist/client/index.js +20 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client.iife.js +309 -0
- package/dist/core/index.d.ts +78 -0
- package/dist/core/index.js +31 -0
- package/dist/core/index.js.map +1 -0
- package/dist/daemon/index.d.ts +58 -0
- package/dist/daemon/index.js +32 -0
- package/dist/daemon/index.js.map +1 -0
- package/dist/engine-DKloFjvs.d.ts +157 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +50 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/index.d.ts +11 -0
- package/dist/mcp/index.js +12 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/notes-CBvN91Wf.d.ts +260 -0
- package/dist/projects-CY8ungMt.d.ts +99 -0
- package/dist/server-CN-se8td.d.ts +55 -0
- package/examples/test-app/index.html +299 -0
- package/package.json +52 -7
- package/packages/cli/src/index.ts +413 -0
- package/packages/client/package.json +28 -0
- package/packages/client/src/breadcrumbs.ts +30 -0
- package/packages/client/src/client.ts +278 -0
- package/packages/client/src/commands/handler.ts +301 -0
- package/packages/client/src/config.ts +37 -0
- package/packages/client/src/index.ts +50 -0
- package/packages/client/src/interceptors/console.ts +68 -0
- package/packages/client/src/interceptors/interaction.ts +119 -0
- package/packages/client/src/interceptors/navigation.ts +93 -0
- package/packages/client/src/interceptors/network.ts +165 -0
- package/packages/client/src/interceptors/runtime.ts +65 -0
- package/packages/client/src/notes/inspector.ts +943 -0
- package/packages/client/src/screenshot/browser-script-driver.ts +192 -0
- package/packages/client/src/screenshot/driver.ts +14 -0
- package/packages/client/src/transport/websocket.ts +179 -0
- package/packages/client/tsconfig.json +8 -0
- package/packages/core/dist/index.d.ts +317 -0
- package/packages/core/dist/index.js +221 -0
- package/packages/core/package.json +23 -0
- package/packages/core/src/fingerprint.ts +120 -0
- package/packages/core/src/index.ts +9 -0
- package/packages/core/src/redaction.ts +139 -0
- package/packages/core/src/selector.ts +77 -0
- package/packages/core/src/types/commands.ts +101 -0
- package/packages/core/src/types/events.ts +108 -0
- package/packages/core/src/types/incidents.ts +54 -0
- package/packages/core/src/types/notes.ts +106 -0
- package/packages/core/src/types/probes.ts +44 -0
- package/packages/core/src/types/projects.ts +20 -0
- package/packages/core/tsconfig.json +8 -0
- package/packages/daemon/src/config.ts +29 -0
- package/packages/daemon/src/incidents/engine.ts +211 -0
- package/packages/daemon/src/index.ts +18 -0
- package/packages/daemon/src/notes/engine.ts +92 -0
- package/packages/daemon/src/notes/verification.ts +191 -0
- package/packages/daemon/src/server/daemon.ts +112 -0
- package/packages/daemon/src/server/http.ts +165 -0
- package/packages/daemon/src/server/ws.ts +175 -0
- package/packages/daemon/src/session/manager.ts +126 -0
- package/packages/daemon/src/storage/db.ts +733 -0
- package/packages/daemon/src/storage/screenshot-store.ts +49 -0
- package/packages/daemon/src/verification/engine.ts +264 -0
- package/packages/mcp/src/handlers.ts +398 -0
- package/packages/mcp/src/index.ts +3 -0
- package/packages/mcp/src/server.ts +86 -0
- package/packages/mcp/src/tools.ts +236 -0
- package/src/index.ts +4 -0
- package/test/client/interceptors.test.ts +69 -0
- package/test/core/fingerprint.test.ts +53 -0
- package/test/core/notes.test.ts +66 -0
- package/test/core/redaction.test.ts +48 -0
- package/test/daemon/incident-engine.test.ts +98 -0
- package/test/daemon/notes-storage.test.ts +130 -0
- package/test/daemon/notes-verification.test.ts +135 -0
- package/test/daemon/storage.test.ts +123 -0
- package/test/daemon/verification-engine.test.ts +88 -0
- package/test/e2e/daemon-mcp-e2e.test.ts +153 -0
- package/test/e2e/visual-notes-e2e.test.ts +205 -0
- package/test/mcp/handlers.test.ts +116 -0
- package/test/mcp/notes.test.ts +107 -0
- package/tsconfig.base.json +17 -0
- package/tsconfig.json +26 -0
- package/tsup.config.ts +54 -0
- package/vitest.config.ts +9 -0
|
@@ -0,0 +1,659 @@
|
|
|
1
|
+
import {
|
|
2
|
+
NoteVerificationEngine,
|
|
3
|
+
NotesEngine,
|
|
4
|
+
ScreenshotStore,
|
|
5
|
+
SessionManager,
|
|
6
|
+
StorageDB,
|
|
7
|
+
VerificationEngine,
|
|
8
|
+
getDaemonConfig
|
|
9
|
+
} from "./chunk-BSKNG4V7.js";
|
|
10
|
+
|
|
11
|
+
// packages/mcp/src/tools.ts
|
|
12
|
+
var TOOLS = [
|
|
13
|
+
{
|
|
14
|
+
name: "list_projects",
|
|
15
|
+
description: "List all registered projects tracked by BrowserTrack/BrowserDiag",
|
|
16
|
+
inputSchema: {
|
|
17
|
+
type: "object",
|
|
18
|
+
properties: {}
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
name: "list_sessions",
|
|
23
|
+
description: "List active and recent browser sessions connected to the local development daemon",
|
|
24
|
+
inputSchema: {
|
|
25
|
+
type: "object",
|
|
26
|
+
properties: {
|
|
27
|
+
projectId: { type: "string", description: "Filter sessions by project ID or name" },
|
|
28
|
+
activeOnly: { type: "boolean", description: "Show only currently active WebSocket sessions (default: true)" }
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
name: "list_incidents",
|
|
34
|
+
description: "List recorded browser runtime errors, unhandled rejections, and console errors grouped into incidents",
|
|
35
|
+
inputSchema: {
|
|
36
|
+
type: "object",
|
|
37
|
+
properties: {
|
|
38
|
+
projectId: { type: "string", description: "Filter by project ID or name" },
|
|
39
|
+
status: {
|
|
40
|
+
type: "string",
|
|
41
|
+
enum: ["OPEN", "FIX_ATTEMPTED", "VERIFYING", "VERIFIED", "FAILED", "INCONCLUSIVE"],
|
|
42
|
+
description: "Filter by incident status"
|
|
43
|
+
},
|
|
44
|
+
severity: {
|
|
45
|
+
type: "string",
|
|
46
|
+
enum: ["error", "warn", "fatal"],
|
|
47
|
+
description: "Filter by severity"
|
|
48
|
+
},
|
|
49
|
+
limit: { type: "number", description: "Maximum number of incidents to return (default: 20)" }
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
name: "get_incident",
|
|
55
|
+
description: "Retrieve compact and high-signal debugging context for a specific error incident (stack trace, breadcrumbs, network failures, last interacted element, error screenshot)",
|
|
56
|
+
inputSchema: {
|
|
57
|
+
type: "object",
|
|
58
|
+
properties: {
|
|
59
|
+
incidentId: { type: "string", description: "The unique ID of the incident (e.g. inc_42)" }
|
|
60
|
+
},
|
|
61
|
+
required: ["incidentId"]
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: "get_console",
|
|
66
|
+
description: "Get recent console logs, warnings, and errors from a browser session",
|
|
67
|
+
inputSchema: {
|
|
68
|
+
type: "object",
|
|
69
|
+
properties: {
|
|
70
|
+
sessionId: { type: "string", description: "Browser session ID (optional, defaults to active session)" },
|
|
71
|
+
limit: { type: "number", description: "Number of console logs to retrieve (default: 30)" }
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: "get_network_failures",
|
|
77
|
+
description: "Get recent failed HTTP network requests (4xx, 5xx, network errors, timeouts, aborts)",
|
|
78
|
+
inputSchema: {
|
|
79
|
+
type: "object",
|
|
80
|
+
properties: {
|
|
81
|
+
sessionId: { type: "string", description: "Browser session ID (optional)" },
|
|
82
|
+
limit: { type: "number", description: "Maximum number of failed requests to return (default: 20)" }
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: "get_breadcrumbs",
|
|
88
|
+
description: "Get the sequence of recent user interactions, navigations, console logs, and network events prior to an error",
|
|
89
|
+
inputSchema: {
|
|
90
|
+
type: "object",
|
|
91
|
+
properties: {
|
|
92
|
+
sessionId: { type: "string", description: "Browser session ID (optional)" },
|
|
93
|
+
incidentId: { type: "string", description: "Incident ID to fetch breadcrumbs from (optional)" },
|
|
94
|
+
limit: { type: "number", description: "Maximum number of breadcrumbs (default: 50)" }
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
name: "get_page_state",
|
|
100
|
+
description: "Query the live page state (URL, route, document title, readyState, active element) from the connected browser session",
|
|
101
|
+
inputSchema: {
|
|
102
|
+
type: "object",
|
|
103
|
+
properties: {
|
|
104
|
+
sessionId: { type: "string", description: "Target session ID (optional, defaults to active)" }
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: "capture_element",
|
|
110
|
+
description: "Capture a screenshot of a specific DOM element or the entire visible page in the active browser tab",
|
|
111
|
+
inputSchema: {
|
|
112
|
+
type: "object",
|
|
113
|
+
properties: {
|
|
114
|
+
selector: { type: "string", description: 'CSS selector of the element to capture (e.g. [data-testid="user-card"])' },
|
|
115
|
+
sessionId: { type: "string", description: "Browser session ID (optional)" }
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
name: "verify_incident",
|
|
121
|
+
description: "Trigger closed-loop verification of a bug fix: reloads the browser, checks if the incident reoccurs, evaluates optional verification probes, and records before/after screenshots",
|
|
122
|
+
inputSchema: {
|
|
123
|
+
type: "object",
|
|
124
|
+
properties: {
|
|
125
|
+
incidentId: { type: "string", description: "The ID of the incident to verify" },
|
|
126
|
+
route: { type: "string", description: "Optional route to navigate to for verification (defaults to incident route)" },
|
|
127
|
+
targetSelector: { type: "string", description: "Optional element selector to inspect and capture after-fix screenshot" },
|
|
128
|
+
expect: {
|
|
129
|
+
type: "array",
|
|
130
|
+
description: "Optional verification probes to evaluate after reload",
|
|
131
|
+
items: {
|
|
132
|
+
type: "object",
|
|
133
|
+
properties: {
|
|
134
|
+
type: {
|
|
135
|
+
type: "string",
|
|
136
|
+
enum: ["element_exists", "element_visible", "text_contains", "route_is", "no_incident"]
|
|
137
|
+
},
|
|
138
|
+
selector: { type: "string" },
|
|
139
|
+
text: { type: "string" },
|
|
140
|
+
route: { type: "string" }
|
|
141
|
+
},
|
|
142
|
+
required: ["type"]
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
observationWindowMs: { type: "number", description: "Observation window in milliseconds (default: 2000)" }
|
|
146
|
+
},
|
|
147
|
+
required: ["incidentId"]
|
|
148
|
+
}
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
name: "get_verification",
|
|
152
|
+
description: "Retrieve the latest verification result and before/after screenshot artifacts for an incident",
|
|
153
|
+
inputSchema: {
|
|
154
|
+
type: "object",
|
|
155
|
+
properties: {
|
|
156
|
+
incidentId: { type: "string", description: "The ID of the incident" }
|
|
157
|
+
},
|
|
158
|
+
required: ["incidentId"]
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
name: "list_notes",
|
|
163
|
+
description: "List visual development notes / screen annotations left on elements, regions, or pages during development",
|
|
164
|
+
inputSchema: {
|
|
165
|
+
type: "object",
|
|
166
|
+
properties: {
|
|
167
|
+
projectId: { type: "string", description: "Filter notes by project ID or name" },
|
|
168
|
+
status: {
|
|
169
|
+
type: "string",
|
|
170
|
+
enum: ["OPEN", "IN_PROGRESS", "VERIFYING", "RESOLVED", "FAILED", "INCONCLUSIVE"],
|
|
171
|
+
description: "Filter by note status (default: OPEN)"
|
|
172
|
+
},
|
|
173
|
+
limit: { type: "number", description: "Maximum number of notes to return (default: 20)" }
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
name: "get_note",
|
|
179
|
+
description: "Retrieve full debugging context for a visual note (message, route, viewport dimensions, target element selector, DOM context, screenshot file path, project path)",
|
|
180
|
+
inputSchema: {
|
|
181
|
+
type: "object",
|
|
182
|
+
properties: {
|
|
183
|
+
noteId: { type: "string", description: "The unique ID of the visual note (e.g. note_42)" }
|
|
184
|
+
},
|
|
185
|
+
required: ["noteId"]
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
name: "resolve_note",
|
|
190
|
+
description: "Mark a visual note as RESOLVED once the layout or styling issue has been fixed",
|
|
191
|
+
inputSchema: {
|
|
192
|
+
type: "object",
|
|
193
|
+
properties: {
|
|
194
|
+
noteId: { type: "string", description: "The ID of the visual note to resolve" }
|
|
195
|
+
},
|
|
196
|
+
required: ["noteId"]
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
name: "reopen_note",
|
|
201
|
+
description: "Reopen a previously resolved visual note",
|
|
202
|
+
inputSchema: {
|
|
203
|
+
type: "object",
|
|
204
|
+
properties: {
|
|
205
|
+
noteId: { type: "string", description: "The ID of the visual note to reopen" }
|
|
206
|
+
},
|
|
207
|
+
required: ["noteId"]
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
name: "verify_note",
|
|
212
|
+
description: "Run closed-loop layout & visual verification for a note: checks route, element existence/visibility, evaluates viewport overflow probes, captures after-screenshot, and computes geometry diff",
|
|
213
|
+
inputSchema: {
|
|
214
|
+
type: "object",
|
|
215
|
+
properties: {
|
|
216
|
+
noteId: { type: "string", description: "The ID of the visual note to verify" },
|
|
217
|
+
observationWindowMs: { type: "number", description: "Observation window in milliseconds (default: 1000)" }
|
|
218
|
+
},
|
|
219
|
+
required: ["noteId"]
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
name: "get_note_verification",
|
|
224
|
+
description: "Retrieve the latest verification result, before/after screenshot references, and layout geometry diff for a visual note",
|
|
225
|
+
inputSchema: {
|
|
226
|
+
type: "object",
|
|
227
|
+
properties: {
|
|
228
|
+
noteId: { type: "string", description: "The ID of the visual note" }
|
|
229
|
+
},
|
|
230
|
+
required: ["noteId"]
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
name: "capture_note_context",
|
|
235
|
+
description: "Inspect live DOM context, bounding box, overflow, and styles for a target element in the active browser tab",
|
|
236
|
+
inputSchema: {
|
|
237
|
+
type: "object",
|
|
238
|
+
properties: {
|
|
239
|
+
selector: { type: "string", description: "CSS selector of the target element" },
|
|
240
|
+
sessionId: { type: "string", description: "Browser session ID (optional)" }
|
|
241
|
+
},
|
|
242
|
+
required: ["selector"]
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
];
|
|
246
|
+
|
|
247
|
+
// packages/mcp/src/handlers.ts
|
|
248
|
+
async function handleToolCall(name, args, ctx) {
|
|
249
|
+
const { db, sessionManager, verificationEngine, noteVerificationEngine } = ctx;
|
|
250
|
+
switch (name) {
|
|
251
|
+
case "list_projects": {
|
|
252
|
+
const projects = db.listProjects();
|
|
253
|
+
return {
|
|
254
|
+
projects: projects.map((p) => ({
|
|
255
|
+
id: p.id,
|
|
256
|
+
name: p.name,
|
|
257
|
+
origin: p.origin,
|
|
258
|
+
path: p.path,
|
|
259
|
+
updatedAt: p.updatedAt
|
|
260
|
+
}))
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
case "list_sessions": {
|
|
264
|
+
const activeOnly = args.activeOnly !== false;
|
|
265
|
+
const sessions = db.listSessions(args.projectId, activeOnly);
|
|
266
|
+
return {
|
|
267
|
+
count: sessions.length,
|
|
268
|
+
sessions: sessions.map((s) => ({
|
|
269
|
+
id: s.id,
|
|
270
|
+
projectId: s.projectId,
|
|
271
|
+
origin: s.origin,
|
|
272
|
+
url: s.url,
|
|
273
|
+
title: s.title,
|
|
274
|
+
active: s.active,
|
|
275
|
+
lastSeenAt: s.lastSeenAt
|
|
276
|
+
}))
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
case "list_incidents": {
|
|
280
|
+
const incidents = db.listIncidents({
|
|
281
|
+
projectId: args.projectId,
|
|
282
|
+
status: args.status,
|
|
283
|
+
severity: args.severity,
|
|
284
|
+
limit: args.limit || 20
|
|
285
|
+
});
|
|
286
|
+
return {
|
|
287
|
+
total: incidents.length,
|
|
288
|
+
incidents: incidents.map((inc) => ({
|
|
289
|
+
id: inc.id,
|
|
290
|
+
type: inc.type,
|
|
291
|
+
severity: inc.severity,
|
|
292
|
+
message: inc.message,
|
|
293
|
+
source: `${inc.source.file}:${inc.source.line}`,
|
|
294
|
+
route: inc.route,
|
|
295
|
+
status: inc.status,
|
|
296
|
+
occurrences: inc.occurrences,
|
|
297
|
+
firstSeen: inc.firstSeen,
|
|
298
|
+
lastSeen: inc.lastSeen
|
|
299
|
+
}))
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
case "get_incident": {
|
|
303
|
+
const incident = db.getIncident(args.incidentId);
|
|
304
|
+
if (!incident) {
|
|
305
|
+
throw new Error(`Incident '${args.incidentId}' not found.`);
|
|
306
|
+
}
|
|
307
|
+
const breadcrumbsTimeline = incident.breadcrumbs.slice(-15).map((b) => {
|
|
308
|
+
const time = new Date(b.timestamp).toISOString().split("T")[1]?.slice(0, 8);
|
|
309
|
+
return `[${time}] ${b.message}`;
|
|
310
|
+
});
|
|
311
|
+
return {
|
|
312
|
+
id: incident.id,
|
|
313
|
+
status: incident.status,
|
|
314
|
+
type: incident.type,
|
|
315
|
+
severity: incident.severity,
|
|
316
|
+
message: incident.message,
|
|
317
|
+
source: {
|
|
318
|
+
file: incident.source.file,
|
|
319
|
+
line: incident.source.line,
|
|
320
|
+
column: incident.source.column
|
|
321
|
+
},
|
|
322
|
+
route: incident.route,
|
|
323
|
+
occurrences: incident.occurrences,
|
|
324
|
+
firstSeen: incident.firstSeen,
|
|
325
|
+
lastSeen: incident.lastSeen,
|
|
326
|
+
stack: incident.stack,
|
|
327
|
+
lastInteractedElement: incident.lastElement ? {
|
|
328
|
+
selector: incident.lastElement.selector,
|
|
329
|
+
tag: incident.lastElement.tag,
|
|
330
|
+
visible: incident.lastElement.visible,
|
|
331
|
+
innerText: incident.lastElement.innerText,
|
|
332
|
+
outerHTML: incident.lastElement.outerHTML
|
|
333
|
+
} : void 0,
|
|
334
|
+
recentBreadcrumbs: breadcrumbsTimeline,
|
|
335
|
+
networkFailures: incident.networkFailures,
|
|
336
|
+
screenshot: incident.screenshots?.error
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
case "get_console": {
|
|
340
|
+
const limit = args.limit || 30;
|
|
341
|
+
const events = db.getEvents({
|
|
342
|
+
sessionId: args.sessionId,
|
|
343
|
+
eventType: "console",
|
|
344
|
+
limit
|
|
345
|
+
});
|
|
346
|
+
return {
|
|
347
|
+
logs: events.map((e) => ({
|
|
348
|
+
level: e.payload.level,
|
|
349
|
+
message: e.payload.message,
|
|
350
|
+
timestamp: new Date(e.timestamp).toISOString(),
|
|
351
|
+
route: e.route
|
|
352
|
+
}))
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
case "get_network_failures": {
|
|
356
|
+
const limit = args.limit || 20;
|
|
357
|
+
const events = db.getEvents({
|
|
358
|
+
sessionId: args.sessionId,
|
|
359
|
+
limit: 100
|
|
360
|
+
});
|
|
361
|
+
const failures = events.filter((e) => (e.eventType === "fetch" || e.eventType === "xhr") && (e.payload.status >= 400 || e.payload.error)).slice(0, limit).map((e) => ({
|
|
362
|
+
url: e.payload.url,
|
|
363
|
+
method: e.payload.method,
|
|
364
|
+
status: e.payload.status,
|
|
365
|
+
error: e.payload.error,
|
|
366
|
+
durationMs: e.payload.durationMs,
|
|
367
|
+
timestamp: new Date(e.timestamp).toISOString()
|
|
368
|
+
}));
|
|
369
|
+
return { failures };
|
|
370
|
+
}
|
|
371
|
+
case "get_breadcrumbs": {
|
|
372
|
+
if (args.incidentId) {
|
|
373
|
+
const incident = db.getIncident(args.incidentId);
|
|
374
|
+
if (!incident) {
|
|
375
|
+
throw new Error(`Incident '${args.incidentId}' not found.`);
|
|
376
|
+
}
|
|
377
|
+
return {
|
|
378
|
+
incidentId: args.incidentId,
|
|
379
|
+
breadcrumbs: incident.breadcrumbs.slice(-(args.limit || 50))
|
|
380
|
+
};
|
|
381
|
+
}
|
|
382
|
+
const events = db.getEvents({
|
|
383
|
+
sessionId: args.sessionId,
|
|
384
|
+
limit: args.limit || 50
|
|
385
|
+
});
|
|
386
|
+
return {
|
|
387
|
+
breadcrumbs: events.map((e) => ({
|
|
388
|
+
type: e.eventType,
|
|
389
|
+
message: e.payload.message || `${e.eventType} on ${e.route}`,
|
|
390
|
+
timestamp: new Date(e.timestamp).toISOString(),
|
|
391
|
+
route: e.route
|
|
392
|
+
}))
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
case "get_page_state": {
|
|
396
|
+
if (!sessionManager) {
|
|
397
|
+
throw new Error("Live browser connection not available: Daemon session manager not attached.");
|
|
398
|
+
}
|
|
399
|
+
let session = args.sessionId ? db.getSession(args.sessionId) : sessionManager.getAnyActiveSession();
|
|
400
|
+
if (!session) {
|
|
401
|
+
throw new Error("No active browser session connected.");
|
|
402
|
+
}
|
|
403
|
+
const cmdRes = await sessionManager.sendCommand(session.id, {
|
|
404
|
+
id: `cmd_mcp_${Date.now()}`,
|
|
405
|
+
type: "get_page_state"
|
|
406
|
+
});
|
|
407
|
+
if (!cmdRes.ok) {
|
|
408
|
+
throw new Error(cmdRes.error || "Failed to retrieve page state from browser.");
|
|
409
|
+
}
|
|
410
|
+
return cmdRes.result;
|
|
411
|
+
}
|
|
412
|
+
case "capture_element": {
|
|
413
|
+
if (!sessionManager) {
|
|
414
|
+
throw new Error("Live browser connection not available: Daemon session manager not attached.");
|
|
415
|
+
}
|
|
416
|
+
let session = args.sessionId ? db.getSession(args.sessionId) : sessionManager.getAnyActiveSession();
|
|
417
|
+
if (!session) {
|
|
418
|
+
throw new Error("No active browser session connected.");
|
|
419
|
+
}
|
|
420
|
+
const cmdRes = await sessionManager.sendCommand(session.id, {
|
|
421
|
+
id: `cmd_mcp_${Date.now()}`,
|
|
422
|
+
type: "capture_element",
|
|
423
|
+
params: { selector: args.selector }
|
|
424
|
+
});
|
|
425
|
+
if (!cmdRes.ok) {
|
|
426
|
+
throw new Error(cmdRes.error || cmdRes.reason || "Failed to capture element screenshot.");
|
|
427
|
+
}
|
|
428
|
+
return {
|
|
429
|
+
ok: true,
|
|
430
|
+
format: cmdRes.result?.format || "webp",
|
|
431
|
+
width: cmdRes.result?.width,
|
|
432
|
+
height: cmdRes.result?.height,
|
|
433
|
+
dataUrlPreview: cmdRes.result?.dataUrl ? `${cmdRes.result.dataUrl.slice(0, 100)}...` : void 0
|
|
434
|
+
};
|
|
435
|
+
}
|
|
436
|
+
case "verify_incident": {
|
|
437
|
+
if (!verificationEngine) {
|
|
438
|
+
throw new Error("Verification engine not available: Daemon session manager not attached.");
|
|
439
|
+
}
|
|
440
|
+
const res = await verificationEngine.verifyIncident(args.incidentId, {
|
|
441
|
+
route: args.route,
|
|
442
|
+
targetSelector: args.targetSelector,
|
|
443
|
+
expect: args.expect,
|
|
444
|
+
observationWindowMs: args.observationWindowMs
|
|
445
|
+
});
|
|
446
|
+
return res;
|
|
447
|
+
}
|
|
448
|
+
case "get_verification": {
|
|
449
|
+
const v = db.getLatestVerification(args.incidentId);
|
|
450
|
+
if (!v) {
|
|
451
|
+
throw new Error(`No verification records found for incident '${args.incidentId}'.`);
|
|
452
|
+
}
|
|
453
|
+
return v;
|
|
454
|
+
}
|
|
455
|
+
case "list_notes": {
|
|
456
|
+
const notes = db.listNotes({
|
|
457
|
+
projectId: args.projectId,
|
|
458
|
+
status: args.status,
|
|
459
|
+
limit: args.limit || 20
|
|
460
|
+
});
|
|
461
|
+
return {
|
|
462
|
+
total: notes.length,
|
|
463
|
+
notes: notes.map((n) => ({
|
|
464
|
+
id: n.id,
|
|
465
|
+
type: n.type,
|
|
466
|
+
status: n.status,
|
|
467
|
+
route: n.route,
|
|
468
|
+
viewport: `${n.viewport.width} \xD7 ${n.viewport.height}`,
|
|
469
|
+
target: n.target?.selector || n.type,
|
|
470
|
+
message: n.message,
|
|
471
|
+
screenshotAvailable: !!n.screenshots?.original,
|
|
472
|
+
createdAt: n.createdAt
|
|
473
|
+
}))
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
case "get_note": {
|
|
477
|
+
const note = db.getNote(args.noteId);
|
|
478
|
+
if (!note) {
|
|
479
|
+
throw new Error(`Visual note '${args.noteId}' not found.`);
|
|
480
|
+
}
|
|
481
|
+
const project = db.getProject(note.projectId);
|
|
482
|
+
return {
|
|
483
|
+
id: note.id,
|
|
484
|
+
type: note.type,
|
|
485
|
+
status: note.status,
|
|
486
|
+
message: note.message,
|
|
487
|
+
route: note.route,
|
|
488
|
+
url: note.url,
|
|
489
|
+
viewport: note.viewport,
|
|
490
|
+
scroll: note.scroll,
|
|
491
|
+
target: note.target,
|
|
492
|
+
elementContext: note.elementContext,
|
|
493
|
+
region: note.region,
|
|
494
|
+
screenshot: {
|
|
495
|
+
available: !!note.screenshots?.original,
|
|
496
|
+
original: note.screenshots?.original,
|
|
497
|
+
after: note.screenshots?.after
|
|
498
|
+
},
|
|
499
|
+
project: project ? {
|
|
500
|
+
id: project.id,
|
|
501
|
+
name: project.name,
|
|
502
|
+
origin: project.origin,
|
|
503
|
+
path: project.path
|
|
504
|
+
} : void 0,
|
|
505
|
+
relatedIncidentId: note.incidentId,
|
|
506
|
+
createdAt: note.createdAt,
|
|
507
|
+
updatedAt: note.updatedAt,
|
|
508
|
+
resolvedAt: note.resolvedAt
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
case "resolve_note": {
|
|
512
|
+
const note = db.getNote(args.noteId);
|
|
513
|
+
if (!note) {
|
|
514
|
+
throw new Error(`Visual note '${args.noteId}' not found.`);
|
|
515
|
+
}
|
|
516
|
+
db.updateNoteStatus(args.noteId, "RESOLVED");
|
|
517
|
+
return {
|
|
518
|
+
ok: true,
|
|
519
|
+
noteId: args.noteId,
|
|
520
|
+
status: "RESOLVED",
|
|
521
|
+
resolvedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
case "reopen_note": {
|
|
525
|
+
const note = db.getNote(args.noteId);
|
|
526
|
+
if (!note) {
|
|
527
|
+
throw new Error(`Visual note '${args.noteId}' not found.`);
|
|
528
|
+
}
|
|
529
|
+
db.updateNoteStatus(args.noteId, "OPEN");
|
|
530
|
+
return {
|
|
531
|
+
ok: true,
|
|
532
|
+
noteId: args.noteId,
|
|
533
|
+
status: "OPEN"
|
|
534
|
+
};
|
|
535
|
+
}
|
|
536
|
+
case "verify_note": {
|
|
537
|
+
if (!noteVerificationEngine) {
|
|
538
|
+
throw new Error("Note verification engine not available: Daemon session manager not attached.");
|
|
539
|
+
}
|
|
540
|
+
const res = await noteVerificationEngine.verifyNote(args.noteId, {
|
|
541
|
+
observationWindowMs: args.observationWindowMs
|
|
542
|
+
});
|
|
543
|
+
return res;
|
|
544
|
+
}
|
|
545
|
+
case "get_note_verification": {
|
|
546
|
+
const v = db.getLatestNoteVerification(args.noteId);
|
|
547
|
+
if (!v) {
|
|
548
|
+
throw new Error(`No verification records found for visual note '${args.noteId}'.`);
|
|
549
|
+
}
|
|
550
|
+
return v;
|
|
551
|
+
}
|
|
552
|
+
case "capture_note_context": {
|
|
553
|
+
if (!sessionManager) {
|
|
554
|
+
throw new Error("Live browser connection not available: Daemon session manager not attached.");
|
|
555
|
+
}
|
|
556
|
+
let session = args.sessionId ? db.getSession(args.sessionId) : sessionManager.getAnyActiveSession();
|
|
557
|
+
if (!session) {
|
|
558
|
+
throw new Error("No active browser session connected.");
|
|
559
|
+
}
|
|
560
|
+
const queryCmd = await sessionManager.sendCommand(session.id, {
|
|
561
|
+
id: `cmd_ctx_${Date.now()}`,
|
|
562
|
+
type: "query_element",
|
|
563
|
+
params: { selector: args.selector }
|
|
564
|
+
});
|
|
565
|
+
const overflowCmd = await sessionManager.sendCommand(session.id, {
|
|
566
|
+
id: `cmd_ovf_${Date.now()}`,
|
|
567
|
+
type: "check_overflow",
|
|
568
|
+
params: { selector: args.selector }
|
|
569
|
+
});
|
|
570
|
+
const styleCmd = await sessionManager.sendCommand(session.id, {
|
|
571
|
+
id: `cmd_sty_${Date.now()}`,
|
|
572
|
+
type: "get_element_style",
|
|
573
|
+
params: { selector: args.selector }
|
|
574
|
+
});
|
|
575
|
+
return {
|
|
576
|
+
selector: args.selector,
|
|
577
|
+
element: queryCmd.result,
|
|
578
|
+
overflow: overflowCmd.result,
|
|
579
|
+
styles: styleCmd.result?.styles
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
default:
|
|
583
|
+
throw new Error(`Unknown MCP tool: ${name}`);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
// packages/mcp/src/server.ts
|
|
588
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
589
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
590
|
+
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
591
|
+
function createMcpServer(options = {}) {
|
|
592
|
+
const config = getDaemonConfig({ dbPath: options.dbPath });
|
|
593
|
+
const db = options.context?.db || new StorageDB(config.dbPath);
|
|
594
|
+
const screenshotStore = new ScreenshotStore(config.screenshotsDir);
|
|
595
|
+
const sessionManager = options.context?.sessionManager || new SessionManager(db);
|
|
596
|
+
const verificationEngine = options.context?.verificationEngine || new VerificationEngine(db, sessionManager, screenshotStore);
|
|
597
|
+
const notesEngine = new NotesEngine(db, screenshotStore);
|
|
598
|
+
const noteVerificationEngine = options.context?.noteVerificationEngine || new NoteVerificationEngine(db, sessionManager, notesEngine);
|
|
599
|
+
const ctx = {
|
|
600
|
+
db,
|
|
601
|
+
sessionManager,
|
|
602
|
+
verificationEngine,
|
|
603
|
+
noteVerificationEngine,
|
|
604
|
+
daemonUrl: `http://${config.host}:${config.port}`,
|
|
605
|
+
...options.context
|
|
606
|
+
};
|
|
607
|
+
const server = new Server(
|
|
608
|
+
{
|
|
609
|
+
name: "browsertrack-mcp",
|
|
610
|
+
version: "0.1.0"
|
|
611
|
+
},
|
|
612
|
+
{
|
|
613
|
+
capabilities: {
|
|
614
|
+
tools: {}
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
);
|
|
618
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
619
|
+
return { tools: TOOLS };
|
|
620
|
+
});
|
|
621
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
622
|
+
const { name, arguments: args } = request.params;
|
|
623
|
+
try {
|
|
624
|
+
const result = await handleToolCall(name, args || {}, ctx);
|
|
625
|
+
return {
|
|
626
|
+
content: [
|
|
627
|
+
{
|
|
628
|
+
type: "text",
|
|
629
|
+
text: JSON.stringify(result, null, 2)
|
|
630
|
+
}
|
|
631
|
+
]
|
|
632
|
+
};
|
|
633
|
+
} catch (err) {
|
|
634
|
+
return {
|
|
635
|
+
isError: true,
|
|
636
|
+
content: [
|
|
637
|
+
{
|
|
638
|
+
type: "text",
|
|
639
|
+
text: `Error executing tool ${name}: ${err?.message || String(err)}`
|
|
640
|
+
}
|
|
641
|
+
]
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
});
|
|
645
|
+
return {
|
|
646
|
+
server,
|
|
647
|
+
async startStdio() {
|
|
648
|
+
const transport = new StdioServerTransport();
|
|
649
|
+
await server.connect(transport);
|
|
650
|
+
}
|
|
651
|
+
};
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
export {
|
|
655
|
+
TOOLS,
|
|
656
|
+
handleToolCall,
|
|
657
|
+
createMcpServer
|
|
658
|
+
};
|
|
659
|
+
//# sourceMappingURL=chunk-ANMR5WBH.js.map
|