mcp-web-inspector 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/LICENSE +21 -0
- package/README.md +1017 -0
- package/dist/evals/evals.d.ts +5 -0
- package/dist/evals/evals.js +41 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +62 -0
- package/dist/requestHandler.d.ts +3 -0
- package/dist/requestHandler.js +53 -0
- package/dist/toolHandler.d.ts +91 -0
- package/dist/toolHandler.js +725 -0
- package/dist/tools/api/base.d.ts +33 -0
- package/dist/tools/api/base.js +49 -0
- package/dist/tools/api/index.d.ts +2 -0
- package/dist/tools/api/index.js +3 -0
- package/dist/tools/api/requests.d.ts +47 -0
- package/dist/tools/api/requests.js +168 -0
- package/dist/tools/browser/base.d.ts +51 -0
- package/dist/tools/browser/base.js +111 -0
- package/dist/tools/browser/cleanSession.d.ts +10 -0
- package/dist/tools/browser/cleanSession.js +42 -0
- package/dist/tools/browser/comparePositions.d.ts +11 -0
- package/dist/tools/browser/comparePositions.js +149 -0
- package/dist/tools/browser/computedStyles.d.ts +11 -0
- package/dist/tools/browser/computedStyles.js +128 -0
- package/dist/tools/browser/console.d.ts +37 -0
- package/dist/tools/browser/console.js +106 -0
- package/dist/tools/browser/elementExists.d.ts +9 -0
- package/dist/tools/browser/elementExists.js +57 -0
- package/dist/tools/browser/elementInspection.d.ts +21 -0
- package/dist/tools/browser/elementInspection.js +151 -0
- package/dist/tools/browser/elementPosition.d.ts +11 -0
- package/dist/tools/browser/elementPosition.js +107 -0
- package/dist/tools/browser/elementVisibility.d.ts +12 -0
- package/dist/tools/browser/elementVisibility.js +224 -0
- package/dist/tools/browser/findByText.d.ts +13 -0
- package/dist/tools/browser/findByText.js +207 -0
- package/dist/tools/browser/getRequestDetails.d.ts +9 -0
- package/dist/tools/browser/getRequestDetails.js +137 -0
- package/dist/tools/browser/getTestIds.d.ts +12 -0
- package/dist/tools/browser/getTestIds.js +148 -0
- package/dist/tools/browser/index.d.ts +7 -0
- package/dist/tools/browser/index.js +7 -0
- package/dist/tools/browser/inspectDom.d.ts +12 -0
- package/dist/tools/browser/inspectDom.js +447 -0
- package/dist/tools/browser/interaction.d.ts +104 -0
- package/dist/tools/browser/interaction.js +259 -0
- package/dist/tools/browser/listNetworkRequests.d.ts +10 -0
- package/dist/tools/browser/listNetworkRequests.js +74 -0
- package/dist/tools/browser/measureElement.d.ts +9 -0
- package/dist/tools/browser/measureElement.js +139 -0
- package/dist/tools/browser/navigation.d.ts +38 -0
- package/dist/tools/browser/navigation.js +109 -0
- package/dist/tools/browser/output.d.ts +11 -0
- package/dist/tools/browser/output.js +29 -0
- package/dist/tools/browser/querySelectorAll.d.ts +12 -0
- package/dist/tools/browser/querySelectorAll.js +201 -0
- package/dist/tools/browser/response.d.ts +29 -0
- package/dist/tools/browser/response.js +67 -0
- package/dist/tools/browser/screenshot.d.ts +16 -0
- package/dist/tools/browser/screenshot.js +70 -0
- package/dist/tools/browser/useragent.d.ts +15 -0
- package/dist/tools/browser/useragent.js +32 -0
- package/dist/tools/browser/visiblePage.d.ts +20 -0
- package/dist/tools/browser/visiblePage.js +170 -0
- package/dist/tools/browser/waitForElement.d.ts +10 -0
- package/dist/tools/browser/waitForElement.js +38 -0
- package/dist/tools/browser/waitForNetworkIdle.d.ts +8 -0
- package/dist/tools/browser/waitForNetworkIdle.js +32 -0
- package/dist/tools/codegen/generator.d.ts +21 -0
- package/dist/tools/codegen/generator.js +158 -0
- package/dist/tools/codegen/index.d.ts +11 -0
- package/dist/tools/codegen/index.js +187 -0
- package/dist/tools/codegen/recorder.d.ts +14 -0
- package/dist/tools/codegen/recorder.js +62 -0
- package/dist/tools/codegen/types.d.ts +28 -0
- package/dist/tools/codegen/types.js +1 -0
- package/dist/tools/common/types.d.ts +17 -0
- package/dist/tools/common/types.js +20 -0
- package/dist/tools/index.d.ts +2 -0
- package/dist/tools/index.js +2 -0
- package/dist/tools.d.ts +557 -0
- package/dist/tools.js +554 -0
- package/dist/types.d.ts +16 -0
- package/dist/types.js +1 -0
- package/package.json +60 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
//evals.ts
|
|
2
|
+
import { openai } from "@ai-sdk/openai";
|
|
3
|
+
import { grade } from "mcp-evals";
|
|
4
|
+
const startCodegenSessionEval = {
|
|
5
|
+
name: 'startCodegenSession Evaluation',
|
|
6
|
+
description: 'Evaluates the start codegen session tool',
|
|
7
|
+
run: async () => {
|
|
8
|
+
const result = await grade(openai("gpt-4"), "Please start a new code generation session with an output path of /my/test/path, a testNamePrefix of MyPrefix, and comments enabled. Confirm the session was created successfully.");
|
|
9
|
+
return JSON.parse(result);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
const end_codegen_sessionEval = {
|
|
13
|
+
name: 'end_codegen_session Evaluation',
|
|
14
|
+
description: 'Evaluates the end_codegen_session tool functionality',
|
|
15
|
+
run: async () => {
|
|
16
|
+
const result = await grade(openai("gpt-4"), "Please end the code generation session with ID session123 and generate the Playwright test code");
|
|
17
|
+
return JSON.parse(result);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const get_codegen_sessionEval = {
|
|
21
|
+
name: 'get_codegen_session Tool Evaluation',
|
|
22
|
+
description: 'Evaluates the retrieval of code generation session details',
|
|
23
|
+
run: async () => {
|
|
24
|
+
const result = await grade(openai("gpt-4"), "Please retrieve the code generation session details using session ID abc123.");
|
|
25
|
+
return JSON.parse(result);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const clearCodegenSessionEval = {
|
|
29
|
+
name: 'clear_codegen_session Evaluation',
|
|
30
|
+
description: 'Evaluates the functionality of clearing a code generation session',
|
|
31
|
+
run: async () => {
|
|
32
|
+
const result = await grade(openai("gpt-4"), "Please clear the code generation session with the ID testSession_123 to verify removal.");
|
|
33
|
+
return JSON.parse(result);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
const config = {
|
|
37
|
+
model: openai("gpt-4"),
|
|
38
|
+
evals: [startCodegenSessionEval, end_codegen_sessionEval, get_codegen_sessionEval, clearCodegenSessionEval]
|
|
39
|
+
};
|
|
40
|
+
export default config;
|
|
41
|
+
export const evals = [startCodegenSessionEval, end_codegen_sessionEval, get_codegen_sessionEval, clearCodegenSessionEval];
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
import { createToolDefinitions } from "./tools.js";
|
|
5
|
+
import { setupRequestHandlers } from "./requestHandler.js";
|
|
6
|
+
import { parseArgs } from "node:util";
|
|
7
|
+
import { setSessionConfig } from "./toolHandler.js";
|
|
8
|
+
// Parse command line arguments
|
|
9
|
+
const { values } = parseArgs({
|
|
10
|
+
options: {
|
|
11
|
+
'no-save-session': {
|
|
12
|
+
type: 'boolean',
|
|
13
|
+
default: false,
|
|
14
|
+
},
|
|
15
|
+
'user-data-dir': {
|
|
16
|
+
type: 'string',
|
|
17
|
+
default: './.mcp-web-inspector',
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
strict: false,
|
|
21
|
+
});
|
|
22
|
+
// Configure session settings (session saving is enabled by default)
|
|
23
|
+
const baseDir = String(values['user-data-dir'] || './.mcp-web-inspector');
|
|
24
|
+
const sessionConfig = {
|
|
25
|
+
saveSession: !Boolean(values['no-save-session']),
|
|
26
|
+
userDataDir: `${baseDir}/user-data`,
|
|
27
|
+
screenshotsDir: `${baseDir}/screenshots`,
|
|
28
|
+
};
|
|
29
|
+
setSessionConfig(sessionConfig);
|
|
30
|
+
async function runServer() {
|
|
31
|
+
const server = new Server({
|
|
32
|
+
name: "mcp-web-inspector",
|
|
33
|
+
version: "0.1.0",
|
|
34
|
+
}, {
|
|
35
|
+
capabilities: {
|
|
36
|
+
resources: {},
|
|
37
|
+
tools: {},
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
// Create tool definitions with session config
|
|
41
|
+
const TOOLS = createToolDefinitions(sessionConfig);
|
|
42
|
+
// Setup request handlers
|
|
43
|
+
setupRequestHandlers(server, TOOLS);
|
|
44
|
+
// Graceful shutdown logic
|
|
45
|
+
function shutdown() {
|
|
46
|
+
console.log('Shutdown signal received');
|
|
47
|
+
process.exit(0);
|
|
48
|
+
}
|
|
49
|
+
process.on('SIGINT', shutdown);
|
|
50
|
+
process.on('SIGTERM', shutdown);
|
|
51
|
+
process.on('exit', shutdown);
|
|
52
|
+
process.on('uncaughtException', (err) => {
|
|
53
|
+
console.error('Uncaught Exception:', err);
|
|
54
|
+
});
|
|
55
|
+
// Create transport and connect
|
|
56
|
+
const transport = new StdioServerTransport();
|
|
57
|
+
await server.connect(transport);
|
|
58
|
+
}
|
|
59
|
+
runServer().catch((error) => {
|
|
60
|
+
console.error("Fatal error in main():", error);
|
|
61
|
+
process.exit(1);
|
|
62
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { ListResourcesRequestSchema, ReadResourceRequestSchema, ListToolsRequestSchema, CallToolRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
+
import { handleToolCall, getConsoleLogs, getScreenshots } from "./toolHandler.js";
|
|
3
|
+
export function setupRequestHandlers(server, tools) {
|
|
4
|
+
// List resources handler
|
|
5
|
+
server.setRequestHandler(ListResourcesRequestSchema, async () => ({
|
|
6
|
+
resources: [
|
|
7
|
+
{
|
|
8
|
+
uri: "console://logs",
|
|
9
|
+
mimeType: "text/plain",
|
|
10
|
+
name: "Browser console logs",
|
|
11
|
+
},
|
|
12
|
+
...Array.from(getScreenshots().keys()).map(name => ({
|
|
13
|
+
uri: `screenshot://${name}`,
|
|
14
|
+
mimeType: "image/png",
|
|
15
|
+
name: `Screenshot: ${name}`,
|
|
16
|
+
})),
|
|
17
|
+
],
|
|
18
|
+
}));
|
|
19
|
+
// Read resource handler
|
|
20
|
+
server.setRequestHandler(ReadResourceRequestSchema, async (request) => {
|
|
21
|
+
const uri = request.params.uri.toString();
|
|
22
|
+
if (uri === "console://logs") {
|
|
23
|
+
const logs = getConsoleLogs().join("\n");
|
|
24
|
+
return {
|
|
25
|
+
contents: [{
|
|
26
|
+
uri,
|
|
27
|
+
mimeType: "text/plain",
|
|
28
|
+
text: logs,
|
|
29
|
+
}],
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
if (uri.startsWith("screenshot://")) {
|
|
33
|
+
const name = uri.split("://")[1];
|
|
34
|
+
const screenshot = getScreenshots().get(name);
|
|
35
|
+
if (screenshot) {
|
|
36
|
+
return {
|
|
37
|
+
contents: [{
|
|
38
|
+
uri,
|
|
39
|
+
mimeType: "image/png",
|
|
40
|
+
blob: screenshot,
|
|
41
|
+
}],
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
throw new Error(`Resource not found: ${uri}`);
|
|
46
|
+
});
|
|
47
|
+
// List tools handler
|
|
48
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
49
|
+
tools: tools,
|
|
50
|
+
}));
|
|
51
|
+
// Call tool handler
|
|
52
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => handleToolCall(request.params.name, request.params.arguments ?? {}, server));
|
|
53
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { Page } from 'playwright';
|
|
2
|
+
import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
3
|
+
export interface NetworkRequest {
|
|
4
|
+
index: number;
|
|
5
|
+
method: string;
|
|
6
|
+
url: string;
|
|
7
|
+
resourceType: string;
|
|
8
|
+
timestamp: number;
|
|
9
|
+
status?: number;
|
|
10
|
+
statusText?: string;
|
|
11
|
+
timing?: number;
|
|
12
|
+
requestData: {
|
|
13
|
+
headers: Record<string, string>;
|
|
14
|
+
postData: string | null;
|
|
15
|
+
};
|
|
16
|
+
responseData?: {
|
|
17
|
+
headers: Record<string, string>;
|
|
18
|
+
body: string | null;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
interface SessionConfig {
|
|
22
|
+
saveSession: boolean;
|
|
23
|
+
userDataDir: string;
|
|
24
|
+
screenshotsDir: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Sets the session configuration
|
|
28
|
+
*/
|
|
29
|
+
export declare function setSessionConfig(config: Partial<SessionConfig>): void;
|
|
30
|
+
/**
|
|
31
|
+
* Gets the screenshots directory
|
|
32
|
+
*/
|
|
33
|
+
export declare function getScreenshotsDir(): string;
|
|
34
|
+
/**
|
|
35
|
+
* Resets browser and page variables
|
|
36
|
+
* Used when browser is closed
|
|
37
|
+
*/
|
|
38
|
+
export declare function resetBrowserState(): void;
|
|
39
|
+
/**
|
|
40
|
+
* Gets the network log
|
|
41
|
+
*/
|
|
42
|
+
export declare function getNetworkLog(): NetworkRequest[];
|
|
43
|
+
/**
|
|
44
|
+
* Clears the network log
|
|
45
|
+
*/
|
|
46
|
+
export declare function clearNetworkLog(): void;
|
|
47
|
+
/**
|
|
48
|
+
* Sets the provided page to the global page variable
|
|
49
|
+
* @param newPage The Page object to set as the global page
|
|
50
|
+
*/
|
|
51
|
+
export declare function setGlobalPage(newPage: Page): void;
|
|
52
|
+
interface BrowserSettings {
|
|
53
|
+
viewport?: {
|
|
54
|
+
width?: number;
|
|
55
|
+
height?: number;
|
|
56
|
+
};
|
|
57
|
+
userAgent?: string;
|
|
58
|
+
headless?: boolean;
|
|
59
|
+
browserType?: 'chromium' | 'firefox' | 'webkit';
|
|
60
|
+
device?: string;
|
|
61
|
+
}
|
|
62
|
+
declare function registerConsoleMessage(page: any): Promise<void>;
|
|
63
|
+
/**
|
|
64
|
+
* Ensures a browser is launched and returns the page
|
|
65
|
+
*/
|
|
66
|
+
export declare function ensureBrowser(browserSettings?: BrowserSettings): Promise<Page>;
|
|
67
|
+
/**
|
|
68
|
+
* Main handler for tool calls
|
|
69
|
+
*/
|
|
70
|
+
export declare function handleToolCall(name: string, args: any, server: any): Promise<CallToolResult>;
|
|
71
|
+
/**
|
|
72
|
+
* Get console logs
|
|
73
|
+
*/
|
|
74
|
+
export declare function getConsoleLogs(): string[];
|
|
75
|
+
/**
|
|
76
|
+
* Get screenshots
|
|
77
|
+
*/
|
|
78
|
+
export declare function getScreenshots(): Map<string, string>;
|
|
79
|
+
/**
|
|
80
|
+
* Update last interaction timestamp
|
|
81
|
+
*/
|
|
82
|
+
export declare function updateLastInteractionTimestamp(): void;
|
|
83
|
+
/**
|
|
84
|
+
* Update last navigation timestamp
|
|
85
|
+
*/
|
|
86
|
+
export declare function updateLastNavigationTimestamp(): void;
|
|
87
|
+
/**
|
|
88
|
+
* Clear console logs
|
|
89
|
+
*/
|
|
90
|
+
export declare function clearConsoleLogs(): void;
|
|
91
|
+
export { registerConsoleMessage };
|