@lovable.dev/mcp-js 4.0.0-rc.0 → 4.0.0-rc.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/README.md +104 -1
- package/dist/{authorize-Chb9Sb1f.d.ts → authorize-8crkySbp.d.ts} +1 -1
- package/dist/{authorize-Ba1deW5O.d.cts → authorize-BZdUmD37.d.cts} +1 -1
- package/dist/{base-D7ei8TjY.d.cts → base-CChLZaEN.d.cts} +1 -1
- package/dist/{base-D-lvtqSA.d.ts → base-DQPu0cno.d.ts} +1 -1
- package/dist/cli/check-server.cjs +61 -0
- package/dist/cli/check-server.d.cts +1 -0
- package/dist/cli/check-server.d.ts +1 -0
- package/dist/cli/check-server.js +62 -0
- package/dist/cli/extract-manifest.cjs +1 -1
- package/dist/cli/extract-manifest.js +1 -1
- package/dist/{cors-BuPvEjxu.cjs → cors-Ct-kdMcl.cjs} +1 -1
- package/dist/{cors-D9LajKfo.js → cors-Ct8SFh-_.js} +1 -1
- package/dist/diagnostic-ClI2_5MW.js +11 -0
- package/dist/diagnostic-DRKjgCsW.d.cts +12 -0
- package/dist/diagnostic-DRKjgCsW.d.ts +12 -0
- package/dist/diagnostic-ol9IE9Dl.cjs +16 -0
- package/dist/{errors-BEl2IOnx.js → errors-Cul5Uyfw.js} +3 -2
- package/dist/{errors-BlSu6Nrn.cjs → errors-ebgNFNvm.cjs} +3 -2
- package/dist/format-DDzvc92Z.cjs +41 -0
- package/dist/format-DKEuO8Tn.js +30 -0
- package/dist/hooks-BOdDe251.js +353 -0
- package/dist/hooks-xQl3EkDa.cjs +382 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/{io-B72X5KDG.d.ts → io-4N9Hcw0w.d.ts} +1 -1
- package/dist/{io-foChTR9t.d.cts → io-Be8y8E2V.d.cts} +1 -1
- package/dist/{io-BpxqVag8.cjs → io-Bf4Narx6.cjs} +17 -5
- package/dist/{io-DFsll31O.js → io-VMIaguRH.js} +14 -2
- package/dist/{mcp-DMMqfwKm.cjs → mcp-By6C2M4i.cjs} +156 -70
- package/dist/{mcp-B1wBn_X-.js → mcp-DWxIy07i.js} +154 -68
- package/dist/{package-Bt33FsvP.cjs → package-CBMX__7C.cjs} +1 -1
- package/dist/{package-BWLBCBmc.js → package-Ci4yKJUI.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/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 +40 -19
- package/dist/stacks/supabase/vite.d.cts +1 -1
- package/dist/stacks/supabase/vite.d.ts +1 -1
- package/dist/stacks/supabase/vite.js +34 -13
- package/dist/stacks/tanstack/index.cjs +2 -2
- package/dist/stacks/tanstack/index.d.cts +2 -2
- package/dist/stacks/tanstack/index.d.ts +2 -2
- package/dist/stacks/tanstack/index.js +2 -2
- package/dist/stacks/tanstack/vite.cjs +33 -25
- package/dist/stacks/tanstack/vite.d.cts +1 -1
- package/dist/stacks/tanstack/vite.d.ts +1 -1
- package/dist/stacks/tanstack/vite.js +26 -18
- package/dist/testing/index.cjs +46 -0
- package/dist/testing/index.d.cts +10 -0
- package/dist/testing/index.d.ts +10 -0
- package/dist/testing/index.js +44 -0
- package/dist/testing/server.cjs +197 -0
- package/dist/testing/server.d.cts +31 -0
- package/dist/testing/server.d.ts +31 -0
- package/dist/testing/server.js +195 -0
- package/dist/tool-result-teeTDoM1.js +70 -0
- package/dist/tool-result-yqOfZUOP.cjs +87 -0
- package/dist/{types-srTXYLoX.d.cts → types-CyDJi9Jb.d.cts} +7 -1
- package/dist/{types-srTXYLoX.d.ts → types-CyDJi9Jb.d.ts} +7 -1
- package/package.json +40 -4
- package/skill-imports.d.cts +1 -0
- package/skill-imports.d.ts +11 -0
- package/dist/fs-errors-CWNzOV75.cjs +0 -11
- package/dist/fs-errors-PA2t1TIp.js +0 -6
- package/dist/supabase-config-CakTU8YF.js +0 -26
- package/dist/supabase-config-Dz7dnUv0.cjs +0 -31
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
const require_logger = require("./logger-C-Hdu57K.cjs");
|
|
2
2
|
const require_schema = require("./schema-CjFpqCEP.cjs");
|
|
3
|
-
const require_errors = require("./errors-
|
|
4
|
-
const require_cors = require("./cors-
|
|
3
|
+
const require_errors = require("./errors-ebgNFNvm.cjs");
|
|
4
|
+
const require_cors = require("./cors-Ct-kdMcl.cjs");
|
|
5
|
+
const require_tool_result = require("./tool-result-yqOfZUOP.cjs");
|
|
5
6
|
let zod_v4_core = require("zod/v4/core");
|
|
6
7
|
let _modelcontextprotocol_server = require("@modelcontextprotocol/server");
|
|
7
8
|
//#region src/core/content.ts
|
|
@@ -15,72 +16,67 @@ function extractTextContent(content) {
|
|
|
15
16
|
return text.length > 0 ? text : void 0;
|
|
16
17
|
}
|
|
17
18
|
//#endregion
|
|
18
|
-
//#region src/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const normalized = sizes.trim();
|
|
23
|
-
return normalized === "" ? rest : {
|
|
24
|
-
...rest,
|
|
25
|
-
sizes: normalized.split(/\s+/)
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
function normalizeToolContent(content) {
|
|
29
|
-
return (content ?? []).map((block) => {
|
|
30
|
-
if (block.type !== "resource_link" || block.icons === void 0) return block;
|
|
31
|
-
return {
|
|
32
|
-
...block,
|
|
33
|
-
icons: block.icons.map(normalizeResourceLinkIcon)
|
|
34
|
-
};
|
|
35
|
-
});
|
|
19
|
+
//#region src/skills/runtime.ts
|
|
20
|
+
const SKILLS_EXTENSION_ID = "io.modelcontextprotocol/skills";
|
|
21
|
+
function indexLines(skills) {
|
|
22
|
+
return skills.map((skill) => `- name: ${JSON.stringify(skill.frontmatter.name)}; description: ${JSON.stringify(skill.frontmatter.description)}; uri: ${skill.uri}`);
|
|
36
23
|
}
|
|
37
|
-
function
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
function isJsonValue(value, ancestors = /* @__PURE__ */ new Set()) {
|
|
47
|
-
if (value === null || typeof value === "boolean" || typeof value === "string") return true;
|
|
48
|
-
if (typeof value === "number") return Number.isFinite(value);
|
|
49
|
-
if (typeof value !== "object" || ancestors.has(value)) return false;
|
|
50
|
-
const prototype = Object.getPrototypeOf(value);
|
|
51
|
-
if (!Array.isArray(value) && prototype !== Object.prototype && prototype !== null) return false;
|
|
52
|
-
ancestors.add(value);
|
|
53
|
-
const valid = (Array.isArray(value) ? value : Object.values(value).filter((entry) => entry !== void 0)).every((entry) => isJsonValue(entry, ancestors));
|
|
54
|
-
ancestors.delete(value);
|
|
55
|
-
return valid;
|
|
24
|
+
function longestRun(text, char) {
|
|
25
|
+
let best = 0;
|
|
26
|
+
let current = 0;
|
|
27
|
+
for (const c of text) {
|
|
28
|
+
current = c === char ? current + 1 : 0;
|
|
29
|
+
if (current > best) best = current;
|
|
30
|
+
}
|
|
31
|
+
return best;
|
|
56
32
|
}
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
33
|
+
function prepareSkills(serverName, importedSkills) {
|
|
34
|
+
const skills = importedSkills;
|
|
35
|
+
const files = /* @__PURE__ */ new Map();
|
|
36
|
+
const skillsByUri = /* @__PURE__ */ new Map();
|
|
37
|
+
for (const skill of skills) {
|
|
38
|
+
skillsByUri.set(skill.uri, skill);
|
|
39
|
+
for (const file of skill.files) {
|
|
40
|
+
const existing = files.get(file.uri);
|
|
41
|
+
if (existing === void 0) files.set(file.uri, {
|
|
42
|
+
...file,
|
|
43
|
+
roots: [skill.rootUri]
|
|
44
|
+
});
|
|
45
|
+
else if (!existing.roots.includes(skill.rootUri)) files.set(file.uri, {
|
|
46
|
+
...existing,
|
|
47
|
+
roots: [...existing.roots, skill.rootUri]
|
|
48
|
+
});
|
|
68
49
|
}
|
|
69
50
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
51
|
+
const index = indexLines(skills);
|
|
52
|
+
const indexText = [
|
|
53
|
+
`## Agent Skills published by this server (${SKILLS_EXTENSION_ID})`,
|
|
54
|
+
"When a task matches, use the host's skill loader with this server and URI. Resolve references with skills/get; reading resources alone does not activate a skill.",
|
|
55
|
+
...index
|
|
56
|
+
].join("\n");
|
|
57
|
+
let delimiterLength = 8;
|
|
58
|
+
for (const file of files.values()) delimiterLength = Math.max(delimiterLength, longestRun(file.text, "@") + 1);
|
|
59
|
+
const delimiter = "@".repeat(delimiterLength);
|
|
60
|
+
const sections = [];
|
|
61
|
+
for (const file of files.values()) sections.push(`${delimiter} BEGIN FILE ${file.uri} (server: ${JSON.stringify(serverName)}; skill roots: ${file.roots.join(", ")})\n${file.text}\n${delimiter} END FILE ${file.uri}`);
|
|
78
62
|
return {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
63
|
+
skills,
|
|
64
|
+
files,
|
|
65
|
+
skillsByUri,
|
|
66
|
+
indexText,
|
|
67
|
+
fallbackText: [
|
|
68
|
+
`## Agent Skills reference text from server ${JSON.stringify(serverName)}`,
|
|
69
|
+
"This is a text copy of the server's Agent Skills. It installs no files and grants no execution or frontmatter permissions; the host may separately provide native Skills support. Use a skill when its description matches the task. Relative paths inside a skill resolve against that skill's root URI; a skill:// URI names another section below.",
|
|
70
|
+
...index,
|
|
71
|
+
`Each file appears once between lines starting with "${delimiter} BEGIN FILE <uri>" and "${delimiter} END FILE <uri>".`,
|
|
72
|
+
...sections
|
|
73
|
+
].join("\n")
|
|
82
74
|
};
|
|
83
75
|
}
|
|
76
|
+
function composeInstructions(authored, prepared, declared) {
|
|
77
|
+
const addition = declared ? prepared.indexText : prepared.fallbackText;
|
|
78
|
+
return authored.length > 0 ? `${authored}\n\n${addition}` : addition;
|
|
79
|
+
}
|
|
84
80
|
//#endregion
|
|
85
81
|
//#region src/protocols/gate.ts
|
|
86
82
|
function createGatedHandler(gate) {
|
|
@@ -206,6 +202,19 @@ function standardSchemaFromDefinition(definition, strict) {
|
|
|
206
202
|
function isPlainObject(value) {
|
|
207
203
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
208
204
|
}
|
|
205
|
+
function declaresSkillsSupport(parsedBody) {
|
|
206
|
+
if (Array.isArray(parsedBody)) {
|
|
207
|
+
const initializations = parsedBody.filter((value) => isPlainObject(value) && value.method === "initialize");
|
|
208
|
+
return initializations.length > 0 && initializations.every(declaresSkillsSupport);
|
|
209
|
+
}
|
|
210
|
+
if (!isPlainObject(parsedBody) || !isPlainObject(parsedBody.params)) return false;
|
|
211
|
+
const params = parsedBody.params;
|
|
212
|
+
let capabilities;
|
|
213
|
+
if (parsedBody.method === "initialize") capabilities = params.capabilities;
|
|
214
|
+
else if (isPlainObject(params._meta)) capabilities = params._meta[_modelcontextprotocol_server.CLIENT_CAPABILITIES_META_KEY];
|
|
215
|
+
if (!isPlainObject(capabilities) || !isPlainObject(capabilities.extensions)) return false;
|
|
216
|
+
return isPlainObject(capabilities.extensions[SKILLS_EXTENSION_ID]);
|
|
217
|
+
}
|
|
209
218
|
function toolRequestContext(sdkCtx, protocol) {
|
|
210
219
|
const mcpReq = sdkCtx?.mcpReq;
|
|
211
220
|
const client = { protocol };
|
|
@@ -258,7 +267,7 @@ async function invokeTool(tool, auth, recorder, args, protocol, sdkCtx, appConte
|
|
|
258
267
|
endUserId,
|
|
259
268
|
protocol
|
|
260
269
|
});
|
|
261
|
-
return finalizeToolResult(tool, {
|
|
270
|
+
return require_tool_result.finalizeToolResult(tool, {
|
|
262
271
|
content: [{
|
|
263
272
|
type: "text",
|
|
264
273
|
text: "tool execution failed"
|
|
@@ -284,7 +293,7 @@ async function invokeTool(tool, auth, recorder, args, protocol, sdkCtx, appConte
|
|
|
284
293
|
endUserId,
|
|
285
294
|
protocol
|
|
286
295
|
});
|
|
287
|
-
return finalizeToolResult(tool, {
|
|
296
|
+
return require_tool_result.finalizeToolResult(tool, {
|
|
288
297
|
content: [{
|
|
289
298
|
type: "text",
|
|
290
299
|
text: `tool "${tool.name}" returned no result`
|
|
@@ -292,7 +301,7 @@ async function invokeTool(tool, auth, recorder, args, protocol, sdkCtx, appConte
|
|
|
292
301
|
isError: true
|
|
293
302
|
});
|
|
294
303
|
}
|
|
295
|
-
result = await finalizeToolResult(tool, result);
|
|
304
|
+
result = await require_tool_result.finalizeToolResult(tool, result);
|
|
296
305
|
await recorder.emit({
|
|
297
306
|
tool: tool.name,
|
|
298
307
|
toolConditional,
|
|
@@ -316,7 +325,66 @@ function adaptToolCallback(tool, auth, recorder, protocol, appContext) {
|
|
|
316
325
|
};
|
|
317
326
|
};
|
|
318
327
|
}
|
|
319
|
-
|
|
328
|
+
const SKILL_CACHE = {
|
|
329
|
+
ttlMs: 0,
|
|
330
|
+
cacheScope: "private"
|
|
331
|
+
};
|
|
332
|
+
function paramsSchema(check) {
|
|
333
|
+
return { "~standard": {
|
|
334
|
+
version: 1,
|
|
335
|
+
vendor: "lovable-mcp-js",
|
|
336
|
+
validate: (value) => {
|
|
337
|
+
value ??= {};
|
|
338
|
+
if (!isPlainObject(value)) return { issues: [{ message: "params must be an object" }] };
|
|
339
|
+
const problem = check(value);
|
|
340
|
+
return problem ? { issues: [{ message: problem }] } : { value };
|
|
341
|
+
}
|
|
342
|
+
} };
|
|
343
|
+
}
|
|
344
|
+
const skillsListParams = paramsSchema((value) => value.cursor === void 0 ? void 0 : "This catalog has no continuation cursor");
|
|
345
|
+
const skillsGetParams = paramsSchema((value) => typeof value.uri === "string" ? void 0 : "uri must be a string");
|
|
346
|
+
function skillEntry(skill) {
|
|
347
|
+
return {
|
|
348
|
+
uri: skill.uri,
|
|
349
|
+
frontmatter: skill.frontmatter,
|
|
350
|
+
resources: skill.files.map((file) => ({
|
|
351
|
+
uri: file.uri,
|
|
352
|
+
digest: file.digest,
|
|
353
|
+
size: file.size
|
|
354
|
+
}))
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
function registerSkills(server, skills, era) {
|
|
358
|
+
const resultMetadata = era === "modern" ? {
|
|
359
|
+
resultType: "complete",
|
|
360
|
+
...SKILL_CACHE
|
|
361
|
+
} : {};
|
|
362
|
+
for (const file of skills.files.values()) {
|
|
363
|
+
const owner = skills.skillsByUri.get(file.uri);
|
|
364
|
+
server.registerResource(owner ? owner.frontmatter.name : file.uri, file.uri, {
|
|
365
|
+
mimeType: file.mimeType,
|
|
366
|
+
...owner ? { description: owner.frontmatter.description } : {},
|
|
367
|
+
cacheHint: SKILL_CACHE
|
|
368
|
+
}, async () => ({ contents: [{
|
|
369
|
+
uri: file.uri,
|
|
370
|
+
mimeType: file.mimeType,
|
|
371
|
+
text: file.text
|
|
372
|
+
}] }));
|
|
373
|
+
}
|
|
374
|
+
server.server.setRequestHandler("skills/list", { params: skillsListParams }, async () => ({
|
|
375
|
+
skills: skills.skills.map(skillEntry),
|
|
376
|
+
...resultMetadata
|
|
377
|
+
}));
|
|
378
|
+
server.server.setRequestHandler("skills/get", { params: skillsGetParams }, async ({ uri }) => {
|
|
379
|
+
const skill = skills.skillsByUri.get(uri);
|
|
380
|
+
if (!skill) throw new _modelcontextprotocol_server.ProtocolError(_modelcontextprotocol_server.ProtocolErrorCode.InvalidParams, `No skill is served at ${uri}`);
|
|
381
|
+
return {
|
|
382
|
+
skill: skillEntry(skill),
|
|
383
|
+
...resultMetadata
|
|
384
|
+
};
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
async function buildServer(mcp, auth, recorder, era, signal, operations, skills) {
|
|
320
388
|
const calledTools = operations ? mcp.tools.filter((tool) => operations.calledTools.has(tool.name)) : mcp.tools;
|
|
321
389
|
const selectedTools = !operations || operations.listTools ? mcp.tools : calledTools;
|
|
322
390
|
const hasConditionalTools = mcp.tools.some((tool) => tool.enabled !== void 0);
|
|
@@ -332,8 +400,15 @@ async function buildServer(mcp, auth, recorder, era, signal, operations) {
|
|
|
332
400
|
version: mcp.version,
|
|
333
401
|
title: mcp.title
|
|
334
402
|
}, {
|
|
335
|
-
instructions: mcp.instructions,
|
|
336
|
-
capabilities:
|
|
403
|
+
instructions: skills ? skills.instructions : mcp.instructions,
|
|
404
|
+
capabilities: skills ? {
|
|
405
|
+
tools: { listChanged: false },
|
|
406
|
+
resources: {
|
|
407
|
+
listChanged: false,
|
|
408
|
+
subscribe: false
|
|
409
|
+
},
|
|
410
|
+
extensions: { [SKILLS_EXTENSION_ID]: {} }
|
|
411
|
+
} : { tools: { listChanged: false } },
|
|
337
412
|
cacheHints: {
|
|
338
413
|
"tools/list": {
|
|
339
414
|
ttlMs: 0,
|
|
@@ -342,9 +417,14 @@ async function buildServer(mcp, auth, recorder, era, signal, operations) {
|
|
|
342
417
|
"server/discover": {
|
|
343
418
|
ttlMs: 0,
|
|
344
419
|
cacheScope: "private"
|
|
345
|
-
}
|
|
420
|
+
},
|
|
421
|
+
...skills ? {
|
|
422
|
+
"resources/list": SKILL_CACHE,
|
|
423
|
+
"resources/read": SKILL_CACHE
|
|
424
|
+
} : {}
|
|
346
425
|
}
|
|
347
426
|
});
|
|
427
|
+
if (skills) registerSkills(server, skills.prepared, era);
|
|
348
428
|
for (const tool of selectedTools) {
|
|
349
429
|
if (tool.enabled) {
|
|
350
430
|
const { enabled } = tool;
|
|
@@ -378,6 +458,7 @@ async function buildServer(mcp, auth, recorder, era, signal, operations) {
|
|
|
378
458
|
*/
|
|
379
459
|
function createMcpProtocolHandler(mcp, options = {}) {
|
|
380
460
|
const authorizer = require_cors.createRequestAuthorizer(mcp, options);
|
|
461
|
+
const preparedSkills = mcp.skills && mcp.skills.length > 0 ? prepareSkills(mcp.name, mcp.skills) : void 0;
|
|
381
462
|
const handle = async (request, authResult, recorder) => {
|
|
382
463
|
let protocolError;
|
|
383
464
|
const reportTransportError = async (error) => {
|
|
@@ -395,8 +476,13 @@ function createMcpProtocolHandler(mcp, options = {}) {
|
|
|
395
476
|
});
|
|
396
477
|
};
|
|
397
478
|
try {
|
|
398
|
-
const classified = mcp.createAppContext ? await classifyRequest(request) : void 0;
|
|
399
|
-
const
|
|
479
|
+
const classified = mcp.createAppContext || preparedSkills ? await classifyRequest(request) : void 0;
|
|
480
|
+
const operations = mcp.createAppContext ? classified?.operations : void 0;
|
|
481
|
+
const skills = preparedSkills ? {
|
|
482
|
+
prepared: preparedSkills,
|
|
483
|
+
instructions: composeInstructions(mcp.instructions, preparedSkills, declaresSkillsSupport(classified?.parsedBody))
|
|
484
|
+
} : void 0;
|
|
485
|
+
const response = await (0, _modelcontextprotocol_server.createMcpHandler)(({ era, requestInfo }) => buildServer(mcp, authResult.auth, recorder, era, requestInfo?.signal ?? request.signal, operations, skills), {
|
|
400
486
|
legacy: "stateless",
|
|
401
487
|
maxSubscriptions: 0,
|
|
402
488
|
onerror: (error) => {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { i as log, r as describeError } from "./logger-CpLgYbCG.js";
|
|
2
2
|
import { n as schemaFromDefinition, t as jsonSchemaFromDefinition } from "./schema-DBTR1XbM.js";
|
|
3
|
-
import { a as ToolContext, c as toolRequiresAppContext, i as AuthContext, n as errorSummary, r as resolveToolErrorMessage } from "./errors-
|
|
4
|
-
import { d as nowMs, i as normalizeHttpMethod, l as emitBeforeResponse, n as createRequestAuthorizer, p as finalizeWireResponse, t as evaluateCors, u as createNoopRecorder } from "./cors-
|
|
3
|
+
import { a as ToolContext, c as toolRequiresAppContext, i as AuthContext, n as errorSummary, r as resolveToolErrorMessage } from "./errors-Cul5Uyfw.js";
|
|
4
|
+
import { d as nowMs, i as normalizeHttpMethod, l as emitBeforeResponse, n as createRequestAuthorizer, p as finalizeWireResponse, t as evaluateCors, u as createNoopRecorder } from "./cors-Ct8SFh-_.js";
|
|
5
|
+
import { t as finalizeToolResult } from "./tool-result-teeTDoM1.js";
|
|
5
6
|
import { safeParseAsync } from "zod/v4/core";
|
|
6
|
-
import { CLIENT_CAPABILITIES_META_KEY, CLIENT_INFO_META_KEY, McpServer, createMcpHandler } from "@modelcontextprotocol/server";
|
|
7
|
+
import { CLIENT_CAPABILITIES_META_KEY, CLIENT_INFO_META_KEY, McpServer, ProtocolError, ProtocolErrorCode, createMcpHandler } from "@modelcontextprotocol/server";
|
|
7
8
|
//#region src/core/content.ts
|
|
8
9
|
/** Join the text of a result's `type: "text"` blocks into one string, dropping
|
|
9
10
|
* binary/resource blocks. Used to surface a `tool_error` message in the local
|
|
@@ -15,72 +16,67 @@ function extractTextContent(content) {
|
|
|
15
16
|
return text.length > 0 ? text : void 0;
|
|
16
17
|
}
|
|
17
18
|
//#endregion
|
|
18
|
-
//#region src/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const normalized = sizes.trim();
|
|
23
|
-
return normalized === "" ? rest : {
|
|
24
|
-
...rest,
|
|
25
|
-
sizes: normalized.split(/\s+/)
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
function normalizeToolContent(content) {
|
|
29
|
-
return (content ?? []).map((block) => {
|
|
30
|
-
if (block.type !== "resource_link" || block.icons === void 0) return block;
|
|
31
|
-
return {
|
|
32
|
-
...block,
|
|
33
|
-
icons: block.icons.map(normalizeResourceLinkIcon)
|
|
34
|
-
};
|
|
35
|
-
});
|
|
19
|
+
//#region src/skills/runtime.ts
|
|
20
|
+
const SKILLS_EXTENSION_ID = "io.modelcontextprotocol/skills";
|
|
21
|
+
function indexLines(skills) {
|
|
22
|
+
return skills.map((skill) => `- name: ${JSON.stringify(skill.frontmatter.name)}; description: ${JSON.stringify(skill.frontmatter.description)}; uri: ${skill.uri}`);
|
|
36
23
|
}
|
|
37
|
-
function
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
function isJsonValue(value, ancestors = /* @__PURE__ */ new Set()) {
|
|
47
|
-
if (value === null || typeof value === "boolean" || typeof value === "string") return true;
|
|
48
|
-
if (typeof value === "number") return Number.isFinite(value);
|
|
49
|
-
if (typeof value !== "object" || ancestors.has(value)) return false;
|
|
50
|
-
const prototype = Object.getPrototypeOf(value);
|
|
51
|
-
if (!Array.isArray(value) && prototype !== Object.prototype && prototype !== null) return false;
|
|
52
|
-
ancestors.add(value);
|
|
53
|
-
const valid = (Array.isArray(value) ? value : Object.values(value).filter((entry) => entry !== void 0)).every((entry) => isJsonValue(entry, ancestors));
|
|
54
|
-
ancestors.delete(value);
|
|
55
|
-
return valid;
|
|
24
|
+
function longestRun(text, char) {
|
|
25
|
+
let best = 0;
|
|
26
|
+
let current = 0;
|
|
27
|
+
for (const c of text) {
|
|
28
|
+
current = c === char ? current + 1 : 0;
|
|
29
|
+
if (current > best) best = current;
|
|
30
|
+
}
|
|
31
|
+
return best;
|
|
56
32
|
}
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
33
|
+
function prepareSkills(serverName, importedSkills) {
|
|
34
|
+
const skills = importedSkills;
|
|
35
|
+
const files = /* @__PURE__ */ new Map();
|
|
36
|
+
const skillsByUri = /* @__PURE__ */ new Map();
|
|
37
|
+
for (const skill of skills) {
|
|
38
|
+
skillsByUri.set(skill.uri, skill);
|
|
39
|
+
for (const file of skill.files) {
|
|
40
|
+
const existing = files.get(file.uri);
|
|
41
|
+
if (existing === void 0) files.set(file.uri, {
|
|
42
|
+
...file,
|
|
43
|
+
roots: [skill.rootUri]
|
|
44
|
+
});
|
|
45
|
+
else if (!existing.roots.includes(skill.rootUri)) files.set(file.uri, {
|
|
46
|
+
...existing,
|
|
47
|
+
roots: [...existing.roots, skill.rootUri]
|
|
48
|
+
});
|
|
68
49
|
}
|
|
69
50
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
51
|
+
const index = indexLines(skills);
|
|
52
|
+
const indexText = [
|
|
53
|
+
`## Agent Skills published by this server (${SKILLS_EXTENSION_ID})`,
|
|
54
|
+
"When a task matches, use the host's skill loader with this server and URI. Resolve references with skills/get; reading resources alone does not activate a skill.",
|
|
55
|
+
...index
|
|
56
|
+
].join("\n");
|
|
57
|
+
let delimiterLength = 8;
|
|
58
|
+
for (const file of files.values()) delimiterLength = Math.max(delimiterLength, longestRun(file.text, "@") + 1);
|
|
59
|
+
const delimiter = "@".repeat(delimiterLength);
|
|
60
|
+
const sections = [];
|
|
61
|
+
for (const file of files.values()) sections.push(`${delimiter} BEGIN FILE ${file.uri} (server: ${JSON.stringify(serverName)}; skill roots: ${file.roots.join(", ")})\n${file.text}\n${delimiter} END FILE ${file.uri}`);
|
|
78
62
|
return {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
63
|
+
skills,
|
|
64
|
+
files,
|
|
65
|
+
skillsByUri,
|
|
66
|
+
indexText,
|
|
67
|
+
fallbackText: [
|
|
68
|
+
`## Agent Skills reference text from server ${JSON.stringify(serverName)}`,
|
|
69
|
+
"This is a text copy of the server's Agent Skills. It installs no files and grants no execution or frontmatter permissions; the host may separately provide native Skills support. Use a skill when its description matches the task. Relative paths inside a skill resolve against that skill's root URI; a skill:// URI names another section below.",
|
|
70
|
+
...index,
|
|
71
|
+
`Each file appears once between lines starting with "${delimiter} BEGIN FILE <uri>" and "${delimiter} END FILE <uri>".`,
|
|
72
|
+
...sections
|
|
73
|
+
].join("\n")
|
|
82
74
|
};
|
|
83
75
|
}
|
|
76
|
+
function composeInstructions(authored, prepared, declared) {
|
|
77
|
+
const addition = declared ? prepared.indexText : prepared.fallbackText;
|
|
78
|
+
return authored.length > 0 ? `${authored}\n\n${addition}` : addition;
|
|
79
|
+
}
|
|
84
80
|
//#endregion
|
|
85
81
|
//#region src/protocols/gate.ts
|
|
86
82
|
function createGatedHandler(gate) {
|
|
@@ -206,6 +202,19 @@ function standardSchemaFromDefinition(definition, strict) {
|
|
|
206
202
|
function isPlainObject(value) {
|
|
207
203
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
208
204
|
}
|
|
205
|
+
function declaresSkillsSupport(parsedBody) {
|
|
206
|
+
if (Array.isArray(parsedBody)) {
|
|
207
|
+
const initializations = parsedBody.filter((value) => isPlainObject(value) && value.method === "initialize");
|
|
208
|
+
return initializations.length > 0 && initializations.every(declaresSkillsSupport);
|
|
209
|
+
}
|
|
210
|
+
if (!isPlainObject(parsedBody) || !isPlainObject(parsedBody.params)) return false;
|
|
211
|
+
const params = parsedBody.params;
|
|
212
|
+
let capabilities;
|
|
213
|
+
if (parsedBody.method === "initialize") capabilities = params.capabilities;
|
|
214
|
+
else if (isPlainObject(params._meta)) capabilities = params._meta[CLIENT_CAPABILITIES_META_KEY];
|
|
215
|
+
if (!isPlainObject(capabilities) || !isPlainObject(capabilities.extensions)) return false;
|
|
216
|
+
return isPlainObject(capabilities.extensions[SKILLS_EXTENSION_ID]);
|
|
217
|
+
}
|
|
209
218
|
function toolRequestContext(sdkCtx, protocol) {
|
|
210
219
|
const mcpReq = sdkCtx?.mcpReq;
|
|
211
220
|
const client = { protocol };
|
|
@@ -316,7 +325,66 @@ function adaptToolCallback(tool, auth, recorder, protocol, appContext) {
|
|
|
316
325
|
};
|
|
317
326
|
};
|
|
318
327
|
}
|
|
319
|
-
|
|
328
|
+
const SKILL_CACHE = {
|
|
329
|
+
ttlMs: 0,
|
|
330
|
+
cacheScope: "private"
|
|
331
|
+
};
|
|
332
|
+
function paramsSchema(check) {
|
|
333
|
+
return { "~standard": {
|
|
334
|
+
version: 1,
|
|
335
|
+
vendor: "lovable-mcp-js",
|
|
336
|
+
validate: (value) => {
|
|
337
|
+
value ??= {};
|
|
338
|
+
if (!isPlainObject(value)) return { issues: [{ message: "params must be an object" }] };
|
|
339
|
+
const problem = check(value);
|
|
340
|
+
return problem ? { issues: [{ message: problem }] } : { value };
|
|
341
|
+
}
|
|
342
|
+
} };
|
|
343
|
+
}
|
|
344
|
+
const skillsListParams = paramsSchema((value) => value.cursor === void 0 ? void 0 : "This catalog has no continuation cursor");
|
|
345
|
+
const skillsGetParams = paramsSchema((value) => typeof value.uri === "string" ? void 0 : "uri must be a string");
|
|
346
|
+
function skillEntry(skill) {
|
|
347
|
+
return {
|
|
348
|
+
uri: skill.uri,
|
|
349
|
+
frontmatter: skill.frontmatter,
|
|
350
|
+
resources: skill.files.map((file) => ({
|
|
351
|
+
uri: file.uri,
|
|
352
|
+
digest: file.digest,
|
|
353
|
+
size: file.size
|
|
354
|
+
}))
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
function registerSkills(server, skills, era) {
|
|
358
|
+
const resultMetadata = era === "modern" ? {
|
|
359
|
+
resultType: "complete",
|
|
360
|
+
...SKILL_CACHE
|
|
361
|
+
} : {};
|
|
362
|
+
for (const file of skills.files.values()) {
|
|
363
|
+
const owner = skills.skillsByUri.get(file.uri);
|
|
364
|
+
server.registerResource(owner ? owner.frontmatter.name : file.uri, file.uri, {
|
|
365
|
+
mimeType: file.mimeType,
|
|
366
|
+
...owner ? { description: owner.frontmatter.description } : {},
|
|
367
|
+
cacheHint: SKILL_CACHE
|
|
368
|
+
}, async () => ({ contents: [{
|
|
369
|
+
uri: file.uri,
|
|
370
|
+
mimeType: file.mimeType,
|
|
371
|
+
text: file.text
|
|
372
|
+
}] }));
|
|
373
|
+
}
|
|
374
|
+
server.server.setRequestHandler("skills/list", { params: skillsListParams }, async () => ({
|
|
375
|
+
skills: skills.skills.map(skillEntry),
|
|
376
|
+
...resultMetadata
|
|
377
|
+
}));
|
|
378
|
+
server.server.setRequestHandler("skills/get", { params: skillsGetParams }, async ({ uri }) => {
|
|
379
|
+
const skill = skills.skillsByUri.get(uri);
|
|
380
|
+
if (!skill) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `No skill is served at ${uri}`);
|
|
381
|
+
return {
|
|
382
|
+
skill: skillEntry(skill),
|
|
383
|
+
...resultMetadata
|
|
384
|
+
};
|
|
385
|
+
});
|
|
386
|
+
}
|
|
387
|
+
async function buildServer(mcp, auth, recorder, era, signal, operations, skills) {
|
|
320
388
|
const calledTools = operations ? mcp.tools.filter((tool) => operations.calledTools.has(tool.name)) : mcp.tools;
|
|
321
389
|
const selectedTools = !operations || operations.listTools ? mcp.tools : calledTools;
|
|
322
390
|
const hasConditionalTools = mcp.tools.some((tool) => tool.enabled !== void 0);
|
|
@@ -332,8 +400,15 @@ async function buildServer(mcp, auth, recorder, era, signal, operations) {
|
|
|
332
400
|
version: mcp.version,
|
|
333
401
|
title: mcp.title
|
|
334
402
|
}, {
|
|
335
|
-
instructions: mcp.instructions,
|
|
336
|
-
capabilities:
|
|
403
|
+
instructions: skills ? skills.instructions : mcp.instructions,
|
|
404
|
+
capabilities: skills ? {
|
|
405
|
+
tools: { listChanged: false },
|
|
406
|
+
resources: {
|
|
407
|
+
listChanged: false,
|
|
408
|
+
subscribe: false
|
|
409
|
+
},
|
|
410
|
+
extensions: { [SKILLS_EXTENSION_ID]: {} }
|
|
411
|
+
} : { tools: { listChanged: false } },
|
|
337
412
|
cacheHints: {
|
|
338
413
|
"tools/list": {
|
|
339
414
|
ttlMs: 0,
|
|
@@ -342,9 +417,14 @@ async function buildServer(mcp, auth, recorder, era, signal, operations) {
|
|
|
342
417
|
"server/discover": {
|
|
343
418
|
ttlMs: 0,
|
|
344
419
|
cacheScope: "private"
|
|
345
|
-
}
|
|
420
|
+
},
|
|
421
|
+
...skills ? {
|
|
422
|
+
"resources/list": SKILL_CACHE,
|
|
423
|
+
"resources/read": SKILL_CACHE
|
|
424
|
+
} : {}
|
|
346
425
|
}
|
|
347
426
|
});
|
|
427
|
+
if (skills) registerSkills(server, skills.prepared, era);
|
|
348
428
|
for (const tool of selectedTools) {
|
|
349
429
|
if (tool.enabled) {
|
|
350
430
|
const { enabled } = tool;
|
|
@@ -378,6 +458,7 @@ async function buildServer(mcp, auth, recorder, era, signal, operations) {
|
|
|
378
458
|
*/
|
|
379
459
|
function createMcpProtocolHandler(mcp, options = {}) {
|
|
380
460
|
const authorizer = createRequestAuthorizer(mcp, options);
|
|
461
|
+
const preparedSkills = mcp.skills && mcp.skills.length > 0 ? prepareSkills(mcp.name, mcp.skills) : void 0;
|
|
381
462
|
const handle = async (request, authResult, recorder) => {
|
|
382
463
|
let protocolError;
|
|
383
464
|
const reportTransportError = async (error) => {
|
|
@@ -395,8 +476,13 @@ function createMcpProtocolHandler(mcp, options = {}) {
|
|
|
395
476
|
});
|
|
396
477
|
};
|
|
397
478
|
try {
|
|
398
|
-
const classified = mcp.createAppContext ? await classifyRequest(request) : void 0;
|
|
399
|
-
const
|
|
479
|
+
const classified = mcp.createAppContext || preparedSkills ? await classifyRequest(request) : void 0;
|
|
480
|
+
const operations = mcp.createAppContext ? classified?.operations : void 0;
|
|
481
|
+
const skills = preparedSkills ? {
|
|
482
|
+
prepared: preparedSkills,
|
|
483
|
+
instructions: composeInstructions(mcp.instructions, preparedSkills, declaresSkillsSupport(classified?.parsedBody))
|
|
484
|
+
} : void 0;
|
|
485
|
+
const response = await createMcpHandler(({ era, requestInfo }) => buildServer(mcp, authResult.auth, recorder, era, requestInfo?.signal ?? request.signal, operations, skills), {
|
|
400
486
|
legacy: "stateless",
|
|
401
487
|
maxSubscriptions: 0,
|
|
402
488
|
onerror: (error) => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { m as McpDefinition } from "../../types-
|
|
2
|
-
import { t as MetricsRecorder } from "../../base-
|
|
3
|
-
import { n as ScheduleBackground, t as McpRuntimeOptions } from "../../authorize-
|
|
1
|
+
import { m as McpDefinition } from "../../types-CyDJi9Jb.cjs";
|
|
2
|
+
import { t as MetricsRecorder } from "../../base-CChLZaEN.cjs";
|
|
3
|
+
import { n as ScheduleBackground, t as McpRuntimeOptions } from "../../authorize-BZdUmD37.cjs";
|
|
4
4
|
//#region src/protocols/mcp/protocol.d.ts
|
|
5
5
|
type McpProtocolHandler = (request: Request, recorder?: MetricsRecorder, scheduleBackground?: ScheduleBackground) => Promise<Response>;
|
|
6
6
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { m as McpDefinition } from "../../types-
|
|
2
|
-
import { t as MetricsRecorder } from "../../base-
|
|
3
|
-
import { n as ScheduleBackground, t as McpRuntimeOptions } from "../../authorize-
|
|
1
|
+
import { m as McpDefinition } from "../../types-CyDJi9Jb.js";
|
|
2
|
+
import { t as MetricsRecorder } from "../../base-DQPu0cno.js";
|
|
3
|
+
import { n as ScheduleBackground, t as McpRuntimeOptions } from "../../authorize-8crkySbp.js";
|
|
4
4
|
//#region src/protocols/mcp/protocol.d.ts
|
|
5
5
|
type McpProtocolHandler = (request: Request, recorder?: MetricsRecorder, scheduleBackground?: ScheduleBackground) => Promise<Response>;
|
|
6
6
|
/**
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as createMcpProtocolHandler } from "../../mcp-
|
|
1
|
+
import { t as createMcpProtocolHandler } from "../../mcp-DWxIy07i.js";
|
|
2
2
|
export { createMcpProtocolHandler };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_logger = require("../logger-C-Hdu57K.cjs");
|
|
3
|
-
const require_cors = require("../cors-
|
|
3
|
+
const require_cors = require("../cors-Ct-kdMcl.cjs");
|
|
4
4
|
//#region src/protocols/oauth-metadata.ts
|
|
5
5
|
function notFound() {
|
|
6
6
|
return new Response(JSON.stringify({ error: "not found" }), {
|