bidi-browser-mcp 0.1.9

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.
Files changed (61) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +343 -0
  3. package/dist/bin.d.ts +6 -0
  4. package/dist/bin.js +37 -0
  5. package/dist/config.d.ts +6 -0
  6. package/dist/config.js +122 -0
  7. package/dist/connection/bidi-client.d.ts +29 -0
  8. package/dist/connection/bidi-client.js +298 -0
  9. package/dist/connection/browser-discovery.d.ts +30 -0
  10. package/dist/connection/browser-discovery.js +393 -0
  11. package/dist/connection/chromium-mapper.d.ts +55 -0
  12. package/dist/connection/chromium-mapper.js +293 -0
  13. package/dist/connection/event-pipeline.d.ts +37 -0
  14. package/dist/connection/event-pipeline.js +167 -0
  15. package/dist/index.d.ts +19 -0
  16. package/dist/index.js +66 -0
  17. package/dist/profile/profile-store.d.ts +88 -0
  18. package/dist/profile/profile-store.js +350 -0
  19. package/dist/session/context-manager.d.ts +17 -0
  20. package/dist/session/context-manager.js +179 -0
  21. package/dist/session/session-manager.d.ts +31 -0
  22. package/dist/session/session-manager.js +366 -0
  23. package/dist/snapshot/cache.d.ts +15 -0
  24. package/dist/snapshot/cache.js +37 -0
  25. package/dist/snapshot/dom-snapshot.d.ts +5 -0
  26. package/dist/snapshot/dom-snapshot.js +270 -0
  27. package/dist/snapshot/element-resolver.d.ts +13 -0
  28. package/dist/snapshot/element-resolver.js +25 -0
  29. package/dist/snapshot/token-optimizer.d.ts +16 -0
  30. package/dist/snapshot/token-optimizer.js +103 -0
  31. package/dist/tools/base-tool.d.ts +34 -0
  32. package/dist/tools/base-tool.js +55 -0
  33. package/dist/tools/browser.d.ts +1 -0
  34. package/dist/tools/browser.js +75 -0
  35. package/dist/tools/cleanup.d.ts +1 -0
  36. package/dist/tools/cleanup.js +64 -0
  37. package/dist/tools/console.d.ts +1 -0
  38. package/dist/tools/console.js +87 -0
  39. package/dist/tools/context.d.ts +1 -0
  40. package/dist/tools/context.js +156 -0
  41. package/dist/tools/observe.d.ts +1 -0
  42. package/dist/tools/observe.js +92 -0
  43. package/dist/tools/page.d.ts +1 -0
  44. package/dist/tools/page.js +139 -0
  45. package/dist/tools/ping.d.ts +1 -0
  46. package/dist/tools/ping.js +71 -0
  47. package/dist/tools/registry.d.ts +13 -0
  48. package/dist/tools/registry.js +47 -0
  49. package/dist/tools/spaces.d.ts +1 -0
  50. package/dist/tools/spaces.js +98 -0
  51. package/dist/tools/tabs.d.ts +1 -0
  52. package/dist/tools/tabs.js +155 -0
  53. package/dist/types.d.ts +277 -0
  54. package/dist/types.js +5 -0
  55. package/dist/utils/assert.d.ts +12 -0
  56. package/dist/utils/assert.js +74 -0
  57. package/dist/utils/errors.d.ts +24 -0
  58. package/dist/utils/errors.js +60 -0
  59. package/dist/utils/result.d.ts +14 -0
  60. package/dist/utils/result.js +37 -0
  61. package/package.json +86 -0
