@milaboratories/pl-mcp-server 53.0.0 → 54.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/README.md +36 -2
  2. package/dist/instructions.cjs +3 -2
  3. package/dist/instructions.cjs.map +1 -1
  4. package/dist/instructions.js +3 -2
  5. package/dist/instructions.js.map +1 -1
  6. package/dist/package.cjs +1 -1
  7. package/dist/package.js +1 -1
  8. package/dist/project-holds.cjs +72 -0
  9. package/dist/project-holds.cjs.map +1 -0
  10. package/dist/project-holds.js +72 -0
  11. package/dist/project-holds.js.map +1 -0
  12. package/dist/server-log.cjs +373 -0
  13. package/dist/server-log.cjs.map +1 -0
  14. package/dist/server-log.js +371 -0
  15. package/dist/server-log.js.map +1 -0
  16. package/dist/server.cjs +77 -22
  17. package/dist/server.cjs.map +1 -1
  18. package/dist/server.d.ts +31 -7
  19. package/dist/server.d.ts.map +1 -1
  20. package/dist/server.js +77 -23
  21. package/dist/server.js.map +1 -1
  22. package/dist/tools/await.cjs +59 -60
  23. package/dist/tools/await.cjs.map +1 -1
  24. package/dist/tools/await.js +60 -61
  25. package/dist/tools/await.js.map +1 -1
  26. package/dist/tools/block-action-context.cjs +11 -9
  27. package/dist/tools/block-action-context.cjs.map +1 -1
  28. package/dist/tools/block-action-context.js +11 -9
  29. package/dist/tools/block-action-context.js.map +1 -1
  30. package/dist/tools/block-params.cjs +4 -3
  31. package/dist/tools/block-params.cjs.map +1 -1
  32. package/dist/tools/block-params.js +4 -3
  33. package/dist/tools/block-params.js.map +1 -1
  34. package/dist/tools/block-state.cjs +46 -41
  35. package/dist/tools/block-state.cjs.map +1 -1
  36. package/dist/tools/block-state.js +47 -42
  37. package/dist/tools/block-state.js.map +1 -1
  38. package/dist/tools/blocks.cjs +30 -20
  39. package/dist/tools/blocks.cjs.map +1 -1
  40. package/dist/tools/blocks.js +30 -20
  41. package/dist/tools/blocks.js.map +1 -1
  42. package/dist/tools/connection.cjs.map +1 -1
  43. package/dist/tools/connection.js.map +1 -1
  44. package/dist/tools/data-query.cjs +111 -80
  45. package/dist/tools/data-query.cjs.map +1 -1
  46. package/dist/tools/data-query.js +114 -83
  47. package/dist/tools/data-query.js.map +1 -1
  48. package/dist/tools/ids.cjs +16 -0
  49. package/dist/tools/ids.cjs.map +1 -1
  50. package/dist/tools/ids.js +13 -1
  51. package/dist/tools/ids.js.map +1 -1
  52. package/dist/tools/logs.cjs +28 -26
  53. package/dist/tools/logs.cjs.map +1 -1
  54. package/dist/tools/logs.js +28 -26
  55. package/dist/tools/logs.js.map +1 -1
  56. package/dist/tools/ping.cjs.map +1 -1
  57. package/dist/tools/ping.js.map +1 -1
  58. package/dist/tools/projects.cjs +10 -27
  59. package/dist/tools/projects.cjs.map +1 -1
  60. package/dist/tools/projects.js +11 -28
  61. package/dist/tools/projects.js.map +1 -1
  62. package/dist/tools/sandbox.cjs +110 -8
  63. package/dist/tools/sandbox.cjs.map +1 -1
  64. package/dist/tools/sandbox.js +107 -9
  65. package/dist/tools/sandbox.js.map +1 -1
  66. package/dist/tools/screenshot.cjs +9 -1
  67. package/dist/tools/screenshot.cjs.map +1 -1
  68. package/dist/tools/screenshot.js +9 -1
  69. package/dist/tools/screenshot.js.map +1 -1
  70. package/dist/tools/types.cjs +29 -0
  71. package/dist/tools/types.cjs.map +1 -1
  72. package/dist/tools/types.js +27 -1
  73. package/dist/tools/types.js.map +1 -1
  74. package/dist/tools/ui-interaction.cjs.map +1 -1
  75. package/dist/tools/ui-interaction.js.map +1 -1
  76. package/package.json +6 -5
  77. package/src/instructions.ts +3 -2
  78. package/src/project-holds.test.ts +183 -0
  79. package/src/project-holds.ts +105 -0
  80. package/src/server-log.test.ts +871 -0
  81. package/src/server-log.ts +504 -0
  82. package/src/server.logging.test.ts +383 -0
  83. package/src/server.request-failure.test.ts +49 -0
  84. package/src/server.test.ts +15 -5
  85. package/src/server.ts +111 -26
  86. package/src/test/recording-logger.ts +33 -0
  87. package/src/tools/await.ts +96 -98
  88. package/src/tools/block-action-context.ts +16 -16
  89. package/src/tools/block-params.ts +6 -6
  90. package/src/tools/block-state.ts +61 -60
  91. package/src/tools/blocks.ts +49 -40
  92. package/src/tools/connection.ts +2 -3
  93. package/src/tools/data-query.ts +151 -108
  94. package/src/tools/ids.ts +22 -1
  95. package/src/tools/logs.ts +43 -43
  96. package/src/tools/ping.ts +2 -3
  97. package/src/tools/projects.ts +22 -45
  98. package/src/tools/sandbox.test.ts +183 -0
  99. package/src/tools/sandbox.ts +126 -10
  100. package/src/tools/screenshot.ts +15 -4
  101. package/src/tools/types.test.ts +4 -3
  102. package/src/tools/types.ts +73 -3
  103. package/src/tools/ui-interaction.ts +2 -3
