@webmcp-gate/protocol 0.0.0-stage → 0.1.0-alpha.1

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 hon2be
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.
package/README.md CHANGED
@@ -1,3 +1,10 @@
1
- # Temporary Holding Version
1
+ # @webmcp-gate/protocol
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Message types, constants and the connection string format shared by the [webmcp-gate](https://github.com/hon2be/webmcp-gate) relay and the browser client. No dependencies.
4
+
5
+ The page and the local relay prove they share a per-session pairing code with a mutual HMAC-SHA256 handshake, and the code itself is never sent.
6
+ The wire format and a test vector for writing your own client are in [docs/protocol.md](https://github.com/hon2be/webmcp-gate/blob/main/docs/protocol.md).
7
+
8
+ Most apps want [`@webmcp-gate/client`](https://www.npmjs.com/package/@webmcp-gate/client) instead.
9
+
10
+ Part of [webmcp-gate](https://github.com/hon2be/webmcp-gate).
@@ -0,0 +1,82 @@
1
+ /**
2
+ * Messages exchanged between the browser tab and the relay. See `docs/protocol.md`.
3
+ */
4
+ /** Bump when the message shapes change. */
5
+ export declare const PROTOCOL_VERSION = 1;
6
+ /** WebSocket path on the relay. */
7
+ export declare const SOCKET_PATH = "/bridge";
8
+ /** Reasons the relay or the tab closes the socket. */
9
+ export declare const CLOSE: {
10
+ readonly badCode: 4001;
11
+ readonly badProtocol: 4002;
12
+ readonly replaced: 4003;
13
+ readonly badMessage: 4004;
14
+ };
15
+ /** A tool the tab publishes (WebMCP shape, same as `document.modelContext.registerTool`). */
16
+ export interface TabTool {
17
+ name: string;
18
+ description: string;
19
+ inputSchema?: Record<string, unknown>;
20
+ annotations?: {
21
+ readOnlyHint?: boolean;
22
+ consequentialHint?: boolean;
23
+ untrustedContentHint?: boolean;
24
+ };
25
+ }
26
+ /**
27
+ * Tab → relay.
28
+ * The pairing code is never sent, each side only proves it knows it. A program that grabbed the port
29
+ * can neither collect the code nor pose as the relay.
30
+ */
31
+ export type TabMessage = {
32
+ type: "hello";
33
+ protocol: number;
34
+ nonce: string;
35
+ title: string;
36
+ url: string;
37
+ } | {
38
+ type: "auth";
39
+ proof: string;
40
+ } | {
41
+ type: "tools";
42
+ tools: TabTool[];
43
+ } | {
44
+ type: "check";
45
+ id: string;
46
+ } | {
47
+ type: "result";
48
+ id: string;
49
+ result?: unknown;
50
+ error?: string;
51
+ };
52
+ /** Relay → tab. The tab must not run a call after `expiresAt`. */
53
+ export type BridgeMessage = {
54
+ type: "challenge";
55
+ nonce: string;
56
+ proof: string;
57
+ } | {
58
+ type: "welcome";
59
+ protocol: number;
60
+ } | {
61
+ type: "call";
62
+ id: string;
63
+ name: string;
64
+ input: Record<string, unknown>;
65
+ expiresAt: number;
66
+ } | {
67
+ type: "checked";
68
+ id: string;
69
+ ok: boolean;
70
+ } | {
71
+ type: "cancel";
72
+ id: string;
73
+ };
74
+ /** Text fed to the HMAC. The side is mixed in so one proof can't be replayed in the other direction. */
75
+ export declare const proofText: (side: "relay" | "tab", first: string, second: string) => string;
76
+ /** The string pasted into the page: `wgate1.<port>.<code>`. */
77
+ export declare const formatConnection: (port: number, code: string) => string;
78
+ /** Parses a connection string, `null` if the shape is wrong. */
79
+ export declare function parseConnection(text: string): {
80
+ port: number;
81
+ code: string;
82
+ } | null;
package/dist/index.mjs ADDED
@@ -0,0 +1,26 @@
1
+ // src/index.ts
2
+ var PROTOCOL_VERSION = 1;
3
+ var SOCKET_PATH = "/bridge";
4
+ var CLOSE = {
5
+ badCode: 4001,
6
+ badProtocol: 4002,
7
+ replaced: 4003,
8
+ badMessage: 4004
9
+ };
10
+ var proofText = (side, first, second) => `${side}:${first}:${second}`;
11
+ var formatConnection = (port, code) => `wgate${PROTOCOL_VERSION}.${port}.${code}`;
12
+ var CONNECTION = new RegExp(`^wgate${PROTOCOL_VERSION}\\.(\\d{2,5})\\.([0-9A-Z]{5}(?:-[0-9A-Z]{5}){3})$`);
13
+ function parseConnection(text) {
14
+ const match = CONNECTION.exec(text.trim());
15
+ if (!match) return null;
16
+ const port = Number(match[1]);
17
+ return port > 0 && port < 65536 ? { port, code: match[2] } : null;
18
+ }
19
+ export {
20
+ CLOSE,
21
+ PROTOCOL_VERSION,
22
+ SOCKET_PATH,
23
+ formatConnection,
24
+ parseConnection,
25
+ proofText
26
+ };
package/package.json CHANGED
@@ -1,6 +1,46 @@
1
1
  {
2
- "name": "@webmcp-gate/protocol",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@webmcp-gate/protocol",
3
+ "version": "0.1.0-alpha.1",
4
+ "description": "Message shapes, constants and the connection string of the webmcp-gate WebSocket protocol, a mutual HMAC handshake between a web page and a local relay",
5
+ "keywords": [
6
+ "webmcp",
7
+ "mcp",
8
+ "websocket",
9
+ "protocol",
10
+ "hmac",
11
+ "agent-tools"
12
+ ],
13
+ "homepage": "https://github.com/hon2be/webmcp-gate#readme",
14
+ "bugs": {
15
+ "url": "https://github.com/hon2be/webmcp-gate/issues"
16
+ },
17
+ "license": "MIT",
18
+ "type": "module",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/hon2be/webmcp-gate.git",
22
+ "directory": "packages/protocol"
23
+ },
24
+ "engines": {
25
+ "node": ">=20"
26
+ },
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/index.d.ts",
30
+ "default": "./dist/index.mjs"
31
+ }
32
+ },
33
+ "types": "./dist/index.d.ts",
34
+ "files": [
35
+ "dist",
36
+ "README.md",
37
+ "LICENSE"
38
+ ],
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "scripts": {
43
+ "typecheck": "tsc --noEmit",
44
+ "build": "node build.mjs"
45
+ }
46
+ }