@n8n/mcp-browser 0.1.0-rc1
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.md +88 -0
- package/README.md +175 -0
- package/dist/adapters/playwright.d.ts +72 -0
- package/dist/adapters/playwright.js +684 -0
- package/dist/adapters/playwright.js.map +1 -0
- package/dist/browser-discovery.d.ts +12 -0
- package/dist/browser-discovery.js +219 -0
- package/dist/browser-discovery.js.map +1 -0
- package/dist/build.tsbuildinfo +1 -0
- package/dist/cdp-relay-protocol.d.ts +81 -0
- package/dist/cdp-relay-protocol.js +5 -0
- package/dist/cdp-relay-protocol.js.map +1 -0
- package/dist/cdp-relay.d.ts +52 -0
- package/dist/cdp-relay.js +508 -0
- package/dist/cdp-relay.js.map +1 -0
- package/dist/connection.d.ts +15 -0
- package/dist/connection.js +137 -0
- package/dist/connection.js.map +1 -0
- package/dist/errors.d.ts +40 -0
- package/dist/errors.js +83 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +10 -0
- package/dist/logger.js +88 -0
- package/dist/logger.js.map +1 -0
- package/dist/server-config.d.ts +7 -0
- package/dist/server-config.js +45 -0
- package/dist/server-config.js.map +1 -0
- package/dist/server.d.ts +2 -0
- package/dist/server.js +93 -0
- package/dist/server.js.map +1 -0
- package/dist/tools/helpers.d.ts +15 -0
- package/dist/tools/helpers.js +77 -0
- package/dist/tools/helpers.js.map +1 -0
- package/dist/tools/index.d.ts +2 -0
- package/dist/tools/index.js +25 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/inspection.d.ts +3 -0
- package/dist/tools/inspection.js +205 -0
- package/dist/tools/inspection.js.map +1 -0
- package/dist/tools/interaction.d.ts +3 -0
- package/dist/tools/interaction.js +211 -0
- package/dist/tools/interaction.js.map +1 -0
- package/dist/tools/navigation.d.ts +3 -0
- package/dist/tools/navigation.js +75 -0
- package/dist/tools/navigation.js.map +1 -0
- package/dist/tools/response-envelope.d.ts +13 -0
- package/dist/tools/response-envelope.js +92 -0
- package/dist/tools/response-envelope.js.map +1 -0
- package/dist/tools/schemas.d.ts +236 -0
- package/dist/tools/schemas.js +46 -0
- package/dist/tools/schemas.js.map +1 -0
- package/dist/tools/session.d.ts +3 -0
- package/dist/tools/session.js +81 -0
- package/dist/tools/session.js.map +1 -0
- package/dist/tools/state.d.ts +3 -0
- package/dist/tools/state.js +108 -0
- package/dist/tools/state.js.map +1 -0
- package/dist/tools/tabs.d.ts +3 -0
- package/dist/tools/tabs.js +121 -0
- package/dist/tools/tabs.js.map +1 -0
- package/dist/tools/wait.d.ts +3 -0
- package/dist/tools/wait.js +39 -0
- package/dist/tools/wait.js.map +1 -0
- package/dist/types.d.ts +170 -0
- package/dist/types.js +15 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +8 -0
- package/dist/utils.js +54 -0
- package/dist/utils.js.map +1 -0
- package/package.json +48 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createNavigationTools = createNavigationTools;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
const helpers_1 = require("./helpers");
|
|
7
|
+
const waitUntilField = zod_1.z
|
|
8
|
+
.enum(['load', 'domcontentloaded', 'networkidle'])
|
|
9
|
+
.optional()
|
|
10
|
+
.describe('When to consider navigation done (default: "load")');
|
|
11
|
+
function createNavigationTools(connection) {
|
|
12
|
+
return [
|
|
13
|
+
browserNavigate(connection),
|
|
14
|
+
browserBack(connection),
|
|
15
|
+
browserForward(connection),
|
|
16
|
+
browserReload(connection),
|
|
17
|
+
];
|
|
18
|
+
}
|
|
19
|
+
const browserNavigateSchema = zod_1.z.object({
|
|
20
|
+
url: zod_1.z.string().describe('Full URL to navigate to'),
|
|
21
|
+
waitUntil: waitUntilField,
|
|
22
|
+
pageId: helpers_1.pageIdField,
|
|
23
|
+
});
|
|
24
|
+
const browserNavigateOutputSchema = (0, helpers_1.withSnapshotEnvelope)({
|
|
25
|
+
title: zod_1.z.string(),
|
|
26
|
+
url: zod_1.z.string(),
|
|
27
|
+
status: zod_1.z.number(),
|
|
28
|
+
});
|
|
29
|
+
function browserNavigate(connection) {
|
|
30
|
+
return (0, helpers_1.createConnectedTool)(connection, 'browser_navigate', 'Navigate to a URL and wait for the page to load.', browserNavigateSchema, async (state, input, pageId) => {
|
|
31
|
+
const result = await state.adapter.navigate(pageId, input.url, input.waitUntil);
|
|
32
|
+
return (0, utils_1.formatCallToolResult)({ title: result.title, url: result.url, status: result.status });
|
|
33
|
+
}, browserNavigateOutputSchema, { autoSnapshot: true, waitForCompletion: true }, (args) => (0, helpers_1.extractDomain)(args.url));
|
|
34
|
+
}
|
|
35
|
+
const browserBackSchema = zod_1.z.object({
|
|
36
|
+
pageId: helpers_1.pageIdField,
|
|
37
|
+
});
|
|
38
|
+
const browserBackOutputSchema = (0, helpers_1.withSnapshotEnvelope)({
|
|
39
|
+
title: zod_1.z.string(),
|
|
40
|
+
url: zod_1.z.string(),
|
|
41
|
+
});
|
|
42
|
+
function browserBack(connection) {
|
|
43
|
+
return (0, helpers_1.createConnectedTool)(connection, 'browser_back', 'Navigate back in browser history.', browserBackSchema, async (state, _input, pageId) => {
|
|
44
|
+
const result = await state.adapter.back(pageId);
|
|
45
|
+
return (0, utils_1.formatCallToolResult)({ title: result.title, url: result.url });
|
|
46
|
+
}, browserBackOutputSchema, { autoSnapshot: true, waitForCompletion: true });
|
|
47
|
+
}
|
|
48
|
+
const browserForwardSchema = zod_1.z.object({
|
|
49
|
+
pageId: helpers_1.pageIdField,
|
|
50
|
+
});
|
|
51
|
+
const browserForwardOutputSchema = (0, helpers_1.withSnapshotEnvelope)({
|
|
52
|
+
title: zod_1.z.string(),
|
|
53
|
+
url: zod_1.z.string(),
|
|
54
|
+
});
|
|
55
|
+
function browserForward(connection) {
|
|
56
|
+
return (0, helpers_1.createConnectedTool)(connection, 'browser_forward', 'Navigate forward in browser history.', browserForwardSchema, async (state, _input, pageId) => {
|
|
57
|
+
const result = await state.adapter.forward(pageId);
|
|
58
|
+
return (0, utils_1.formatCallToolResult)({ title: result.title, url: result.url });
|
|
59
|
+
}, browserForwardOutputSchema, { autoSnapshot: true, waitForCompletion: true });
|
|
60
|
+
}
|
|
61
|
+
const browserReloadSchema = zod_1.z.object({
|
|
62
|
+
waitUntil: waitUntilField,
|
|
63
|
+
pageId: helpers_1.pageIdField,
|
|
64
|
+
});
|
|
65
|
+
const browserReloadOutputSchema = (0, helpers_1.withSnapshotEnvelope)({
|
|
66
|
+
title: zod_1.z.string(),
|
|
67
|
+
url: zod_1.z.string(),
|
|
68
|
+
});
|
|
69
|
+
function browserReload(connection) {
|
|
70
|
+
return (0, helpers_1.createConnectedTool)(connection, 'browser_reload', 'Reload the current page.', browserReloadSchema, async (state, input, pageId) => {
|
|
71
|
+
const result = await state.adapter.reload(pageId, input.waitUntil);
|
|
72
|
+
return (0, utils_1.formatCallToolResult)({ title: result.title, url: result.url });
|
|
73
|
+
}, browserReloadOutputSchema, { autoSnapshot: true, waitForCompletion: true });
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=navigation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"navigation.js","sourceRoot":"","sources":["../../src/tools/navigation.ts"],"names":[],"mappings":";;AAYA,sDAOC;AAnBD,6BAAwB;AAIxB,oCAAgD;AAChD,uCAAkG;AAElG,MAAM,cAAc,GAAG,OAAC;KACtB,IAAI,CAAC,CAAC,MAAM,EAAE,kBAAkB,EAAE,aAAa,CAAC,CAAC;KACjD,QAAQ,EAAE;KACV,QAAQ,CAAC,oDAAoD,CAAC,CAAC;AAEjE,SAAgB,qBAAqB,CAAC,UAA6B;IAClE,OAAO;QACN,eAAe,CAAC,UAAU,CAAC;QAC3B,WAAW,CAAC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,GAAG,EAAE,CAAC,CAAC;IACvE,CAAC,EACD,0BAA0B,EAC1B,EAAE,YAAY,EAAE,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,CAC/C,CAAC;AACH,CAAC;AAED,MAAM,mBAAmB,GAAG,OAAC,CAAC,MAAM,CAAC;IACpC,SAAS,EAAE,cAAc;IACzB,MAAM,EAAE,qBAAW;CACnB,CAAC,CAAC;AAEH,MAAM,yBAAyB,GAAG,IAAA,8BAAoB,EAAC;IACtD,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE;IACjB,GAAG,EAAE,OAAC,CAAC,MAAM,EAAE;CACf,CAAC,CAAC;AAEH,SAAS,aAAa,CAAC,UAA6B;IACnD,OAAO,IAAA,6BAAmB,EACzB,UAAU,EACV,gBAAgB,EAChB,0BAA0B,EAC1B,mBAAmB,EACnB,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE;QAC9B,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC;QACnE,OAAO,IAAA,4BAAoB,EAAC,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC;IACvE,CAAC,EACD,yBAAyB,EACzB,EAAE,YAAY,EAAE,IAAI,EAAE,iBAAiB,EAAE,IAAI,EAAE,CAC/C,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { BrowserConnection } from '../connection';
|
|
2
|
+
import type { CallToolResult, ConnectionState } from '../types';
|
|
3
|
+
import type { ConnectedToolOptions } from './helpers';
|
|
4
|
+
export declare function resolvePageContext(connection: BrowserConnection, args: {
|
|
5
|
+
pageId?: string;
|
|
6
|
+
}): {
|
|
7
|
+
state: ConnectionState;
|
|
8
|
+
pageId: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function enrichResponse(result: CallToolResult, state: ConnectionState, pageId: string, options: ConnectedToolOptions, tabsBefore?: Set<string>): Promise<void>;
|
|
11
|
+
export declare function buildErrorResponse(error: unknown, connection: BrowserConnection, args: {
|
|
12
|
+
pageId?: string;
|
|
13
|
+
}, options: ConnectedToolOptions): Promise<CallToolResult>;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolvePageContext = resolvePageContext;
|
|
4
|
+
exports.enrichResponse = enrichResponse;
|
|
5
|
+
exports.buildErrorResponse = buildErrorResponse;
|
|
6
|
+
const errors_1 = require("../errors");
|
|
7
|
+
const logger_1 = require("../logger");
|
|
8
|
+
const log = (0, logger_1.createLogger)('response-envelope');
|
|
9
|
+
function resolvePageContext(connection, args) {
|
|
10
|
+
const state = connection.getConnection();
|
|
11
|
+
const pageId = args.pageId ?? state.activePageId;
|
|
12
|
+
return { state, pageId };
|
|
13
|
+
}
|
|
14
|
+
async function enrichResponse(result, state, pageId, options, tabsBefore) {
|
|
15
|
+
const data = result.structuredContent;
|
|
16
|
+
if (!data || typeof data !== 'object')
|
|
17
|
+
return;
|
|
18
|
+
const record = data;
|
|
19
|
+
if (options.autoSnapshot) {
|
|
20
|
+
try {
|
|
21
|
+
const snap = await state.adapter.snapshot(pageId);
|
|
22
|
+
record.snapshot = snap.tree;
|
|
23
|
+
}
|
|
24
|
+
catch {
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const modals = state.adapter.getModalStates(pageId);
|
|
29
|
+
if (modals.length > 0)
|
|
30
|
+
record.modalStates = modals;
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
}
|
|
34
|
+
if (options.autoSnapshot) {
|
|
35
|
+
try {
|
|
36
|
+
const summary = state.adapter.getConsoleSummary(pageId);
|
|
37
|
+
if (summary.errors > 0 || summary.warnings > 0)
|
|
38
|
+
record.consoleSummary = summary;
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
if (tabsBefore) {
|
|
44
|
+
try {
|
|
45
|
+
const tabsNow = await state.adapter.listTabs();
|
|
46
|
+
log.debug(`tab diff: before=${tabsBefore.size}, now=${tabsNow.length}`);
|
|
47
|
+
const newTabs = tabsNow
|
|
48
|
+
.filter((t) => !tabsBefore.has(t.id))
|
|
49
|
+
.map((t) => ({ id: t.id, title: t.title, url: t.url }));
|
|
50
|
+
if (newTabs.length > 0) {
|
|
51
|
+
log.debug(`detected ${newTabs.length} new tab(s): ${JSON.stringify(newTabs.map((t) => t.url))}`);
|
|
52
|
+
record.newTabs = newTabs;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch {
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
async function buildErrorResponse(error, connection, args, options) {
|
|
60
|
+
const mcpError = error instanceof errors_1.McpBrowserError
|
|
61
|
+
? error
|
|
62
|
+
: new errors_1.McpBrowserError(error instanceof Error ? error.message : String(error));
|
|
63
|
+
const errorData = { error: mcpError.message };
|
|
64
|
+
if (mcpError.hint)
|
|
65
|
+
errorData.hint = mcpError.hint;
|
|
66
|
+
try {
|
|
67
|
+
const { state, pageId } = resolvePageContext(connection, args);
|
|
68
|
+
if (options.autoSnapshot) {
|
|
69
|
+
try {
|
|
70
|
+
const snap = await state.adapter.snapshot(pageId);
|
|
71
|
+
errorData.snapshot = snap.tree;
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
const modals = state.adapter.getModalStates(pageId);
|
|
78
|
+
if (modals.length > 0)
|
|
79
|
+
errorData.modalStates = modals;
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
content: [{ type: 'text', text: JSON.stringify(errorData, null, 2) }],
|
|
88
|
+
structuredContent: errorData,
|
|
89
|
+
isError: true,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=response-envelope.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"response-envelope.js","sourceRoot":"","sources":["../../src/tools/response-envelope.ts"],"names":[],"mappings":";;AAaA,gDAOC;AAWD,wCAsDC;AAUD,gDA0CC;AAxID,sCAA4C;AAC5C,sCAAyC;AAIzC,MAAM,GAAG,GAAG,IAAA,qBAAY,EAAC,mBAAmB,CAAC,CAAC;AAO9C,SAAgB,kBAAkB,CACjC,UAA6B,EAC7B,IAAyB;IAEzB,MAAM,KAAK,GAAG,UAAU,CAAC,aAAa,EAAE,CAAC;IACzC,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC;IACjD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AAC1B,CAAC;AAWM,KAAK,UAAU,cAAc,CACnC,MAAsB,EACtB,KAAsB,EACtB,MAAc,EACd,OAA6B,EAC7B,UAAwB;IAExB,MAAM,IAAI,GAAG,MAAM,CAAC,iBAAiB,CAAC;IACtC,IAAI,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO;IAC9C,MAAM,MAAM,GAAG,IAA+B,CAAC;IAE/C,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;QAC1B,IAAI,CAAC;YACJ,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;YAClD,MAAM,CAAC,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC;QAC7B,CAAC;QAAC,MAAM,CAAC;QAET,CAAC;IACF,CAAC;IAED,IAAI,CAAC;QACJ,MAAM,MAAM,GAAiB,KAAK,CAAC,OAAO,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QAClE,IAAI,MAAM,CAAC,M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e,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;QAC9E,iBAAiB,EAAE,SAAS;QAC5B,OAAO,EAAE,IAAI;KACb,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const pageIdField: z.ZodOptional<z.ZodString>;
|
|
3
|
+
export declare const elementTargetSchema: z.ZodUnion<[z.ZodObject<{
|
|
4
|
+
ref: z.ZodString;
|
|
5
|
+
}, "strict", z.ZodTypeAny, {
|
|
6
|
+
ref: string;
|
|
7
|
+
}, {
|
|
8
|
+
ref: string;
|
|
9
|
+
}>, z.ZodObject<{
|
|
10
|
+
selector: z.ZodString;
|
|
11
|
+
}, "strict", z.ZodTypeAny, {
|
|
12
|
+
selector: string;
|
|
13
|
+
}, {
|
|
14
|
+
selector: string;
|
|
15
|
+
}>]>;
|
|
16
|
+
export type ElementTargetInput = z.infer<typeof elementTargetSchema>;
|
|
17
|
+
export declare const modalStateSchema: z.ZodObject<{
|
|
18
|
+
type: z.ZodEnum<["dialog", "filechooser"]>;
|
|
19
|
+
description: z.ZodString;
|
|
20
|
+
clearedBy: z.ZodString;
|
|
21
|
+
dialogType: z.ZodOptional<z.ZodEnum<["alert", "confirm", "prompt", "beforeunload"]>>;
|
|
22
|
+
message: z.ZodOptional<z.ZodString>;
|
|
23
|
+
}, "strip", z.ZodTypeAny, {
|
|
24
|
+
type: "dialog" | "filechooser";
|
|
25
|
+
description: string;
|
|
26
|
+
clearedBy: string;
|
|
27
|
+
message?: string | undefined;
|
|
28
|
+
dialogType?: "alert" | "confirm" | "prompt" | "beforeunload" | undefined;
|
|
29
|
+
}, {
|
|
30
|
+
type: "dialog" | "filechooser";
|
|
31
|
+
description: string;
|
|
32
|
+
clearedBy: string;
|
|
33
|
+
message?: string | undefined;
|
|
34
|
+
dialogType?: "alert" | "confirm" | "prompt" | "beforeunload" | undefined;
|
|
35
|
+
}>;
|
|
36
|
+
export declare const consoleSummarySchema: z.ZodObject<{
|
|
37
|
+
errors: z.ZodNumber;
|
|
38
|
+
warnings: z.ZodNumber;
|
|
39
|
+
}, "strip", z.ZodTypeAny, {
|
|
40
|
+
errors: number;
|
|
41
|
+
warnings: number;
|
|
42
|
+
}, {
|
|
43
|
+
errors: number;
|
|
44
|
+
warnings: number;
|
|
45
|
+
}>;
|
|
46
|
+
export declare const newTabSchema: z.ZodObject<{
|
|
47
|
+
id: z.ZodString;
|
|
48
|
+
title: z.ZodString;
|
|
49
|
+
url: z.ZodString;
|
|
50
|
+
}, "strip", z.ZodTypeAny, {
|
|
51
|
+
id: string;
|
|
52
|
+
title: string;
|
|
53
|
+
url: string;
|
|
54
|
+
}, {
|
|
55
|
+
id: string;
|
|
56
|
+
title: string;
|
|
57
|
+
url: string;
|
|
58
|
+
}>;
|
|
59
|
+
export declare const snapshotEnvelopeFields: {
|
|
60
|
+
readonly snapshot: z.ZodOptional<z.ZodString>;
|
|
61
|
+
readonly modalStates: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
62
|
+
type: z.ZodEnum<["dialog", "filechooser"]>;
|
|
63
|
+
description: z.ZodString;
|
|
64
|
+
clearedBy: z.ZodString;
|
|
65
|
+
dialogType: z.ZodOptional<z.ZodEnum<["alert", "confirm", "prompt", "beforeunload"]>>;
|
|
66
|
+
message: z.ZodOptional<z.ZodString>;
|
|
67
|
+
}, "strip", z.ZodTypeAny, {
|
|
68
|
+
type: "dialog" | "filechooser";
|
|
69
|
+
description: string;
|
|
70
|
+
clearedBy: string;
|
|
71
|
+
message?: string | undefined;
|
|
72
|
+
dialogType?: "alert" | "confirm" | "prompt" | "beforeunload" | undefined;
|
|
73
|
+
}, {
|
|
74
|
+
type: "dialog" | "filechooser";
|
|
75
|
+
description: string;
|
|
76
|
+
clearedBy: string;
|
|
77
|
+
message?: string | undefined;
|
|
78
|
+
dialogType?: "alert" | "confirm" | "prompt" | "beforeunload" | undefined;
|
|
79
|
+
}>, "many">>;
|
|
80
|
+
readonly consoleSummary: z.ZodOptional<z.ZodObject<{
|
|
81
|
+
errors: z.ZodNumber;
|
|
82
|
+
warnings: z.ZodNumber;
|
|
83
|
+
}, "strip", z.ZodTypeAny, {
|
|
84
|
+
errors: number;
|
|
85
|
+
warnings: number;
|
|
86
|
+
}, {
|
|
87
|
+
errors: number;
|
|
88
|
+
warnings: number;
|
|
89
|
+
}>>;
|
|
90
|
+
readonly newTabs: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
91
|
+
id: z.ZodString;
|
|
92
|
+
title: z.ZodString;
|
|
93
|
+
url: z.ZodString;
|
|
94
|
+
}, "strip", z.ZodTypeAny, {
|
|
95
|
+
id: string;
|
|
96
|
+
title: string;
|
|
97
|
+
url: string;
|
|
98
|
+
}, {
|
|
99
|
+
id: string;
|
|
100
|
+
title: string;
|
|
101
|
+
url: string;
|
|
102
|
+
}>, "many">>;
|
|
103
|
+
};
|
|
104
|
+
export declare function withSnapshotEnvelope<T extends z.ZodRawShape>(shape: T): z.ZodObject<T & {
|
|
105
|
+
readonly snapshot: z.ZodOptional<z.ZodString>;
|
|
106
|
+
readonly modalStates: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
107
|
+
type: z.ZodEnum<["dialog", "filechooser"]>;
|
|
108
|
+
description: z.ZodString;
|
|
109
|
+
clearedBy: z.ZodString;
|
|
110
|
+
dialogType: z.ZodOptional<z.ZodEnum<["alert", "confirm", "prompt", "beforeunload"]>>;
|
|
111
|
+
message: z.ZodOptional<z.ZodString>;
|
|
112
|
+
}, "strip", z.ZodTypeAny, {
|
|
113
|
+
type: "dialog" | "filechooser";
|
|
114
|
+
description: string;
|
|
115
|
+
clearedBy: string;
|
|
116
|
+
message?: string | undefined;
|
|
117
|
+
dialogType?: "alert" | "confirm" | "prompt" | "beforeunload" | undefined;
|
|
118
|
+
}, {
|
|
119
|
+
type: "dialog" | "filechooser";
|
|
120
|
+
description: string;
|
|
121
|
+
clearedBy: string;
|
|
122
|
+
message?: string | undefined;
|
|
123
|
+
dialogType?: "alert" | "confirm" | "prompt" | "beforeunload" | undefined;
|
|
124
|
+
}>, "many">>;
|
|
125
|
+
readonly consoleSummary: z.ZodOptional<z.ZodObject<{
|
|
126
|
+
errors: z.ZodNumber;
|
|
127
|
+
warnings: z.ZodNumber;
|
|
128
|
+
}, "strip", z.ZodTypeAny, {
|
|
129
|
+
errors: number;
|
|
130
|
+
warnings: number;
|
|
131
|
+
}, {
|
|
132
|
+
errors: number;
|
|
133
|
+
warnings: number;
|
|
134
|
+
}>>;
|
|
135
|
+
readonly newTabs: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
136
|
+
id: z.ZodString;
|
|
137
|
+
title: z.ZodString;
|
|
138
|
+
url: z.ZodString;
|
|
139
|
+
}, "strip", z.ZodTypeAny, {
|
|
140
|
+
id: string;
|
|
141
|
+
title: string;
|
|
142
|
+
url: string;
|
|
143
|
+
}, {
|
|
144
|
+
id: string;
|
|
145
|
+
title: string;
|
|
146
|
+
url: string;
|
|
147
|
+
}>, "many">>;
|
|
148
|
+
}, "strip", z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<T & {
|
|
149
|
+
readonly snapshot: z.ZodOptional<z.ZodString>;
|
|
150
|
+
readonly modalStates: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
151
|
+
type: z.ZodEnum<["dialog", "filechooser"]>;
|
|
152
|
+
description: z.ZodString;
|
|
153
|
+
clearedBy: z.ZodString;
|
|
154
|
+
dialogType: z.ZodOptional<z.ZodEnum<["alert", "confirm", "prompt", "beforeunload"]>>;
|
|
155
|
+
message: z.ZodOptional<z.ZodString>;
|
|
156
|
+
}, "strip", z.ZodTypeAny, {
|
|
157
|
+
type: "dialog" | "filechooser";
|
|
158
|
+
description: string;
|
|
159
|
+
clearedBy: string;
|
|
160
|
+
message?: string | undefined;
|
|
161
|
+
dialogType?: "alert" | "confirm" | "prompt" | "beforeunload" | undefined;
|
|
162
|
+
}, {
|
|
163
|
+
type: "dialog" | "filechooser";
|
|
164
|
+
description: string;
|
|
165
|
+
clearedBy: string;
|
|
166
|
+
message?: string | undefined;
|
|
167
|
+
dialogType?: "alert" | "confirm" | "prompt" | "beforeunload" | undefined;
|
|
168
|
+
}>, "many">>;
|
|
169
|
+
readonly consoleSummary: z.ZodOptional<z.ZodObject<{
|
|
170
|
+
errors: z.ZodNumber;
|
|
171
|
+
warnings: z.ZodNumber;
|
|
172
|
+
}, "strip", z.ZodTypeAny, {
|
|
173
|
+
errors: number;
|
|
174
|
+
warnings: number;
|
|
175
|
+
}, {
|
|
176
|
+
errors: number;
|
|
177
|
+
warnings: number;
|
|
178
|
+
}>>;
|
|
179
|
+
readonly newTabs: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
180
|
+
id: z.ZodString;
|
|
181
|
+
title: z.ZodString;
|
|
182
|
+
url: z.ZodString;
|
|
183
|
+
}, "strip", z.ZodTypeAny, {
|
|
184
|
+
id: string;
|
|
185
|
+
title: string;
|
|
186
|
+
url: string;
|
|
187
|
+
}, {
|
|
188
|
+
id: string;
|
|
189
|
+
title: string;
|
|
190
|
+
url: string;
|
|
191
|
+
}>, "many">>;
|
|
192
|
+
}>, any> extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never, z.baseObjectInputType<T & {
|
|
193
|
+
readonly snapshot: z.ZodOptional<z.ZodString>;
|
|
194
|
+
readonly modalStates: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
195
|
+
type: z.ZodEnum<["dialog", "filechooser"]>;
|
|
196
|
+
description: z.ZodString;
|
|
197
|
+
clearedBy: z.ZodString;
|
|
198
|
+
dialogType: z.ZodOptional<z.ZodEnum<["alert", "confirm", "prompt", "beforeunload"]>>;
|
|
199
|
+
message: z.ZodOptional<z.ZodString>;
|
|
200
|
+
}, "strip", z.ZodTypeAny, {
|
|
201
|
+
type: "dialog" | "filechooser";
|
|
202
|
+
description: string;
|
|
203
|
+
clearedBy: string;
|
|
204
|
+
message?: string | undefined;
|
|
205
|
+
dialogType?: "alert" | "confirm" | "prompt" | "beforeunload" | undefined;
|
|
206
|
+
}, {
|
|
207
|
+
type: "dialog" | "filechooser";
|
|
208
|
+
description: string;
|
|
209
|
+
clearedBy: string;
|
|
210
|
+
message?: string | undefined;
|
|
211
|
+
dialogType?: "alert" | "confirm" | "prompt" | "beforeunload" | undefined;
|
|
212
|
+
}>, "many">>;
|
|
213
|
+
readonly consoleSummary: z.ZodOptional<z.ZodObject<{
|
|
214
|
+
errors: z.ZodNumber;
|
|
215
|
+
warnings: z.ZodNumber;
|
|
216
|
+
}, "strip", z.ZodTypeAny, {
|
|
217
|
+
errors: number;
|
|
218
|
+
warnings: number;
|
|
219
|
+
}, {
|
|
220
|
+
errors: number;
|
|
221
|
+
warnings: number;
|
|
222
|
+
}>>;
|
|
223
|
+
readonly newTabs: z.ZodOptional<z.ZodArray<z.ZodObject<{
|
|
224
|
+
id: z.ZodString;
|
|
225
|
+
title: z.ZodString;
|
|
226
|
+
url: z.ZodString;
|
|
227
|
+
}, "strip", z.ZodTypeAny, {
|
|
228
|
+
id: string;
|
|
229
|
+
title: string;
|
|
230
|
+
url: string;
|
|
231
|
+
}, {
|
|
232
|
+
id: string;
|
|
233
|
+
title: string;
|
|
234
|
+
url: string;
|
|
235
|
+
}>, "many">>;
|
|
236
|
+
}> extends infer T_2 ? { [k_1 in keyof T_2]: T_2[k_1]; } : never>;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.snapshotEnvelopeFields = exports.newTabSchema = exports.consoleSummarySchema = exports.modalStateSchema = exports.elementTargetSchema = exports.pageIdField = void 0;
|
|
4
|
+
exports.withSnapshotEnvelope = withSnapshotEnvelope;
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
exports.pageIdField = zod_1.z
|
|
7
|
+
.string()
|
|
8
|
+
.optional()
|
|
9
|
+
.describe('Target page/tab ID. Defaults to active page');
|
|
10
|
+
const refTargetSchema = zod_1.z
|
|
11
|
+
.object({
|
|
12
|
+
ref: zod_1.z.string().describe('Element ref from browser_snapshot (preferred)'),
|
|
13
|
+
})
|
|
14
|
+
.strict();
|
|
15
|
+
const selectorTargetSchema = zod_1.z
|
|
16
|
+
.object({
|
|
17
|
+
selector: zod_1.z.string().describe('CSS/text/role/XPath selector (fallback — prefer ref)'),
|
|
18
|
+
})
|
|
19
|
+
.strict();
|
|
20
|
+
exports.elementTargetSchema = zod_1.z.union([refTargetSchema, selectorTargetSchema]);
|
|
21
|
+
exports.modalStateSchema = zod_1.z.object({
|
|
22
|
+
type: zod_1.z.enum(['dialog', 'filechooser']),
|
|
23
|
+
description: zod_1.z.string(),
|
|
24
|
+
clearedBy: zod_1.z.string(),
|
|
25
|
+
dialogType: zod_1.z.enum(['alert', 'confirm', 'prompt', 'beforeunload']).optional(),
|
|
26
|
+
message: zod_1.z.string().optional(),
|
|
27
|
+
});
|
|
28
|
+
exports.consoleSummarySchema = zod_1.z.object({
|
|
29
|
+
errors: zod_1.z.number(),
|
|
30
|
+
warnings: zod_1.z.number(),
|
|
31
|
+
});
|
|
32
|
+
exports.newTabSchema = zod_1.z.object({
|
|
33
|
+
id: zod_1.z.string(),
|
|
34
|
+
title: zod_1.z.string(),
|
|
35
|
+
url: zod_1.z.string(),
|
|
36
|
+
});
|
|
37
|
+
exports.snapshotEnvelopeFields = {
|
|
38
|
+
snapshot: zod_1.z.string().optional(),
|
|
39
|
+
modalStates: zod_1.z.array(exports.modalStateSchema).optional(),
|
|
40
|
+
consoleSummary: exports.consoleSummarySchema.optional(),
|
|
41
|
+
newTabs: zod_1.z.array(exports.newTabSchema).optional().describe('Tabs opened as a result of this action'),
|
|
42
|
+
};
|
|
43
|
+
function withSnapshotEnvelope(shape) {
|
|
44
|
+
return zod_1.z.object({ ...shape, ...exports.snapshotEnvelopeFields });
|
|
45
|
+
}
|
|
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AAM,EAAE;CACpB,CAAC,CAAC;AAMU,QAAA,YAAY,GAAG,OAAC,CAAC,MAAM,CAAC;IACpC,EAAE,EAAE,OAAC,CAAC,MAAM,EAAE;IACd,KAAK,EAAE,OAAC,CAAC,MAAM,EAAE;IACjB,GAAG,EAAE,OAAC,CAAC,MAAM,EAAE;CACf,CAAC,CAAC;AAGU,QAAA,sBAAsB,GAAG;IACrC,QAAQ,EAAE,OAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAC/B,WAAW,EAAE,OAAC,CAAC,KAAK,CAAC,wBAAgB,CAAC,CAAC,QAAQ,EAAE;IACjD,cAAc,EAAE,4BAAoB,CAAC,QAAQ,EAAE;IAC/C,OAAO,EAAE,OAAC,CAAC,KAAK,CAAC,oBAAY,CAAC,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,wCAAwC,CAAC;CACnF,CAAC;AAYX,SAAgB,oBAAoB,CAA0B,KAAQ;IACrE,OAAO,OAAC,CAAC,MAAM,CAAC,EAAE,GAAG,KAAK,EAAE,GAAG,8BAAsB,EAAE,CAAC,CAAC;AAC1D,CAAC"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSessionTools = createSessionTools;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const errors_1 = require("../errors");
|
|
6
|
+
const types_1 = require("../types");
|
|
7
|
+
const utils_1 = require("../utils");
|
|
8
|
+
function createSessionTools(connection) {
|
|
9
|
+
return [browserConnect(connection), browserDisconnect(connection)];
|
|
10
|
+
}
|
|
11
|
+
const browserConnectSchema = zod_1.z.object({
|
|
12
|
+
browser: types_1.browserNameSchema
|
|
13
|
+
.optional()
|
|
14
|
+
.describe('Chromium-based browser to connect to. Options: chrome, brave, edge, chromium. ' +
|
|
15
|
+
'Defaults to chrome. Only Chromium-based browsers are supported (they provide the CDP protocol required by the browser bridge extension).'),
|
|
16
|
+
});
|
|
17
|
+
const browserConnectOutputSchema = zod_1.z.object({
|
|
18
|
+
browser: zod_1.z.string(),
|
|
19
|
+
pages: zod_1.z.array(zod_1.z.object({
|
|
20
|
+
id: zod_1.z.string(),
|
|
21
|
+
title: zod_1.z.string(),
|
|
22
|
+
url: zod_1.z.string(),
|
|
23
|
+
})),
|
|
24
|
+
});
|
|
25
|
+
function browserConnect(connection) {
|
|
26
|
+
return {
|
|
27
|
+
name: 'browser_connect',
|
|
28
|
+
description: "Connect to the user's browser for web automation. " +
|
|
29
|
+
'Optionally specify a Chromium-based browser (chrome, brave, edge, chromium). ' +
|
|
30
|
+
'Requires the n8n AI Browser Bridge extension to be installed. ' +
|
|
31
|
+
'Must be called before using any other browser tools.',
|
|
32
|
+
inputSchema: browserConnectSchema,
|
|
33
|
+
outputSchema: browserConnectOutputSchema,
|
|
34
|
+
async execute(args, _context) {
|
|
35
|
+
try {
|
|
36
|
+
const result = await connection.connect(args.browser);
|
|
37
|
+
return (0, utils_1.formatCallToolResult)({
|
|
38
|
+
browser: result.browser,
|
|
39
|
+
pages: result.pages,
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (error instanceof errors_1.McpBrowserError)
|
|
44
|
+
return (0, utils_1.formatErrorResponse)(error);
|
|
45
|
+
return (0, utils_1.formatErrorResponse)(new errors_1.McpBrowserError(error instanceof Error ? error.message : String(error)));
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
getAffectedResources(_args, _context) {
|
|
49
|
+
return [{ toolGroup: 'browser', resource: 'browser', description: 'Connect to browser' }];
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
const browserDisconnectSchema = zod_1.z.object({});
|
|
54
|
+
const browserDisconnectOutputSchema = zod_1.z.object({
|
|
55
|
+
disconnected: zod_1.z.boolean(),
|
|
56
|
+
});
|
|
57
|
+
function browserDisconnect(connection) {
|
|
58
|
+
return {
|
|
59
|
+
name: 'browser_disconnect',
|
|
60
|
+
description: 'Disconnect from the browser and release all resources.',
|
|
61
|
+
inputSchema: browserDisconnectSchema,
|
|
62
|
+
outputSchema: browserDisconnectOutputSchema,
|
|
63
|
+
async execute(_args, _context) {
|
|
64
|
+
try {
|
|
65
|
+
await connection.disconnect();
|
|
66
|
+
return (0, utils_1.formatCallToolResult)({ disconnected: true });
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
if (error instanceof errors_1.McpBrowserError)
|
|
70
|
+
return (0, utils_1.formatErrorResponse)(error);
|
|
71
|
+
return (0, utils_1.formatErrorResponse)(new errors_1.McpBrowserError(error instanceof Error ? error.message : String(error)));
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
getAffectedResources(_args, _context) {
|
|
75
|
+
return [
|
|
76
|
+
{ toolGroup: 'browser', resource: 'browser', description: 'Disconnect from browser' },
|
|
77
|
+
];
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.js","sourceRoot":"","sources":["../../src/tools/session.ts"],"names":[],"mappings":";;AAQA,gDAEC;AAVD,6BAAwB;AAGxB,sCAA4C;AAE5C,oCAA6C;AAC7C,oCAAqE;AAErE,SAAgB,kBAAkB,CAAC,UAA6B;IAC/D,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,EAAE,iBAAiB,CAAC,UAAU,CAAC,CAAC,CAAC;AACpE,CAAC;AAMD,MAAM,oBAAoB,GAAG,OAAC,CAAC,MAAM,CAAC;IACrC,OAAO,EAAE,yBAAiB;SACxB,QAAQ,EAAE;SACV,QAAQ,CACR,gFAAgF;QAC/E,0IAA0I,CAC3I;CACF,CAAC,CAAC;AAEH,MAAM,0BAA0B,GAAG,OAAC,CAAC,MAAM,CAAC;IAC3C,OAAO,EAAE,OAAC,CAAC,MAAM,EAAE;IACnB,KAAK,EAAE,OAAC,CAAC,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