@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.
Files changed (78) hide show
  1. package/README.md +104 -1
  2. package/dist/{authorize-Chb9Sb1f.d.ts → authorize-8crkySbp.d.ts} +1 -1
  3. package/dist/{authorize-Ba1deW5O.d.cts → authorize-BZdUmD37.d.cts} +1 -1
  4. package/dist/{base-D7ei8TjY.d.cts → base-CChLZaEN.d.cts} +1 -1
  5. package/dist/{base-D-lvtqSA.d.ts → base-DQPu0cno.d.ts} +1 -1
  6. package/dist/cli/check-server.cjs +61 -0
  7. package/dist/cli/check-server.d.cts +1 -0
  8. package/dist/cli/check-server.d.ts +1 -0
  9. package/dist/cli/check-server.js +62 -0
  10. package/dist/cli/extract-manifest.cjs +1 -1
  11. package/dist/cli/extract-manifest.js +1 -1
  12. package/dist/{cors-BuPvEjxu.cjs → cors-Ct-kdMcl.cjs} +1 -1
  13. package/dist/{cors-D9LajKfo.js → cors-Ct8SFh-_.js} +1 -1
  14. package/dist/diagnostic-ClI2_5MW.js +11 -0
  15. package/dist/diagnostic-DRKjgCsW.d.cts +12 -0
  16. package/dist/diagnostic-DRKjgCsW.d.ts +12 -0
  17. package/dist/diagnostic-ol9IE9Dl.cjs +16 -0
  18. package/dist/{errors-BEl2IOnx.js → errors-Cul5Uyfw.js} +3 -2
  19. package/dist/{errors-BlSu6Nrn.cjs → errors-ebgNFNvm.cjs} +3 -2
  20. package/dist/format-DDzvc92Z.cjs +41 -0
  21. package/dist/format-DKEuO8Tn.js +30 -0
  22. package/dist/hooks-BOdDe251.js +353 -0
  23. package/dist/hooks-xQl3EkDa.cjs +382 -0
  24. package/dist/index.cjs +1 -1
  25. package/dist/index.d.cts +2 -2
  26. package/dist/index.d.ts +2 -2
  27. package/dist/index.js +1 -1
  28. package/dist/{io-B72X5KDG.d.ts → io-4N9Hcw0w.d.ts} +1 -1
  29. package/dist/{io-foChTR9t.d.cts → io-Be8y8E2V.d.cts} +1 -1
  30. package/dist/{io-BpxqVag8.cjs → io-Bf4Narx6.cjs} +17 -5
  31. package/dist/{io-DFsll31O.js → io-VMIaguRH.js} +14 -2
  32. package/dist/{mcp-DMMqfwKm.cjs → mcp-By6C2M4i.cjs} +156 -70
  33. package/dist/{mcp-B1wBn_X-.js → mcp-DWxIy07i.js} +154 -68
  34. package/dist/{package-Bt33FsvP.cjs → package-CBMX__7C.cjs} +1 -1
  35. package/dist/{package-BWLBCBmc.js → package-Ci4yKJUI.js} +1 -1
  36. package/dist/protocols/mcp/index.cjs +1 -1
  37. package/dist/protocols/mcp/index.d.cts +3 -3
  38. package/dist/protocols/mcp/index.d.ts +3 -3
  39. package/dist/protocols/mcp/index.js +1 -1
  40. package/dist/protocols/oauth-metadata.cjs +1 -1
  41. package/dist/protocols/oauth-metadata.d.cts +3 -3
  42. package/dist/protocols/oauth-metadata.d.ts +3 -3
  43. package/dist/protocols/oauth-metadata.js +1 -1
  44. package/dist/stacks/supabase/index.cjs +2 -2
  45. package/dist/stacks/supabase/index.d.cts +1 -1
  46. package/dist/stacks/supabase/index.d.ts +1 -1
  47. package/dist/stacks/supabase/index.js +2 -2
  48. package/dist/stacks/supabase/vite.cjs +40 -19
  49. package/dist/stacks/supabase/vite.d.cts +1 -1
  50. package/dist/stacks/supabase/vite.d.ts +1 -1
  51. package/dist/stacks/supabase/vite.js +34 -13
  52. package/dist/stacks/tanstack/index.cjs +2 -2
  53. package/dist/stacks/tanstack/index.d.cts +2 -2
  54. package/dist/stacks/tanstack/index.d.ts +2 -2
  55. package/dist/stacks/tanstack/index.js +2 -2
  56. package/dist/stacks/tanstack/vite.cjs +33 -25
  57. package/dist/stacks/tanstack/vite.d.cts +1 -1
  58. package/dist/stacks/tanstack/vite.d.ts +1 -1
  59. package/dist/stacks/tanstack/vite.js +26 -18
  60. package/dist/testing/index.cjs +46 -0
  61. package/dist/testing/index.d.cts +10 -0
  62. package/dist/testing/index.d.ts +10 -0
  63. package/dist/testing/index.js +44 -0
  64. package/dist/testing/server.cjs +197 -0
  65. package/dist/testing/server.d.cts +31 -0
  66. package/dist/testing/server.d.ts +31 -0
  67. package/dist/testing/server.js +195 -0
  68. package/dist/tool-result-teeTDoM1.js +70 -0
  69. package/dist/tool-result-yqOfZUOP.cjs +87 -0
  70. package/dist/{types-srTXYLoX.d.cts → types-CyDJi9Jb.d.cts} +7 -1
  71. package/dist/{types-srTXYLoX.d.ts → types-CyDJi9Jb.d.ts} +7 -1
  72. package/package.json +40 -4
  73. package/skill-imports.d.cts +1 -0
  74. package/skill-imports.d.ts +11 -0
  75. package/dist/fs-errors-CWNzOV75.cjs +0 -11
  76. package/dist/fs-errors-PA2t1TIp.js +0 -6
  77. package/dist/supabase-config-CakTU8YF.js +0 -26
  78. 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-BlSu6Nrn.cjs");
