@casys/mcp-bridge 0.2.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/esm/_dnt.shims.d.ts +2 -0
- package/esm/_dnt.shims.d.ts.map +1 -0
- package/esm/_dnt.shims.js +57 -0
- package/esm/adapters/base-adapter.d.ts +25 -0
- package/esm/adapters/base-adapter.d.ts.map +1 -0
- package/esm/adapters/base-adapter.js +86 -0
- package/esm/adapters/line/adapter.d.ts +11 -0
- package/esm/adapters/line/adapter.d.ts.map +1 -0
- package/esm/adapters/line/adapter.js +10 -0
- package/esm/adapters/line/types.d.ts +25 -0
- package/esm/adapters/line/types.d.ts.map +1 -0
- package/esm/adapters/line/types.js +4 -0
- package/esm/adapters/telegram/adapter.d.ts +11 -0
- package/esm/adapters/telegram/adapter.d.ts.map +1 -0
- package/esm/adapters/telegram/adapter.js +10 -0
- package/esm/adapters/telegram/platform-adapter.d.ts +40 -0
- package/esm/adapters/telegram/platform-adapter.d.ts.map +1 -0
- package/esm/adapters/telegram/platform-adapter.js +214 -0
- package/esm/adapters/telegram/sdk-bridge.d.ts +8 -0
- package/esm/adapters/telegram/sdk-bridge.d.ts.map +1 -0
- package/esm/adapters/telegram/sdk-bridge.js +22 -0
- package/esm/adapters/telegram/types.d.ts +93 -0
- package/esm/adapters/telegram/types.d.ts.map +1 -0
- package/esm/adapters/telegram/types.js +6 -0
- package/esm/client/bridge.js +424 -0
- package/esm/core/adapter.d.ts +88 -0
- package/esm/core/adapter.d.ts.map +1 -0
- package/esm/core/adapter.js +10 -0
- package/esm/core/bridge-client.d.ts +77 -0
- package/esm/core/bridge-client.d.ts.map +1 -0
- package/esm/core/bridge-client.js +275 -0
- package/esm/core/message-router.d.ts +71 -0
- package/esm/core/message-router.d.ts.map +1 -0
- package/esm/core/message-router.js +187 -0
- package/esm/core/protocol.d.ts +116 -0
- package/esm/core/protocol.d.ts.map +1 -0
- package/esm/core/protocol.js +203 -0
- package/esm/core/resource-resolver.d.ts +27 -0
- package/esm/core/resource-resolver.d.ts.map +1 -0
- package/esm/core/resource-resolver.js +85 -0
- package/esm/core/transport.d.ts +46 -0
- package/esm/core/transport.d.ts.map +1 -0
- package/esm/core/transport.js +85 -0
- package/esm/core/types.d.ts +187 -0
- package/esm/core/types.d.ts.map +1 -0
- package/esm/core/types.js +35 -0
- package/esm/mod.d.ts +36 -0
- package/esm/mod.d.ts.map +1 -0
- package/esm/mod.js +33 -0
- package/esm/package.json +3 -0
- package/esm/resource-server/csp.d.ts +36 -0
- package/esm/resource-server/csp.d.ts.map +1 -0
- package/esm/resource-server/csp.js +36 -0
- package/esm/resource-server/injector.d.ts +18 -0
- package/esm/resource-server/injector.d.ts.map +1 -0
- package/esm/resource-server/injector.js +39 -0
- package/esm/resource-server/server.d.ts +107 -0
- package/esm/resource-server/server.d.ts.map +1 -0
- package/esm/resource-server/server.js +483 -0
- package/esm/resource-server/session.d.ts +60 -0
- package/esm/resource-server/session.d.ts.map +1 -0
- package/esm/resource-server/session.js +86 -0
- package/esm/resource-server/telegram-auth.d.ts +45 -0
- package/esm/resource-server/telegram-auth.d.ts.map +1 -0
- package/esm/resource-server/telegram-auth.js +161 -0
- package/package.json +31 -0
- package/script/_dnt.shims.d.ts +2 -0
- package/script/_dnt.shims.d.ts.map +1 -0
- package/script/_dnt.shims.js +60 -0
- package/script/adapters/base-adapter.d.ts +25 -0
- package/script/adapters/base-adapter.d.ts.map +1 -0
- package/script/adapters/base-adapter.js +113 -0
- package/script/adapters/line/adapter.d.ts +11 -0
- package/script/adapters/line/adapter.d.ts.map +1 -0
- package/script/adapters/line/adapter.js +14 -0
- package/script/adapters/line/types.d.ts +25 -0
- package/script/adapters/line/types.d.ts.map +1 -0
- package/script/adapters/line/types.js +5 -0
- package/script/adapters/telegram/adapter.d.ts +11 -0
- package/script/adapters/telegram/adapter.d.ts.map +1 -0
- package/script/adapters/telegram/adapter.js +14 -0
- package/script/adapters/telegram/platform-adapter.d.ts +40 -0
- package/script/adapters/telegram/platform-adapter.d.ts.map +1 -0
- package/script/adapters/telegram/platform-adapter.js +241 -0
- package/script/adapters/telegram/sdk-bridge.d.ts +8 -0
- package/script/adapters/telegram/sdk-bridge.d.ts.map +1 -0
- package/script/adapters/telegram/sdk-bridge.js +48 -0
- package/script/adapters/telegram/types.d.ts +93 -0
- package/script/adapters/telegram/types.d.ts.map +1 -0
- package/script/adapters/telegram/types.js +7 -0
- package/script/client/bridge.js +424 -0
- package/script/core/adapter.d.ts +88 -0
- package/script/core/adapter.d.ts.map +1 -0
- package/script/core/adapter.js +11 -0
- package/script/core/bridge-client.d.ts +77 -0
- package/script/core/bridge-client.d.ts.map +1 -0
- package/script/core/bridge-client.js +302 -0
- package/script/core/message-router.d.ts +71 -0
- package/script/core/message-router.d.ts.map +1 -0
- package/script/core/message-router.js +191 -0
- package/script/core/protocol.d.ts +116 -0
- package/script/core/protocol.d.ts.map +1 -0
- package/script/core/protocol.js +230 -0
- package/script/core/resource-resolver.d.ts +27 -0
- package/script/core/resource-resolver.d.ts.map +1 -0
- package/script/core/resource-resolver.js +89 -0
- package/script/core/transport.d.ts +46 -0
- package/script/core/transport.d.ts.map +1 -0
- package/script/core/transport.js +112 -0
- package/script/core/types.d.ts +187 -0
- package/script/core/types.d.ts.map +1 -0
- package/script/core/types.js +38 -0
- package/script/mod.d.ts +36 -0
- package/script/mod.d.ts.map +1 -0
- package/script/mod.js +76 -0
- package/script/package.json +3 -0
- package/script/resource-server/csp.d.ts +36 -0
- package/script/resource-server/csp.d.ts.map +1 -0
- package/script/resource-server/csp.js +39 -0
- package/script/resource-server/injector.d.ts +18 -0
- package/script/resource-server/injector.d.ts.map +1 -0
- package/script/resource-server/injector.js +42 -0
- package/script/resource-server/server.d.ts +107 -0
- package/script/resource-server/server.d.ts.map +1 -0
- package/script/resource-server/server.js +487 -0
- package/script/resource-server/session.d.ts +60 -0
- package/script/resource-server/session.d.ts.map +1 -0
- package/script/resource-server/session.js +90 -0
- package/script/resource-server/telegram-auth.d.ts +45 -0
- package/script/resource-server/telegram-auth.d.ts.map +1 -0
- package/script/resource-server/telegram-auth.js +164 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/core/protocol.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EACV,gBAAgB,EAChB,WAAW,EACX,oBAAoB,EACpB,cAAc,EACd,mBAAmB,EACnB,cAAc,EACd,eAAe,EAChB,MAAM,YAAY,CAAC;AASpB,sDAAsD;AACtD,wBAAgB,aAAa,IAAI,MAAM,CAEtC;AAED,iEAAiE;AACjE,wBAAgB,qBAAqB,IAAI,IAAI,CAE5C;AAMD,wDAAwD;AACxD,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAOxE;AAED,wEAAwE;AACxE,wBAAgB,SAAS,CAAC,GAAG,EAAE,cAAc,GAAG,GAAG,IAAI,cAAc,CAEpE;AAED,6EAA6E;AAC7E,wBAAgB,cAAc,CAC5B,GAAG,EAAE,cAAc,GAClB,GAAG,IAAI,mBAAmB,CAE5B;AAED,yDAAyD;AACzD,wBAAgB,UAAU,CAAC,GAAG,EAAE,cAAc,GAAG,GAAG,IAAI,eAAe,CAEtE;AAED,uDAAuD;AACvD,wBAAgB,eAAe,CAC7B,GAAG,EAAE,cAAc,GAClB,GAAG,IAAI,oBAAoB,CAE7B;AAMD,uCAAuC;AACvC,wBAAgB,sBAAsB,CAAC,MAAM,EAAE;IAC7C,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAC9C,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACxC,GAAG,cAAc,CAOjB;AAED,oCAAoC;AACpC,wBAAgB,oBAAoB,CAAC,MAAM,EAAE;IAC3C,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C1B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,OAAO,GACb,oBAAoB,CAMtB;AAMD,eAAO,MAAM,gBAAgB;;;;;;CAMnB,CAAC"}
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* JSON-RPC 2.0 message builders and validators for the MCP Apps protocol.
|
|
4
|
+
*
|
|
5
|
+
* Provides type-safe construction of all MCP Apps messages and a
|
|
6
|
+
* message validator to guard incoming data at system boundaries.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.JsonRpcErrorCode = void 0;
|
|
10
|
+
exports.nextRequestId = nextRequestId;
|
|
11
|
+
exports.resetRequestIdCounter = resetRequestIdCounter;
|
|
12
|
+
exports.isJsonRpcMessage = isJsonRpcMessage;
|
|
13
|
+
exports.isRequest = isRequest;
|
|
14
|
+
exports.isNotification = isNotification;
|
|
15
|
+
exports.isResponse = isResponse;
|
|
16
|
+
exports.isErrorResponse = isErrorResponse;
|
|
17
|
+
exports.buildInitializeRequest = buildInitializeRequest;
|
|
18
|
+
exports.buildToolCallRequest = buildToolCallRequest;
|
|
19
|
+
exports.buildResourceReadRequest = buildResourceReadRequest;
|
|
20
|
+
exports.buildOpenLinkRequest = buildOpenLinkRequest;
|
|
21
|
+
exports.buildMessageRequest = buildMessageRequest;
|
|
22
|
+
exports.buildUpdateModelContextRequest = buildUpdateModelContextRequest;
|
|
23
|
+
exports.buildDisplayModeRequest = buildDisplayModeRequest;
|
|
24
|
+
exports.buildInitializedNotification = buildInitializedNotification;
|
|
25
|
+
exports.buildToolInputNotification = buildToolInputNotification;
|
|
26
|
+
exports.buildToolResultNotification = buildToolResultNotification;
|
|
27
|
+
exports.buildToolCancelledNotification = buildToolCancelledNotification;
|
|
28
|
+
exports.buildHostContextChangedNotification = buildHostContextChangedNotification;
|
|
29
|
+
exports.buildResourceTeardownRequest = buildResourceTeardownRequest;
|
|
30
|
+
exports.buildLogNotification = buildLogNotification;
|
|
31
|
+
exports.buildInitializeResponse = buildInitializeResponse;
|
|
32
|
+
exports.buildSuccessResponse = buildSuccessResponse;
|
|
33
|
+
exports.buildErrorResponse = buildErrorResponse;
|
|
34
|
+
const types_js_1 = require("./types.js");
|
|
35
|
+
// ---------------------------------------------------------------------------
|
|
36
|
+
// ID generation
|
|
37
|
+
// ---------------------------------------------------------------------------
|
|
38
|
+
let _nextId = 1;
|
|
39
|
+
/** Generate a monotonically increasing request ID. */
|
|
40
|
+
function nextRequestId() {
|
|
41
|
+
return _nextId++;
|
|
42
|
+
}
|
|
43
|
+
/** Reset the ID counter. @internal — exported for tests only. */
|
|
44
|
+
function resetRequestIdCounter() {
|
|
45
|
+
_nextId = 1;
|
|
46
|
+
}
|
|
47
|
+
// ---------------------------------------------------------------------------
|
|
48
|
+
// Message type guards
|
|
49
|
+
// ---------------------------------------------------------------------------
|
|
50
|
+
/** Check if a value is a valid JSON-RPC 2.0 message. */
|
|
51
|
+
function isJsonRpcMessage(value) {
|
|
52
|
+
return (typeof value === "object" &&
|
|
53
|
+
value !== null &&
|
|
54
|
+
"jsonrpc" in value &&
|
|
55
|
+
value.jsonrpc === "2.0");
|
|
56
|
+
}
|
|
57
|
+
/** Check if a message is a JSON-RPC request (has `id` and `method`). */
|
|
58
|
+
function isRequest(msg) {
|
|
59
|
+
return "method" in msg && "id" in msg;
|
|
60
|
+
}
|
|
61
|
+
/** Check if a message is a JSON-RPC notification (has `method`, no `id`). */
|
|
62
|
+
function isNotification(msg) {
|
|
63
|
+
return "method" in msg && !("id" in msg);
|
|
64
|
+
}
|
|
65
|
+
/** Check if a message is a JSON-RPC success response. */
|
|
66
|
+
function isResponse(msg) {
|
|
67
|
+
return "result" in msg && "id" in msg && !("method" in msg);
|
|
68
|
+
}
|
|
69
|
+
/** Check if a message is a JSON-RPC error response. */
|
|
70
|
+
function isErrorResponse(msg) {
|
|
71
|
+
return "error" in msg && "id" in msg;
|
|
72
|
+
}
|
|
73
|
+
// ---------------------------------------------------------------------------
|
|
74
|
+
// Request builders (App -> Host)
|
|
75
|
+
// ---------------------------------------------------------------------------
|
|
76
|
+
/** Build a `ui/initialize` request. */
|
|
77
|
+
function buildInitializeRequest(params) {
|
|
78
|
+
return {
|
|
79
|
+
jsonrpc: "2.0",
|
|
80
|
+
id: nextRequestId(),
|
|
81
|
+
method: types_js_1.McpAppsMethod.UI_INITIALIZE,
|
|
82
|
+
params,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/** Build a `tools/call` request. */
|
|
86
|
+
function buildToolCallRequest(params) {
|
|
87
|
+
return {
|
|
88
|
+
jsonrpc: "2.0",
|
|
89
|
+
id: nextRequestId(),
|
|
90
|
+
method: types_js_1.McpAppsMethod.TOOLS_CALL,
|
|
91
|
+
params,
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/** Build a `resources/read` request. */
|
|
95
|
+
function buildResourceReadRequest(params) {
|
|
96
|
+
return {
|
|
97
|
+
jsonrpc: "2.0",
|
|
98
|
+
id: nextRequestId(),
|
|
99
|
+
method: types_js_1.McpAppsMethod.RESOURCES_READ,
|
|
100
|
+
params,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/** Build a `ui/open-link` request. */
|
|
104
|
+
function buildOpenLinkRequest(params) {
|
|
105
|
+
return {
|
|
106
|
+
jsonrpc: "2.0",
|
|
107
|
+
id: nextRequestId(),
|
|
108
|
+
method: types_js_1.McpAppsMethod.UI_OPEN_LINK,
|
|
109
|
+
params,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/** Build a `ui/message` request. */
|
|
113
|
+
function buildMessageRequest(params) {
|
|
114
|
+
return {
|
|
115
|
+
jsonrpc: "2.0",
|
|
116
|
+
id: nextRequestId(),
|
|
117
|
+
method: types_js_1.McpAppsMethod.UI_MESSAGE,
|
|
118
|
+
params,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/** Build a `ui/update-model-context` request. */
|
|
122
|
+
function buildUpdateModelContextRequest(params) {
|
|
123
|
+
return {
|
|
124
|
+
jsonrpc: "2.0",
|
|
125
|
+
id: nextRequestId(),
|
|
126
|
+
method: types_js_1.McpAppsMethod.UI_UPDATE_MODEL_CONTEXT,
|
|
127
|
+
params,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
/** Build a `ui/request-display-mode` request. */
|
|
131
|
+
function buildDisplayModeRequest(params) {
|
|
132
|
+
return {
|
|
133
|
+
jsonrpc: "2.0",
|
|
134
|
+
id: nextRequestId(),
|
|
135
|
+
method: types_js_1.McpAppsMethod.UI_REQUEST_DISPLAY_MODE,
|
|
136
|
+
params,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
// ---------------------------------------------------------------------------
|
|
140
|
+
// Notification builders (Host -> App)
|
|
141
|
+
// ---------------------------------------------------------------------------
|
|
142
|
+
/** Build a `ui/notifications/initialized` notification (App -> Host). */
|
|
143
|
+
function buildInitializedNotification() {
|
|
144
|
+
return {
|
|
145
|
+
jsonrpc: "2.0",
|
|
146
|
+
method: types_js_1.McpAppsMethod.UI_NOTIFICATIONS_INITIALIZED,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/** Build a `ui/notifications/tool-input` notification (Host -> App). */
|
|
150
|
+
function buildToolInputNotification(params) {
|
|
151
|
+
return {
|
|
152
|
+
jsonrpc: "2.0",
|
|
153
|
+
method: types_js_1.McpAppsMethod.UI_TOOL_INPUT,
|
|
154
|
+
params,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
/** Build a `ui/notifications/tool-result` notification (Host -> App). */
|
|
158
|
+
function buildToolResultNotification(params) {
|
|
159
|
+
return {
|
|
160
|
+
jsonrpc: "2.0",
|
|
161
|
+
method: types_js_1.McpAppsMethod.UI_TOOL_RESULT,
|
|
162
|
+
params,
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
/** Build a `ui/notifications/tool-cancelled` notification (Host -> App). */
|
|
166
|
+
function buildToolCancelledNotification(params) {
|
|
167
|
+
return {
|
|
168
|
+
jsonrpc: "2.0",
|
|
169
|
+
method: types_js_1.McpAppsMethod.UI_TOOL_CANCELLED,
|
|
170
|
+
params,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
/** Build a `ui/notifications/host-context-changed` notification. */
|
|
174
|
+
function buildHostContextChangedNotification(params) {
|
|
175
|
+
return {
|
|
176
|
+
jsonrpc: "2.0",
|
|
177
|
+
method: types_js_1.McpAppsMethod.UI_HOST_CONTEXT_CHANGED,
|
|
178
|
+
params: params,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
/** Build a `ui/resource-teardown` request (Host -> App). */
|
|
182
|
+
function buildResourceTeardownRequest(params) {
|
|
183
|
+
return {
|
|
184
|
+
jsonrpc: "2.0",
|
|
185
|
+
id: nextRequestId(),
|
|
186
|
+
method: types_js_1.McpAppsMethod.UI_RESOURCE_TEARDOWN,
|
|
187
|
+
params,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
/** Build a `notifications/message` notification (logging). */
|
|
191
|
+
function buildLogNotification(params) {
|
|
192
|
+
return {
|
|
193
|
+
jsonrpc: "2.0",
|
|
194
|
+
method: types_js_1.McpAppsMethod.NOTIFICATIONS_MESSAGE,
|
|
195
|
+
params,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
// ---------------------------------------------------------------------------
|
|
199
|
+
// Response builders
|
|
200
|
+
// ---------------------------------------------------------------------------
|
|
201
|
+
/** Build a `ui/initialize` success response. */
|
|
202
|
+
function buildInitializeResponse(id, params) {
|
|
203
|
+
return {
|
|
204
|
+
jsonrpc: "2.0",
|
|
205
|
+
id,
|
|
206
|
+
result: params,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
/** Build a generic JSON-RPC success response. */
|
|
210
|
+
function buildSuccessResponse(id, result) {
|
|
211
|
+
return { jsonrpc: "2.0", id, result };
|
|
212
|
+
}
|
|
213
|
+
/** Build a JSON-RPC error response. */
|
|
214
|
+
function buildErrorResponse(id, code, message, data) {
|
|
215
|
+
return {
|
|
216
|
+
jsonrpc: "2.0",
|
|
217
|
+
id,
|
|
218
|
+
error: { code, message, ...(data !== undefined ? { data } : {}) },
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
// ---------------------------------------------------------------------------
|
|
222
|
+
// Standard JSON-RPC error codes
|
|
223
|
+
// ---------------------------------------------------------------------------
|
|
224
|
+
exports.JsonRpcErrorCode = {
|
|
225
|
+
PARSE_ERROR: -32700,
|
|
226
|
+
INVALID_REQUEST: -32600,
|
|
227
|
+
METHOD_NOT_FOUND: -32601,
|
|
228
|
+
INVALID_PARAMS: -32602,
|
|
229
|
+
INTERNAL_ERROR: -32603,
|
|
230
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves `ui://` resource URIs to HTTP URLs served by the resource server.
|
|
3
|
+
*
|
|
4
|
+
* The `ui://` scheme is defined by the MCP Apps specification:
|
|
5
|
+
* `ui://<server>/<path>?<query>`
|
|
6
|
+
*
|
|
7
|
+
* The resolver rewrites these to the resource server's HTTP base URL so that
|
|
8
|
+
* platform WebViews can fetch the assets over plain HTTP(S).
|
|
9
|
+
*/
|
|
10
|
+
import type { ResourceUri } from "./types.js";
|
|
11
|
+
/**
|
|
12
|
+
* Parse a raw `ui://` URI string into its components.
|
|
13
|
+
*
|
|
14
|
+
* @throws {Error} if the URI does not start with `ui://`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseResourceUri(raw: string): ResourceUri;
|
|
17
|
+
/**
|
|
18
|
+
* Resolve a `ui://` URI to an HTTP URL using the given base URL.
|
|
19
|
+
*
|
|
20
|
+
* Example:
|
|
21
|
+
* ```
|
|
22
|
+
* resolveToHttp("ui://my-app/index.html", "https://resource.example.com")
|
|
23
|
+
* // => "https://resource.example.com/my-app/index.html"
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function resolveToHttp(uriOrString: ResourceUri | string, httpBaseUrl: string): string;
|
|
27
|
+
//# sourceMappingURL=resource-resolver.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-resolver.d.ts","sourceRoot":"","sources":["../../src/core/resource-resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAI9C;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,WAAW,CAqDzD;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC3B,WAAW,EAAE,WAAW,GAAG,MAAM,EACjC,WAAW,EAAE,MAAM,GAClB,MAAM,CAwBR"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Resolves `ui://` resource URIs to HTTP URLs served by the resource server.
|
|
4
|
+
*
|
|
5
|
+
* The `ui://` scheme is defined by the MCP Apps specification:
|
|
6
|
+
* `ui://<server>/<path>?<query>`
|
|
7
|
+
*
|
|
8
|
+
* The resolver rewrites these to the resource server's HTTP base URL so that
|
|
9
|
+
* platform WebViews can fetch the assets over plain HTTP(S).
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.parseResourceUri = parseResourceUri;
|
|
13
|
+
exports.resolveToHttp = resolveToHttp;
|
|
14
|
+
const UI_SCHEME = "ui://";
|
|
15
|
+
/**
|
|
16
|
+
* Parse a raw `ui://` URI string into its components.
|
|
17
|
+
*
|
|
18
|
+
* @throws {Error} if the URI does not start with `ui://`.
|
|
19
|
+
*/
|
|
20
|
+
function parseResourceUri(raw) {
|
|
21
|
+
if (!raw.startsWith(UI_SCHEME)) {
|
|
22
|
+
throw new Error(`[ResourceResolver] Invalid resource URI: expected "ui://" scheme, got "${raw}".`);
|
|
23
|
+
}
|
|
24
|
+
const withoutScheme = raw.slice(UI_SCHEME.length);
|
|
25
|
+
const queryIdx = withoutScheme.indexOf("?");
|
|
26
|
+
let serverAndPath;
|
|
27
|
+
let queryString = "";
|
|
28
|
+
if (queryIdx >= 0) {
|
|
29
|
+
serverAndPath = withoutScheme.slice(0, queryIdx);
|
|
30
|
+
queryString = withoutScheme.slice(queryIdx + 1);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
serverAndPath = withoutScheme;
|
|
34
|
+
}
|
|
35
|
+
const slashIdx = serverAndPath.indexOf("/");
|
|
36
|
+
let server;
|
|
37
|
+
let path;
|
|
38
|
+
if (slashIdx >= 0) {
|
|
39
|
+
server = serverAndPath.slice(0, slashIdx);
|
|
40
|
+
path = serverAndPath.slice(slashIdx);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
server = serverAndPath;
|
|
44
|
+
path = "/";
|
|
45
|
+
}
|
|
46
|
+
if (server.length === 0) {
|
|
47
|
+
throw new Error(`[ResourceResolver] Invalid resource URI: empty server in "${raw}".`);
|
|
48
|
+
}
|
|
49
|
+
const query = {};
|
|
50
|
+
if (queryString.length > 0) {
|
|
51
|
+
for (const pair of queryString.split("&")) {
|
|
52
|
+
const eqIdx = pair.indexOf("=");
|
|
53
|
+
if (eqIdx >= 0) {
|
|
54
|
+
query[decodeURIComponent(pair.slice(0, eqIdx))] = decodeURIComponent(pair.slice(eqIdx + 1));
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
query[decodeURIComponent(pair)] = "";
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return { raw, server, path, query };
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Resolve a `ui://` URI to an HTTP URL using the given base URL.
|
|
65
|
+
*
|
|
66
|
+
* Example:
|
|
67
|
+
* ```
|
|
68
|
+
* resolveToHttp("ui://my-app/index.html", "https://resource.example.com")
|
|
69
|
+
* // => "https://resource.example.com/my-app/index.html"
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
function resolveToHttp(uriOrString, httpBaseUrl) {
|
|
73
|
+
const uri = typeof uriOrString === "string"
|
|
74
|
+
? parseResourceUri(uriOrString)
|
|
75
|
+
: uriOrString;
|
|
76
|
+
const base = httpBaseUrl.endsWith("/")
|
|
77
|
+
? httpBaseUrl.slice(0, -1)
|
|
78
|
+
: httpBaseUrl;
|
|
79
|
+
const pathPart = uri.path.startsWith("/") ? uri.path : `/${uri.path}`;
|
|
80
|
+
const queryEntries = Object.entries(uri.query);
|
|
81
|
+
let url = `${base}/${uri.server}${pathPart}`;
|
|
82
|
+
if (queryEntries.length > 0) {
|
|
83
|
+
const qs = queryEntries
|
|
84
|
+
.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)
|
|
85
|
+
.join("&");
|
|
86
|
+
url += `?${qs}`;
|
|
87
|
+
}
|
|
88
|
+
return url;
|
|
89
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { McpAppsMessage } from "./types.js";
|
|
2
|
+
/** Handler invoked when the transport receives a message. */
|
|
3
|
+
export type TransportMessageHandler = (message: McpAppsMessage) => void;
|
|
4
|
+
/** Handler invoked when the transport connection state changes. */
|
|
5
|
+
export type TransportStateHandler = (connected: boolean) => void;
|
|
6
|
+
/**
|
|
7
|
+
* Transport layer for bidirectional JSON-RPC communication between
|
|
8
|
+
* the bridge adapter and the resource server.
|
|
9
|
+
*/
|
|
10
|
+
export interface BridgeTransport {
|
|
11
|
+
/** Send a JSON-RPC message to the resource server. */
|
|
12
|
+
send(message: McpAppsMessage): void;
|
|
13
|
+
/** Register a handler for incoming messages from the resource server. */
|
|
14
|
+
onMessage(handler: TransportMessageHandler): void;
|
|
15
|
+
/** Register a handler for connection state changes. */
|
|
16
|
+
onStateChange(handler: TransportStateHandler): void;
|
|
17
|
+
/** Connect to the resource server at the given URL. */
|
|
18
|
+
connect(url: string): Promise<void>;
|
|
19
|
+
/** Disconnect from the resource server. */
|
|
20
|
+
disconnect(): void;
|
|
21
|
+
/** Whether the transport is currently connected. */
|
|
22
|
+
readonly connected: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* WebSocket-based transport for the MCP Apps Bridge.
|
|
26
|
+
*
|
|
27
|
+
* This is the primary transport. It provides full-duplex communication
|
|
28
|
+
* so the resource server can push notifications (tool results, context
|
|
29
|
+
* changes) to the app without polling.
|
|
30
|
+
*
|
|
31
|
+
* NOTE: This class uses browser WebSocket APIs. It is designed to run
|
|
32
|
+
* inside a platform webview (Telegram, LINE), not on the server side.
|
|
33
|
+
*/
|
|
34
|
+
export declare class WebSocketTransport implements BridgeTransport {
|
|
35
|
+
private ws;
|
|
36
|
+
private messageHandlers;
|
|
37
|
+
private stateHandlers;
|
|
38
|
+
send(message: McpAppsMessage): void;
|
|
39
|
+
onMessage(handler: TransportMessageHandler): void;
|
|
40
|
+
onStateChange(handler: TransportStateHandler): void;
|
|
41
|
+
connect(url: string): Promise<void>;
|
|
42
|
+
disconnect(): void;
|
|
43
|
+
get connected(): boolean;
|
|
44
|
+
private notifyState;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../../src/core/transport.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,6DAA6D;AAC7D,MAAM,MAAM,uBAAuB,GAAG,CAAC,OAAO,EAAE,cAAc,KAAK,IAAI,CAAC;AAExE,mEAAmE;AACnE,MAAM,MAAM,qBAAqB,GAAG,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,CAAC;AAEjE;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,sDAAsD;IACtD,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAAC;IAEpC,yEAAyE;IACzE,SAAS,CAAC,OAAO,EAAE,uBAAuB,GAAG,IAAI,CAAC;IAElD,uDAAuD;IACvD,aAAa,CAAC,OAAO,EAAE,qBAAqB,GAAG,IAAI,CAAC;IAEpD,uDAAuD;IACvD,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAEpC,2CAA2C;IAC3C,UAAU,IAAI,IAAI,CAAC;IAEnB,oDAAoD;IACpD,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC7B;AAED;;;;;;;;;GASG;AACH,qBAAa,kBAAmB,YAAW,eAAe;IAExD,OAAO,CAAC,EAAE,CAAa;IACvB,OAAO,CAAC,eAAe,CAAiC;IACxD,OAAO,CAAC,aAAa,CAA+B;IAEpD,IAAI,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI;IASnC,SAAS,CAAC,OAAO,EAAE,uBAAuB,GAAG,IAAI;IAIjD,aAAa,CAAC,OAAO,EAAE,qBAAqB,GAAG,IAAI;IAInD,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA8CnC,UAAU,IAAI,IAAI;IAOlB,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,OAAO,CAAC,WAAW;CAKpB"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.WebSocketTransport = void 0;
|
|
27
|
+
/**
|
|
28
|
+
* Transport abstraction for the MCP Apps Bridge.
|
|
29
|
+
*
|
|
30
|
+
* Defines how JSON-RPC messages travel between the bridge adapter
|
|
31
|
+
* (client-side, in the webview) and the resource server.
|
|
32
|
+
*
|
|
33
|
+
* The primary implementation is WebSocket, with HTTP POST as a fallback.
|
|
34
|
+
*/
|
|
35
|
+
const dntShim = __importStar(require("../_dnt.shims.js"));
|
|
36
|
+
/**
|
|
37
|
+
* WebSocket-based transport for the MCP Apps Bridge.
|
|
38
|
+
*
|
|
39
|
+
* This is the primary transport. It provides full-duplex communication
|
|
40
|
+
* so the resource server can push notifications (tool results, context
|
|
41
|
+
* changes) to the app without polling.
|
|
42
|
+
*
|
|
43
|
+
* NOTE: This class uses browser WebSocket APIs. It is designed to run
|
|
44
|
+
* inside a platform webview (Telegram, LINE), not on the server side.
|
|
45
|
+
*/
|
|
46
|
+
class WebSocketTransport {
|
|
47
|
+
// deno-lint-ignore no-explicit-any
|
|
48
|
+
ws = null; // WebSocket instance (browser API)
|
|
49
|
+
messageHandlers = [];
|
|
50
|
+
stateHandlers = [];
|
|
51
|
+
send(message) {
|
|
52
|
+
if (!this.ws || this.ws.readyState !== 1 /* WebSocket.OPEN */) {
|
|
53
|
+
throw new Error("[WebSocketTransport] Not connected. Call connect() first.");
|
|
54
|
+
}
|
|
55
|
+
this.ws.send(JSON.stringify(message));
|
|
56
|
+
}
|
|
57
|
+
onMessage(handler) {
|
|
58
|
+
this.messageHandlers.push(handler);
|
|
59
|
+
}
|
|
60
|
+
onStateChange(handler) {
|
|
61
|
+
this.stateHandlers.push(handler);
|
|
62
|
+
}
|
|
63
|
+
connect(url) {
|
|
64
|
+
// deno-lint-ignore no-explicit-any
|
|
65
|
+
const WS = dntShim.dntGlobalThis.WebSocket;
|
|
66
|
+
if (!WS) {
|
|
67
|
+
throw new Error("[WebSocketTransport] WebSocket API not available. " +
|
|
68
|
+
"This transport requires a browser environment.");
|
|
69
|
+
}
|
|
70
|
+
return new Promise((resolve, reject) => {
|
|
71
|
+
const ws = new WS(url);
|
|
72
|
+
ws.onopen = () => {
|
|
73
|
+
this.ws = ws;
|
|
74
|
+
this.notifyState(true);
|
|
75
|
+
resolve();
|
|
76
|
+
};
|
|
77
|
+
ws.onerror = () => {
|
|
78
|
+
reject(new Error(`[WebSocketTransport] Failed to connect to ${url}.`));
|
|
79
|
+
};
|
|
80
|
+
ws.onmessage = (event) => {
|
|
81
|
+
try {
|
|
82
|
+
const message = JSON.parse(event.data);
|
|
83
|
+
for (const handler of this.messageHandlers) {
|
|
84
|
+
handler(message);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
console.warn("[WebSocketTransport] Received non-JSON message, dropping:", err instanceof Error ? err.message : err);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
ws.onclose = () => {
|
|
92
|
+
this.ws = null;
|
|
93
|
+
this.notifyState(false);
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
disconnect() {
|
|
98
|
+
if (this.ws) {
|
|
99
|
+
this.ws.close();
|
|
100
|
+
this.ws = null;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
get connected() {
|
|
104
|
+
return this.ws !== null && this.ws.readyState === 1; /* WebSocket.OPEN */
|
|
105
|
+
}
|
|
106
|
+
notifyState(connected) {
|
|
107
|
+
for (const handler of this.stateHandlers) {
|
|
108
|
+
handler(connected);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.WebSocketTransport = WebSocketTransport;
|