@@ -1 +1 @@
1
- {"version":3,"file":"block-state.cjs","names":["hints","z","projectIdInput","errorResult","textResult","blockIdInput","deriveDataFromStorage","safeEval","summarizeOutputs","ModelAPIVersionMismatchError"],"sources":["../../src/tools/block-state.ts"],"sourcesContent":["import type { McpServer } from \"@modelcontextprotocol/server\";\nimport { deriveDataFromStorage } from \"@platforma-sdk/model\";\nimport { ModelAPIVersionMismatchError } from \"@milaboratories/pl-errors\";\nimport { z } from \"zod\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport type { ToolContext } from \"./types\";\nimport { summarizeOutputs } from \"./tokens\";\nimport { safeEval } from \"./sandbox\";\nimport { errorResult, hints, textResult } from \"./types\";\n\nexport function registerBlockStateTools(server: McpServer, ctx: ToolContext): void {\n server.registerTool(\n \"get_project_overview\",\n {\n title: \"Get Project Overview\",\n annotations: hints.read,\n description:\n \"Get project overview with all blocks and their statuses (calculationStatus, canRun, stale, errors, upstreams/downstreams)\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID (must be opened)\"),\n }),\n },\n async ({ projectId }) => {\n const project = await ctx.getOpenedProject(projectId);\n const overview = await project.overview.getValue();\n if (!overview) return errorResult(\"Project overview not available yet.\");\n return textResult({\n label: overview.meta.label,\n blocks: overview.blocks.map((b) => ({\n id: b.id,\n title: b.title ?? b.label,\n calculationStatus: b.calculationStatus,\n canRun: b.canRun,\n stale: b.stale,\n inputsValid: b.inputsValid,\n outputErrors: b.outputErrors,\n upstreams: b.upstreams,\n downstreams: b.downstreams,\n })),\n });\n },\n );\n\n server.registerTool(\n \"get_block_state\",\n {\n title: \"Get Block State\",\n annotations: hints.read,\n description:\n \"Get block state. Returns block args (data) and a concise output summary with token estimates by default. \" +\n \"Use `transform` to extract specific data server-side without loading full outputs into context.\\n\\n\" +\n \"Default: returns `{ data, outputs: [{ key, ok, hasValue, tokensEstimate }] }`\\n\\n\" +\n \"Transform examples:\\n\" +\n \"- `outputs.logs?.value` — get one specific output value\\n\" +\n \"- `data` — get only block args\\n\" +\n \"- `({ preset: outputs.preset?.value, qc: outputs.qc?.value })` — get specific outputs\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID\"),\n transform: z\n .string()\n .optional()\n .describe(\n \"JS expression evaluated server-side against full block state. \" +\n \"Available variables: `data` (block args), `outputs` (raw outputs object). \" +\n \"Omit for default concise summary.\",\n ),\n transformTimeout: z\n .number()\n .optional()\n .default(5000)\n .describe(\"Timeout in ms for transform evaluation (default 5000).\"),\n }),\n },\n async ({ projectId, blockId, transform, transformTimeout }) => {\n const project = await ctx.getOpenedProject(projectId);\n const state = await project.getBlockState(blockId).getValue();\n const data = deriveDataFromStorage(state.blockStorage);\n if (transform) {\n try {\n const result = await safeEval(\n transform,\n { data, outputs: state.outputs },\n transformTimeout,\n );\n return textResult(result);\n } catch (e: unknown) {\n return errorResult(\n `Transform failed: ${e instanceof Error ? e.message : String(e)}`,\n \"Check your JS expression syntax. Available variables: data, outputs.\",\n );\n }\n }\n return textResult({\n data,\n outputs: summarizeOutputs(state.outputs as Record<string, unknown> | undefined),\n });\n },\n );\n\n server.registerTool(\n \"set_block_data\",\n {\n title: \"Set Block Data\",\n annotations: hints.destructive,\n description: \"Set the user-facing data of a block (triggers args derivation and staging)\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID\"),\n data: z.record(z.string(), z.unknown()).describe(\"Block data object\"),\n }),\n },\n async ({ projectId, blockId, data }) => {\n const project = await ctx.getOpenedProject(projectId);\n\n // V1 state shape: { args, uiState } — callers may pass either the full state\n // or just the args object. Unwrap once for both V2 and V1 paths.\n const value = data.args ?? data;\n\n // Try V2 (BlockModelV3 storage facade) first, fall back to V1 (legacy setBlockArgs).\n try {\n await project.mutateBlockStorage(\n blockId,\n { operation: \"update-block-data\", value },\n ctx.getAuthorMarker(),\n );\n } catch (e: unknown) {\n if (e instanceof ModelAPIVersionMismatchError) {\n await project.setBlockArgs(blockId, value, ctx.getAuthorMarker());\n } else {\n throw e;\n }\n }\n return textResult({ ok: true });\n },\n );\n}\n"],"mappings":";;;;;;;;AAUA,SAAgB,wBAAwB,QAAmB,KAAwB;CACjF,OAAO,aACL,wBACA;EACE,OAAO;EACP,aAAaA,cAAAA,MAAM;EACnB,aACE;EACF,aAAaC,IAAAA,EAAE,OAAO,EACpB,WAAWC,YAAAA,eAAe,SAAS,6BAA6B,EAClE,CAAC;CACH,GACA,OAAO,EAAE,gBAAgB;EAEvB,MAAM,WAAW,OAAM,MADD,IAAI,iBAAiB,SAAS,EAAA,CACrB,SAAS,SAAS;EACjD,IAAI,CAAC,UAAU,OAAOC,cAAAA,YAAY,qCAAqC;EACvE,OAAOC,cAAAA,WAAW;GAChB,OAAO,SAAS,KAAK;GACrB,QAAQ,SAAS,OAAO,KAAK,OAAO;IAClC,IAAI,EAAE;IACN,OAAO,EAAE,SAAS,EAAE;IACpB,mBAAmB,EAAE;IACrB,QAAQ,EAAE;IACV,OAAO,EAAE;IACT,aAAa,EAAE;IACf,cAAc,EAAE;IAChB,WAAW,EAAE;IACb,aAAa,EAAE;GACjB,EAAE;EACJ,CAAC;CACH,CACF;CAEA,OAAO,aACL,mBACA;EACE,OAAO;EAC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,UAAU,MAAM,IAAI,iBAAiB,SAAS;EAIpD,MAAM,QAAQ,KAAK,QAAQ;EAG3B,IAAI;GACF,MAAM,QAAQ,mBACZ,SACA;IAAE,WAAW;IAAqB;GAAM,GACxC,IAAI,gBAAgB,CACtB;EACF,SAAS,GAAY;GACnB,IAAI,aAAaQ,0BAAAA,8BACf,MAAM,QAAQ,aAAa,SAAS,OAAO,IAAI,gBAAgB,CAAC;QAEhE,MAAM;EAEV;EACA,OAAOL,cAAAA,WAAW,EAAE,IAAI,KAAK,CAAC;CAChC,CACF;AACF"}
1
+ {"version":3,"file":"block-state.cjs","names":["hints","z","projectIdInput","errorResult","textResult","blockIdInput","deriveDataFromStorage","safeEval","transformFailedResult","summarizeOutputs","ModelAPIVersionMismatchError"],"sources":["../../src/tools/block-state.ts"],"sourcesContent":["import { deriveDataFromStorage } from \"@platforma-sdk/model\";\nimport { ModelAPIVersionMismatchError } from \"@milaboratories/pl-errors\";\nimport { z } from \"zod\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport type { ToolContext, ToolRegistrar } from \"./types\";\nimport { summarizeOutputs } from \"./tokens\";\nimport { safeEval } from \"./sandbox\";\nimport { errorResult, hints, textResult, transformFailedResult } from \"./types\";\n\nexport function registerBlockStateTools(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"get_project_overview\",\n {\n title: \"Get Project Overview\",\n annotations: hints.read,\n description:\n \"Get project overview with all blocks and their statuses (calculationStatus, canRun, stale, errors, upstreams/downstreams)\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n }),\n },\n async ({ projectId }) => {\n return await ctx.withProject(projectId, async (project) => {\n const overview = await project.overview.getValue();\n if (!overview) return errorResult(\"Project overview not available yet.\");\n return textResult({\n label: overview.meta.label,\n blocks: overview.blocks.map((b) => ({\n id: b.id,\n title: b.title ?? b.label,\n calculationStatus: b.calculationStatus,\n canRun: b.canRun,\n stale: b.stale,\n inputsValid: b.inputsValid,\n outputErrors: b.outputErrors,\n upstreams: b.upstreams,\n downstreams: b.downstreams,\n })),\n });\n });\n },\n );\n\n server.registerTool(\n \"get_block_state\",\n {\n title: \"Get Block State\",\n annotations: hints.read,\n description:\n \"Get block state. Returns block args (data) and a concise output summary with token estimates by default. \" +\n \"Use `transform` to extract specific data server-side without loading full outputs into context.\\n\\n\" +\n \"Default: returns `{ data, outputs: [{ key, ok, hasValue, tokensEstimate }] }`\\n\\n\" +\n \"Transform examples:\\n\" +\n \"- `outputs.logs?.value` — get one specific output value\\n\" +\n \"- `data` — get only block args\\n\" +\n \"- `({ preset: outputs.preset?.value, qc: outputs.qc?.value })` — get specific outputs\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID\"),\n transform: z\n .string()\n .optional()\n .describe(\n \"JS expression evaluated server-side against full block state. \" +\n \"Available variables: `data` (block args), `outputs` (raw outputs object). \" +\n \"Omit for default concise summary.\",\n ),\n transformTimeout: z\n .number()\n .optional()\n .default(5000)\n .describe(\"Timeout in ms for transform evaluation (default 5000).\"),\n }),\n },\n async ({ projectId, blockId, transform, transformTimeout }) => {\n return await ctx.withProject(projectId, async (project) => {\n const state = await project.getBlockState(blockId).getValue();\n const data = deriveDataFromStorage(state.blockStorage);\n if (transform) {\n try {\n const result = await safeEval(\n transform,\n { data, outputs: state.outputs },\n transformTimeout,\n );\n return textResult(result);\n } catch (e: unknown) {\n return transformFailedResult(\n e,\n \"Check your JS expression syntax. Available variables: data, outputs.\",\n );\n }\n }\n return textResult({\n data,\n outputs: summarizeOutputs(state.outputs as Record<string, unknown> | undefined),\n });\n });\n },\n );\n\n server.registerTool(\n \"set_block_data\",\n {\n title: \"Set Block Data\",\n annotations: hints.destructive,\n description: \"Set the user-facing data of a block (triggers args derivation and staging)\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID\"),\n data: z.record(z.string(), z.unknown()).describe(\"Block data object\"),\n }),\n },\n async ({ projectId, blockId, data }) => {\n return await ctx.withProject(projectId, async (project) => {\n // V1 state shape: { args, uiState } — callers may pass either the full state\n // or just the args object. Unwrap once for both V2 and V1 paths.\n const value = data.args ?? data;\n\n // Try V2 (BlockModelV3 storage facade) first, fall back to V1 (legacy setBlockArgs).\n try {\n await project.mutateBlockStorage(\n blockId,\n { operation: \"update-block-data\", value },\n ctx.getAuthorMarker(),\n );\n } catch (e: unknown) {\n if (e instanceof ModelAPIVersionMismatchError) {\n await project.setBlockArgs(blockId, value, ctx.getAuthorMarker());\n } else {\n throw e;\n }\n }\n return textResult({ ok: true });\n });\n },\n );\n}\n"],"mappings":";;;;;;;;AASA,SAAgB,wBAAwB,QAAuB,KAAwB;CACrF,OAAO,aACL,wBACA;EACE,OAAO;EACP,aAAaA,cAAAA,MAAM;EACnB,aACE;EACF,aAAaC,IAAAA,EAAE,OAAO,EACpB,WAAWC,YAAAA,eAAe,SAAS,YAAY,EACjD,CAAC;CACH,GACA,OAAO,EAAE,gBAAgB;EACvB,OAAO,MAAM,IAAI,YAAY,WAAW,OAAO,YAAY;GACzD,MAAM,WAAW,MAAM,QAAQ,SAAS,SAAS;GACjD,IAAI,CAAC,UAAU,OAAOC,cAAAA,YAAY,qCAAqC;GACvE,OAAOC,cAAAA,WAAW;IAChB,OAAO,SAAS,KAAK;IACrB,QAAQ,SAAS,OAAO,KAAK,OAAO;KAClC,IAAI,EAAE;KACN,OAAO,EAAE,SAAS,EAAE;KACpB,mBAAmB,EAAE;KACrB,QAAQ,EAAE;KACV,OAAO,EAAE;KACT,aAAa,EAAE;KACf,cAAc,EAAE;KAChB,WAAW,EAAE;KACb,aAAa,EAAE;IACjB,EAAE;GACJ,CAAC;EACH,CAAC;CACH,CACF;CAEA,OAAO,aACL,mBACA;EACE,OAAO;EACP,aAAaJ,cAAAA,MAAM;EACnB,aACE;EAOF,aAAaC,IAAAA,EAAE,OAAO;GACpB,WAAWC,YAAAA,eAAe,SAAS,YAAY;GAC/C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AqB;IAAM,GACxC,IAAI,gBAAgB,CACtB;GACF,SAAS,GAAY;IACnB,IAAI,aAAaS,0BAAAA,8BACf,MAAM,QAAQ,aAAa,SAAS,OAAO,IAAI,gBAAgB,CAAC;SAEhE,MAAM;GAEV;GACA,OAAON,cAAAA,WAAW,EAAE,IAAI,KAAK,CAAC;EAChC,CAAC;CACH,CACF;AACF"}
@@ -1,4 +1,4 @@
1
- import { errorResult, hints, textResult } from "./types.js";
1
+ import { errorResult, hints, textResult, transformFailedResult } from "./types.js";
2
2
  import { blockIdInput, projectIdInput } from "./ids.js";
3
3
  import { summarizeOutputs } from "./tokens.js";
4
4
  import { safeEval } from "./sandbox.js";
