@lovable.dev/mcp-js 3.3.1 → 3.5.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/README.internal.md +38 -12
- package/README.md +140 -12
- package/dist/THIRD_PARTY_NOTICES +75 -0
- package/dist/apps-CWG3rGhB.js +132 -0
- package/dist/apps-DyoDrwfi.cjs +185 -0
- package/dist/{authorize-CoaAw6wg.d.cts → authorize--W1XtwdB.d.cts} +1 -1
- package/dist/{authorize-BV62MDan.d.ts → authorize-DpNYioXM.d.ts} +1 -1
- package/dist/{base-Cx0spfMk.d.ts → base-Ce9JYirF.d.ts} +1 -1
- package/dist/{base-CzWe8AD1.d.cts → base-qEX8YVcD.d.cts} +1 -1
- package/dist/cli/check-server.cjs +1 -1
- package/dist/cli/check-server.js +1 -1
- package/dist/cli/extract-manifest.cjs +1 -1
- package/dist/cli/extract-manifest.js +1 -1
- package/dist/{cors-3HjrsmEW.cjs → cors-B_Oui5La.cjs} +1 -1
- package/dist/{cors-CNNmKKIg.js → cors-D83r8WUF.js} +1 -1
- package/dist/dist-CIu-UFye.js +6738 -0
- package/dist/dist-CqY2qXpc.cjs +6738 -0
- package/dist/{errors-CIpFAb6i.js → errors-CfaxXr2T.js} +15 -2
- package/dist/{errors-C97I7VOC.cjs → errors-xJ_7Su1K.cjs} +20 -1
- package/dist/index.cjs +2 -1
- package/dist/index.d.cts +6 -2
- package/dist/index.d.ts +6 -2
- package/dist/index.js +2 -2
- package/dist/{io-D7cpdBJO.d.ts → io-BEpyfk4G.d.ts} +1 -1
- package/dist/{io-CaBSlPwS.cjs → io-CUnV4kTL.cjs} +12 -2
- package/dist/{io-DC-Y6R61.d.cts → io-Di5ljvZY.d.cts} +1 -1
- package/dist/{io-CahnhUhA.js → io-STpVLkbi.js} +13 -3
- package/dist/{mcp-DC8AoD18.js → mcp-BgIFUoo1.js} +110 -49
- package/dist/{mcp-DlWLIwX9.cjs → mcp-DpI0wwnW.cjs} +110 -49
- package/dist/mcp-app.d.ts +4 -0
- package/dist/{package-B488glmj.cjs → package-CuCho6-k.cjs} +1 -1
- package/dist/{package-CukfP_vq.js → package-Cz6Z5F_X.js} +1 -1
- package/dist/protocols/mcp/index.cjs +1 -1
- package/dist/protocols/mcp/index.d.cts +3 -3
- package/dist/protocols/mcp/index.d.ts +3 -3
- package/dist/protocols/mcp/index.js +1 -1
- package/dist/protocols/oauth-metadata.cjs +1 -1
- package/dist/protocols/oauth-metadata.d.cts +3 -3
- package/dist/protocols/oauth-metadata.d.ts +3 -3
- package/dist/protocols/oauth-metadata.js +1 -1
- package/dist/src-D7RtXSV0.cjs +311 -0
- package/dist/src-sWQwyLwS.js +310 -0
- package/dist/stacks/supabase/index.cjs +2 -2
- package/dist/stacks/supabase/index.d.cts +1 -1
- package/dist/stacks/supabase/index.d.ts +1 -1
- package/dist/stacks/supabase/index.js +2 -2
- package/dist/stacks/supabase/vite.cjs +10 -1
- package/dist/stacks/supabase/vite.d.cts +1 -1
- package/dist/stacks/supabase/vite.d.ts +1 -1
- package/dist/stacks/supabase/vite.js +21 -12
- package/dist/stacks/tanstack/index.cjs +33 -2
- package/dist/stacks/tanstack/index.d.cts +7 -4
- package/dist/stacks/tanstack/index.d.ts +7 -4
- package/dist/stacks/tanstack/index.js +33 -2
- package/dist/stacks/tanstack/vite.cjs +995 -15
- package/dist/stacks/tanstack/vite.d.cts +1 -1
- package/dist/stacks/tanstack/vite.d.ts +1 -1
- package/dist/stacks/tanstack/vite.js +1001 -21
- package/dist/testing/browser/LICENSE.ext-apps +218 -0
- package/dist/testing/browser/host.ts +151 -0
- package/dist/testing/browser/sandbox.ts +137 -0
- package/dist/testing/browser.cjs +382 -0
- package/dist/testing/browser.d.cts +46 -0
- package/dist/testing/browser.d.ts +46 -0
- package/dist/testing/browser.js +381 -0
- package/dist/testing/index.cjs +2 -1
- package/dist/testing/index.d.cts +2 -1
- package/dist/testing/index.d.ts +2 -1
- package/dist/testing/index.js +2 -1
- package/dist/testing/server.cjs +36 -0
- package/dist/testing/server.d.cts +6 -2
- package/dist/testing/server.d.ts +6 -2
- package/dist/testing/server.js +36 -1
- package/dist/{tool-result-DcNioyiI.js → tool-result-BG-HsSQu.js} +8 -1
- package/dist/{tool-result-rU-PpNNi.cjs → tool-result-BQcr7VV-.cjs} +8 -1
- package/dist/{types-z7T5bBIU.d.cts → types-B_dVw-zM.d.cts} +55 -1
- package/dist/{types-z7T5bBIU.d.ts → types-B_dVw-zM.d.ts} +55 -1
- package/package.json +66 -25
|
@@ -0,0 +1,381 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
import { build } from "esbuild";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { createServer } from "node:http";
|
|
7
|
+
//#region src/testing/browser/serve.ts
|
|
8
|
+
function sanitizeCspDomains(domains) {
|
|
9
|
+
if (!domains) return [];
|
|
10
|
+
return domains.filter((d) => typeof d === "string" && !/[;\r\n'" ]/.test(d));
|
|
11
|
+
}
|
|
12
|
+
function buildReleasedSpecCsp(csp) {
|
|
13
|
+
const frameDomains = sanitizeCspDomains(csp?.frameDomains).join(" ");
|
|
14
|
+
const baseUriDomains = sanitizeCspDomains(csp?.baseUriDomains).join(" ");
|
|
15
|
+
const tail = [
|
|
16
|
+
frameDomains ? `frame-src ${frameDomains}` : "frame-src 'none'",
|
|
17
|
+
"object-src 'none'",
|
|
18
|
+
baseUriDomains ? `base-uri ${baseUriDomains}` : "base-uri 'self'"
|
|
19
|
+
];
|
|
20
|
+
if (!csp) return [
|
|
21
|
+
"default-src 'none'",
|
|
22
|
+
"script-src 'self' 'unsafe-inline'",
|
|
23
|
+
"style-src 'self' 'unsafe-inline'",
|
|
24
|
+
"img-src 'self' data:",
|
|
25
|
+
"media-src 'self' data:",
|
|
26
|
+
"connect-src 'none'",
|
|
27
|
+
...tail
|
|
28
|
+
].join("; ");
|
|
29
|
+
const resourceDomains = sanitizeCspDomains(csp.resourceDomains).join(" ");
|
|
30
|
+
const connectDomains = sanitizeCspDomains(csp.connectDomains).join(" ");
|
|
31
|
+
return [
|
|
32
|
+
"default-src 'none'",
|
|
33
|
+
`script-src 'self' 'unsafe-inline' ${resourceDomains}`.trim(),
|
|
34
|
+
`style-src 'self' 'unsafe-inline' ${resourceDomains}`.trim(),
|
|
35
|
+
`connect-src 'self' ${connectDomains}`.trim(),
|
|
36
|
+
`img-src 'self' data: ${resourceDomains}`.trim(),
|
|
37
|
+
`font-src 'self' ${resourceDomains}`.trim(),
|
|
38
|
+
`media-src 'self' data: ${resourceDomains}`.trim(),
|
|
39
|
+
...tail
|
|
40
|
+
].join("; ");
|
|
41
|
+
}
|
|
42
|
+
function buildReferenceHostCsp(csp) {
|
|
43
|
+
const resourceDomains = sanitizeCspDomains(csp?.resourceDomains).join(" ");
|
|
44
|
+
const connectDomains = sanitizeCspDomains(csp?.connectDomains).join(" ");
|
|
45
|
+
const frameDomains = sanitizeCspDomains(csp?.frameDomains).join(" ") || null;
|
|
46
|
+
const baseUriDomains = sanitizeCspDomains(csp?.baseUriDomains).join(" ") || null;
|
|
47
|
+
return [
|
|
48
|
+
"default-src 'self' 'unsafe-inline'",
|
|
49
|
+
`script-src 'self' 'unsafe-inline' 'unsafe-eval' blob: data: ${resourceDomains}`.trim(),
|
|
50
|
+
`style-src 'self' 'unsafe-inline' blob: data: ${resourceDomains}`.trim(),
|
|
51
|
+
`img-src 'self' data: blob: ${resourceDomains}`.trim(),
|
|
52
|
+
`font-src 'self' data: blob: ${resourceDomains}`.trim(),
|
|
53
|
+
`media-src 'self' data: blob: ${resourceDomains}`.trim(),
|
|
54
|
+
`connect-src 'self' ${connectDomains}`.trim(),
|
|
55
|
+
`worker-src 'self' blob: ${resourceDomains}`.trim(),
|
|
56
|
+
frameDomains ? `frame-src ${frameDomains}` : "frame-src 'none'",
|
|
57
|
+
"object-src 'none'",
|
|
58
|
+
baseUriDomains ? `base-uri ${baseUriDomains}` : "base-uri 'none'"
|
|
59
|
+
].join("; ");
|
|
60
|
+
}
|
|
61
|
+
const cspPolicies = {
|
|
62
|
+
"released-spec": buildReleasedSpecCsp,
|
|
63
|
+
"reference-host": buildReferenceHostCsp
|
|
64
|
+
};
|
|
65
|
+
const SANDBOX_HTML = `<!doctype html>
|
|
66
|
+
<html>
|
|
67
|
+
<head>
|
|
68
|
+
<meta charset="utf-8" />
|
|
69
|
+
<meta name="color-scheme" content="light dark">
|
|
70
|
+
<title>MCP-UI Proxy</title>
|
|
71
|
+
<style>
|
|
72
|
+
html, body { margin: 0; height: 100vh; width: 100vw; background-color: transparent; }
|
|
73
|
+
body { display: flex; flex-direction: column; }
|
|
74
|
+
* { box-sizing: border-box; }
|
|
75
|
+
iframe { background-color: transparent; border: 0px none transparent; padding: 0px; overflow: hidden; flex-grow: 1; color-scheme: inherit; }
|
|
76
|
+
</style>
|
|
77
|
+
</head>
|
|
78
|
+
<body>
|
|
79
|
+
<script src="/sandbox.js"><\/script>
|
|
80
|
+
</body>
|
|
81
|
+
</html>`;
|
|
82
|
+
const HOST_HTML = `<!doctype html>
|
|
83
|
+
<html>
|
|
84
|
+
<head><meta charset="utf-8" /><title>MCP Apps test host</title></head>
|
|
85
|
+
<body><script src="/host.js"><\/script></body>
|
|
86
|
+
</html>`;
|
|
87
|
+
async function bundle(entry, globalName) {
|
|
88
|
+
return (await build({
|
|
89
|
+
entryPoints: [fileURLToPath(entry)],
|
|
90
|
+
bundle: true,
|
|
91
|
+
write: false,
|
|
92
|
+
format: "iife",
|
|
93
|
+
globalName,
|
|
94
|
+
platform: "browser",
|
|
95
|
+
plugins: [{
|
|
96
|
+
name: "fixture-bridge-compatibility",
|
|
97
|
+
setup(builder) {
|
|
98
|
+
builder.onResolve({ filter: /^@modelcontextprotocol\/ext-apps\/app-bridge$/ }, async (args) => {
|
|
99
|
+
if (args.pluginData?.bridgeResolved) return;
|
|
100
|
+
const resolved = await builder.resolve(args.path, {
|
|
101
|
+
importer: args.importer,
|
|
102
|
+
resolveDir: args.resolveDir,
|
|
103
|
+
kind: args.kind,
|
|
104
|
+
pluginData: { bridgeResolved: true }
|
|
105
|
+
});
|
|
106
|
+
if (resolved.errors.length > 0) return resolved;
|
|
107
|
+
for (let dir = dirname(resolved.path);; dir = dirname(dir)) {
|
|
108
|
+
let manifest;
|
|
109
|
+
try {
|
|
110
|
+
manifest = JSON.parse(readFileSync(join(dir, "package.json"), "utf8"));
|
|
111
|
+
} catch (error) {
|
|
112
|
+
if (error.code !== "ENOENT") throw error;
|
|
113
|
+
}
|
|
114
|
+
if (manifest?.name === "@modelcontextprotocol/ext-apps") {
|
|
115
|
+
const version = String(manifest.version);
|
|
116
|
+
const stable = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:\+[\da-zA-Z-]+(?:\.[\da-zA-Z-]+)*)?$/.exec(version);
|
|
117
|
+
if (!stable || Number(stable[1]) !== 1 || Number(stable[2]) < 7 || Number(stable[2]) === 7 && Number(stable[3]) < 3) throw new Error(`MCP Apps browser fixture resolved @modelcontextprotocol/ext-apps ${version} at ${dir}; supported range is ^1.7.3 (stable releases). Preserve existing project pins; use a compatible installation for this fixture or explicitly agree a dependency change before testing.`);
|
|
118
|
+
return resolved;
|
|
119
|
+
}
|
|
120
|
+
if (dirname(dir) === dir) throw new Error(`Cannot identify the MCP Apps fixture bridge package at ${resolved.path}`);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
}]
|
|
125
|
+
})).outputFiles[0].text;
|
|
126
|
+
}
|
|
127
|
+
function listen(server) {
|
|
128
|
+
return new Promise((resolve, reject) => {
|
|
129
|
+
server.once("error", reject);
|
|
130
|
+
server.listen(0, "127.0.0.1", () => resolve(`http://127.0.0.1:${server.address().port}`));
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
function close(server) {
|
|
134
|
+
return new Promise((resolve) => {
|
|
135
|
+
server.closeAllConnections();
|
|
136
|
+
server.close(() => resolve());
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
async function readBody(request) {
|
|
140
|
+
const chunks = [];
|
|
141
|
+
for await (const chunk of request) chunks.push(chunk);
|
|
142
|
+
return Buffer.concat(chunks);
|
|
143
|
+
}
|
|
144
|
+
function send(response, status, type, body, headers = {}) {
|
|
145
|
+
response.writeHead(status, {
|
|
146
|
+
"Content-Type": type,
|
|
147
|
+
...headers
|
|
148
|
+
});
|
|
149
|
+
response.end(body);
|
|
150
|
+
}
|
|
151
|
+
async function forward(request, body, response, origin, handler) {
|
|
152
|
+
const headers = new Headers();
|
|
153
|
+
for (const [name, value] of Object.entries(request.headers)) {
|
|
154
|
+
if ([
|
|
155
|
+
"host",
|
|
156
|
+
"connection",
|
|
157
|
+
"content-length"
|
|
158
|
+
].includes(name) || value === void 0) continue;
|
|
159
|
+
for (const item of Array.isArray(value) ? value : [value]) headers.append(name, item);
|
|
160
|
+
}
|
|
161
|
+
const method = request.method ?? "GET";
|
|
162
|
+
const result = await handler(new Request(new URL("/mcp", origin), {
|
|
163
|
+
method,
|
|
164
|
+
headers,
|
|
165
|
+
body: method === "GET" || method === "HEAD" ? void 0 : Uint8Array.from(body)
|
|
166
|
+
}));
|
|
167
|
+
response.writeHead(result.status, Object.fromEntries(result.headers));
|
|
168
|
+
if (result.body) {
|
|
169
|
+
const reader = result.body.getReader();
|
|
170
|
+
for (;;) {
|
|
171
|
+
const { done, value } = await reader.read();
|
|
172
|
+
if (done) break;
|
|
173
|
+
response.write(value);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
response.end();
|
|
177
|
+
}
|
|
178
|
+
function parseRpc(body) {
|
|
179
|
+
try {
|
|
180
|
+
const message = JSON.parse(body.toString("utf8"));
|
|
181
|
+
return {
|
|
182
|
+
method: message?.method,
|
|
183
|
+
params: message?.params
|
|
184
|
+
};
|
|
185
|
+
} catch {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Starts the host origin (host page + authenticated MCP endpoints) and a
|
|
191
|
+
* separate sandbox origin that serves only the proxy with an HTTP CSP header.
|
|
192
|
+
* Both bind to 127.0.0.1 on different ports, as upstream uses 8080/8081.
|
|
193
|
+
*/
|
|
194
|
+
async function startServers(assets) {
|
|
195
|
+
const [hostScript, sandboxScript] = await Promise.all([bundle(new URL("host.ts", assets), "host"), bundle(new URL("sandbox.ts", assets))]);
|
|
196
|
+
const backends = /* @__PURE__ */ new Map();
|
|
197
|
+
const hostRequests = [];
|
|
198
|
+
const sandboxRequests = [];
|
|
199
|
+
const policies = /* @__PURE__ */ new Map();
|
|
200
|
+
let hostOrigin = "";
|
|
201
|
+
const host = createServer((request, response) => {
|
|
202
|
+
const url = new URL(request.url ?? "/", hostOrigin);
|
|
203
|
+
const backend = backends.get(url.pathname);
|
|
204
|
+
if (backend) {
|
|
205
|
+
(async () => {
|
|
206
|
+
const body = await readBody(request);
|
|
207
|
+
hostRequests.push({
|
|
208
|
+
method: request.method ?? "GET",
|
|
209
|
+
path: url.pathname,
|
|
210
|
+
authorization: request.headers.authorization,
|
|
211
|
+
rpc: body.length > 0 ? parseRpc(body) : void 0
|
|
212
|
+
});
|
|
213
|
+
await forward(request, body, response, hostOrigin, backend);
|
|
214
|
+
})().catch(() => {
|
|
215
|
+
if (!response.headersSent) send(response, 500, "text/plain", "Fixture handler failed");
|
|
216
|
+
else response.end();
|
|
217
|
+
});
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
hostRequests.push({
|
|
221
|
+
method: request.method ?? "GET",
|
|
222
|
+
path: url.pathname
|
|
223
|
+
});
|
|
224
|
+
if (url.pathname === "/") return send(response, 200, "text/html", HOST_HTML);
|
|
225
|
+
if (url.pathname === "/host.js") return send(response, 200, "text/javascript", hostScript);
|
|
226
|
+
if (url.pathname === "/sandbox.html") return send(response, 404, "text/plain", "Sandbox is served on a different origin");
|
|
227
|
+
send(response, 404, "text/plain", "Not found");
|
|
228
|
+
});
|
|
229
|
+
const sandbox = createServer((request, response) => {
|
|
230
|
+
const url = new URL(request.url ?? "/", "http://sandbox.invalid");
|
|
231
|
+
if (url.pathname === "/sandbox.js") {
|
|
232
|
+
sandboxRequests.push({ url: request.url ?? "" });
|
|
233
|
+
return send(response, 200, "text/javascript", sandboxScript);
|
|
234
|
+
}
|
|
235
|
+
if (url.pathname !== "/sandbox.html") {
|
|
236
|
+
sandboxRequests.push({ url: request.url ?? "" });
|
|
237
|
+
return send(response, 404, "text/plain", "Only sandbox.html is served on this origin");
|
|
238
|
+
}
|
|
239
|
+
const csp = policies.get(url.searchParams.get("mount") ?? "");
|
|
240
|
+
if (!csp) return send(response, 404, "text/plain", "Unknown mount");
|
|
241
|
+
sandboxRequests.push({
|
|
242
|
+
url: request.url ?? "",
|
|
243
|
+
csp
|
|
244
|
+
});
|
|
245
|
+
send(response, 200, "text/html", SANDBOX_HTML, {
|
|
246
|
+
"Content-Security-Policy": csp,
|
|
247
|
+
"Cache-Control": "no-cache, no-store, must-revalidate",
|
|
248
|
+
Pragma: "no-cache",
|
|
249
|
+
Expires: "0"
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
hostOrigin = await listen(host);
|
|
253
|
+
const sandboxOrigin = await listen(sandbox).catch(async (error) => {
|
|
254
|
+
await close(host);
|
|
255
|
+
throw error;
|
|
256
|
+
});
|
|
257
|
+
return {
|
|
258
|
+
hostOrigin,
|
|
259
|
+
sandboxOrigin,
|
|
260
|
+
registerResource(csp, policy = "released-spec") {
|
|
261
|
+
const id = randomUUID();
|
|
262
|
+
policies.set(id, cspPolicies[policy](csp));
|
|
263
|
+
return `${sandboxOrigin}/sandbox.html?mount=${id}`;
|
|
264
|
+
},
|
|
265
|
+
/** Mount an MCP handler at a host-origin path, e.g. `/mcp`. */
|
|
266
|
+
backends,
|
|
267
|
+
hostRequests,
|
|
268
|
+
sandboxRequests,
|
|
269
|
+
close: () => Promise.all([close(host), close(sandbox)])
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
//#endregion
|
|
273
|
+
//#region src/testing/browser.ts
|
|
274
|
+
async function createAppFixture(browser, options = {}) {
|
|
275
|
+
const servers = await startServers(new URL("./browser/", import.meta.url));
|
|
276
|
+
const context = await browser.newContext({
|
|
277
|
+
viewport: options.viewport ?? {
|
|
278
|
+
width: 800,
|
|
279
|
+
height: 700
|
|
280
|
+
},
|
|
281
|
+
serviceWorkers: "block",
|
|
282
|
+
acceptDownloads: false
|
|
283
|
+
}).catch(async (error) => {
|
|
284
|
+
await servers.close();
|
|
285
|
+
throw error;
|
|
286
|
+
});
|
|
287
|
+
const pending = /* @__PURE__ */ new Map();
|
|
288
|
+
const requests = [];
|
|
289
|
+
try {
|
|
290
|
+
await context.routeWebSocket("**/*", (socket) => socket.close());
|
|
291
|
+
await context.route("**/*", (route) => {
|
|
292
|
+
const url = new URL(route.request().url());
|
|
293
|
+
return (url.origin === servers.hostOrigin && ["/", "/host.js"].includes(url.pathname) || url.origin === servers.sandboxOrigin && ["/sandbox.html", "/sandbox.js"].includes(url.pathname)) && route.request().method() === "GET" ? route.continue() : route.abort();
|
|
294
|
+
});
|
|
295
|
+
const page = await context.newPage();
|
|
296
|
+
context.on("page", (popup) => {
|
|
297
|
+
popup.close();
|
|
298
|
+
});
|
|
299
|
+
page.setDefaultTimeout(options.timeoutMs ?? 1e4);
|
|
300
|
+
await page.exposeBinding("mcpFixtureCall", async ({ frame }, id, params) => {
|
|
301
|
+
if (frame !== page.mainFrame() || frame.url() !== `${servers.hostOrigin}/`) throw new Error("Only the fixture host may call tools.");
|
|
302
|
+
requests.push(params);
|
|
303
|
+
const controller = new AbortController();
|
|
304
|
+
pending.set(id, controller);
|
|
305
|
+
try {
|
|
306
|
+
if (!options.onCallTool) return {
|
|
307
|
+
isError: true,
|
|
308
|
+
content: [{
|
|
309
|
+
type: "text",
|
|
310
|
+
text: "No test response configured for this tool call."
|
|
311
|
+
}]
|
|
312
|
+
};
|
|
313
|
+
return await options.onCallTool(params, controller.signal);
|
|
314
|
+
} catch {
|
|
315
|
+
return {
|
|
316
|
+
isError: true,
|
|
317
|
+
content: [{
|
|
318
|
+
type: "text",
|
|
319
|
+
text: "The test's tool response failed. Inspect the Node-side test."
|
|
320
|
+
}]
|
|
321
|
+
};
|
|
322
|
+
} finally {
|
|
323
|
+
pending.delete(id);
|
|
324
|
+
}
|
|
325
|
+
});
|
|
326
|
+
await page.exposeBinding("mcpFixtureCancel", ({ frame }, id) => {
|
|
327
|
+
if (frame === page.mainFrame() && frame.url() === `${servers.hostOrigin}/`) pending.get(id)?.abort();
|
|
328
|
+
});
|
|
329
|
+
await page.goto(`${servers.hostOrigin}/`);
|
|
330
|
+
return {
|
|
331
|
+
page,
|
|
332
|
+
view: page.frameLocator("iframe[title=\"MCP App\"]").frameLocator("iframe"),
|
|
333
|
+
requests,
|
|
334
|
+
async mount(resource, mount = {}) {
|
|
335
|
+
if (resource.mimeType !== "text/html;profile=mcp-app") throw new Error("Mount a UI resource with MIME text/html;profile=mcp-app.");
|
|
336
|
+
const ui = resource._meta?.ui;
|
|
337
|
+
const data = {
|
|
338
|
+
resource: {
|
|
339
|
+
text: resource.text,
|
|
340
|
+
uri: resource.uri,
|
|
341
|
+
mimeType: resource.mimeType
|
|
342
|
+
},
|
|
343
|
+
sandboxUrl: servers.registerResource(ui?.csp, mount.policy),
|
|
344
|
+
csp: ui?.csp,
|
|
345
|
+
permissions: ui?.permissions,
|
|
346
|
+
capabilities: mount.capabilities ?? { serverTools: {} },
|
|
347
|
+
context: mount.context ?? {},
|
|
348
|
+
arguments: mount.arguments,
|
|
349
|
+
result: mount.result,
|
|
350
|
+
initialize: mount.initialize
|
|
351
|
+
};
|
|
352
|
+
let timer;
|
|
353
|
+
try {
|
|
354
|
+
await Promise.race([page.evaluate((value) => host.mount(value), data), new Promise((_, reject) => {
|
|
355
|
+
timer = setTimeout(() => reject(/* @__PURE__ */ new Error("App did not initialize; inspect the view's bridge connection and browser errors.")), options.timeoutMs ?? 1e4);
|
|
356
|
+
})]);
|
|
357
|
+
} finally {
|
|
358
|
+
clearTimeout(timer);
|
|
359
|
+
}
|
|
360
|
+
},
|
|
361
|
+
deliverResult: (result) => page.evaluate((value) => host.bridge.sendToolResult(value), result),
|
|
362
|
+
updateContext: (value) => page.evaluate((value) => host.bridge.sendHostContextChange(value), value),
|
|
363
|
+
cancel: (reason) => page.evaluate((reason) => host.bridge.sendToolCancelled({ reason }), reason),
|
|
364
|
+
teardown: () => page.evaluate(() => host.teardown()),
|
|
365
|
+
settle: async () => {
|
|
366
|
+
await page.evaluate(() => host.settle());
|
|
367
|
+
},
|
|
368
|
+
async close() {
|
|
369
|
+
for (const controller of pending.values()) controller.abort();
|
|
370
|
+
await context.close();
|
|
371
|
+
await servers.close();
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
} catch (error) {
|
|
375
|
+
await context.close();
|
|
376
|
+
await servers.close();
|
|
377
|
+
throw error;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
//#endregion
|
|
381
|
+
export { createAppFixture };
|
package/dist/testing/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_schema = require("../schema-DNMsvJwE.cjs");
|
|
3
|
-
const require_tool_result = require("../tool-result-
|
|
3
|
+
const require_tool_result = require("../tool-result-BQcr7VV-.cjs");
|
|
4
4
|
const require_diagnostic = require("../diagnostic-ol9IE9Dl.cjs");
|
|
5
5
|
let _modelcontextprotocol_sdk_server_zod_compat_js = require("@modelcontextprotocol/sdk/server/zod-compat.js");
|
|
6
6
|
let _modelcontextprotocol_core = require("@modelcontextprotocol/core");
|
|
@@ -40,6 +40,7 @@ async function assertToolResult(result, expected = {}) {
|
|
|
40
40
|
} catch {}
|
|
41
41
|
if (!valid) fail("result.output-schema", "Successful structuredContent must be present and match the declared outputSchema.");
|
|
42
42
|
}
|
|
43
|
+
if (expected.ui && require_tool_result.normalizeToolContent(value.content).length === 0) fail("result.ui-fallback", "mcp-js UI tools need content for hosts without a view; include a text summary.");
|
|
43
44
|
}
|
|
44
45
|
//#endregion
|
|
45
46
|
exports.McpCheckError = require_diagnostic.McpCheckError;
|
package/dist/testing/index.d.cts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { j as ZodOutputSchema } from "../types-B_dVw-zM.cjs";
|
|
2
2
|
import { n as McpCheckError, t as Diagnostic } from "../diagnostic-DRKjgCsW.cjs";
|
|
3
3
|
//#region src/testing/result.d.ts
|
|
4
4
|
interface ToolResultExpectation {
|
|
5
5
|
outputSchema?: ZodOutputSchema;
|
|
6
6
|
isError?: boolean;
|
|
7
|
+
ui?: boolean;
|
|
7
8
|
}
|
|
8
9
|
declare function assertToolResult(result: unknown, expected?: ToolResultExpectation): Promise<void>;
|
|
9
10
|
//#endregion
|
package/dist/testing/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { j as ZodOutputSchema } from "../types-B_dVw-zM.js";
|
|
2
2
|
import { n as McpCheckError, t as Diagnostic } from "../diagnostic-DRKjgCsW.js";
|
|
3
3
|
//#region src/testing/result.d.ts
|
|
4
4
|
interface ToolResultExpectation {
|
|
5
5
|
outputSchema?: ZodOutputSchema;
|
|
6
6
|
isError?: boolean;
|
|
7
|
+
ui?: boolean;
|
|
7
8
|
}
|
|
8
9
|
declare function assertToolResult(result: unknown, expected?: ToolResultExpectation): Promise<void>;
|
|
9
10
|
//#endregion
|
package/dist/testing/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as schemaFromDefinition } from "../schema-JK_1KkOa.js";
|
|
2
|
-
import { n as isJsonValue, r as normalizeToolContent } from "../tool-result-
|
|
2
|
+
import { n as isJsonValue, r as normalizeToolContent } from "../tool-result-BG-HsSQu.js";
|
|
3
3
|
import { t as McpCheckError } from "../diagnostic-ClI2_5MW.js";
|
|
4
4
|
import { safeParseAsync } from "@modelcontextprotocol/sdk/server/zod-compat.js";
|
|
5
5
|
import { CallToolResultSchema } from "@modelcontextprotocol/core";
|
|
@@ -39,6 +39,7 @@ async function assertToolResult(result, expected = {}) {
|
|
|
39
39
|
} catch {}
|
|
40
40
|
if (!valid) fail("result.output-schema", "Successful structuredContent must be present and match the declared outputSchema.");
|
|
41
41
|
}
|
|
42
|
+
if (expected.ui && normalizeToolContent(value.content).length === 0) fail("result.ui-fallback", "mcp-js UI tools need content for hosts without a view; include a text summary.");
|
|
42
43
|
}
|
|
43
44
|
//#endregion
|
|
44
45
|
export { McpCheckError, assertToolResult };
|
package/dist/testing/server.cjs
CHANGED
|
@@ -70,6 +70,27 @@ async function withMcpClient(options, run) {
|
|
|
70
70
|
await client.close();
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
|
+
async function readUiResource(client, uri, timeoutMs = 1e4) {
|
|
74
|
+
const content = (await client.readResource({ uri }, {
|
|
75
|
+
cacheMode: "bypass",
|
|
76
|
+
timeout: timeoutMs
|
|
77
|
+
}).catch(() => {
|
|
78
|
+
throw new require_diagnostic.McpCheckError({
|
|
79
|
+
code: "resource.read",
|
|
80
|
+
basis: "protocol-requirement",
|
|
81
|
+
message: "The UI resource could not be read. Check registration and the configured caller's access; response details are omitted."
|
|
82
|
+
});
|
|
83
|
+
})).contents.find((entry) => entry.uri === uri && entry.mimeType === "text/html;profile=mcp-app");
|
|
84
|
+
if (!content) throw new require_diagnostic.McpCheckError({
|
|
85
|
+
code: "resource.ui-content",
|
|
86
|
+
basis: "protocol-requirement",
|
|
87
|
+
message: "The linked resource must return HTML with MIME text/html;profile=mcp-app at its URI."
|
|
88
|
+
});
|
|
89
|
+
return {
|
|
90
|
+
...content,
|
|
91
|
+
text: "text" in content ? content.text : Buffer.from(content.blob, "base64").toString("utf8")
|
|
92
|
+
};
|
|
93
|
+
}
|
|
73
94
|
async function checkMcpServer(options) {
|
|
74
95
|
const checks = [];
|
|
75
96
|
const calls = options.calls ?? [];
|
|
@@ -96,6 +117,7 @@ async function checkMcpServer(options) {
|
|
|
96
117
|
}) : { tools: [] };
|
|
97
118
|
record(stage, "The official client decoded the tool catalog; the tools capability is optional.");
|
|
98
119
|
const unsupported = /* @__PURE__ */ new Set();
|
|
120
|
+
const read = /* @__PURE__ */ new Set();
|
|
99
121
|
for (const [index, tool] of tools.entries()) {
|
|
100
122
|
location = `tools[${index}]`;
|
|
101
123
|
stage = "server.schemas";
|
|
@@ -107,6 +129,19 @@ async function checkMcpServer(options) {
|
|
|
107
129
|
} else new _modelcontextprotocol_client_validators_ajv.AjvJsonSchemaValidator().getValidator(schema);
|
|
108
130
|
}
|
|
109
131
|
if (!unsupported.has(tool.name)) record(stage, "Advertised schemas compile with the SDK validator.");
|
|
132
|
+
const uri = (tool._meta?.ui)?.resourceUri ?? tool._meta?.["ui/resourceUri"];
|
|
133
|
+
if (uri === void 0) continue;
|
|
134
|
+
stage = "resource.ui-link";
|
|
135
|
+
if (typeof uri !== "string" || !uri.startsWith("ui://")) throw new require_diagnostic.McpCheckError({
|
|
136
|
+
code: stage,
|
|
137
|
+
basis: "protocol-requirement",
|
|
138
|
+
message: "Tool UI resourceUri must name a ui:// resource."
|
|
139
|
+
});
|
|
140
|
+
if (read.has(uri)) continue;
|
|
141
|
+
stage = "resource.read";
|
|
142
|
+
await readUiResource(client, uri, timeout);
|
|
143
|
+
record(stage, "The linked UI resource is readable as HTML.");
|
|
144
|
+
read.add(uri);
|
|
110
145
|
}
|
|
111
146
|
for (; nextCall < calls.length; nextCall++) {
|
|
112
147
|
const call = calls[nextCall];
|
|
@@ -194,4 +229,5 @@ async function checkMcpServer(options) {
|
|
|
194
229
|
}
|
|
195
230
|
//#endregion
|
|
196
231
|
exports.checkMcpServer = checkMcpServer;
|
|
232
|
+
exports.readUiResource = readUiResource;
|
|
197
233
|
exports.withMcpClient = withMcpClient;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as Diagnostic } from "../diagnostic-DRKjgCsW.cjs";
|
|
2
|
-
import { Client, ClientCapabilities } from "@modelcontextprotocol/client";
|
|
2
|
+
import { Client, ClientCapabilities, ReadResourceResult } from "@modelcontextprotocol/client";
|
|
3
3
|
//#region src/testing/server.d.ts
|
|
4
4
|
type ProtocolVersion = "2025-11-25" | "2026-07-28";
|
|
5
5
|
interface McpTestConnection {
|
|
@@ -11,6 +11,10 @@ interface McpTestConnection {
|
|
|
11
11
|
timeoutMs?: number;
|
|
12
12
|
}
|
|
13
13
|
declare function withMcpClient<T>(options: McpTestConnection, run: (client: Client) => Promise<T>): Promise<T>;
|
|
14
|
+
type UiResource = ReadResourceResult["contents"][number] & {
|
|
15
|
+
text: string;
|
|
16
|
+
};
|
|
17
|
+
declare function readUiResource(client: Client, uri: string, timeoutMs?: number): Promise<UiResource>;
|
|
14
18
|
interface ServerCheck extends Diagnostic {
|
|
15
19
|
status: "passed" | "failed" | "not-tested";
|
|
16
20
|
location?: string;
|
|
@@ -28,4 +32,4 @@ interface ServerCheckOptions extends McpTestConnection {
|
|
|
28
32
|
}
|
|
29
33
|
declare function checkMcpServer(options: ServerCheckOptions): Promise<ServerCheckReport>;
|
|
30
34
|
//#endregion
|
|
31
|
-
export { McpTestConnection, ProtocolVersion, ServerCheck, ServerCheckOptions, ServerCheckReport, checkMcpServer, withMcpClient };
|
|
35
|
+
export { McpTestConnection, ProtocolVersion, ServerCheck, ServerCheckOptions, ServerCheckReport, UiResource, checkMcpServer, readUiResource, withMcpClient };
|
package/dist/testing/server.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as Diagnostic } from "../diagnostic-DRKjgCsW.js";
|
|
2
|
-
import { Client, ClientCapabilities } from "@modelcontextprotocol/client";
|
|
2
|
+
import { Client, ClientCapabilities, ReadResourceResult } from "@modelcontextprotocol/client";
|
|
3
3
|
//#region src/testing/server.d.ts
|
|
4
4
|
type ProtocolVersion = "2025-11-25" | "2026-07-28";
|
|
5
5
|
interface McpTestConnection {
|
|
@@ -11,6 +11,10 @@ interface McpTestConnection {
|
|
|
11
11
|
timeoutMs?: number;
|
|
12
12
|
}
|
|
13
13
|
declare function withMcpClient<T>(options: McpTestConnection, run: (client: Client) => Promise<T>): Promise<T>;
|
|
14
|
+
type UiResource = ReadResourceResult["contents"][number] & {
|
|
15
|
+
text: string;
|
|
16
|
+
};
|
|
17
|
+
declare function readUiResource(client: Client, uri: string, timeoutMs?: number): Promise<UiResource>;
|
|
14
18
|
interface ServerCheck extends Diagnostic {
|
|
15
19
|
status: "passed" | "failed" | "not-tested";
|
|
16
20
|
location?: string;
|
|
@@ -28,4 +32,4 @@ interface ServerCheckOptions extends McpTestConnection {
|
|
|
28
32
|
}
|
|
29
33
|
declare function checkMcpServer(options: ServerCheckOptions): Promise<ServerCheckReport>;
|
|
30
34
|
//#endregion
|
|
31
|
-
export { McpTestConnection, ProtocolVersion, ServerCheck, ServerCheckOptions, ServerCheckReport, checkMcpServer, withMcpClient };
|
|
35
|
+
export { McpTestConnection, ProtocolVersion, ServerCheck, ServerCheckOptions, ServerCheckReport, UiResource, checkMcpServer, readUiResource, withMcpClient };
|
package/dist/testing/server.js
CHANGED
|
@@ -69,6 +69,27 @@ async function withMcpClient(options, run) {
|
|
|
69
69
|
await client.close();
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
+
async function readUiResource(client, uri, timeoutMs = 1e4) {
|
|
73
|
+
const content = (await client.readResource({ uri }, {
|
|
74
|
+
cacheMode: "bypass",
|
|
75
|
+
timeout: timeoutMs
|
|
76
|
+
}).catch(() => {
|
|
77
|
+
throw new McpCheckError({
|
|
78
|
+
code: "resource.read",
|
|
79
|
+
basis: "protocol-requirement",
|
|
80
|
+
message: "The UI resource could not be read. Check registration and the configured caller's access; response details are omitted."
|
|
81
|
+
});
|
|
82
|
+
})).contents.find((entry) => entry.uri === uri && entry.mimeType === "text/html;profile=mcp-app");
|
|
83
|
+
if (!content) throw new McpCheckError({
|
|
84
|
+
code: "resource.ui-content",
|
|
85
|
+
basis: "protocol-requirement",
|
|
86
|
+
message: "The linked resource must return HTML with MIME text/html;profile=mcp-app at its URI."
|
|
87
|
+
});
|
|
88
|
+
return {
|
|
89
|
+
...content,
|
|
90
|
+
text: "text" in content ? content.text : Buffer.from(content.blob, "base64").toString("utf8")
|
|
91
|
+
};
|
|
92
|
+
}
|
|
72
93
|
async function checkMcpServer(options) {
|
|
73
94
|
const checks = [];
|
|
74
95
|
const calls = options.calls ?? [];
|
|
@@ -95,6 +116,7 @@ async function checkMcpServer(options) {
|
|
|
95
116
|
}) : { tools: [] };
|
|
96
117
|
record(stage, "The official client decoded the tool catalog; the tools capability is optional.");
|
|
97
118
|
const unsupported = /* @__PURE__ */ new Set();
|
|
119
|
+
const read = /* @__PURE__ */ new Set();
|
|
98
120
|
for (const [index, tool] of tools.entries()) {
|
|
99
121
|
location = `tools[${index}]`;
|
|
100
122
|
stage = "server.schemas";
|
|
@@ -106,6 +128,19 @@ async function checkMcpServer(options) {
|
|
|
106
128
|
} else new AjvJsonSchemaValidator().getValidator(schema);
|
|
107
129
|
}
|
|
108
130
|
if (!unsupported.has(tool.name)) record(stage, "Advertised schemas compile with the SDK validator.");
|
|
131
|
+
const uri = (tool._meta?.ui)?.resourceUri ?? tool._meta?.["ui/resourceUri"];
|
|
132
|
+
if (uri === void 0) continue;
|
|
133
|
+
stage = "resource.ui-link";
|
|
134
|
+
if (typeof uri !== "string" || !uri.startsWith("ui://")) throw new McpCheckError({
|
|
135
|
+
code: stage,
|
|
136
|
+
basis: "protocol-requirement",
|
|
137
|
+
message: "Tool UI resourceUri must name a ui:// resource."
|
|
138
|
+
});
|
|
139
|
+
if (read.has(uri)) continue;
|
|
140
|
+
stage = "resource.read";
|
|
141
|
+
await readUiResource(client, uri, timeout);
|
|
142
|
+
record(stage, "The linked UI resource is readable as HTML.");
|
|
143
|
+
read.add(uri);
|
|
109
144
|
}
|
|
110
145
|
for (; nextCall < calls.length; nextCall++) {
|
|
111
146
|
const call = calls[nextCall];
|
|
@@ -192,4 +227,4 @@ async function checkMcpServer(options) {
|
|
|
192
227
|
};
|
|
193
228
|
}
|
|
194
229
|
//#endregion
|
|
195
|
-
export { checkMcpServer, withMcpClient };
|
|
230
|
+
export { checkMcpServer, readUiResource, withMcpClient };
|
|
@@ -42,6 +42,7 @@ function isJsonValue(value, ancestors = /* @__PURE__ */ new Set()) {
|
|
|
42
42
|
async function finalizeToolResult(tool, result) {
|
|
43
43
|
const content = normalizeToolContent(result.content);
|
|
44
44
|
let structuredContent = result.structuredContent;
|
|
45
|
+
let meta = result._meta;
|
|
45
46
|
if (tool.outputSchema && !result.isError) {
|
|
46
47
|
if (structuredContent === void 0) return outputValidationError(`Output validation error: Tool ${tool.name} has an output schema but no structured content was provided`);
|
|
47
48
|
try {
|
|
@@ -56,14 +57,20 @@ async function finalizeToolResult(tool, result) {
|
|
|
56
57
|
if (!result.isError) return outputValidationError(`Output validation error: Tool ${tool.name} returned a non-JSON structured value`);
|
|
57
58
|
structuredContent = void 0;
|
|
58
59
|
}
|
|
60
|
+
if (meta !== void 0 && (meta === null || typeof meta !== "object" || Array.isArray(meta) || !isJsonValue(meta))) {
|
|
61
|
+
if (!result.isError) return outputValidationError(`Output validation error: Tool ${tool.name} returned invalid _meta; expected a JSON object`);
|
|
62
|
+
meta = void 0;
|
|
63
|
+
}
|
|
59
64
|
if (structuredContent !== void 0 && (structuredContent === null || typeof structuredContent !== "object" || Array.isArray(structuredContent)) && !content.some((block) => block.type === "text")) content.push({
|
|
60
65
|
type: "text",
|
|
61
66
|
text: JSON.stringify(structuredContent)
|
|
62
67
|
});
|
|
68
|
+
if (tool.ui && content.length === 0) return outputValidationError(`Output validation error: Tool ${tool.name} has a UI but returned no content; include at least one content block (e.g. a text summary) for hosts without MCP Apps support`);
|
|
63
69
|
return {
|
|
64
70
|
content,
|
|
65
71
|
structuredContent,
|
|
66
|
-
isError: result.isError
|
|
72
|
+
isError: result.isError,
|
|
73
|
+
_meta: meta
|
|
67
74
|
};
|
|
68
75
|
}
|
|
69
76
|
//#endregion
|
|
@@ -42,6 +42,7 @@ function isJsonValue(value, ancestors = /* @__PURE__ */ new Set()) {
|
|
|
42
42
|
async function finalizeToolResult(tool, result) {
|
|
43
43
|
const content = normalizeToolContent(result.content);
|
|
44
44
|
let structuredContent = result.structuredContent;
|
|
45
|
+
let meta = result._meta;
|
|
45
46
|
if (tool.outputSchema && !result.isError) {
|
|
46
47
|
if (structuredContent === void 0) return outputValidationError(`Output validation error: Tool ${tool.name} has an output schema but no structured content was provided`);
|
|
47
48
|
try {
|
|
@@ -56,14 +57,20 @@ async function finalizeToolResult(tool, result) {
|
|
|
56
57
|
if (!result.isError) return outputValidationError(`Output validation error: Tool ${tool.name} returned a non-JSON structured value`);
|
|
57
58
|
structuredContent = void 0;
|
|
58
59
|
}
|
|
60
|
+
if (meta !== void 0 && (meta === null || typeof meta !== "object" || Array.isArray(meta) || !isJsonValue(meta))) {
|
|
61
|
+
if (!result.isError) return outputValidationError(`Output validation error: Tool ${tool.name} returned invalid _meta; expected a JSON object`);
|
|
62
|
+
meta = void 0;
|
|
63
|
+
}
|
|
59
64
|
if (structuredContent !== void 0 && (structuredContent === null || typeof structuredContent !== "object" || Array.isArray(structuredContent)) && !content.some((block) => block.type === "text")) content.push({
|
|
60
65
|
type: "text",
|
|
61
66
|
text: JSON.stringify(structuredContent)
|
|
62
67
|
});
|
|
68
|
+
if (tool.ui && content.length === 0) return outputValidationError(`Output validation error: Tool ${tool.name} has a UI but returned no content; include at least one content block (e.g. a text summary) for hosts without MCP Apps support`);
|
|
63
69
|
return {
|
|
64
70
|
content,
|
|
65
71
|
structuredContent,
|
|
66
|
-
isError: result.isError
|
|
72
|
+
isError: result.isError,
|
|
73
|
+
_meta: meta
|
|
67
74
|
};
|
|
68
75
|
}
|
|
69
76
|
//#endregion
|