@plitzi/sdk-mcp 0.39.2 → 0.39.4

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 (99) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/README.md +39 -39
  3. package/dist/index.d.ts +1 -0
  4. package/dist/index.js +2 -1
  5. package/dist/modules/mcp/answerBudgets.d.ts +29 -0
  6. package/dist/modules/mcp/answerBudgets.js +37 -0
  7. package/dist/modules/mcp/apps/example/view/index.tsx +0 -1
  8. package/dist/modules/mcp/apps/render/view/index.tsx +0 -1
  9. package/dist/modules/mcp/helpers/guide/reference.d.ts +1 -1
  10. package/dist/modules/mcp/helpers/guide/reference.js +7 -2
  11. package/dist/modules/mcp/helpers/guide/structure.d.ts +1 -1
  12. package/dist/modules/mcp/helpers/guide/structure.js +1 -0
  13. package/dist/modules/mcp/helpers/opResult.d.ts +3 -1
  14. package/dist/modules/mcp/helpers/opResult.js +3 -1
  15. package/dist/modules/mcp/localScreenshotClient.d.ts +10 -0
  16. package/dist/modules/mcp/localScreenshotClient.js +46 -16
  17. package/dist/modules/mcp/previewClient.js +2 -2
  18. package/dist/modules/mcp/resources/canonical.js +2 -2
  19. package/dist/modules/mcp/server.d.ts +1 -1
  20. package/dist/modules/mcp/server.js +3 -2
  21. package/dist/modules/mcp/tools/activity.js +2 -2
  22. package/dist/modules/mcp/tools/apply/dispatch.js +7 -1
  23. package/dist/modules/mcp/tools/apply/index.d.ts +25 -1
  24. package/dist/modules/mcp/tools/apply/index.js +21 -5
  25. package/dist/modules/mcp/tools/describeOperation.js +1 -1
  26. package/dist/modules/mcp/tools/intents.js +26 -4
  27. package/dist/modules/mcp/tools/look.d.ts +1 -0
  28. package/dist/modules/mcp/tools/look.js +2 -1
  29. package/dist/modules/mcp/tools/operations/actions/deleteAction.js +1 -1
  30. package/dist/modules/mcp/tools/operations/actions/patchAction.js +3 -3
  31. package/dist/modules/mcp/tools/operations/actions/upsertAction.js +1 -1
  32. package/dist/modules/mcp/tools/operations/connectors/deleteConnector.js +1 -1
  33. package/dist/modules/mcp/tools/operations/connectors/patchConnector.js +2 -2
  34. package/dist/modules/mcp/tools/operations/data/index.js +3 -3
  35. package/dist/modules/mcp/tools/operations/functions/index.js +2 -2
  36. package/dist/modules/mcp/tools/operations/index.d.ts +97 -4
  37. package/dist/modules/mcp/tools/operations/index.js +1 -0
  38. package/dist/modules/mcp/tools/operations/schema/bindings/deleteBinding.js +1 -1
  39. package/dist/modules/mcp/tools/operations/schema/bindings/patchBinding.js +1 -1
  40. package/dist/modules/mcp/tools/operations/schema/components/deleteComponent.js +2 -2
  41. package/dist/modules/mcp/tools/operations/schema/components/upsertComponent.js +8 -8
  42. package/dist/modules/mcp/tools/operations/schema/elements/addSpec.d.ts +29 -0
  43. package/dist/modules/mcp/tools/operations/schema/elements/addSpec.js +118 -0
  44. package/dist/modules/mcp/tools/operations/schema/elements/deleteElement.js +2 -2
  45. package/dist/modules/mcp/tools/operations/schema/elements/moveElement.js +4 -4
  46. package/dist/modules/mcp/tools/operations/schema/elements/patchElement.js +2 -2
  47. package/dist/modules/mcp/tools/operations/schema/elements/repeatElement.js +2 -0
  48. package/dist/modules/mcp/tools/operations/schema/elements/upsertElement.js +3 -3
  49. package/dist/modules/mcp/tools/operations/schema/flags/deleteFlag.js +1 -1
  50. package/dist/modules/mcp/tools/operations/schema/flags/upsertFlag.js +2 -2
  51. package/dist/modules/mcp/tools/operations/schema/folders/deleteFolder.js +1 -1
  52. package/dist/modules/mcp/tools/operations/schema/folders/upsertFolder.js +1 -1
  53. package/dist/modules/mcp/tools/operations/schema/index.d.ts +1 -0
  54. package/dist/modules/mcp/tools/operations/schema/interactions/deleteInteraction.js +4 -4
  55. package/dist/modules/mcp/tools/operations/schema/interactions/patchInteractionNode.js +1 -1
  56. package/dist/modules/mcp/tools/operations/schema/operations.d.ts +25 -1
  57. package/dist/modules/mcp/tools/operations/schema/operations.js +2 -0
  58. package/dist/modules/mcp/tools/operations/schema/pages/deleteLayout.js +2 -2
  59. package/dist/modules/mcp/tools/operations/schema/pages/deletePage.js +1 -1
  60. package/dist/modules/mcp/tools/operations/schema/pages/upsertPage.d.ts +4 -0
  61. package/dist/modules/mcp/tools/operations/schema/pages/upsertPage.js +14 -7
  62. package/dist/modules/mcp/tools/operations/schema/settings/patchSettings.d.ts +8 -1
  63. package/dist/modules/mcp/tools/operations/schema/settings/patchSettings.js +9 -6
  64. package/dist/modules/mcp/tools/operations/schema/variables/deleteVariable.js +3 -2
  65. package/dist/modules/mcp/tools/operations/schema/write.js +3 -3
  66. package/dist/modules/mcp/tools/operations/style/definitions/deleteDefinition.js +2 -1
  67. package/dist/modules/mcp/tools/operations/style/definitions/patchDefinition.js +1 -1
  68. package/dist/modules/mcp/tools/operations/style/fonts/deleteFont.js +2 -2
  69. package/dist/modules/mcp/tools/operations/style/fonts/upsertFont.js +1 -1
  70. package/dist/modules/mcp/tools/operations/style/globalStyles/deleteGlobalStyle.js +2 -1
  71. package/dist/modules/mcp/tools/operations/style/globalStyles/patchGlobalStyle.js +1 -1
  72. package/dist/modules/mcp/tools/operations/style/idStyles/deleteIdStyle.js +2 -1
  73. package/dist/modules/mcp/tools/operations/style/idStyles/patchIdStyle.js +1 -1
  74. package/dist/modules/mcp/tools/operations/style/validate.js +6 -6
  75. package/dist/modules/mcp/tools/operations/style/variables/deleteStyleVariable.js +3 -2
  76. package/dist/modules/mcp/tools/operations/style/write.js +1 -1
  77. package/dist/modules/mcp/tools/render.d.ts +24 -1
  78. package/dist/modules/mcp/tools/renderWidget.d.ts +24 -1
  79. package/dist/modules/mcp/tools/search.js +1 -1
  80. package/dist/modules/mcp/tools/shared/agentHtml.d.ts +8 -0
  81. package/dist/modules/mcp/tools/shared/agentHtml.js +18 -0
  82. package/dist/modules/mcp/tools/shared/lintDraft.js +1 -0
  83. package/dist/modules/mcp/tools/shared/look.d.ts +2 -0
  84. package/dist/modules/mcp/tools/shared/look.js +15 -8
  85. package/dist/modules/mcp/tools/shared/repeats.d.ts +1 -1
  86. package/dist/modules/mcp/tools/shared/repeats.js +1 -1
  87. package/dist/modules/mcp/tools/shared/tool.d.ts +2 -0
  88. package/dist/modules/mcp/tools/shared/validator/connectors.js +3 -0
  89. package/dist/modules/mcp/tools/shared/validator/css.js +2 -0
  90. package/dist/modules/mcp/tools/shared/validator/elements.js +3 -0
  91. package/dist/modules/mcp/tools/shared/validator/index.js +39 -0
  92. package/dist/modules/mcp/tools/shared/validator/interactions.js +1 -0
  93. package/dist/modules/mcp/tools/shared/validator/refs.js +3 -0
  94. package/dist/modules/mcp/tools/tryFunction.js +2 -2
  95. package/dist/modules/mcp/types/aiSchema.d.ts +3 -0
  96. package/dist/modules/mcp/types/previewTypes.d.ts +9 -1
  97. package/dist/options.d.ts +1 -1
  98. package/dist/preview/createPreview.js +38 -7
  99. package/package.json +8 -8