@@ -11,23 +11,25 @@ function registerBlockStateTools(server, ctx) {
11
11
  title: "Get Project Overview",
12
12
  annotations: hints.read,
13
13
  description: "Get project overview with all blocks and their statuses (calculationStatus, canRun, stale, errors, upstreams/downstreams)",
14
- inputSchema: z.object({ projectId: projectIdInput.describe("Project ID (must be opened)") })
14
+ inputSchema: z.object({ projectId: projectIdInput.describe("Project ID") })
15
15
  }, async ({ projectId }) => {
16
- const overview = await (await ctx.getOpenedProject(projectId)).overview.getValue();
17
- if (!overview) return errorResult("Project overview not available yet.");
18
- return textResult({
19
- label: overview.meta.label,
20
- blocks: overview.blocks.map((b) => ({
21
- id: b.id,
22
- title: b.title ?? b.label,
23
- calculationStatus: b.calculationStatus,
24
- canRun: b.canRun,
25
- stale: b.stale,
26
- inputsValid: b.inputsValid,
27
- outputErrors: b.outputErrors,
28
- upstreams: b.upstreams,
29
- downstreams: b.downstreams
30
- }))
16
+ return await ctx.withProject(projectId, async (project) => {
17
+ const overview = await project.overview.getValue();
18
+ if (!overview) return errorResult("Project overview not available yet.");
19
+ return textResult({
20
+ label: overview.meta.label,
21
+ blocks: overview.blocks.map((b) => ({
22
+ id: b.id,
23
+ title: b.title ?? b.label,
24
+ calculationStatus: b.calculationStatus,
25
+ canRun: b.canRun,
26
+ stale: b.stale,
27
+ inputsValid: b.inputsValid,
28
+ outputErrors: b.outputErrors,
29
+ upstreams: b.upstreams,
30
+ downstreams: b.downstreams
31
+ }))
32
+ });
31
33
  });
32
34
  });
33
35
  server.registerTool("get_block_state", {
@@ -41,20 +43,22 @@ function registerBlockStateTools(server, ctx) {
41
43
  transformTimeout: z.number().optional().default(5e3).describe("Timeout in ms for transform evaluation (default 5000).")
42
44
  })
43
45
  }, async ({ projectId, blockId, transform, transformTimeout }) => {
44
- const state = await (await ctx.getOpenedProject(projectId)).getBlockState(blockId).getValue();
45
- const data = deriveDataFromStorage(state.blockStorage);
46
- if (transform) try {
47
- const result = await safeEval(transform, {
46
+ return await ctx.withProject(projectId, async (project) => {
47
+ const state = await project.getBlockState(blockId).getValue();
48
+ const data = deriveDataFromStorage(state.blockStorage);
49
+ if (transform) try {
50
+ const result = await safeEval(transform, {
51
+ data,
52
+ outputs: state.outputs
53
+ }, transformTimeout);
54
+ return textResult(result);
55
+ } catch (e) {
56
+ return transformFailedResult(e, "Check your JS expression syntax. Available variables: data, outputs.");
57
+ }
58
+ return textResult({
48
59
  data,
49
- outputs: state.outputs
50
- }, transformTimeout);
51
- return textResult(result);
52
- } catch (e) {
53
- return errorResult(`Transform failed: ${e instanceof Error ? e.message : String(e)}`, "Check your JS expression syntax. Available variables: data, outputs.");
54
- }
55
- return textResult({
56
- data,
57
- outputs: summarizeOutputs(state.outputs)
60
+ outputs: summarizeOutputs(state.outputs)
61
+ });
58
62
  });
59
63
  });
60
64
  server.registerTool("set_block_data", {
@@ -67,18 +71,19 @@ function registerBlockStateTools(server, ctx) {
67
71
  data: z.record(z.string(), z.unknown()).describe("Block data object")
68
72
  })
69
73
  }, async ({ projectId, blockId, data }) => {
70
- const project = await ctx.getOpenedProject(projectId);
71
- const value = data.args ?? data;
72
- try {
73
- await project.mutateBlockStorage(blockId, {
74
- operation: "update-block-data",
75
- value
76
- }, ctx.getAuthorMarker());
77
- } catch (e) {
78
- if (e instanceof ModelAPIVersionMismatchError) await project.setBlockArgs(blockId, value, ctx.getAuthorMarker());
79
- else throw e;
80
- }
81
- return textResult({ ok: true });
74
+ return await ctx.withProject(projectId, async (project) => {
75
+ const value = data.args ?? data;
76
+ try {
77
+ await project.mutateBlockStorage(blockId, {
78
+ operation: "update-block-data",
79
+ value
80
+ }, ctx.getAuthorMarker());
81
+ } catch (e) {
82
+ if (e instanceof ModelAPIVersionMismatchError) await project.setBlockArgs(blockId, value, ctx.getAuthorMarker());
83
+ else throw e;
84
+ }
85
+ return textResult({ ok: true });
86
+ });
82
87
  });
83
88
  }
84
89
  export { registerBlockStateTools };
@@ -1 +1 @@
1
- {"version":3,"file":"block-state.js","names":[],"sources":["../../src/tools/block-state.ts"],"sourcesContent":["import type { McpServer } from \"@modelcontextprotocol/server\";\nimport { deriveDataFromStorage } from \"@platforma-sdk/model\";\nimport { ModelAPIVersionMismatchError } from \"@milaboratories/pl-errors\";\nimport { z } from \"zod\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport type { ToolContext } from \"./types\";\nimport { summarizeOutputs } from \"./tokens\";\nimport { safeEval } from \"./sandbox\";\nimport { errorResult, hints, textResult } from \"./types\";\n\nexport function registerBlockStateTools(server: McpServer, ctx: ToolContext): void {\n server.registerTool(\n \"get_project_overview\",\n {\n title: \"Get Project Overview\",\n annotations: hints.read,\n description:\n \"Get project overview with all blocks and their statuses (calculationStatus, canRun, stale, errors, upstreams/downstreams)\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID (must be opened)\"),\n }),\n },\n async ({ projectId }) => {\n const project = await ctx.getOpenedProject(projectId);\n const overview = await project.overview.getValue();\n if (!overview) return errorResult(\"Project overview not available yet.\");\n return textResult({\n label: overview.meta.label,\n blocks: overview.blocks.map((b) => ({\n id: b.id,\n title: b.title ?? b.label,\n calculationStatus: b.calculationStatus,\n canRun: b.canRun,\n stale: b.stale,\n inputsValid: b.inputsValid,\n outputErrors: b.outputErrors,\n upstreams: b.upstreams,\n downstreams: b.downstreams,\n })),\n });\n },\n );\n\n server.registerTool(\n \"get_block_state\",\n {\n title: \"Get Block State\",\n annotations: hints.read,\n description:\n \"Get block state. Returns block args (data) and a concise output summary with token estimates by default. \" +\n \"Use `transform` to extract specific data server-side without loading full outputs into context.\\n\\n\" +\n \"Default: returns `{ data, outputs: [{ key, ok, hasValue, tokensEstimate }] }`\\n\\n\" +\n \"Transform examples:\\n\" +\n \"- `outputs.logs?.value` — get one specific output value\\n\" +\n \"- `data` — get only block args\\n\" +\n \"- `({ preset: outputs.preset?.value, qc: outputs.qc?.value })` — get specific outputs\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID\"),\n transform: z\n .string()\n .optional()\n .describe(\n \"JS expression evaluated server-side against full block state. \" +\n \"Available variables: `data` (block args), `outputs` (raw outputs object). \" +\n \"Omit for default concise summary.\",\n ),\n transformTimeout: z\n .number()\n .optional()\n .default(5000)\n .describe(\"Timeout in ms for transform evaluation (default 5000).\"),\n }),\n },\n async ({ projectId, blockId, transform, transformTimeout }) => {\n const project = await ctx.getOpenedProject(projectId);\n const state = await project.getBlockState(blockId).getValue();\n const data = deriveDataFromStorage(state.blockStorage);\n if (transform) {\n try {\n const result = await safeEval(\n transform,\n { data, outputs: state.outputs },\n transformTimeout,\n );\n return textResult(result);\n } catch (e: unknown) {\n return errorResult(\n `Transform failed: ${e instanceof Error ? e.message : String(e)}`,\n \"Check your JS expression syntax. Available variables: data, outputs.\",\n );\n }\n }\n return textResult({\n data,\n outputs: summarizeOutputs(state.outputs as Record<string, unknown> | undefined),\n });\n },\n );\n\n server.registerTool(\n \"set_block_data\",\n {\n title: \"Set Block Data\",\n annotations: hints.destructive,\n description: \"Set the user-facing data of a block (triggers args derivation and staging)\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID\"),\n data: z.record(z.string(), z.unknown()).describe(\"Block data object\"),\n }),\n },\n async ({ projectId, blockId, data }) => {\n const project = await ctx.getOpenedProject(projectId);\n\n // V1 state shape: { args, uiState } — callers may pass either the full state\n // or just the args object. Unwrap once for both V2 and V1 paths.\n const value = data.args ?? data;\n\n // Try V2 (BlockModelV3 storage facade) first, fall back to V1 (legacy setBlockArgs).\n try {\n await project.mutateBlockStorage(\n blockId,\n { operation: \"update-block-data\", value },\n ctx.getAuthorMarker(),\n );\n } catch (e: unknown) {\n if (e instanceof ModelAPIVersionMismatchError) {\n await project.setBlockArgs(blockId, value, ctx.getAuthorMarker());\n } else {\n throw e;\n }\n }\n return textResult({ ok: true });\n },\n );\n}\n"],"mappings":";;;;;;;;AAUA,SAAgB,wBAAwB,QAAmB,KAAwB;CACjF,OAAO,aACL,wBACA;EACE,OAAO;EACP,aAAa,MAAM;EACnB,aACE;EACF,aAAa,EAAE,OAAO,EACpB,WAAW,eAAe,SAAS,6BAA6B,EAClE,CAAC;CACH,GACA,OAAO,EAAE,gBAAgB;EAEvB,MAAM,WAAW,OAAM,MADD,IAAI,iBAAiB,SAAS,EAAA,CACrB,SAAS,SAAS;EACjD,IAAI,CAAC,UAAU,OAAO,YAAY,qCAAqC;EACvE,OAAO,WAAW;GAChB,OAAO,SAAS,KAAK;GACrB,QAAQ,SAAS,OAAO,KAAK,OAAO;IAClC,IAAI,EAAE;IACN,OAAO,EAAE,SAAS,EAAE;IACpB,mBAAmB,EAAE;IACrB,QAAQ,EAAE;IACV,OAAO,EAAE;IACT,aAAa,EAAE;IACf,cAAc,EAAE;IAChB,WAAW,EAAE;IACb,aAAa,EAAE;GACjB,EAAE;EACJ,CAAC;CACH,CACF;CAEA,OAAO,aACL,mBACA;EACE,OAAO;EACP,aAAa,MAAM;EACnB,aACE;EAOF,aAAa,EAAE,OAAO;GACpB,WAAW,eAAe,SAAS,YAAY;GAC/C,SAAS,aAAa,SAAS,UAAU;GACzC,WAAW,EACR,OAAO,CAAC,CACR,SAAS,CAAC,CACV,SACC,2KAGF;GACF,kBAAkB,EACf,OAAO,CAAC,CACR,SAA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sourcesContent":["import { deriveDataFromStorage } from \"@platforma-sdk/model\";\nimport { ModelAPIVersionMismatchError } from \"@milaboratories/pl-errors\";\nimport { z } from \"zod\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport type { ToolContext, ToolRegistrar } from \"./types\";\nimport { summarizeOutputs } from \"./tokens\";\nimport { safeEval } from \"./sandbox\";\nimport { errorResult, hints, textResult, transformFailedResult } from \"./types\";\n\nexport function registerBlockStateTools(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"get_project_overview\",\n {\n title: \"Get Project Overview\",\n annotations: hints.read,\n description:\n \"Get project overview with all blocks and their statuses (calculationStatus, canRun, stale, errors, upstreams/downstreams)\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n }),\n },\n async ({ projectId }) => {\n return await ctx.withProject(projectId, async (project) => {\n const overview = await project.overview.getValue();\n if (!overview) return errorResult(\"Project overview not available yet.\");\n return textResult({\n label: overview.meta.label,\n blocks: overview.blocks.map((b) => ({\n id: b.id,\n title: b.title ?? b.label,\n calculationStatus: b.calculationStatus,\n canRun: b.canRun,\n stale: b.stale,\n inputsValid: b.inputsValid,\n outputErrors: b.outputErrors,\n upstreams: b.upstreams,\n downstreams: b.downstreams,\n })),\n });\n });\n },\n );\n\n server.registerTool(\n \"get_block_state\",\n {\n title: \"Get Block State\",\n annotations: hints.read,\n description:\n \"Get block state. Returns block args (data) and a concise output summary with token estimates by default. \" +\n \"Use `transform` to extract specific data server-side without loading full outputs into context.\\n\\n\" +\n \"Default: returns `{ data, outputs: [{ key, ok, hasValue, tokensEstimate }] }`\\n\\n\" +\n \"Transform examples:\\n\" +\n \"- `outputs.logs?.value` — get one specific output value\\n\" +\n \"- `data` — get only block args\\n\" +\n \"- `({ preset: outputs.preset?.value, qc: outputs.qc?.value })` — get specific outputs\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID\"),\n transform: z\n .string()\n .optional()\n .describe(\n \"JS expression evaluated server-side against full block state. \" +\n \"Available variables: `data` (block args), `outputs` (raw outputs object). \" +\n \"Omit for default concise summary.\",\n ),\n transformTimeout: z\n .number()\n .optional()\n .default(5000)\n .describe(\"Timeout in ms for transform evaluation (default 5000).\"),\n }),\n },\n async ({ projectId, blockId, transform, transformTimeout }) => {\n return await ctx.withProject(projectId, async (project) => {\n const state = await project.getBlockState(blockId).getValue();\n const data = deriveDataFromStorage(state.blockStorage);\n if (transform) {\n try {\n const result = await safeEval(\n transform,\n { data, outputs: state.outputs },\n transformTimeout,\n );\n return textResult(result);\n } catch (e: unknown) {\n return transformFailedResult(\n e,\n \"Check your JS expression syntax. Available variables: data, outputs.\",\n );\n }\n }\n return textResult({\n data,\n outputs: summarizeOutputs(state.outputs as Record<string, unknown> | undefined),\n });\n });\n },\n );\n\n server.registerTool(\n \"set_block_data\",\n {\n title: \"Set Block Data\",\n annotations: hints.destructive,\n description: \"Set the user-facing data of a block (triggers args derivation and staging)\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID\"),\n data: z.record(z.string(), z.unknown()).describe(\"Block data object\"),\n }),\n },\n async ({ projectId, blockId, data }) => {\n return await ctx.withProject(projectId, async (project) => {\n // V1 state shape: { args, uiState } — callers may pass either the full state\n // or just the args object. Unwrap once for both V2 and V1 paths.\n const value = data.args ?? data;\n\n // Try V2 (BlockModelV3 storage facade) first, fall back to V1 (legacy setBlockArgs).\n try {\n await project.mutateBlockStorage(\n blockId,\n { operation: \"update-block-data\", value },\n ctx.getAuthorMarker(),\n );\n } catch (e: unknown) {\n if (e instanceof ModelAPIVersionMismatchError) {\n await project.setBlockArgs(blockId, value, ctx.getAuthorMarker());\n } else {\n throw e;\n }\n }\n return textResult({ ok: true });\n });\n },\n );\n}\n"],"mappings":";;;;;;;;AASA,SAAgB,wBAAwB,QAAuB,KAAwB;CACrF,OAAO,aACL,wBACA;EACE,OAAO;EACP,aAAa,MA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EF,OAAO,WAAW;IAChB;IACA,SAAS,iBAAiB,MAAM,OAA8C;GAChF,CAAC;EACH,CAAC;CACH,CACF;CAEA,OAAO,aACL,kBACA;EACE,OAAO;EACP,aAAa,MAAM;EACnB,aAAa;EACb,aAAa,EAAE,OAAO;GACpB,WAAW,eAAe,SAAS,YAAY;GAC/C,SAAS,aAAa,SAAS,UAAU;GACzC,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS,mBAAmB;EACtE,CAAC;CACH,GACA,OAAO,EAAE,WAAW,SAAS,WAAW;EACtC,OAAO,MAAM,IAAI,YAAY,WAAW,OAAO,YAAY;GAGzD,MAAM,QAAQ,KAAK,QAAQ;GAG3B,IAAI;IACF,MAAM,QAAQ,mBACZ,SACA;KAAE,WAAW;KAAqB;IAAM,GACxC,IAAI,gBAAgB,CACtB;GACF,SAAS,GAAY;IACnB,IAAI,aAAa,8BACf,MAAM,QAAQ,aAAa,SAAS,OAAO,IAAI,gBAAgB,CAAC;SAEhE,MAAM;GAEV;GACA,OAAO,WAAW,EAAE,IAAI,KAAK,CAAC;EAChC,CAAC;CACH,CACF;AACF"}
@@ -1,8 +1,8 @@
1
1
  const require_types = require("./types.cjs");