4
- const require_cors = require("./cors-BuPvEjxu.cjs");
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/core/tool-result.ts
19
- function normalizeResourceLinkIcon(icon) {
20
- if (typeof icon.sizes !== "string") return icon;
21
- const { sizes, ...rest } = icon;
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 outputValidationError(text) {
38
- return {
39
- content: [{
40
- type: "text",
41
- text
42
- }],
43
- isError: true
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
- async function finalizeToolResult(tool, result) {
58
- const content = normalizeToolContent(result.content);
59
- let structuredContent = result.structuredContent;
60
- if (tool.outputSchema && !result.isError) {
61
- if (structuredContent === void 0) return outputValidationError(`Output validation error: Tool ${tool.name} has an output schema but no structured content was provided`);
62
- try {
63
- const parsed = await (0, zod_v4_core.safeParseAsync)(require_schema.schemaFromDefinition(tool.outputSchema, false), structuredContent);
64
- if (!parsed.success) return outputValidationError(`Output validation error: Invalid structured content for tool ${tool.name}: ${parsed.error.message}`);
65
- structuredContent = parsed.data;
66
- } catch {
67
- return outputValidationError(`Output validation error: Could not validate structured content for tool ${tool.name}`);
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
- if (structuredContent !== void 0 && !isJsonValue(structuredContent)) {
71
- if (!result.isError) return outputValidationError(`Output validation error: Tool ${tool.name} returned a non-JSON structured value`);
72
- structuredContent = void 0;
73
- }
74
- if (structuredContent !== void 0 && (structuredContent === null || typeof structuredContent !== "object" || Array.isArray(structuredContent)) && !content.some((block) => block.type === "text")) content.push({
75
- type: "text",
76
- text: JSON.stringify(structuredContent)
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
- content,
80
- structuredContent,
81
- isError: result.isError
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
- async function buildServer(mcp, auth, recorder, era, signal, operations) {
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: { tools: { listChanged: false } },
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 response = await (0, _modelcontextprotocol_server.createMcpHandler)(({ era, requestInfo }) => buildServer(mcp, authResult.auth, recorder, era, requestInfo?.signal ?? request.signal, classified?.operations), {
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-BEl2IOnx.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-D9LajKfo.js";
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/core/tool-result.ts
19
- function normalizeResourceLinkIcon(icon) {
20
- if (typeof icon.sizes !== "string") return icon;
21
- const { sizes, ...rest } = icon;
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 outputValidationError(text) {
38
- return {
39
- content: [{
40
- type: "text",
41
- text
42
- }],
43
- isError: true
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
- async function finalizeToolResult(tool, result) {
58
- const content = normalizeToolContent(result.content);
59
- let structuredContent = result.structuredContent;
60
- if (tool.outputSchema && !result.isError) {
61
- if (structuredContent === void 0) return outputValidationError(`Output validation error: Tool ${tool.name} has an output schema but no structured content was provided`);
62
- try {
63
- const parsed = await safeParseAsync(schemaFromDefinition(tool.outputSchema, false), structuredContent);
64
- if (!parsed.success) return outputValidationError(`Output validation error: Invalid structured content for tool ${tool.name}: ${parsed.error.message}`);
65
- structuredContent = parsed.data;
66
- } catch {
67
- return outputValidationError(`Output validation error: Could not validate structured content for tool ${tool.name}`);
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
- if (structuredContent !== void 0 && !isJsonValue(structuredContent)) {
71
- if (!result.isError) return outputValidationError(`Output validation error: Tool ${tool.name} returned a non-JSON structured value`);
72
- structuredContent = void 0;
73
- }
74
- if (structuredContent !== void 0 && (structuredContent === null || typeof structuredContent !== "object" || Array.isArray(structuredContent)) && !content.some((block) => block.type === "text")) content.push({
75
- type: "text",
76
- text: JSON.stringify(structuredContent)
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
- content,
80
- structuredContent,
81
- isError: result.isError
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
- async function buildServer(mcp, auth, recorder, era, signal, operations) {
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: { tools: { listChanged: false } },
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 response = await createMcpHandler(({ era, requestInfo }) => buildServer(mcp, authResult.auth, recorder, era, requestInfo?.signal ?? request.signal, classified?.operations), {
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,5 +1,5 @@
1
1
  //#region package.json
2
- var version = "4.0.0-rc.0";
2
+ var version = "4.0.0-rc.1";
3
3
  //#endregion
4
4
  Object.defineProperty(exports, "version", {
5
5
  enumerable: true,
@@ -1,4 +1,4 @@
1
1
  //#region package.json
2
- var version = "4.0.0-rc.0";
2
+ var version = "4.0.0-rc.1";
3
3
  //#endregion
4
4
  export { version as t };
@@ -1,3 +1,3 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_mcp = require("../../mcp-DMMqfwKm.cjs");
2
+ const require_mcp = require("../../mcp-By6C2M4i.cjs");
3
3
  exports.createMcpProtocolHandler = require_mcp.createMcpProtocolHandler;
@@ -1,6 +1,6 @@
1
- import { m as McpDefinition } from "../../types-srTXYLoX.cjs";
2
- import { t as MetricsRecorder } from "../../base-D7ei8TjY.cjs";
3
- import { n as ScheduleBackground, t as McpRuntimeOptions } from "../../authorize-Ba1deW5O.cjs";
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-srTXYLoX.js";
2
- import { t as MetricsRecorder } from "../../base-D-lvtqSA.js";
3
- import { n as ScheduleBackground, t as McpRuntimeOptions } from "../../authorize-Chb9Sb1f.js";
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-B1wBn_X-.js";
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-BuPvEjxu.cjs");
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" }), {