@@ -5,6 +5,7 @@ import { ToolContext } from './tool';
5
5
  type LookViewport = 'desktop' | 'mobile' | 'both';
6
6
  type LookView = 'html' | 'image' | 'accessibility' | 'both';
7
7
  export declare const pageRef: z.ZodOptional<z.ZodString>;
8
+ export declare const routeParams: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
8
9
  export declare const viewport: z.ZodOptional<z.ZodEnum<{
9
10
  desktop: "desktop";
10
11
  mobile: "mobile";
@@ -13,6 +14,7 @@ export declare const viewport: z.ZodOptional<z.ZodEnum<{
13
14
  export declare const fullPage: z.ZodOptional<z.ZodBoolean>;
14
15
  type LookRequest = {
15
16
  pageRef?: string;
17
+ routeParams?: Record<string, string>;
16
18
  /** A batch to render without saving it; left out, what is saved. */
17
19
  operations?: Operation[];
18
20
  view: LookView;
@@ -1,5 +1,7 @@
1
+ import { agentHtml } from "./agentHtml.js";
1
2
  import { unnamedControls } from "../../accessibilityOutline.js";
2
3
  import { z } from "zod";
4
+ import { SPACE_TOKEN_PARAM } from "@plitzi/sdk-kernel/identity";
3
5
  // src/modules/mcp/tools/shared/look.ts
4
6
  /**
5
7
  * How a page looks — as HTML, as a picture, or as a screen reader and a browser agent read it — rendered from the saved
@@ -31,6 +33,7 @@ var CAPTURES = {
31
33
  both: ["image", "accessibility"]
32
34
  };
33
35
  var pageRef = z.string().optional().describe("The page, by name; defaults to the space default page");
36
+ var routeParams = z.record(z.string(), z.string()).optional().describe("The values of the page’s route parameters: { \"spaceId\": \"42\" } for a page at `:spaceId`");
34
37
  var viewport = z.enum([
35
38
  "desktop",
36
39
  "mobile",
@@ -44,9 +47,10 @@ var readingOf = (outlines) => outlines.map(({ label, outline }) => ({
44
47
  unnamed: unnamedControls(outline)
45
48
  }));
46
49
  var ACCESSIBILITY_HINT = "Every entry in `unnamed` is a control or picture announced by its role alone (\"button\") — nobody using a screen reader, and no browser agent, can tell what it does. Name it — a button: `title` or words inside; a link: `label`; a field: `label` (with `hideLabel` to keep it out of sight); an image: `alt`, or `decorative: true`; an icon that means something alone: `label`. `line` is where it sits in the outline.";
50
+ var SIGNED_OUT_NOTE = (page) => `"${page}" is for signed-in visitors, and a look is signed out: what it shows is where a signed-out visitor is sent — the page beside it at that address, or the sign-in`;
47
51
  var lookAt = async (ctx, request) => {
48
52
  if (!ctx.preview || ctx.spaceId === void 0) return { refused: {
49
- error: "PREVIEW_UNAVAILABLE",
53
+ error: "not-allowed",
50
54
  message: "Visual preview is not enabled on this server.",
51
55
  hint: "Preview needs the SSR render service; it is unavailable in MCP-only mode."
52
56
  } };
@@ -54,6 +58,7 @@ var lookAt = async (ctx, request) => {
54
58
  spaceId: ctx.spaceId,
55
59
  env: ctx.env,
56
60
  pageRef: request.pageRef,
61
+ ...request.routeParams ? { routeParams: request.routeParams } : {},
57
62
  operations: request.operations
58
63
  };
59
64
  const page = request.pageRef ?? "default";
@@ -66,12 +71,13 @@ var lookAt = async (ctx, request) => {
66
71
  const facts = {
67
72
  pageRef: page,
68
73
  pagePath: rendered.pagePath,
69
- stateVersion: rendered.stateVersion
74
+ stateVersion: rendered.stateVersion,
75
+ ...rendered.signedInOnly ? { note: SIGNED_OUT_NOTE(page) } : {}
70
76
  };
71
77
  if (request.view === "html") return {
72
78
  meta: {
73
79
  ...facts,
74
- html: rendered.html
80
+ html: agentHtml(rendered.html)
75
81
  },
76
82
  images: []
77
83
  };
@@ -80,13 +86,14 @@ var lookAt = async (ctx, request) => {
80
86
  ...facts,
81
87
  warning: "SCREENSHOT_DISABLED",
82
88
  message: request.view === "image" ? "The screenshot service is not configured; returning the HTML preview instead." : "No browser is configured, so the accessibility tree cannot be read; returning the HTML preview instead. Its roles and names are in the markup: every button, link and field needs words, every image an `alt`.",
83
- html: rendered.html
89
+ html: agentHtml(rendered.html)
84
90
  },
85
91
  images: []
86
92
  };
87
93
  const viewports = resolveViewports(request.viewport);
94
+ const credential = await ctx.renderCredential?.();
88
95
  const shot = await ctx.screenshot.capture({
89
- pagePath: rendered.pagePath,
96
+ pagePath: credential ? `${rendered.pagePath}${rendered.pagePath.includes("?") ? "&" : "?"}${SPACE_TOKEN_PARAM}=${encodeURIComponent(credential)}` : rendered.pagePath,
90
97
  token: rendered.token,
91
98
  viewports,
92
99
  fullPage: request.fullPage,
@@ -99,8 +106,8 @@ var lookAt = async (ctx, request) => {
99
106
  ...facts,
100
107
  warning: "SCREENSHOT_UNAVAILABLE",
101
108
  message: `The screenshot service failed (${shot.message}); returning the HTML preview instead.`,
102
- hint: "The dedicated browser service is down or unreachable. Inspect the HTML, or retry later.",
103
- html: fallback.ok ? fallback.html : ""
109
+ hint: shot.error === "RENDER_FAILED" ? "The page itself answered an error, not the browser: read the HTML below for what it says" : "The dedicated browser service is down or unreachable. Inspect the HTML, or retry later.",
110
+ html: fallback.ok ? agentHtml(fallback.html) : ""
104
111
  },
105
112
  images: []
106
113
  };
@@ -124,4 +131,4 @@ var lookAt = async (ctx, request) => {
124
131
  images: request.view === "accessibility" ? [] : shot.images
125
132
  };
126
133
  };
127
- export { fullPage, lookAt, pageRef, viewport };
134
+ export { fullPage, lookAt, pageRef, routeParams, viewport };
@@ -8,6 +8,6 @@ export declare const noteRefused: (key: string, now?: number) => void;
8
8
  export declare const forgetRefused: (key: string) => void;
9
9
  export declare const AGAIN: string;
10
10
  export declare const REPEATED: {
11
- error: string;
11
+ error: "repeated";
12
12
  message: string;
13
13
  };
@@ -31,7 +31,7 @@ var forgetRefused = (key) => {
31
31
  };
32
32
  var AGAIN = "This batch was refused before, for these reasons. Sending it again will not change the answer: change what the errors name — plitzi_describe_operation { type } gives an operation’s fields, a hint its way out — or stop and ask the person what they meant.";
33
33
  var REPEATED = {
34
- error: "REPEATED_BATCH",
34
+ error: "repeated",
35
35
  message: "This exact batch was refused twice, and was not run again. Change what the errors named, or ask the person."
36
36
  };
37
37
  export { AGAIN, REPEATED, batchKey, forgetRefused, noteRefused, timesRefused };
@@ -30,6 +30,8 @@ export interface ToolContext {
30
30
  } | {
31
31
  notRun: string;
32
32
  }>;
33
+ /** The space's render credential, which the browser taking a look's picture presents — when the host wired it. */
34
+ renderCredential?: () => Promise<string | undefined>;
33
35
  /** What happened on the space after a cursor, waited for — when the host wired it. Only plitzi_activity uses it. */
34
36
  activity?: (query: SpaceActivityQuery) => Promise<SpaceActivityPage>;
35
37
  }
@@ -9,6 +9,7 @@ import { validateConnectorManifest } from "@plitzi/sdk-shared/connectors";
9
9
  var checkManifest = (manifest, base, ctx) => {
10
10
  const report = validateConnectorManifest(manifest);
11
11
  for (const issue of report.errors) ctx.errors.push({
12
+ code: "bad-value",
12
13
  path: issue.path ? `${base}.${issue.path}` : base,
13
14
  message: issue.message,
14
15
  hint: issue.hint ?? "Read plitzi://guide (Connectors) for the manifest shape"
@@ -53,6 +54,7 @@ var checkProviderElement = (space, ctx, ref, runtime, props, batchConnectors, ba
53
54
  const endpoint = asString(props?.endpoint);
54
55
  const reads = Object.keys(entry.manifest.endpoints.read);
55
56
  if (endpoint !== void 0 && !reads.includes(endpoint)) ctx.errors.push({
57
+ code: "missing",
56
58
  path: `${base}.props.endpoint`,
57
59
  message: `Connector "${connectorId}" has no read endpoint named "${endpoint}"`,
58
60
  hint: "Name one the connector declares, or add it with patchConnector",
@@ -64,6 +66,7 @@ var checkProviderElement = (space, ctx, ref, runtime, props, batchConnectors, ba
64
66
  if (filter === null || typeof filter !== "object") return;
65
67
  const operator = asString(filter.operator);
66
68
  if (operator !== void 0 && !operators.includes(operator)) ctx.errors.push({
69
+ code: "missing",
67
70
  path: `${base}.props.filters[${i}].operator`,
68
71
  message: `Connector "${connectorId}" declares no operator "${operator}", so this filter is dropped and the query returns unfiltered records`,
69
72
  hint: "Use an operator the connector declares, or add it with patchConnector",
@@ -6,6 +6,7 @@ var checkCss = (css, path, ctx) => {
6
6
  const declared = {};
7
7
  for (const [key, value] of Object.entries(css)) if (value !== null) declared[key] = value;
8
8
  for (const ambiguous of ambiguousShorthands(declared)) ctx.errors.push({
9
+ code: "bad-value",
9
10
  path: `${path}.${ambiguous.property}`,
10
11
  message: `"${ambiguous.property}: ${ambiguous.value}" cannot be expanded: what the variable holds decides which longhand it is`,
11
12
  hint: `Name the longhand it is: ${ambiguous.fix}`
@@ -14,6 +15,7 @@ var checkCss = (css, path, ctx) => {
14
15
  if (!isCssProperty(key)) {
15
16
  const suggestion = suggestCssProperty(key);
16
17
  ctx.errors.push({
18
+ code: "bad-value",
17
19
  path: `${path}.${key}`,
18
20
  message: `Unknown CSS property "${key}"`,
19
21
  hint: suggestion ? `Use the kebab-case key "${suggestion}"` : "Read plitzi://css-properties for the valid property keys"
@@ -26,6 +26,7 @@ var EXECUTABLE_MARKUP = /<script\b|\son[a-z]+\s*=|javascript:/i;
26
26
  var checkRawMarkup = (type, props, path, ctx) => {
27
27
  if (ctx.mode !== "widget" || !props || !RAW_CODE_TYPES.has(type)) return;
28
28
  for (const [key, value] of Object.entries(props)) if (typeof value === "string" && EXECUTABLE_MARKUP.test(value)) ctx.errors.push({
29
+ code: "not-allowed",
29
30
  path: `${path}.props.${key}`,
30
31
  message: `Executable markup in a "${type}" prop is not allowed in a widget`,
31
32
  hint: "A widget renders inside the host UI, so <script>, javascript: URLs and inline on* handlers are rejected. Keep the markup inert (an inline <svg> is what this type is for) and wire behaviour with upsertInteractionFlow."
@@ -38,12 +39,14 @@ var checkElementProps = (element, path, ctx) => {
38
39
  var checkElementInput = (element, path, ctx, seen) => {
39
40
  checkIdRef(element.ref, `${path}.ref`, ctx);
40
41
  if (seen.has(element.ref)) ctx.errors.push({
42
+ code: "exists",
41
43
  path: `${path}.ref`,
42
44
  message: `Duplicate ref "${element.ref}" in this batch`,
43
45
  hint: "Use a unique ref"
44
46
  });
45
47
  seen.add(element.ref);
46
48
  if (!element.type) ctx.errors.push({
49
+ code: "wrong-options",
47
50
  path: `${path}.type`,
48
51
  message: "Element type is required",
49
52
  hint: "Read plitzi://types for known types"
@@ -11,6 +11,7 @@ import { buildTypeRegistry } from "../../../catalogs/registry.js";
11
11
  import { componentView, findComponentByRef } from "../../../helpers/components.js";
12
12
  import { findElementByRef, findFolderByRef, findPageByRef, findRootByRef, folderAncestorIds, getLayoutElements, getPageElements, pageFoldersOf, resolveRef, routeParamNames } from "../../../helpers/space.js";
13
13
  import { MAX_OPS } from "../../operations/index.js";
14
+ import { authorSpec } from "../../operations/schema/elements/addSpec.js";
14
15
  import { isValidElementId, treeOf } from "@plitzi/sdk-schema";
15
16
  import { closest } from "@plitzi/sdk-authoring";
16
17
  // src/modules/mcp/tools/shared/validator/index.ts
@@ -20,6 +21,7 @@ var STYLE_CATEGORIES = [
20
21
  "shadow",
21
22
  "custom"
22
23
  ];
24
+ var TOKEN_NAME = /^[A-Za-z0-9_-]+$/;
23
25
  /** The element type that reads through a connector. Only this one carries the connector attributes, so only it is
24
26
  * worth cross-checking against the connector store. */
25
27
  var PROVIDER_TYPE = "apiContainer";
@@ -86,6 +88,7 @@ var validateOperations = (space, ops, mode = "space") => {
86
88
  for (const { name, at } of worn) if (!classes.has(name)) {
87
89
  const nearest = closest(name, classes);
88
90
  ctx.errors.push({
91
+ code: "missing",
89
92
  path: at,
90
93
  message: `"${name}" is not a class of the space${nearest ? ` — did you mean "${nearest}"?` : ""}`,
91
94
  hint: "Name one of plitzi://definitions/{env}, or declare it earlier in the batch with upsertDefinition"
@@ -97,6 +100,7 @@ var validateOperations = (space, ops, mode = "space") => {
97
100
  (input.children ?? []).forEach((child, i) => checkTreeClasses(child, `${path}.children[${i}]`));
98
101
  };
99
102
  if (ops.length > 1e3) ctx.errors.push({
103
+ code: "bad-value",
100
104
  path: "operations",
101
105
  message: `Batch has ${ops.length} operations (max ${MAX_OPS})`,
102
106
  hint: `Split into batches of at most ${MAX_OPS}`
@@ -113,6 +117,7 @@ var validateOperations = (space, ops, mode = "space") => {
113
117
  ...Object.keys(space.schema.components)
114
118
  ];
115
119
  ctx.errors.push({
120
+ code: "missing",
116
121
  path: `${base}.pageRef`,
117
122
  message: `Page, layout or component "${op.pageRef}" does not exist`,
118
123
  hint: "Use an existing page, layout or component ref, or create it earlier in the same batch",
@@ -146,6 +151,7 @@ var validateOperations = (space, ops, mode = "space") => {
146
151
  case "upsertDefinitions": {
147
152
  const entries = Object.entries(op.definitions);
148
153
  if (entries.length === 0) ctx.errors.push({
154
+ code: "wrong-options",
149
155
  path: `${base}.definitions`,
150
156
  message: "This operation declares no classes",
151
157
  hint: "Key each class by its name: { \"definitions\": { \"card\": { \"desktop\": { … } } } }"
@@ -174,14 +180,32 @@ var validateOperations = (space, ops, mode = "space") => {
174
180
  for (const [slotName, slotDef] of Object.entries(slots ?? {})) checkSlotCss(slotDef, `${base}.slots.${slotName}`, ctx);
175
181
  break;
176
182
  }
183
+ case "addSpec": {
184
+ const authoring = authorSpec(op);
185
+ if ("authored" in authoring) for (const warning of authoring.authored.warnings) warnOnce(ctx, `${base}.spec: ${warning.message}`);
186
+ break;
187
+ }
177
188
  case "deleteGlobalStyle":
178
189
  checkRef(op.componentType, `${base}.componentType`, ctx);
179
190
  break;
191
+ case "upsertIdStyle":
192
+ case "patchIdStyle": {
193
+ const { type, targetId, slots, ...slot } = op;
194
+ checkRef(targetId, `${base}.targetId`, ctx);
195
+ checkSlotCss(slot, base, ctx);
196
+ for (const [slotName, slotDef] of Object.entries(slots ?? {})) checkSlotCss(slotDef, `${base}.slots.${slotName}`, ctx);
197
+ break;
198
+ }
199
+ case "deleteIdStyle":
200
+ checkRef(op.targetId, `${base}.targetId`, ctx);
201
+ break;
180
202
  case "upsertPage":
181
203
  checkRef(op.ref, `${base}.ref`, ctx);
204
+ checkClasses(op.style, `${base}.style`);
182
205
  if (op.slug === void 0 && !findPageByRef(space.schema, op.ref)) warnOnce(ctx, `Page "${op.ref}" is being created without a slug. Set a slug for a clean, stable URL (good practice); the page ref is used as a fallback.`);
183
206
  if (typeof op.folder === "string" && op.folder !== "") {
184
207
  if (!findFolderByRef(space.schema, op.folder) && !batchFolders.has(op.folder)) ctx.errors.push({
208
+ code: "missing",
185
209
  path: `${base}.folder`,
186
210
  message: `Folder "${op.folder}" does not exist`,
187
211
  hint: "Create it with upsertFolder earlier in the same batch, or read plitzi://folders for valid refs",
@@ -195,6 +219,7 @@ var validateOperations = (space, ops, mode = "space") => {
195
219
  checkRef(op.parentId, `${base}.parentId`, ctx);
196
220
  const parent = findFolderByRef(space.schema, op.parentId);
197
221
  if (!parent && !batchFolders.has(op.parentId)) ctx.errors.push({
222
+ code: "missing",
198
223
  path: `${base}.parentId`,
199
224
  message: `Parent folder "${op.parentId}" does not exist`,
200
225
  hint: "Create the parent with upsertFolder first, or read plitzi://folders for valid refs",
@@ -202,6 +227,7 @@ var validateOperations = (space, ops, mode = "space") => {
202
227
  });
203
228
  const selfId = findFolderByRef(space.schema, op.ref)?.id ?? op.ref;
204
229
  if ((parent?.id ?? op.parentId) === selfId || parent && folderAncestorIds(pageFoldersOf(space.schema), parent.id).includes(selfId)) ctx.errors.push({
230
+ code: "bad-value",
205
231
  path: `${base}.parentId`,
206
232
  message: `Folder "${op.ref}" cannot be nested under itself or one of its descendants`,
207
233
  hint: "Choose a parent that is not this folder or below it"
@@ -217,7 +243,14 @@ var validateOperations = (space, ops, mode = "space") => {
217
243
  break;
218
244
  case "upsertStyleVariable":
219
245
  case "deleteStyleVariable":
246
+ if (!TOKEN_NAME.test(op.name)) ctx.errors.push({
247
+ code: "bad-value",
248
+ path: `${base}.name`,
249
+ message: `"${op.name}" is not a token name: it is written as --${op.name}, which no var() can read`,
250
+ hint: "Letters, digits, \"-\" and \"_\", without the -- prefix: \"brand-primary\""
251
+ });
220
252
  if (!STYLE_CATEGORIES.includes(op.category)) ctx.errors.push({
253
+ code: "bad-value",
221
254
  path: `${base}.category`,
222
255
  message: `Unknown style-variable category "${op.category}"`,
223
256
  hint: "Use one of the valid categories",
@@ -244,11 +277,13 @@ var validateOperations = (space, ops, mode = "space") => {
244
277
  op.nodes.forEach((node, n) => {
245
278
  if (!node.id) return;
246
279
  if (!isValidElementId(node.id)) ctx.errors.push({
280
+ code: "bad-value",
247
281
  path: `${base}.nodes[${n}].id`,
248
282
  message: `"${node.id}" is not a valid step name`,
249
283
  hint: "Letters, numbers, hyphens and underscores, starting with a letter. A later step reads this one as {{ <id>.field }}, so a dot would split that path"
250
284
  });
251
285
  if (named.has(node.id)) ctx.errors.push({
286
+ code: "exists",
252
287
  path: `${base}.nodes[${n}].id`,
253
288
  message: `Two steps of this flow are called "${node.id}"`,
254
289
  hint: "A flow is keyed by step id, so the second would replace the first. Name them apart"
@@ -294,6 +329,7 @@ var validateOperations = (space, ops, mode = "space") => {
294
329
  ].forEach((setting) => {
295
330
  (op[setting] ?? []).forEach((key, index) => {
296
331
  if (key.trim() === "" || key.includes(".")) ctx.errors.push({
332
+ code: "bad-value",
297
333
  path: `${base}.${setting}[${index}]`,
298
334
  message: `"${key}" is not a top-level state key: no dots, not empty`,
299
335
  hint: `Name the key setState writes — "${key.split(".")[0] || "tourStep"}" covers everything under it`
@@ -302,6 +338,7 @@ var validateOperations = (space, ops, mode = "space") => {
302
338
  });
303
339
  (op.paintedState ?? []).forEach((key, index) => {
304
340
  if (op.transientState?.includes(key)) ctx.errors.push({
341
+ code: "wrong-options",
305
342
  path: `${base}.paintedState[${index}]`,
306
343
  message: `"${key}" is in both paintedState and transientState`,
307
344
  hint: "A painted key is kept so the server can draw with it; a transient one never is — remove it from one"
@@ -309,6 +346,7 @@ var validateOperations = (space, ops, mode = "space") => {
309
346
  });
310
347
  (op.browserState ?? []).forEach((key, index) => {
311
348
  if (op.transientState?.includes(key)) ctx.errors.push({
349
+ code: "wrong-options",
312
350
  path: `${base}.browserState[${index}]`,
313
351
  message: `"${key}" is in both browserState and transientState`,
314
352
  hint: "A key of the browser’s is a kept one that no change of account takes away; a transient one is never kept — remove it from one"
@@ -318,6 +356,7 @@ var validateOperations = (space, ops, mode = "space") => {
318
356
  case "deleteInteraction":
319
357
  checkRef(op.ref, `${base}.ref`, ctx);
320
358
  if (Boolean(op.flowId) === Boolean(op.nodeId)) ctx.errors.push({
359
+ code: "wrong-options",
321
360
  path: `${base}.nodeId`,
322
361
  message: "Provide exactly one of flowId or nodeId",
323
362
  hint: "flowId removes a whole flow; nodeId removes a single step"
@@ -60,6 +60,7 @@ var checkUtility = (node, base, ctx) => {
60
60
  var checkInteractionNode = (node, base, ctx, hostRef) => {
61
61
  if (node.nodeType === "task") {
62
62
  ctx.errors.push({
63
+ code: "not-allowed",
63
64
  path: `${base}.nodeType`,
64
65
  message: `Step "${node.action}" is a server task, which cannot run in a page flow`,
65
66
  hint: "Put it in a server action (upsertAction) and call that action from this flow"
@@ -4,6 +4,7 @@ var REF_RE = /^[a-zA-Z0-9._-]+$/;
4
4
  var checkRef = (ref, path, ctx) => {
5
5
  if (!ref || ref.trim().length === 0) {
6
6
  ctx.errors.push({
7
+ code: "bad-value",
7
8
  path,
8
9
  message: "Ref must not be empty",
9
10
  hint: "Use a semantic name like \"hero.title\""
@@ -11,6 +12,7 @@ var checkRef = (ref, path, ctx) => {
11
12
  return;
12
13
  }
13
14
  if (!REF_RE.test(ref)) ctx.errors.push({
15
+ code: "bad-value",
14
16
  path,
15
17
  message: `Ref "${ref}" has invalid characters`,
16
18
  hint: "Allowed characters: letters, numbers, dot, hyphen, underscore"
@@ -19,6 +21,7 @@ var checkRef = (ref, path, ctx) => {
19
21
  var checkIdRef = (ref, path, ctx) => {
20
22
  checkRef(ref, path, ctx);
21
23
  if (ref && REF_RE.test(ref) && !isValidElementId(ref)) ctx.errors.push({
24
+ code: "bad-value",
22
25
  path,
23
26
  message: `"${ref}" is not a valid element name`,
24
27
  hint: "Use only letters, numbers, hyphens and underscores (e.g. \"hero-cta\" or \"my_list_card\"). The name IS the element id, which the runtime embeds in source names like `apiContainer_<id>.field` and in interaction targets — a dot would break those paths."
@@ -3,8 +3,8 @@ import { z } from "zod";
3
3
  // src/modules/mcp/tools/tryFunction.ts
4
4
  var tryFunctionShape = {
5
5
  task: z.string().describe("`<namespace>.<action>`"),
6
- params: z.record(z.string(), z.unknown()).optional(),
7
- dryRun: z.boolean().optional()
6
+ params: z.record(z.string(), z.unknown()).optional().describe("The task’s params, as a page would send them"),
7
+ dryRun: z.boolean().optional().describe("Answers without running: trying a function runs its code for real — its fetches and its writes")
8
8
  };
9
9
  /**
10
10
  * Runs one task of the space's functions — the draft, in the sandbox, with the limits and the record any run has — and
@@ -1,5 +1,6 @@
1
1
  import { DocumentScroll, NotificationsSpec, CssProps } from '@plitzi/sdk-authoring';
2
2
  import { ElementRuntime, Environment, WhileRunning } from '@plitzi/sdk-shared';
3
+ import { RefusalCode } from '@plitzi/sdk-shared/refusals';
3
4
  export type Env = Environment;
4
5
  /** CSS declarations for one selector state. Keys are kebab-case CSS properties (see plitzi://css-properties).
5
6
  * Owned by the style engine, which is also what expands the shorthands an agent is allowed to write. */
@@ -304,6 +305,8 @@ export interface AISettings {
304
305
  sessionRevalidateSeconds?: number;
305
306
  }
306
307
  export interface ValidationError {
308
+ /** Why, as a code of the one list the CLI's refusals share (`plitzi explain <code>`). */
309
+ code: RefusalCode;
307
310
  path: string;
308
311
  message: string;
309
312
  hint: string;
@@ -1,5 +1,6 @@
1
1
  import { ValidationError } from './aiSchema';
2
2
  import { Operation } from '../tools/operations';
3
+ import { RefusalCode } from '@plitzi/sdk-shared/refusals';
3
4
  export type PreviewRequestBody = {
4
5
  spaceId: number;
5
6
  env?: string;
@@ -10,6 +11,8 @@ export type PreviewRequestBody = {
10
11
  */
11
12
  revision?: number;
12
13
  pageRef?: string;
14
+ /** The values of the page's route parameters — `{ spaceId: "42" }` for a page at `:spaceId` — each one required. */
15
+ routeParams?: Record<string, string>;
13
16
  operations?: Operation[];
14
17
  /**
15
18
  * Whether the response should carry the rendered HTML. Default true.
@@ -38,9 +41,14 @@ export type PreviewResult = {
38
41
  html: string;
39
42
  stateVersion: string;
40
43
  expiresInMs?: number;
44
+ /**
45
+ * Set when the page is for signed-in visitors alone. A preview is drawn as a signed-out visitor sees it, so what
46
+ * it shows at that address is what they are sent to — said beside it, never passed off as the page.
47
+ */
48
+ signedInOnly?: true;
41
49
  } | {
42
50
  ok: false;
43
- error: string;
51
+ error: RefusalCode;
44
52
  message: string;
45
53
  errors?: ValidationError[];
46
54
  };
package/dist/options.d.ts CHANGED
@@ -53,7 +53,7 @@ export type McpOptions = {
53
53
  proxy?: McpProxyOptions;
54
54
  /** For an MCP server that runs separately from the renderer (the CLIENT side): where to reach the SSR
55
55
  * `/preview` endpoint so the visual-preview tools work. The SDK builds an HTTP preview client from this;
56
- * absent → those tools report PREVIEW_UNAVAILABLE. */
56
+ * absent → those tools refuse with `not-allowed`. */
57
57
  previewClient?: {
58
58
  url: string;
59
59
  secret?: string;
@@ -2,14 +2,33 @@ import { computeVersion } from "../modules/mcp/helpers/computeVersion.js";
2
2
  import { findPageByRef, getPageElements } from "../modules/mcp/helpers/space.js";
3
3
  import { draftBatch } from "../modules/mcp/tools/shared/draftBatch.js";
4
4
  import { randomUUID } from "node:crypto";
5
+ import { closest } from "@plitzi/sdk-authoring";
5
6
  import { buildBody } from "@plitzi/sdk-server/ssr";
7
+ import { getPageFullPath, getSlugParams } from "@plitzi/sdk-shared/navigation";
6
8
  // src/preview/createPreview.ts
7
- var resolvePagePath = (schema, pageRef) => {
9
+ /** A route parameter, as a slug spells it: `:spaceId` or `{{spaceId}}`. */
10
+ var ROUTE_PARAM = /:([A-Za-z0-9_-]+)|{{\s*([A-Za-z0-9_-]+)\s*}}/g;
11
+ /**
12
+ * The address of the page asked for — its folders' slugs before its own, as a link to it resolves, its parameters
13
+ * filled — or why there is none. A page the space does not have is refused, never drawn as its home, and a page whose
14
+ * path takes a parameter not given is refused naming it, never opened at its pattern (the space's 404).
15
+ */
16
+ var resolvePage = (schema, pageRef, routeParams = {}) => {
8
17
  const pages = getPageElements(schema);
9
18
  const page = pageRef ? findPageByRef(schema, pageRef) : pages.find((p) => p.attributes.default) ?? pages[0];
10
- const slug = page && typeof page.attributes.slug === "string" ? page.attributes.slug : "";
11
- return slug.startsWith("/") ? slug : `/${slug}`;
19
+ if (!page) {
20
+ const nearest = pageRef ? closest(pageRef, pages.map((p) => p.id)) : void 0;
21
+ return { refused: pageRef ? `The space has no page "${pageRef}"${nearest ? ` — did you mean "${nearest}"?` : ""}` : "The space has no page to draw" };
22
+ }
23
+ const pattern = getPageFullPath(schema.flat, schema.pageFolders, page.id, true);
24
+ const missing = getSlugParams(pattern).filter((name) => !routeParams[name]);
25
+ if (missing.length > 0) return { refused: `"${page.id}" is at ${pattern}: give routeParams its ${missing.join(", ")} — { ${missing.map((name) => `"${name}": "…"`).join(", ")} }` };
26
+ return {
27
+ path: pattern.replace(ROUTE_PARAM, (_, colon, braces) => encodeURIComponent(routeParams[colon ?? braces ?? ""] ?? "")),
28
+ signedInOnly: page.attributes.accessLevel === "authenticated"
29
+ };
12
30
  };
31
+ var isStringRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value) && Object.values(value).every((entry) => typeof entry === "string");
13
32
  var syntheticRequest = (pagePath) => ({
14
33
  method: "GET",
15
34
  path: pagePath,
@@ -35,7 +54,7 @@ var createPreview = async (body, config, renderFn, pluginManager, caches) => {
35
54
  const offlineData = await config.adapters.getOfflineData(body.spaceId, env, revision);
36
55
  if (!offlineData) return {
37
56
  ok: false,
38
- error: "NO_DATA",
57
+ error: "missing",
39
58
  message: `No offline data for space ${body.spaceId} (${env}${revision ? ` revision ${revision}` : ""}).`
40
59
  };
41
60
  let draftOffline = offlineData;
@@ -48,7 +67,7 @@ var createPreview = async (body, config, renderFn, pluginManager, caches) => {
48
67
  }, env, body.operations);
49
68
  if (!batch.ok) return {
50
69
  ok: false,
51
- error: "INVALID_OPERATIONS",
70
+ error: "bad-value",
52
71
  message: "The operations were refused, as plitzi_apply would refuse them.",
53
72
  errors: batch.errors
54
73
  };
@@ -58,7 +77,18 @@ var createPreview = async (body, config, renderFn, pluginManager, caches) => {
58
77
  style: batch.draft.style
59
78
  };
60
79
  }
61
- const pagePath = resolvePagePath(draftOffline.schema, body.pageRef);
80
+ if (body.routeParams !== void 0 && !isStringRecord(body.routeParams)) return {
81
+ ok: false,
82
+ error: "bad-value",
83
+ message: "routeParams is an object of strings: { \"spaceId\": \"42\" }"
84
+ };
85
+ const resolved = resolvePage(draftOffline.schema, body.pageRef, body.routeParams);
86
+ if ("refused" in resolved) return {
87
+ ok: false,
88
+ error: "missing",
89
+ message: resolved.refused
90
+ };
91
+ const pagePath = resolved.path;
62
92
  let html;
63
93
  if (body.includeHtml !== false) ({body: html} = await buildBody(syntheticRequest(pagePath), config, body.spaceId, env, revision, renderFn, pluginManager, caches.offlineData, void 0, draftOffline));
64
94
  const reusable = body.mode === "session" || body.mode === "tests";
@@ -80,7 +110,8 @@ var createPreview = async (body, config, renderFn, pluginManager, caches) => {
80
110
  pagePath,
81
111
  html: html ?? "",
82
112
  stateVersion: computeVersion(draftOffline),
83
- ...token ? { expiresInMs: ttlMs } : {}
113
+ ...token ? { expiresInMs: ttlMs } : {},
114
+ ...resolved.signedInOnly ? { signedInOnly: true } : {}
84
115
  };
85
116
  };
86
117
  export { createPreview };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plitzi/sdk-mcp",
3
- "version": "0.39.2",
3
+ "version": "0.39.4",
4
4
  "license": "AGPL-3.0",
5
5
  "files": [
6
6
  "dist",
@@ -47,13 +47,13 @@
47
47
  "dependencies": {
48
48
  "@modelcontextprotocol/ext-apps": "^1.7.5",
49
49
  "@modelcontextprotocol/sdk": "^1.32.2",
50
- "@plitzi/plitzi-sdk": "0.39.2",
51
- "@plitzi/sdk-authoring": "0.39.2",
52
- "@plitzi/sdk-kernel": "0.39.2",
53
- "@plitzi/sdk-schema": "0.39.2",
54
- "@plitzi/sdk-server": "0.39.2",
55
- "@plitzi/sdk-shared": "0.39.2",
56
- "@plitzi/sdk-style": "0.39.2",
50
+ "@plitzi/plitzi-sdk": "0.39.4",
51
+ "@plitzi/sdk-authoring": "0.39.4",
52
+ "@plitzi/sdk-kernel": "0.39.4",
53
+ "@plitzi/sdk-schema": "0.39.4",
54
+ "@plitzi/sdk-server": "0.39.4",
55
+ "@plitzi/sdk-shared": "0.39.4",
56
+ "@plitzi/sdk-style": "0.39.4",
57
57
  "ejs": "^7.0.2",
58
58
  "esbuild": "^0.28.2",
59
59
  "zod": "^4.6.7"