@webmcp-gate/protocol 0.0.0-stage → 0.1.0-alpha.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 +5 -2
- package/dist/index.d.ts +82 -0
- package/dist/index.mjs +26 -0
- package/package.json +33 -5
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,6 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @webmcp-gate/protocol
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Message types, constants and the connection string format shared by the webmcp-gate relay and the browser client.
|
|
4
|
+
No dependencies. The wire format is described in [docs/protocol.md](https://github.com/hon2be/webmcp-gate/blob/main/docs/protocol.md).
|
|
5
|
+
|
|
6
|
+
Part of [webmcp-gate](https://github.com/hon2be/webmcp-gate).
|
package/dist/index.d.ts
ADDED
|
@@ -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,34 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@webmcp-gate/protocol",
|
|
3
|
+
"version": "0.1.0-alpha.0",
|
|
4
|
+
"description": "Message shapes, constants and the connection string of the webmcp-gate WebSocket protocol",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/hon2be/webmcp-gate.git",
|
|
10
|
+
"directory": "packages/protocol"
|
|
11
|
+
},
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=20"
|
|
14
|
+
},
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.mjs"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"README.md",
|
|
25
|
+
"LICENSE"
|
|
26
|
+
],
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
30
|
+
"scripts": {
|
|
31
|
+
"typecheck": "tsc --noEmit",
|
|
32
|
+
"build": "node build.mjs"
|
|
33
|
+
}
|
|
34
|
+
}
|