mcp-page-bridge-protocol 0.1.3

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Eray Ates
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Shared constants and helpers used by both the mcp-page-bridge bridge (Node) and the
3
+ * browser-side client (extension). Keep this dependency-free so it can be
4
+ * bundled into a service worker / content script as well as Node.
5
+ */
6
+ export declare const MCP_PAGE_BRIDGE_VERSION = "0.1.3";
7
+ /** WebSocket subprotocol negotiated between the browser client and the bridge. */
8
+ export declare const WS_SUBPROTOCOL = "mcp";
9
+ /** Default port the bridge listens on for browser WebSocket connections. */
10
+ export declare const DEFAULT_PORT = 8787;
11
+ /** Separator between a provider label and the original tool name. */
12
+ export declare const NAMESPACE_SEP = "__";
13
+ /**
14
+ * Turn an arbitrary provider/server name into a tool-name-safe label.
15
+ * Lowercase, spaces/dots -> hyphen, strip disallowed chars, clamp length.
16
+ */
17
+ export declare function sanitizeLabel(input: string | undefined | null): string;
18
+ /** Build the agent-facing namespaced tool name. */
19
+ export declare function namespaceName(label: string, name: string): string;
20
+ /** Metadata a provider can advertise about the page it lives in. */
21
+ export interface ProviderMeta {
22
+ url?: string;
23
+ title?: string;
24
+ userAgent?: string;
25
+ /** Browser tab id, when the provider is owned by an extension content tab. */
26
+ tabId?: number;
27
+ /** Extension-internal provider id for that tab. */
28
+ providerId?: string;
29
+ }
30
+ /** Bridge -> extension private JSON-RPC methods used by the local dashboard. */
31
+ export declare const MCP_PAGE_BRIDGE_DASHBOARD_ACTIVATE_TAB: "mcpPageBridge/activateTab";
32
+ export declare const MCP_PAGE_BRIDGE_DASHBOARD_CLOSE_TAB: "mcpPageBridge/closeTab";
33
+ /** Direction of an internal channel message relative to the bridge. */
34
+ export type ChannelDir = "up" | "down";
35
+ /**
36
+ * Internal envelope used on the extension's own channel:
37
+ * page (MAIN) <-> content script (ISOLATED) <-> service worker.
38
+ *
39
+ * This is NOT the wire to the bridge (that is raw MCP JSON-RPC). The SW
40
+ * terminates this envelope and forwards `payload` (a JSON-RPC message) onto the
41
+ * per-provider WebSocket. `providerId` lets a single tab host several providers
42
+ * (e.g. built-ins + a page MCP). `providerId === "*"` denotes a control/global
43
+ * message not tied to a specific provider.
44
+ *
45
+ * `dir` prevents postMessage echo loops since MAIN and ISOLATED scripts share
46
+ * the same `window` and both observe every `message` event.
47
+ */
48
+ export interface ChannelMessage {
49
+ /** Magic marker so we can ignore unrelated postMessage traffic. */
50
+ __mcpPageBridge: true;
51
+ dir: ChannelDir;
52
+ providerId: string;
53
+ kind: "rpc" | "open" | "close" | "control" | "ext";
54
+ /**
55
+ * - kind "rpc": a JSON-RPC message object
56
+ * - kind "open": `{ url, title }` source metadata (for the popup)
57
+ * - kind "control": `{ action: "hello" | "activate" | "deactivate", ... }`
58
+ * - kind "ext": up = `ExtCallPayload`, down = `ExtResultPayload`
59
+ */
60
+ payload?: unknown;
61
+ }
62
+ /** Request from the page (MAIN) to the SW to run an extension-only action. */
63
+ export interface ExtCallPayload {
64
+ id: number;
65
+ action: string;
66
+ args?: Record<string, unknown>;
67
+ }
68
+ /** Response from the SW back to the page for an ExtCallPayload. */
69
+ export interface ExtResultPayload {
70
+ id: number;
71
+ result?: unknown;
72
+ error?: string;
73
+ }
74
+ export type ControlAction = "hello" | "activate" | "deactivate";
75
+ export interface ControlPayload {
76
+ action: ControlAction;
77
+ url?: string;
78
+ title?: string;
79
+ }
80
+ export declare const MCP_PAGE_BRIDGE_MARK: "__mcpPageBridge";
package/dist/index.js ADDED
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Shared constants and helpers used by both the mcp-page-bridge bridge (Node) and the
3
+ * browser-side client (extension). Keep this dependency-free so it can be
4
+ * bundled into a service worker / content script as well as Node.
5
+ */
6
+ export const MCP_PAGE_BRIDGE_VERSION = "0.1.3";
7
+ /** WebSocket subprotocol negotiated between the browser client and the bridge. */
8
+ export const WS_SUBPROTOCOL = "mcp";
9
+ /** Default port the bridge listens on for browser WebSocket connections. */
10
+ export const DEFAULT_PORT = 8787;
11
+ /** Separator between a provider label and the original tool name. */
12
+ export const NAMESPACE_SEP = "__";
13
+ /** Allowed characters in an MCP tool name component. */
14
+ const DISALLOWED = /[^a-zA-Z0-9_-]/g;
15
+ /**
16
+ * Turn an arbitrary provider/server name into a tool-name-safe label.
17
+ * Lowercase, spaces/dots -> hyphen, strip disallowed chars, clamp length.
18
+ */
19
+ export function sanitizeLabel(input) {
20
+ const base = (input ?? "")
21
+ .trim()
22
+ .toLowerCase()
23
+ .replace(/[\s.]+/g, "-")
24
+ .replace(DISALLOWED, "")
25
+ .replace(/-{2,}/g, "-")
26
+ .replace(/^[-_]+|[-_]+$/g, "")
27
+ .slice(0, 40);
28
+ return base || "browser";
29
+ }
30
+ /** Build the agent-facing namespaced tool name. */
31
+ export function namespaceName(label, name) {
32
+ return `${label}${NAMESPACE_SEP}${name}`;
33
+ }
34
+ /** Bridge -> extension private JSON-RPC methods used by the local dashboard. */
35
+ export const MCP_PAGE_BRIDGE_DASHBOARD_ACTIVATE_TAB = "mcpPageBridge/activateTab";
36
+ export const MCP_PAGE_BRIDGE_DASHBOARD_CLOSE_TAB = "mcpPageBridge/closeTab";
37
+ export const MCP_PAGE_BRIDGE_MARK = "__mcpPageBridge";
package/package.json ADDED
@@ -0,0 +1,37 @@
1
+ {
2
+ "name": "mcp-page-bridge-protocol",
3
+ "version": "0.1.3",
4
+ "type": "module",
5
+ "description": "Shared constants/helpers for the mcp-page-bridge bridge and browser client",
6
+ "license": "MIT",
7
+ "author": "Eray Ates",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/rytsh/mcp-page-bridge.git"
11
+ },
12
+ "keywords": [
13
+ "mcp",
14
+ "model-context-protocol",
15
+ "browser",
16
+ "websocket",
17
+ "protocol"
18
+ ],
19
+ "main": "./dist/index.js",
20
+ "types": "./dist/index.d.ts",
21
+ "exports": {
22
+ ".": {
23
+ "types": "./dist/index.d.ts",
24
+ "import": "./dist/index.js"
25
+ }
26
+ },
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "scripts": {
34
+ "typecheck": "tsc -p tsconfig.json",
35
+ "build": "tsc -p tsconfig.build.json"
36
+ }
37
+ }