@@ -0,0 +1,60 @@
1
+ /**
2
+ * An error with a stable code and a concrete fix. Every user-facing failure
3
+ * should be one of these; raw errors are converted at the boundary.
4
+ */
5
+ export class ActionableError extends Error {
6
+ code;
7
+ fix;
8
+ details;
9
+ constructor(code, message, options = {}) {
10
+ super(message, options.cause === undefined ? undefined : { cause: options.cause });
11
+ this.name = 'ActionableError';
12
+ this.code = code;
13
+ this.fix = options.fix;
14
+ this.details = options.details;
15
+ }
16
+ toJSON() {
17
+ return {
18
+ code: this.code,
19
+ message: this.message,
20
+ ...(this.fix === undefined ? {} : { fix: this.fix }),
21
+ ...(this.details === undefined ? {} : { details: this.details }),
22
+ };
23
+ }
24
+ }
25
+ export function toActionableError(error) {
26
+ if (error instanceof ActionableError) {
27
+ return error;
28
+ }
29
+ if (error instanceof Error) {
30
+ return new ActionableError('INTERNAL_ERROR', error.message, {
31
+ fix: 'Check the server log, then retry. If it persists, report the error with the action and input.',
32
+ cause: error,
33
+ });
34
+ }
35
+ return new ActionableError('INTERNAL_ERROR', String(error), {
36
+ fix: 'Check the server log, then retry. If it persists, report the error with the action and input.',
37
+ });
38
+ }
39
+ export function formatError(error) {
40
+ const actionable = toActionableError(error);
41
+ return actionable.fix === undefined
42
+ ? `${actionable.code}: ${actionable.message}`
43
+ : `${actionable.code}: ${actionable.message}\nFix: ${actionable.fix}`;
44
+ }
45
+ const CONTEXT_NOT_FOUND_PATTERN = /no such context|unknown context|invalid context/i;
46
+ /**
47
+ * Turn the browser's "no such context" rejection into CONTEXT_NOT_FOUND, so
48
+ * callers get the documented code instead of a raw BiDi message.
49
+ */
50
+ export function toContextError(error) {
51
+ if (error instanceof ActionableError &&
52
+ CONTEXT_NOT_FOUND_PATTERN.test(error.message)) {
53
+ return new ActionableError('CONTEXT_NOT_FOUND', error.message, {
54
+ fix: 'Call tabs.list to see open contexts.',
55
+ cause: error,
56
+ });
57
+ }
58
+ return toActionableError(error);
59
+ }
60
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1,14 @@
1
+ import type { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
2
+ import type { OutputMode, ToolResult } from '../types.js';
3
+ export declare function ok(action: string, data?: unknown, warnings?: readonly string[]): ToolResult;
4
+ export declare function fail(action: string, error: unknown): ToolResult;
5
+ /**
6
+ * Convert the internal result into an MCP tool result.
7
+ * Text is the compatibility path; structuredContent is the typed path.
8
+ * `full` output mode keeps the text whole; `inline` truncates it.
9
+ *
10
+ * `outputMode` is required on purpose: the server-wide default lives in
11
+ * `config.ts`, and a silent fallback here would truncate differently from
12
+ * production.
13
+ */
14
+ export declare function toToolResult(result: ToolResult, maxInlineLen: number, outputMode: OutputMode): CallToolResult;
@@ -0,0 +1,37 @@
1
+ import { toActionableError } from './errors.js';
2
+ export function ok(action, data, warnings) {
3
+ return {
4
+ ok: true,
5
+ action,
6
+ ...(data === undefined ? {} : { data }),
7
+ ...(warnings === undefined || warnings.length === 0 ? {} : { warnings: [...warnings] }),
8
+ };
9
+ }
10
+ export function fail(action, error) {
11
+ return {
12
+ ok: false,
13
+ action,
14
+ error: toActionableError(error).toJSON(),
15
+ };
16
+ }
17
+ /**
18
+ * Convert the internal result into an MCP tool result.
19
+ * Text is the compatibility path; structuredContent is the typed path.
20
+ * `full` output mode keeps the text whole; `inline` truncates it.
21
+ *
22
+ * `outputMode` is required on purpose: the server-wide default lives in
23
+ * `config.ts`, and a silent fallback here would truncate differently from
24
+ * production.
25
+ */
26
+ export function toToolResult(result, maxInlineLen, outputMode) {
27
+ const json = JSON.stringify(result);
28
+ const text = outputMode === 'full' || json.length <= maxInlineLen
29
+ ? json
30
+ : `${json.slice(0, maxInlineLen)}\n... [truncated ${json.length - maxInlineLen} chars]`;
31
+ return {
32
+ content: [{ type: 'text', text }],
33
+ structuredContent: result,
34
+ isError: !result.ok,
35
+ };
36
+ }
37
+ //# sourceMappingURL=result.js.map
package/package.json ADDED
@@ -0,0 +1,86 @@
1
+ {
2
+ "name": "bidi-browser-mcp",
3
+ "version": "0.1.9",
4
+ "description": "WebDriver BiDi browser MCP server — control your real Firefox (native BiDi) or Chromium browser (in-process mapper) over the W3C standard protocol",
5
+ "mcpName": "io.github.tushar49/bidi-browser-mcp",
6
+ "type": "module",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "./package.json": "./package.json"
16
+ },
17
+ "bin": {
18
+ "bidi-browser-mcp": "dist/bin.js"
19
+ },
20
+ "author": "Tushar Agarwal",
21
+ "license": "MIT",
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://github.com/Tushar49/bidi-browser-mcp.git"
25
+ },
26
+ "homepage": "https://github.com/Tushar49/bidi-browser-mcp#readme",
27
+ "bugs": {
28
+ "url": "https://github.com/Tushar49/bidi-browser-mcp/issues"
29
+ },
30
+ "files": [
31
+ "dist",
32
+ "!dist/**/*.map"
33
+ ],
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "keywords": [
38
+ "mcp",
39
+ "automation",
40
+ "bidi",
41
+ "webdriver-bidi",
42
+ "firefox",
43
+ "browser-automation",
44
+ "model-context-protocol",
45
+ "ai-agent",
46
+ "browser-mcp",
47
+ "chromium",
48
+ "chrome",
49
+ "brave"
50
+ ],
51
+ "engines": {
52
+ "node": ">=20.19"
53
+ },
54
+ "packageManager": "pnpm@12.14.0",
55
+ "scripts": {
56
+ "build": "tsc && node scripts/postbuild.mjs",
57
+ "start": "node dist/bin.js",
58
+ "dev": "tsc --watch",
59
+ "test": "vitest run",
60
+ "test:watch": "vitest",
61
+ "smoke": "node scripts/dev-smoke.mjs",
62
+ "detect": "node scripts/dev-detect.mjs",
63
+ "setup": "node scripts/setup.mjs",
64
+ "test:integration": "vitest run --config vitest.integration.config.ts",
65
+ "benchmark": "vitest run --config vitest.benchmark.config.ts",
66
+ "lint": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
67
+ "typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.test.json",
68
+ "clean": "node -e \"const fs=require('fs');fs.rmSync('dist',{recursive:true,force:true})\"",
69
+ "verify:release": "node scripts/verify-release.mjs",
70
+ "verify:package": "node scripts/verify-package.mjs",
71
+ "prepack": "pnpm run build"
72
+ },
73
+ "dependencies": {
74
+ "@modelcontextprotocol/sdk": "^1.0.0",
75
+ "ws": "^8.0.0"
76
+ },
77
+ "devDependencies": {
78
+ "@types/node": "^20.19.39",
79
+ "@types/ws": "^8.18.1",
80
+ "typescript": "^5.9.3",
81
+ "vitest": "^2.1.9"
82
+ },
83
+ "optionalDependencies": {
84
+ "chromium-bidi": "158.0.8123-0"
85
+ }
86
+ }