2
2
  const require_ids = require("./ids.cjs");
3
3
  const require_block_api = require("./block-api.cjs");
4
- let zod = require("zod");
5
4
  let _milaboratories_pl_middle_layer = require("@milaboratories/pl-middle-layer");
5
+ let zod = require("zod");
6
6
  let _milaboratories_pl_errors = require("@milaboratories/pl-errors");
7
7
  // src/tools/blocks.ts
8
8
  /** Where a kind is resolved when the caller names no registry. */
@@ -14,7 +14,7 @@ function errorMessage(e) {
14
14
  return e instanceof Error ? e.message : String(e);
15
15
  }
16
16
  const addBlockInput = zod.z.object({
17
- projectId: require_ids.projectIdInput.describe("Project ID (must be opened)"),
17
+ projectId: require_ids.projectIdInput.describe("Project ID"),
18
18
  label: zod.z.string().describe("Block label"),
19
19
  spec: zod.z.union([
20
20
  zod.z.object({
@@ -74,22 +74,22 @@ function registerBlockTools(server, ctx) {
74
74
  server.registerTool("add_block", {
75
75
  title: "Add Block",
76
76
  annotations: require_types.hints.additive,
77
- description: "Add a block to an opened project, optionally configured from initialization params.\n\n`spec` names the block: `kind` (a block kind reference, resolved to the newest block implementing it), `from-registry-v2` (an exact published block) or `dev-v2` (a local dev block folder).\n\n`params` are the initialization params of the block's kind: the block's own model checks them and builds its initial state from them. Without `params` the block starts in its default state. get_block_params shows the params of an existing block.\n\nReferences to other blocks inside `params` must hold real block ids of this project, copied from tool results. Params copied from another project or a template hold other ids: map each of them to a block of this project with `blockIds`.\n\nOnly blocks on the current block API can be added. On any error nothing is created.",
77
+ description: "Add a block to a project, optionally configured from initialization params.\n\n`spec` names the block: `kind` (a block kind reference, resolved to the newest block implementing it), `from-registry-v2` (an exact published block) or `dev-v2` (a local dev block folder).\n\n`params` are the initialization params of the block's kind: the block's own model checks them and builds its initial state from them. Without `params` the block starts in its default state. get_block_params shows the params of an existing block.\n\nReferences to other blocks inside `params` must hold real block ids of this project, copied from tool results. Params copied from another project or a template hold other ids: map each of them to a block of this project with `blockIds`.\n\nOnly blocks on the current block API can be added. On any error nothing is created.",
78
78
  inputSchema: addBlockInput
79
79
  }, async (input) => {
80
80
  const ml = ctx.requireMl();
81
- return await addBlock({
82
- project: await ctx.getOpenedProject(input.projectId),
81
+ return await ctx.withProject(input.projectId, async (project) => await addBlock({
82
+ project,
83
83
  resolveKind: (kind, registryUrl, allowUnstable) => ml.blockRegistryProvider.getRegistry(registryUrl ?? centralBlockRegistryUrl()).resolveKind(kind, { allowUnstable }),
84
84
  author: ctx.getAuthorMarker()
85
- }, input);
85
+ }, input));
86
86
  });
87
87
  server.registerTool("update_block", {
88
88
  title: "Update Block",
89
89
  annotations: require_types.hints.destructive,
90
90
  description: "Update an existing block's pack (reload from registry or dev folder). Use after rebuilding a dev block to pick up changes without removing/re-adding it.",
91
91
  inputSchema: zod.z.object({
92
- projectId: require_ids.projectIdInput.describe("Project ID (must be opened)"),
92
+ projectId: require_ids.projectIdInput.describe("Project ID"),
93
93
  blockId: require_ids.blockIdInput.describe("Block ID to update"),
94
94
  spec: zod.z.union([zod.z.object({
95
95
  type: zod.z.literal("from-registry-v2"),
@@ -106,20 +106,24 @@ function registerBlockTools(server, ctx) {
106
106
  resetArgs: zod.z.boolean().optional().describe("Reset block arguments to initial values (default: false)")
107
107
  })
108
108
  }, async ({ projectId, blockId, spec, resetArgs }) => {
109
- await (await ctx.getOpenedProject(projectId)).updateBlockPack(blockId, spec, resetArgs ?? false, ctx.getAuthorMarker());
110
- return require_types.textResult({ ok: true });
109
+ return await ctx.withProject(projectId, async (project) => {
110
+ await project.updateBlockPack(blockId, spec, resetArgs ?? false, ctx.getAuthorMarker());
111
+ return require_types.textResult({ ok: true });
112
+ });
111
113
  });
112
114
  server.registerTool("remove_block", {
113
115
  title: "Remove Block",
114
116
  annotations: require_types.hints.destructive,
115
- description: "Remove a block from an opened project, with its configuration and results. Blocks below that refer to it are left with a missing reference.",
117
+ description: "Remove a block from a project, with its configuration and results. Blocks below that refer to it are left with a missing reference.",
116
118
  inputSchema: zod.z.object({
117
119
  projectId: require_ids.projectIdInput.describe("Project ID"),
118
120
  blockId: require_ids.blockIdInput.describe("Block ID to remove")
119
121
  })
120
122
  }, async ({ projectId, blockId }) => {
121
- await (await ctx.getOpenedProject(projectId)).deleteBlock(blockId, ctx.getAuthorMarker());
122
- return require_types.textResult({ ok: true });
123
+ return await ctx.withProject(projectId, async (project) => {
124
+ await project.deleteBlock(blockId, ctx.getAuthorMarker());
125
+ return require_types.textResult({ ok: true });
126
+ });
123
127
  });
124
128
  server.registerTool("run_block", {
125
129
  title: "Run Block",
@@ -133,8 +137,10 @@ function registerBlockTools(server, ctx) {
133
137
  blockId: require_ids.blockIdInput.describe("Block ID to run")
134
138
  })
135
139
  }, async ({ projectId, blockId }) => {
136
- await (await ctx.getOpenedProject(projectId)).runBlock(blockId);
137
- return require_types.textResult({ ok: true });
140
+ return await ctx.withProject(projectId, async (project) => {
141
+ await project.runBlock(blockId);
142
+ return require_types.textResult({ ok: true });
143
+ });
138
144
  });
139
145
  server.registerTool("stop_block", {
140
146
  title: "Stop Block",
@@ -145,8 +151,10 @@ function registerBlockTools(server, ctx) {
145
151
  blockId: require_ids.blockIdInput.describe("Block ID to stop")
146
152
  })
147
153
  }, async ({ projectId, blockId }) => {
148
- await (await ctx.getOpenedProject(projectId)).stopBlock(blockId);
149
- return require_types.textResult({ ok: true });
154
+ return await ctx.withProject(projectId, async (project) => {
155
+ await project.stopBlock(blockId);
156
+ return require_types.textResult({ ok: true });
157
+ });
150
158
  });
151
159
  server.registerTool("reorder_blocks", {
152
160
  title: "Reorder Blocks",
@@ -157,8 +165,10 @@ function registerBlockTools(server, ctx) {
157
165
  blockIds: zod.z.array(require_ids.blockIdInput).describe("All block IDs in the desired order")
158
166
  })
159
167
  }, async ({ projectId, blockIds }) => {
160
- await (await ctx.getOpenedProject(projectId)).reorderBlocks(blockIds);
161
- return require_types.textResult({ ok: true });
168
+ return await ctx.withProject(projectId, async (project) => {
169
+ await project.reorderBlocks(blockIds);
170
+ return require_types.textResult({ ok: true });
171
+ });
162
172
  });
163
173
  server.registerTool("list_available_blocks", {
164
174
  title: "List Available Blocks",
@@ -188,13 +198,13 @@ function registerBlockTools(server, ctx) {
188
198
  server.registerTool("select_block", {
189
199
  title: "Show Block in the Application",
190
200
  annotations: require_types.hints.idempotent,
191
- description: "Navigate the desktop UI to show a specific block's interface",
201
+ description: "Show a block to the user in the application: the application's window opens the block. Use it only when the user asks to be shown something; working with blocks does not need it.",
192
202
  inputSchema: zod.z.object({
193
203
  projectId: require_ids.projectIdInput.describe("Project ID"),
194
204
  blockId: require_ids.blockIdInput.describe("Block ID to display")
195
205
  })
196
206
  }, async ({ projectId, blockId }) => {
197
- if (!ctx.callbacks.selectBlock) return require_types.errorResult("Failed to select the block.", "This feature requires server connected and open project. Use get_connection_status and list_projects to check. If there are no connection, use list_connections and ask user which should be used.");
207
+ if (!ctx.callbacks.selectBlock) return require_types.errorResult("Failed to show the block: this server is not running inside the desktop application.");
198
208
  await ctx.callbacks.selectBlock(projectId, blockId);
199
209
  return require_types.textResult({ ok: true });
200
210
  });
@@ -1 +1 @@
1
- {"version":3,"file":"blocks.cjs","names":["CentralBlockRegistry","z","projectIdInput","blockIdInput","BlockKindRef","errorResult","SUPPORTED_BLOCK_API","textResult","unsupportedBlockApiResult","BlockInitParamsRejectedError","hints"],"sources":["../../src/tools/blocks.ts"],"sourcesContent":["import type { McpServer } from \"@modelcontextprotocol/server\";\nimport type { BlockPackSpecAny, Project } from \"@milaboratories/pl-middle-layer\";\nimport { BlockKindRef, CentralBlockRegistry } from \"@milaboratories/pl-middle-layer\";\nimport { BlockInitParamsRejectedError } from \"@milaboratories/pl-errors\";\nimport type { BlockKindReference } from \"@platforma-sdk/model\";\nimport { z } from \"zod\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport type { AuthorMarker, ToolContext } from \"./types\";\nimport { errorResult, hints, textResult } from \"./types\";\nimport { SUPPORTED_BLOCK_API, unsupportedBlockApiResult } from \"./block-api\";\n\n/** Where a kind is resolved when the caller names no registry. */\nfunction centralBlockRegistryUrl(): string {\n if (CentralBlockRegistry.type !== \"remote-v2\")\n throw new Error(\"The central block registry is expected to be a v2 remote registry.\");\n return CentralBlockRegistry.url;\n}\n\nfunction errorMessage(e: unknown): string {\n return e instanceof Error ? e.message : String(e);\n}\n\nconst addBlockInput = z.object({\n projectId: projectIdInput.describe(\"Project ID (must be opened)\"),\n label: z.string().describe(\"Block label\"),\n spec: z\n .union([\n z.object({\n type: z.literal(\"kind\"),\n kind: z\n .string()\n .describe(\n 'Block kind reference \"<package name>@<version or range>\", ' +\n 'e.g. \"@platforma-open/milaboratories.samples-and-data.kind@1.2.0\"',\n ),\n registryUrl: z\n .string()\n .optional()\n .describe(\"Registry to resolve the kind in (default: the central block registry)\"),\n allowUnstable: z\n .boolean()\n .optional()\n .describe(\"Also consider blocks not published to the stable channel\"),\n }),\n z.object({\n type: z.literal(\"from-registry-v2\"),\n registryUrl: z.string().describe(\"Registry URL\"),\n id: z.object({\n organization: z.string(),\n name: z.string(),\n version: z.string(),\n }),\n }),\n z.object({\n type: z.literal(\"dev-v2\"),\n folder: z.string().describe(\"Path to block folder\"),\n }),\n ])\n .describe(\"Which block to add\"),\n params: z\n .record(z.string(), z.unknown())\n .optional()\n .describe(\"Initialization params of the block's kind. Omit for the default state.\"),\n blockIds: z\n .record(z.string(), blockIdInput)\n .optional()\n .describe(\n \"Ids used inside `params` in place of block ids, each mapped to a block id of this \" +\n \"project. Needed only when `params` do not already hold ids of this project.\",\n ),\n before: blockIdInput\n .optional()\n .describe(\"ID of the block to insert the new block before (default: add at the end)\"),\n});\n\n/** Input of the `add_block` tool. */\nexport type AddBlockInput = z.infer<typeof addBlockInput>;\n\n/** What `add_block` needs from the application. */\nexport type AddBlockDeps = {\n project: Pick<Project, \"addBlock\">;\n /** Resolves a kind reference to the block implementing it; throws when there is none. */\n resolveKind: (\n kind: BlockKindReference,\n registryUrl: string | undefined,\n allowUnstable: boolean,\n ) => Promise<BlockPackSpecAny>;\n author: AuthorMarker;\n};\n\n/**\n * Adds the block the input describes, started from its params when it carries them. Every way the\n * block can be refused comes back as an error result saying nothing was created.\n */\nexport async function addBlock(deps: AddBlockDeps, input: AddBlockInput) {\n const { label, spec, params, blockIds, before } = input;\n\n let blockPackSpec: BlockPackSpecAny;\n if (spec.type === \"kind\") {\n try {\n blockPackSpec = await deps.resolveKind(\n BlockKindRef.parse(spec.kind),\n spec.registryUrl,\n spec.allowUnstable ?? false,\n );\n } catch (e: unknown) {\n return errorResult(\n `Kind \"${spec.kind}\" was not resolved to a block: ${errorMessage(e)}. Nothing was created.`,\n \"Check the kind name and version. Pass allowUnstable: true if the block is not \" +\n \"published to the stable channel, or registryUrl if it lives in another registry.\",\n );\n }\n } else {\n blockPackSpec = spec;\n }\n\n try {\n const blockId = await deps.project.addBlock(\n label,\n blockPackSpec,\n before,\n deps.author,\n undefined,\n {\n init: params === undefined ? undefined : { params, blockIds },\n requireModelAPIVersion: SUPPORTED_BLOCK_API,\n },\n );\n return textResult({ blockId });\n } catch (e: unknown) {\n const unsupported = unsupportedBlockApiResult(e);\n if (unsupported) return unsupported;\n if (e instanceof BlockInitParamsRejectedError)\n return errorResult(\n `The block did not accept the params: ${e.reason}. Nothing was created.`,\n \"Fix the params and call add_block again. get_block_params on a configured block \" +\n \"of the same kind shows the expected shape.\",\n );\n throw e;\n }\n}\n\nexport function registerBlockTools(server: McpServer, ctx: ToolContext): void {\n server.registerTool(\n \"add_block\",\n {\n title: \"Add Block\",\n annotations: hints.additive,\n description:\n \"Add a block to an opened project, optionally configured from initialization params.\\n\\n\" +\n \"`spec` names the block: `kind` (a block kind reference, resolved to the newest block \" +\n \"implementing it), `from-registry-v2` (an exact published block) or `dev-v2` (a local dev \" +\n \"block folder).\\n\\n\" +\n \"`params` are the initialization params of the block's kind: the block's own model checks \" +\n \"them and builds its initial state from them. Without `params` the block starts in its \" +\n \"default state. get_block_params shows the params of an existing block.\\n\\n\" +\n \"References to other blocks inside `params` must hold real block ids of this project, \" +\n \"copied from tool results. Params copied from another project or a template hold other \" +\n \"ids: map each of them to a block of this project with `blockIds`.\\n\\n\" +\n \"Only blocks on the current block API can be added. On any error nothing is created.\",\n inputSchema: addBlockInput,\n },\n async (input) => {\n const ml = ctx.requireMl();\n return await addBlock(\n {\n project: await ctx.getOpenedProject(input.projectId),\n resolveKind: (kind, registryUrl, allowUnstable) =>\n ml.blockRegistryProvider\n .getRegistry(registryUrl ?? centralBlockRegistryUrl())\n .resolveKind(kind, { allowUnstable }),\n author: ctx.getAuthorMarker(),\n },\n input,\n );\n },\n );\n\n server.registerTool(\n \"update_block\",\n {\n title: \"Update Block\",\n annotations: hints.destructive,\n description:\n \"Update an existing block's pack (reload from registry or dev folder). Use after rebuilding a dev block to pick up changes without removing/re-adding it.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID (must be opened)\"),\n blockId: blockIdInput.describe(\"Block ID to update\"),\n spec: z\n .union([\n z.object({\n type: z.literal(\"from-registry-v2\"),\n registryUrl: z.string().describe(\"Registry URL\"),\n id: z.object({\n organization: z.string(),\n name: z.string(),\n version: z.string(),\n }),\n }),\n z.object({\n type: z.literal(\"dev-v2\"),\n folder: z.string().describe(\"Path to block folder\"),\n }),\n ])\n .describe(\"Block pack specification\"),\n resetArgs: z\n .boolean()\n .optional()\n .describe(\"Reset block arguments to initial values (default: false)\"),\n }),\n },\n async ({ projectId, blockId, spec, resetArgs }) => {\n const project = await ctx.getOpenedProject(projectId);\n await project.updateBlockPack(\n blockId,\n spec as BlockPackSpecAny,\n resetArgs ?? false,\n ctx.getAuthorMarker(),\n );\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"remove_block\",\n {\n title: \"Remove Block\",\n annotations: hints.destructive,\n description:\n \"Remove a block from an opened project, with its configuration and results. Blocks below that refer to it are left with a missing reference.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID to remove\"),\n }),\n },\n async ({ projectId, blockId }) => {\n const project = await ctx.getOpenedProject(projectId);\n await project.deleteBlock(blockId, ctx.getAuthorMarker());\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"run_block\",\n {\n title: \"Run Block\",\n // Starts work like an additive tool, but replaces results and stops blocks computing below.\n annotations: { ...hints.additive, destructiveHint: true },\n description:\n \"Run a block. Stale upstream blocks are started automatically. A run replaces the previous results of each block it starts; downstream blocks that are still computing are stopped and their unfinished work is lost.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID to run\"),\n }),\n },\n async ({ projectId, blockId }) => {\n const project = await ctx.getOpenedProject(projectId);\n await project.runBlock(blockId);\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"stop_block\",\n {\n title: \"Stop Block\",\n annotations: hints.destructive,\n description: \"Stop the computation of a running block. Use run_block to start it again.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID to stop\"),\n }),\n },\n async ({ projectId, blockId }) => {\n const project = await ctx.getOpenedProject(projectId);\n await project.stopBlock(blockId);\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"reorder_blocks\",\n {\n title: \"Reorder Blocks\",\n annotations: hints.destructive,\n description: \"Reorder blocks in a project. Must provide ALL block IDs in the desired order.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockIds: z.array(blockIdInput).describe(\"All block IDs in the desired order\"),\n }),\n },\n async ({ projectId, blockIds }) => {\n const project = await ctx.getOpenedProject(projectId);\n await project.reorderBlocks(blockIds);\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"list_available_blocks\",\n {\n title: \"List Available Blocks\",\n annotations: hints.read,\n description:\n \"List available blocks from configured registries. Optional query to filter by name.\",\n inputSchema: z.object({\n query: z\n .string()\n .optional()\n .describe(\"Filter blocks by name (case-insensitive substring match)\"),\n }),\n },\n async ({ query }) => {\n if (!ctx.callbacks.listAvailableBlocks) {\n return errorResult(\n \"Block registry is not available.\",\n \"This usually means the desktop app encounters a problem connecting block registry. Check Settings > Override Main Registry find which registry really in use and check connection.\",\n );\n }\n const blocks = await ctx.callbacks.listAvailableBlocks(query);\n return textResult(blocks);\n },\n );\n\n server.registerTool(\n \"get_block_info\",\n {\n title: \"Get Block Info\",\n annotations: hints.read,\n description:\n \"Get detailed info about a specific block package from the registry. Use list_available_blocks first to find the block.\",\n inputSchema: z.object({\n registryUrl: z.string().describe(\"Registry URL (from list_available_blocks)\"),\n organization: z.string().describe(\"Organization name\"),\n name: z.string().describe(\"Block package name\"),\n version: z.string().describe(\"Block version\"),\n }),\n },\n async ({ registryUrl, organization, name, version }) => {\n if (!ctx.callbacks.getBlockInfo) {\n return errorResult(\n \"Block info is not available in this environment.\",\n 'Maybe the name of the block was written incerrectly. Use list_available_blocks to browse blocks instead. Or ask user to check \"Additional Registries\" in Settings panel',\n );\n }\n const info = await ctx.callbacks.getBlockInfo(registryUrl, organization, name, version);\n return textResult(info);\n },\n );\n\n server.registerTool(\n \"select_block\",\n {\n title: \"Show Block in the Application\",\n annotations: hints.idempotent,\n description: \"Navigate the desktop UI to show a specific block's interface\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID to display\"),\n }),\n },\n async ({ projectId, blockId }) => {\n if (!ctx.callbacks.selectBlock) {\n return errorResult(\n \"Failed to select the block.\",\n \"This feature requires server connected and open project. Use get_connection_status and list_projects to check. If there are no connection, use list_connections and ask user which should be used.\",\n );\n }\n await ctx.callbacks.selectBlock(projectId, blockId);\n return textResult({ ok: true });\n },\n );\n}\n"],"mappings":";;;;;;;;AAYA,SAAS,0BAAkC;CACzC,IAAIA,gCAAAA,qBAAqB,SAAS,aAChC,MAAM,IAAI,MAAM,oEAAoE;CACtF,OAAOA,gCAAAA,qBAAqB;AAC9B;AAEA,SAAS,aAAa,GAAoB;CACxC,OAAO,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC;AAClD;AAEA,MAAM,gBAAgBC,IAAAA,EAAE,OAAO;CAC7B,WAAWC,YAAAA,eAAe,SAAS,6BAA6B;CAChE,OAAOD,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,aAAa;CACxC,MAAMA,IAAAA,EACH,MAAM;EACLA,IAAAA,EAAE,OAAO;GACP,MAAMA,IAAAA,EAAE,QAAQ,MAAM;GACtB,MAAMA,IAAAA,EACH,OAAO,CAAC,CACR,SACC,iIAEF;GACF,aAAaA,IAAAA,EACV,OAAO,CAAC,CACR,SAAS,CAAC,CACV,SAAS,uEAAuE;GACnF,eAAeA,IAAAA,EACZ,QAAQ,CAAC,CACT,SAAS,CAAC,CACV,SAAS,0DAA0D;EACxE,CAAC;EACDA,IAAAA,EAAE,OAAO;GACP,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,EAAE,OAAO,CAAC,CAAC,SAAS,mBAAmB;GACrD,MAAMA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,oBAAoB;GAC9C,SAASA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,eAAe;EAC9C,CAAC;CACH,GACA,OAAO,EAAE,aAAa,cAAc,MAAM,cAAc;EACtD,IAAI,CAAC,IAAI,UAAU,cACjB,OAAOI,cAAAA,YACL,oDACA,2KACF;EAEF,MAAM,OAAO,MAAM,IAAI,UAAU,aAAa,aAAa,cAAc,MAAM,OAAO;EACtF,OAAOE,cAAAA,WAAW,IAAI;CACxB,CACF;CAEA,OAAO,aACL,gBACA;EACE,OAAO;EACP,aAAaG,cAAAA,MAAM;EACnB,aAAa;EACb,aAAaT,IAAAA,EAAE,OAAO;GACpB,WAAWC,YAAAA,eAAe,SAAS,YAAY;GAC/C,SAASC,YAAAA,aAAa,SAAS,qBAAqB;EACtD,CAAC;CACH,GACA,OAAO,EAAE,WAAW,cAAc;EAChC,IAAI,CAAC,IAAI,UAAU,aACjB,OAAOE,cAAAA,YACL,+BACA,oMACF;EAEF,MAAM,IAAI,UAAU,YAAY,WAAW,OAAO;EAClD,OAAOE,cAAAA,WAAW,EAAE,IAAI,KAAK,CAAC;CAChC,CACF;AACF"}
1
+ {"version":3,"file":"blocks.cjs","names":["CentralBlockRegistry","z","projectIdInput","blockIdInput","BlockKindRef","errorResult","SUPPORTED_BLOCK_API","textResult","unsupportedBlockApiResult","BlockInitParamsRejectedError","hints"],"sources":["../../src/tools/blocks.ts"],"sourcesContent":["import type { BlockPackSpecAny, Project } from \"@milaboratories/pl-middle-layer\";\nimport { BlockKindRef, CentralBlockRegistry } from \"@milaboratories/pl-middle-layer\";\nimport { BlockInitParamsRejectedError } from \"@milaboratories/pl-errors\";\nimport type { BlockKindReference } from \"@platforma-sdk/model\";\nimport { z } from \"zod\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport type { AuthorMarker, ToolContext, ToolRegistrar } from \"./types\";\nimport { errorResult, hints, textResult } from \"./types\";\nimport { SUPPORTED_BLOCK_API, unsupportedBlockApiResult } from \"./block-api\";\n\n/** Where a kind is resolved when the caller names no registry. */\nfunction centralBlockRegistryUrl(): string {\n if (CentralBlockRegistry.type !== \"remote-v2\")\n throw new Error(\"The central block registry is expected to be a v2 remote registry.\");\n return CentralBlockRegistry.url;\n}\n\nfunction errorMessage(e: unknown): string {\n return e instanceof Error ? e.message : String(e);\n}\n\nconst addBlockInput = z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n label: z.string().describe(\"Block label\"),\n spec: z\n .union([\n z.object({\n type: z.literal(\"kind\"),\n kind: z\n .string()\n .describe(\n 'Block kind reference \"<package name>@<version or range>\", ' +\n 'e.g. \"@platforma-open/milaboratories.samples-and-data.kind@1.2.0\"',\n ),\n registryUrl: z\n .string()\n .optional()\n .describe(\"Registry to resolve the kind in (default: the central block registry)\"),\n allowUnstable: z\n .boolean()\n .optional()\n .describe(\"Also consider blocks not published to the stable channel\"),\n }),\n z.object({\n type: z.literal(\"from-registry-v2\"),\n registryUrl: z.string().describe(\"Registry URL\"),\n id: z.object({\n organization: z.string(),\n name: z.string(),\n version: z.string(),\n }),\n }),\n z.object({\n type: z.literal(\"dev-v2\"),\n folder: z.string().describe(\"Path to block folder\"),\n }),\n ])\n .describe(\"Which block to add\"),\n params: z\n .record(z.string(), z.unknown())\n .optional()\n .describe(\"Initialization params of the block's kind. Omit for the default state.\"),\n blockIds: z\n .record(z.string(), blockIdInput)\n .optional()\n .describe(\n \"Ids used inside `params` in place of block ids, each mapped to a block id of this \" +\n \"project. Needed only when `params` do not already hold ids of this project.\",\n ),\n before: blockIdInput\n .optional()\n .describe(\"ID of the block to insert the new block before (default: add at the end)\"),\n});\n\n/** Input of the `add_block` tool. */\nexport type AddBlockInput = z.infer<typeof addBlockInput>;\n\n/** What `add_block` needs from the application. */\nexport type AddBlockDeps = {\n project: Pick<Project, \"addBlock\">;\n /** Resolves a kind reference to the block implementing it; throws when there is none. */\n resolveKind: (\n kind: BlockKindReference,\n registryUrl: string | undefined,\n allowUnstable: boolean,\n ) => Promise<BlockPackSpecAny>;\n author: AuthorMarker;\n};\n\n/**\n * Adds the block the input describes, started from its params when it carries them. Every way the\n * block can be refused comes back as an error result saying nothing was created.\n */\nexport async function addBlock(deps: AddBlockDeps, input: AddBlockInput) {\n const { label, spec, params, blockIds, before } = input;\n\n let blockPackSpec: BlockPackSpecAny;\n if (spec.type === \"kind\") {\n try {\n blockPackSpec = await deps.resolveKind(\n BlockKindRef.parse(spec.kind),\n spec.registryUrl,\n spec.allowUnstable ?? false,\n );\n } catch (e: unknown) {\n return errorResult(\n `Kind \"${spec.kind}\" was not resolved to a block: ${errorMessage(e)}. Nothing was created.`,\n \"Check the kind name and version. Pass allowUnstable: true if the block is not \" +\n \"published to the stable channel, or registryUrl if it lives in another registry.\",\n );\n }\n } else {\n blockPackSpec = spec;\n }\n\n try {\n const blockId = await deps.project.addBlock(\n label,\n blockPackSpec,\n before,\n deps.author,\n undefined,\n {\n init: params === undefined ? undefined : { params, blockIds },\n requireModelAPIVersion: SUPPORTED_BLOCK_API,\n },\n );\n return textResult({ blockId });\n } catch (e: unknown) {\n const unsupported = unsupportedBlockApiResult(e);\n if (unsupported) return unsupported;\n if (e instanceof BlockInitParamsRejectedError)\n return errorResult(\n `The block did not accept the params: ${e.reason}. Nothing was created.`,\n \"Fix the params and call add_block again. get_block_params on a configured block \" +\n \"of the same kind shows the expected shape.\",\n );\n throw e;\n }\n}\n\nexport function registerBlockTools(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"add_block\",\n {\n title: \"Add Block\",\n annotations: hints.additive,\n description:\n \"Add a block to a project, optionally configured from initialization params.\\n\\n\" +\n \"`spec` names the block: `kind` (a block kind reference, resolved to the newest block \" +\n \"implementing it), `from-registry-v2` (an exact published block) or `dev-v2` (a local dev \" +\n \"block folder).\\n\\n\" +\n \"`params` are the initialization params of the block's kind: the block's own model checks \" +\n \"them and builds its initial state from them. Without `params` the block starts in its \" +\n \"default state. get_block_params shows the params of an existing block.\\n\\n\" +\n \"References to other blocks inside `params` must hold real block ids of this project, \" +\n \"copied from tool results. Params copied from another project or a template hold other \" +\n \"ids: map each of them to a block of this project with `blockIds`.\\n\\n\" +\n \"Only blocks on the current block API can be added. On any error nothing is created.\",\n inputSchema: addBlockInput,\n },\n async (input) => {\n const ml = ctx.requireMl();\n return await ctx.withProject(\n input.projectId,\n async (project) =>\n await addBlock(\n {\n project,\n resolveKind: (kind, registryUrl, allowUnstable) =>\n ml.blockRegistryProvider\n .getRegistry(registryUrl ?? centralBlockRegistryUrl())\n .resolveKind(kind, { allowUnstable }),\n author: ctx.getAuthorMarker(),\n },\n input,\n ),\n );\n },\n );\n\n server.registerTool(\n \"update_block\",\n {\n title: \"Update Block\",\n annotations: hints.destructive,\n description:\n \"Update an existing block's pack (reload from registry or dev folder). Use after rebuilding a dev block to pick up changes without removing/re-adding it.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID to update\"),\n spec: z\n .union([\n z.object({\n type: z.literal(\"from-registry-v2\"),\n registryUrl: z.string().describe(\"Registry URL\"),\n id: z.object({\n organization: z.string(),\n name: z.string(),\n version: z.string(),\n }),\n }),\n z.object({\n type: z.literal(\"dev-v2\"),\n folder: z.string().describe(\"Path to block folder\"),\n }),\n ])\n .describe(\"Block pack specification\"),\n resetArgs: z\n .boolean()\n .optional()\n .describe(\"Reset block arguments to initial values (default: false)\"),\n }),\n },\n async ({ projectId, blockId, spec, resetArgs }) => {\n return await ctx.withProject(projectId, async (project) => {\n await project.updateBlockPack(\n blockId,\n spec as BlockPackSpecAny,\n resetArgs ?? false,\n ctx.getAuthorMarker(),\n );\n return textResult({ ok: true });\n });\n },\n );\n\n server.registerTool(\n \"remove_block\",\n {\n title: \"Remove Block\",\n annotations: hints.destructive,\n description:\n \"Remove a block from a project, with its configuration and results. Blocks below that refer to it are left with a missing reference.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID to remove\"),\n }),\n },\n async ({ projectId, blockId }) => {\n return await ctx.withProject(projectId, async (project) => {\n await project.deleteBlock(blockId, ctx.getAuthorMarker());\n return textResult({ ok: true });\n });\n },\n );\n\n server.registerTool(\n \"run_block\",\n {\n title: \"Run Block\",\n // Starts work like an additive tool, but replaces results and stops blocks computing below.\n annotations: { ...hints.additive, destructiveHint: true },\n description:\n \"Run a block. Stale upstream blocks are started automatically. A run replaces the previous results of each block it starts; downstream blocks that are still computing are stopped and their unfinished work is lost.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID to run\"),\n }),\n },\n async ({ projectId, blockId }) => {\n return await ctx.withProject(projectId, async (project) => {\n await project.runBlock(blockId);\n return textResult({ ok: true });\n });\n },\n );\n\n server.registerTool(\n \"stop_block\",\n {\n title: \"Stop Block\",\n annotations: hints.destructive,\n description: \"Stop the computation of a running block. Use run_block to start it again.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID to stop\"),\n }),\n },\n async ({ projectId, blockId }) => {\n return await ctx.withProject(projectId, async (project) => {\n await project.stopBlock(blockId);\n return textResult({ ok: true });\n });\n },\n );\n\n server.registerTool(\n \"reorder_blocks\",\n {\n title: \"Reorder Blocks\",\n annotations: hints.destructive,\n description: \"Reorder blocks in a project. Must provide ALL block IDs in the desired order.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockIds: z.array(blockIdInput).describe(\"All block IDs in the desired order\"),\n }),\n },\n async ({ projectId, blockIds }) => {\n return await ctx.withProject(projectId, async (project) => {\n await project.reorderBlocks(blockIds);\n return textResult({ ok: true });\n });\n },\n );\n\n server.registerTool(\n \"list_available_blocks\",\n {\n title: \"List Available Blocks\",\n annotations: hints.read,\n description:\n \"List available blocks from configured registries. Optional query to filter by name.\",\n inputSchema: z.object({\n query: z\n .string()\n .optional()\n .describe(\"Filter blocks by name (case-insensitive substring match)\"),\n }),\n },\n async ({ query }) => {\n if (!ctx.callbacks.listAvailableBlocks) {\n return errorResult(\n \"Block registry is not available.\",\n \"This usually means the desktop app encounters a problem connecting block registry. Check Settings > Override Main Registry find which registry really in use and check connection.\",\n );\n }\n const blocks = await ctx.callbacks.listAvailableBlocks(query);\n return textResult(blocks);\n },\n );\n\n server.registerTool(\n \"get_block_info\",\n {\n title: \"Get Block Info\",\n annotations: hints.read,\n description:\n \"Get detailed info about a specific block package from the registry. Use list_available_blocks first to find the block.\",\n inputSchema: z.object({\n registryUrl: z.string().describe(\"Registry URL (from list_available_blocks)\"),\n organization: z.string().describe(\"Organization name\"),\n name: z.string().describe(\"Block package name\"),\n version: z.string().describe(\"Block version\"),\n }),\n },\n async ({ registryUrl, organization, name, version }) => {\n if (!ctx.callbacks.getBlockInfo) {\n return errorResult(\n \"Block info is not available in this environment.\",\n 'Maybe the name of the block was written incerrectly. Use list_available_blocks to browse blocks instead. Or ask user to check \"Additional Registries\" in Settings panel',\n );\n }\n const info = await ctx.callbacks.getBlockInfo(registryUrl, organization, name, version);\n return textResult(info);\n },\n );\n\n server.registerTool(\n \"select_block\",\n {\n title: \"Show Block in the Application\",\n annotations: hints.idempotent,\n description:\n \"Show a block to the user in the application: the application's window opens the block. \" +\n \"Use it only when the user asks to be shown something; working with blocks does not need it.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID\"),\n blockId: blockIdInput.describe(\"Block ID to display\"),\n }),\n },\n async ({ projectId, blockId }) => {\n if (!ctx.callbacks.selectBlock) {\n return errorResult(\n \"Failed to show the block: this server is not running inside the desktop application.\",\n );\n }\n await ctx.callbacks.selectBlock(projectId, blockId);\n return textResult({ ok: true });\n },\n );\n}\n"],"mappings":";;;;;;;;AAWA,SAAS,0BAAkC;CACzC,IAAIA,gCAAAA,qBAAqB,SAAS,aAChC,MAAM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A,EAAE,OAAO;GACpB,WAAWC,YAAAA,eAAe,SAAS,YAAY;GAC/C,SAASC,YAAAA,aAAa,SAAS,qBAAqB;EACtD,CAAC;CACH,GACA,OAAO,EAAE,WAAW,cAAc;EAChC,IAAI,CAAC,IAAI,UAAU,aACjB,OAAOE,cAAAA,YACL,sFACF;EAEF,MAAM,IAAI,UAAU,YAAY,WAAW,OAAO;EAClD,OAAOE,cAAAA,WAAW,EAAE,IAAI,KAAK,CAAC;CAChC,CACF;AACF"}
@@ -1,8 +1,8 @@
1
1
  import { errorResult, hints, textResult } from "./types.js";
2
2
  import { blockIdInput, projectIdInput } from "./ids.js";
3
3
  import { SUPPORTED_BLOCK_API, unsupportedBlockApiResult } from "./block-api.js";
4
- import { z } from "zod";
5
4
  import { BlockKindRef, CentralBlockRegistry } from "@milaboratories/pl-middle-layer";
5
+ import { z } from "zod";
6
6
  import { BlockInitParamsRejectedError } from "@milaboratories/pl-errors";
7
7
  // src/tools/blocks.ts
8
8
  /** Where a kind is resolved when the caller names no registry. */
@@ -14,7 +14,7 @@ function errorMessage(e) {
14
14
  return e instanceof Error ? e.message : String(e);
15
15
  }
16
16
  const addBlockInput = z.object({
17
- projectId: projectIdInput.describe("Project ID (must be opened)"),
17
+ projectId: projectIdInput.describe("Project ID"),
18
18
  label: z.string().describe("Block label"),
19
19
  spec: z.union([
20
20
  z.object({
@@ -74,22 +74,22 @@ function registerBlockTools(server, ctx) {
74
74
  server.registerTool("add_block", {
75
75
  title: "Add Block",
76
76
  annotations: hints.additive,
77
- description: "Add a block to an opened project, optionally configured from initialization params.\n\n`spec` names the block: `kind` (a block kind reference, resolved to the newest block implementing it), `from-registry-v2` (an exact published block) or `dev-v2` (a local dev block folder).\n\n`params` are the initialization params of the block's kind: the block's own model checks them and builds its initial state from them. Without `params` the block starts in its default state. get_block_params shows the params of an existing block.\n\nReferences to other blocks inside `params` must hold real block ids of this project, copied from tool results. Params copied from another project or a template hold other ids: map each of them to a block of this project with `blockIds`.\n\nOnly blocks on the current block API can be added. On any error nothing is created.",
77
+ description: "Add a block to a project, optionally configured from initialization params.\n\n`spec` names the block: `kind` (a block kind reference, resolved to the newest block implementing it), `from-registry-v2` (an exact published block) or `dev-v2` (a local dev block folder).\n\n`params` are the initialization params of the block's kind: the block's own model checks them and builds its initial state from them. Without `params` the block starts in its default state. get_block_params shows the params of an existing block.\n\nReferences to other blocks inside `params` must hold real block ids of this project, copied from tool results. Params copied from another project or a template hold other ids: map each of them to a block of this project with `blockIds`.\n\nOnly blocks on the current block API can be added. On any error nothing is created.",
78
78
  inputSchema: addBlockInput
79
79
  }, async (input) => {
80
80
  const ml = ctx.requireMl();
81
- return await addBlock({
82
- project: await ctx.getOpenedProject(input.projectId),
81
+ return await ctx.withProject(input.projectId, async (project) => await addBlock({
82
+ project,
83
83
  resolveKind: (kind, registryUrl, allowUnstable) => ml.blockRegistryProvider.getRegistry(registryUrl ?? centralBlockRegistryUrl()).resolveKind(kind, { allowUnstable }),
84
84
  author: ctx.getAuthorMarker()
85
- }, input);
85
+ }, input));
86
86
  });
87
87
  server.registerTool("update_block", {
88
88
  title: "Update Block",
89
89
  annotations: hints.destructive,
90
90
  description: "Update an existing block's pack (reload from registry or dev folder). Use after rebuilding a dev block to pick up changes without removing/re-adding it.",
91
91
  inputSchema: z.object({
92
- projectId: projectIdInput.describe("Project ID (must be opened)"),
92
+ projectId: projectIdInput.describe("Project ID"),
93
93
  blockId: blockIdInput.describe("Block ID to update"),
94
94
  spec: z.union([z.object({
95
95
  type: z.literal("from-registry-v2"),
@@ -106,20 +106,24 @@ function registerBlockTools(server, ctx) {
106
106
  resetArgs: z.boolean().optional().describe("Reset block arguments to initial values (default: false)")
107
107
  })
108
108
  }, async ({ projectId, blockId, spec, resetArgs }) => {
109
- await (await ctx.getOpenedProject(projectId)).updateBlockPack(blockId, spec, resetArgs ?? false, ctx.getAuthorMarker());
110
- return textResult({ ok: true });
109
+ return await ctx.withProject(projectId, async (project) => {
110
+ await project.updateBlockPack(blockId, spec, resetArgs ?? false, ctx.getAuthorMarker());
111
+ return textResult({ ok: true });
112
+ });
111
113
  });
112
114
  server.registerTool("remove_block", {
113
115
  title: "Remove Block",
114
116
  annotations: hints.destructive,
115
- description: "Remove a block from an opened project, with its configuration and results. Blocks below that refer to it are left with a missing reference.",
117
+ description: "Remove a block from a project, with its configuration and results. Blocks below that refer to it are left with a missing reference.",
116
118
  inputSchema: z.object({
117
119
  projectId: projectIdInput.describe("Project ID"),
118
120
  blockId: blockIdInput.describe("Block ID to remove")
119
121
  })
120
122
  }, async ({ projectId, blockId }) => {
121
- await (await ctx.getOpenedProject(projectId)).deleteBlock(blockId, ctx.getAuthorMarker());
122
- return textResult({ ok: true });
123
+ return await ctx.withProject(projectId, async (project) => {
124
+ await project.deleteBlock(blockId, ctx.getAuthorMarker());
125
+ return textResult({ ok: true });
126
+ });
123
127
  });
124
128
  server.registerTool("run_block", {
125
129
  title: "Run Block",
@@ -133,8 +137,10 @@ function registerBlockTools(server, ctx) {
133
137
  blockId: blockIdInput.describe("Block ID to run")
134
138
  })
135
139
  }, async ({ projectId, blockId }) => {
136
- await (await ctx.getOpenedProject(projectId)).runBlock(blockId);
137
- return textResult({ ok: true });
140
+ return await ctx.withProject(projectId, async (project) => {
141
+ await project.runBlock(blockId);
142
+ return textResult({ ok: true });
143
+ });
138
144
  });
139
145
  server.registerTool("stop_block", {
140
146
  title: "Stop Block",
@@ -145,8 +151,10 @@ function registerBlockTools(server, ctx) {
145
151
  blockId: blockIdInput.describe("Block ID to stop")
146
152
  })
147
153
  }, async ({ projectId, blockId }) => {
148
- await (await ctx.getOpenedProject(projectId)).stopBlock(blockId);
149
- return textResult({ ok: true });
154
+ return await ctx.withProject(projectId, async (project) => {
155
+ await project.stopBlock(blockId);
156
+ return textResult({ ok: true });
157
+ });
150
158
  });
151
159
  server.registerTool("reorder_blocks", {
152
160
  title: "Reorder Blocks",
@@ -157,8 +165,10 @@ function registerBlockTools(server, ctx) {
157
165
  blockIds: z.array(blockIdInput).describe("All block IDs in the desired order")
158
166
  })
159
167
  }, async ({ projectId, blockIds }) => {
160
- await (await ctx.getOpenedProject(projectId)).reorderBlocks(blockIds);
161
- return textResult({ ok: true });
168
+ return await ctx.withProject(projectId, async (project) => {
169
+ await project.reorderBlocks(blockIds);
170
+ return textResult({ ok: true });
171
+ });
162
172
  });
163
173
  server.registerTool("list_available_blocks", {
164
174
  title: "List Available Blocks",
@@ -188,13 +198,13 @@ function registerBlockTools(server, ctx) {
188
198
  server.registerTool("select_block", {
189
199
  title: "Show Block in the Application",
190
200
  annotations: hints.idempotent,
191
- description: "Navigate the desktop UI to show a specific block's interface",
201
+ description: "Show a block to the user in the application: the application's window opens the block. Use it only when the user asks to be shown something; working with blocks does not need it.",
192
202
  inputSchema: z.object({
193
203
  projectId: projectIdInput.describe("Project ID"),
194
204
  blockId: blockIdInput.describe("Block ID to display")
195
205
  })
196
206
  }, async ({ projectId, blockId }) => {
197
- if (!ctx.callbacks.selectBlock) return errorResult("Failed to select the block.", "This feature requires server connected and open project. Use get_connection_status and list_projects to check. If there are no connection, use list_connections and ask user which should be used.");
207
+ if (!ctx.callbacks.selectBlock) return errorResult("Failed to show the block: this server is not running inside the desktop application.");
198
208
  await ctx.callbacks.selectBlock(projectId, blockId);
199
209
  return textResult({ ok: true });
200
210
  });