@milaboratories/pl-mcp-server 52.1.0 → 53.1.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 (92) hide show
  1. package/README.md +31 -0
  2. package/dist/instructions.cjs +2 -1
  3. package/dist/instructions.cjs.map +1 -1
  4. package/dist/instructions.js +2 -1
  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/server-log.cjs +365 -0
  9. package/dist/server-log.cjs.map +1 -0
  10. package/dist/server-log.js +363 -0
  11. package/dist/server-log.js.map +1 -0
  12. package/dist/server.cjs +49 -15
  13. package/dist/server.cjs.map +1 -1
  14. package/dist/server.d.ts +12 -0
  15. package/dist/server.d.ts.map +1 -1
  16. package/dist/server.js +49 -15
  17. package/dist/server.js.map +1 -1
  18. package/dist/tools/await.cjs +4 -6
  19. package/dist/tools/await.cjs.map +1 -1
  20. package/dist/tools/await.js +5 -7
  21. package/dist/tools/await.js.map +1 -1
  22. package/dist/tools/block-action-context.cjs.map +1 -1
  23. package/dist/tools/block-action-context.js.map +1 -1
  24. package/dist/tools/block-api.cjs +23 -0
  25. package/dist/tools/block-api.cjs.map +1 -0
  26. package/dist/tools/block-api.js +22 -0
  27. package/dist/tools/block-api.js.map +1 -0
  28. package/dist/tools/block-params.cjs +21 -0
  29. package/dist/tools/block-params.cjs.map +1 -0
  30. package/dist/tools/block-params.js +21 -0
  31. package/dist/tools/block-params.js.map +1 -0
  32. package/dist/tools/block-state.cjs +2 -2
  33. package/dist/tools/block-state.cjs.map +1 -1
  34. package/dist/tools/block-state.js +3 -3
  35. package/dist/tools/block-state.js.map +1 -1
  36. package/dist/tools/blocks.cjs +78 -20
  37. package/dist/tools/blocks.cjs.map +1 -1
  38. package/dist/tools/blocks.js +78 -21
  39. package/dist/tools/blocks.js.map +1 -1
  40. package/dist/tools/connection.cjs.map +1 -1
  41. package/dist/tools/connection.js.map +1 -1
  42. package/dist/tools/data-query.cjs +1 -1
  43. package/dist/tools/data-query.cjs.map +1 -1
  44. package/dist/tools/data-query.js +2 -2
  45. package/dist/tools/data-query.js.map +1 -1
  46. package/dist/tools/logs.cjs.map +1 -1
  47. package/dist/tools/logs.js.map +1 -1
  48. package/dist/tools/ping.cjs.map +1 -1
  49. package/dist/tools/ping.js.map +1 -1
  50. package/dist/tools/projects.cjs.map +1 -1
  51. package/dist/tools/projects.js.map +1 -1
  52. package/dist/tools/sandbox.cjs +110 -8
  53. package/dist/tools/sandbox.cjs.map +1 -1
  54. package/dist/tools/sandbox.js +107 -9
  55. package/dist/tools/sandbox.js.map +1 -1
  56. package/dist/tools/screenshot.cjs +9 -1
  57. package/dist/tools/screenshot.cjs.map +1 -1
  58. package/dist/tools/screenshot.js +9 -1
  59. package/dist/tools/screenshot.js.map +1 -1
  60. package/dist/tools/types.cjs +29 -0
  61. package/dist/tools/types.cjs.map +1 -1
  62. package/dist/tools/types.js +27 -1
  63. package/dist/tools/types.js.map +1 -1
  64. package/dist/tools/ui-interaction.cjs.map +1 -1
  65. package/dist/tools/ui-interaction.js.map +1 -1
  66. package/package.json +5 -4
  67. package/src/instructions.ts +2 -1
  68. package/src/server-log.test.ts +859 -0
  69. package/src/server-log.ts +495 -0
  70. package/src/server.logging.test.ts +380 -0
  71. package/src/server.request-failure.test.ts +49 -0
  72. package/src/server.test.ts +4 -2
  73. package/src/server.ts +70 -15
  74. package/src/test/recording-logger.ts +33 -0
  75. package/src/tools/await.ts +7 -10
  76. package/src/tools/block-action-context.ts +2 -3
  77. package/src/tools/block-api.ts +24 -0
  78. package/src/tools/block-params.ts +29 -0
  79. package/src/tools/block-state.ts +5 -6
  80. package/src/tools/blocks.test.ts +148 -0
  81. package/src/tools/blocks.ts +162 -34
  82. package/src/tools/connection.ts +2 -3
  83. package/src/tools/data-query.ts +5 -6
  84. package/src/tools/logs.ts +2 -3
  85. package/src/tools/ping.ts +2 -3
  86. package/src/tools/projects.ts +2 -3
  87. package/src/tools/sandbox.test.ts +183 -0
  88. package/src/tools/sandbox.ts +126 -10
  89. package/src/tools/screenshot.ts +15 -4
  90. package/src/tools/types.test.ts +4 -3
  91. package/src/tools/types.ts +65 -2
  92. package/src/tools/ui-interaction.ts +2 -3
@@ -0,0 +1,21 @@
1
+ import { hints, textResult } from "./types.js";
2
+ import { blockIdInput, projectIdInput } from "./ids.js";
3
+ import { z } from "zod";
4
+ // src/tools/block-params.ts
5
+ function registerBlockParamsTools(server, ctx) {
6
+ server.registerTool("get_block_params", {
7
+ title: "Get Block Params",
8
+ annotations: hints.read,
9
+ description: "Get a block's configuration as the initialization params of its kind: what a project template stores for this block. The block's own model derives them from its current data. Pass the result as `params` of add_block, with a block of the same kind, to create a block configured the same way. Read-only: params usually leave out view state, so to change an existing block use get_block_state and set_block_data.\n\nReturns `{ kind, params }`. `kind` is absent for a block that declares none.",
10
+ inputSchema: z.object({
11
+ projectId: projectIdInput.describe("Project ID (must be opened)"),
12
+ blockId: blockIdInput.describe("Block ID")
13
+ })
14
+ }, async ({ projectId, blockId }) => {
15
+ const project = await ctx.getOpenedProject(projectId);
16
+ return textResult(await project.getBlockInitializationParams(blockId));
17
+ });
18
+ }
19
+ export { registerBlockParamsTools };
20
+
21
+ //# sourceMappingURL=block-params.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"block-params.js","names":[],"sources":["../../src/tools/block-params.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport type { ToolContext, ToolRegistrar } from \"./types\";\nimport { hints, textResult } from \"./types\";\n\nexport function registerBlockParamsTools(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"get_block_params\",\n {\n title: \"Get Block Params\",\n annotations: hints.read,\n description:\n \"Get a block's configuration as the initialization params of its kind: what a project \" +\n \"template stores for this block. The block's own model derives them from its current data. \" +\n \"Pass the result as `params` of add_block, with a block of the same kind, to create a \" +\n \"block configured the same way. Read-only: params usually leave out view state, so to \" +\n \"change an existing block use get_block_state and set_block_data.\\n\\n\" +\n \"Returns `{ kind, params }`. `kind` is absent for a block that declares none.\",\n inputSchema: z.object({\n projectId: projectIdInput.describe(\"Project ID (must be opened)\"),\n blockId: blockIdInput.describe(\"Block ID\"),\n }),\n },\n async ({ projectId, blockId }) => {\n const project = await ctx.getOpenedProject(projectId);\n return textResult(await project.getBlockInitializationParams(blockId));\n },\n );\n}\n"],"mappings":";;;;AAKA,SAAgB,yBAAyB,QAAuB,KAAwB;CACtF,OAAO,aACL,oBACA;EACE,OAAO;EACP,aAAa,MAAM;EACnB,aACE;EAMF,aAAa,EAAE,OAAO;GACpB,WAAW,eAAe,SAAS,6BAA6B;GAChE,SAAS,aAAa,SAAS,UAAU;EAC3C,CAAC;CACH,GACA,OAAO,EAAE,WAAW,cAAc;EAChC,MAAM,UAAU,MAAM,IAAI,iBAAiB,SAAS;EACpD,OAAO,WAAW,MAAM,QAAQ,6BAA6B,OAAO,CAAC;CACvE,CACF;AACF"}
@@ -3,8 +3,8 @@ const require_ids = require("./ids.cjs");
3
3
  const require_tokens = require("./tokens.cjs");
4
4
  const require_sandbox = require("./sandbox.cjs");
5
5
  let zod = require("zod");
6
- let _platforma_sdk_model = require("@platforma-sdk/model");
7
6
  let _milaboratories_pl_errors = require("@milaboratories/pl-errors");
7
+ let _platforma_sdk_model = require("@platforma-sdk/model");
8
8
  // src/tools/block-state.ts
9
9
  function registerBlockStateTools(server, ctx) {
10
10
  server.registerTool("get_project_overview", {
@@ -50,7 +50,7 @@ function registerBlockStateTools(server, ctx) {
50
50
  }, transformTimeout);
51
51
  return require_types.textResult(result);
52
52
  } catch (e) {
53
- return require_types.errorResult(`Transform failed: ${e instanceof Error ? e.message : String(e)}`, "Check your JS expression syntax. Available variables: data, outputs.");
53
+ return require_types.transformFailedResult(e, "Check your JS expression syntax. Available variables: data, outputs.");
54
54
  }
55
55
  return require_types.textResult({
56
56
  data,
@@ -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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AAOK,qBAAAA,sBAAAA,CAAsB,MAAM,YAAY;EACrD,IAAI,WACF,IAAI;GACF,MAAM,SAAS,MAAMC,gBAAAA,SACnB,WACA;IAAE;IAAM,SAAS,MAAM;GAAQ,GAC/B,gBACF;GACA,OAAOH,cAAAA,WAAW,MAAM;EAC1B,SAAS,GAAY;GACnB,OAAOD,cAAAA,YACL,qBAAqB,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,KAC9D,sEACF;EACF;EAEF,OAAOC,cAAAA,WAAW;GAChB;GACA,SAASI,eAAAA,iBAAiB,MAAM,OAA8C;EAChF,CAAC;CACH,CACF;CAEA,OAAO,aACL,kBACA;EACE,OAAO;EACP,aAAaR,cAAAA,MAAM;EACnB,aAAa;EACb,aAAaC,IAAAA,EAAE,OAAO;GACpB,WAAWC,YAAAA,eAAe,SAAS,YAAY;GAC/C,SAASG,YAAAA,aAAa,SAAS,UAAU;GACzC,MAAMJ,IAAAA,EAAE,OAAOA,IAAAA,EAAE,OAAO,GAAGA,IAAAA,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS,mBAAmB;EACtE,CAAC;CACH,GACA,OAAO,EAAE,WAAW,SAAS,WAAW;EACtC,MAAM,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 (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 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 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":";;;;;;;;AASA,SAAgB,wBAAwB,QAAuB,KAAwB;CACrF,OAAO,aACL,wBACA;EACE,OAAO;EACP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,GAC/B,gBACF;GACA,OAAOH,cAAAA,WAAW,MAAM;EAC1B,SAAS,GAAY;GACnB,OAAOI,cAAAA,sBACL,GACA,sEACF;EACF;EAEF,OAAOJ,cAAAA,WAAW;GAChB;GACA,SAASK,eAAAA,iBAAiB,MAAM,OAA8C;EAChF,CAAC;CACH,CACF;CAEA,OAAO,aACL,kBACA;EACE,OAAO;EACP,aAAaT,cAAAA,MAAM;EACnB,aAAa;EACb,aAAaC,IAAAA,EAAE,OAAO;GACpB,WAAWC,YAAAA,eAAe,SAAS,YAAY;GAC/C,SAASG,YAAAA,aAAa,SAAS,UAAU;GACzC,MAAMJ,IAAAA,EAAE,OAAOA,IAAAA,EAAE,OAAO,GAAGA,IAAAA,EAAE,QAAQ,CAAC,CAAC,CAAC,SAAS,mBAAmB;EACtE,CAAC;CACH,GACA,OAAO,EAAE,WAAW,SAAS,WAAW;EACtC,MAAM,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,aAAaS,0BAAAA,8BACf,MAAM,QAAQ,aAAa,SAAS,OAAO,IAAI,gBAAgB,CAAC;QAEhE,MAAM;EAEV;EACA,OAAON,cAAAA,WAAW,EAAE,IAAI,KAAK,CAAC;CAChC,CACF;AACF"}
@@ -1,10 +1,10 @@
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";
5
5
  import { z } from "zod";
6
- import { deriveDataFromStorage } from "@platforma-sdk/model";
7
6
  import { ModelAPIVersionMismatchError } from "@milaboratories/pl-errors";
7
+ import { deriveDataFromStorage } from "@platforma-sdk/model";
8
8
  // src/tools/block-state.ts
9
9
  function registerBlockStateTools(server, ctx) {
10
10
  server.registerTool("get_project_overview", {
@@ -50,7 +50,7 @@ function registerBlockStateTools(server, ctx) {
50
50
  }, transformTimeout);
51
51
  return textResult(result);
52
52
  } catch (e) {
53
- return errorResult(`Transform failed: ${e instanceof Error ? e.message : String(e)}`, "Check your JS expression syntax. Available variables: data, outputs.");
53
+ return transformFailedResult(e, "Check your JS expression syntax. Available variables: data, outputs.");
54
54
  }
55
55
  return textResult({
56
56
  data,
@@ -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,SAAS,CAAC,CACV,QAAQ,GAAI,CAAC,CACb,SAAS,wDAAwD;EACtE,CAAC;CACH,GACA,OAAO,EAAE,WAAW,SAAS,WAAW,uBAAuB;EAE7D,MAAM,QAAQ,OAAM,MADE,IAAI,iBAAiB,SAAS,EAAA,CACxB,cAAc,OAAO,CAAC,CAAC,SAAS;EAC5D,MAAM,OAAO,sBAAsB,MAAM,YAAY;EACrD,IAAI,WACF,IAAI;GACF,MAAM,SAAS,MAAM,SACnB,WACA;IAAE;IAAM,SAAS,MAAM;GAAQ,GAC/B,gBACF;GACA,OAAO,WAAW,MAAM;EAC1B,SAAS,GAAY;GACnB,OAAO,YACL,qBAAqB,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC,KAC9D,sEACF;EACF;EAEF,OAAO,WAAW;GAChB;GACA,SAAS,iBAAiB,MAAM,OAA8C;EAChF,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,MAAM,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,aAAa,8BACf,MAAM,QAAQ,aAAa,SAAS,OAAO,IAAI,gBAAgB,CAAC;QAEhE,MAAM;EAEV;EACA,OAAO,WAAW,EAAE,IAAI,KAAK,CAAC;CAChC,CACF;AACF"}
1
+ {"version":3,"file":"block-state.js","names":[],"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 (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 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 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":";;;;;;;;AASA,SAAgB,wBAAwB,QAAuB,KAAwB;CACrF,OAAO,aACL,wBACA;EACE,OAAO;EACP,aAAa,MAAM;EACnB,aACE;EACF,aAAa,EAAE,OAAO,EACpB,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,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,MAAM,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,aAAa,8BACf,MAAM,QAAQ,aAAa,SAAS,OAAO,IAAI,gBAAgB,CAAC;QAEhE,MAAM;EAEV;EACA,OAAO,WAAW,EAAE,IAAI,KAAK,CAAC;CAChC,CACF;AACF"}
@@ -1,31 +1,88 @@
1
1
  const require_types = require("./types.cjs");
2
2
  const require_ids = require("./ids.cjs");
3
+ const require_block_api = require("./block-api.cjs");
3
4
  let zod = require("zod");
5
+ let _milaboratories_pl_middle_layer = require("@milaboratories/pl-middle-layer");
6
+ let _milaboratories_pl_errors = require("@milaboratories/pl-errors");
4
7
  // src/tools/blocks.ts
8
+ /** Where a kind is resolved when the caller names no registry. */
9
+ function centralBlockRegistryUrl() {
10
+ if (_milaboratories_pl_middle_layer.CentralBlockRegistry.type !== "remote-v2") throw new Error("The central block registry is expected to be a v2 remote registry.");
11
+ return _milaboratories_pl_middle_layer.CentralBlockRegistry.url;
12
+ }
13
+ function errorMessage(e) {
14
+ return e instanceof Error ? e.message : String(e);
15
+ }
16
+ const addBlockInput = zod.z.object({
17
+ projectId: require_ids.projectIdInput.describe("Project ID (must be opened)"),
18
+ label: zod.z.string().describe("Block label"),
19
+ spec: zod.z.union([
20
+ zod.z.object({
21
+ type: zod.z.literal("kind"),
22
+ kind: zod.z.string().describe("Block kind reference \"<package name>@<version or range>\", e.g. \"@platforma-open/milaboratories.samples-and-data.kind@1.2.0\""),
23
+ registryUrl: zod.z.string().optional().describe("Registry to resolve the kind in (default: the central block registry)"),
24
+ allowUnstable: zod.z.boolean().optional().describe("Also consider blocks not published to the stable channel")
25
+ }),
26
+ zod.z.object({
27
+ type: zod.z.literal("from-registry-v2"),
28
+ registryUrl: zod.z.string().describe("Registry URL"),
29
+ id: zod.z.object({
30
+ organization: zod.z.string(),
31
+ name: zod.z.string(),
32
+ version: zod.z.string()
33
+ })
34
+ }),
35
+ zod.z.object({
36
+ type: zod.z.literal("dev-v2"),
37
+ folder: zod.z.string().describe("Path to block folder")
38
+ })
39
+ ]).describe("Which block to add"),
40
+ params: zod.z.record(zod.z.string(), zod.z.unknown()).optional().describe("Initialization params of the block's kind. Omit for the default state."),
41
+ blockIds: zod.z.record(zod.z.string(), require_ids.blockIdInput).optional().describe("Ids used inside `params` in place of block ids, each mapped to a block id of this project. Needed only when `params` do not already hold ids of this project."),
42
+ before: require_ids.blockIdInput.optional().describe("ID of the block to insert the new block before (default: add at the end)")
43
+ });
44
+ /**
45
+ * Adds the block the input describes, started from its params when it carries them. Every way the
46
+ * block can be refused comes back as an error result saying nothing was created.
47
+ */
48
+ async function addBlock(deps, input) {
49
+ const { label, spec, params, blockIds, before } = input;
50
+ let blockPackSpec;
51
+ if (spec.type === "kind") try {
52
+ blockPackSpec = await deps.resolveKind(_milaboratories_pl_middle_layer.BlockKindRef.parse(spec.kind), spec.registryUrl, spec.allowUnstable ?? false);
53
+ } catch (e) {
54
+ return require_types.errorResult(`Kind "${spec.kind}" was not resolved to a block: ${errorMessage(e)}. Nothing was created.`, "Check the kind name and version. Pass allowUnstable: true if the block is not published to the stable channel, or registryUrl if it lives in another registry.");
55
+ }
56
+ else blockPackSpec = spec;
57
+ try {
58
+ const blockId = await deps.project.addBlock(label, blockPackSpec, before, deps.author, void 0, {
59
+ init: params === void 0 ? void 0 : {
60
+ params,
61
+ blockIds
62
+ },
63
+ requireModelAPIVersion: require_block_api.SUPPORTED_BLOCK_API
64
+ });
65
+ return require_types.textResult({ blockId });
66
+ } catch (e) {
67
+ const unsupported = require_block_api.unsupportedBlockApiResult(e);
68
+ if (unsupported) return unsupported;
69
+ if (e instanceof _milaboratories_pl_errors.BlockInitParamsRejectedError) return require_types.errorResult(`The block did not accept the params: ${e.reason}. Nothing was created.`, "Fix the params and call add_block again. get_block_params on a configured block of the same kind shows the expected shape.");
70
+ throw e;
71
+ }
72
+ }
5
73
  function registerBlockTools(server, ctx) {
6
74
  server.registerTool("add_block", {
7
75
  title: "Add Block",
8
76
  annotations: require_types.hints.additive,
9
- description: "Add a block to an opened project. Spec can be from-registry-v2 (for published blocks) or dev-v2 (for local dev blocks).",
10
- inputSchema: zod.z.object({
11
- projectId: require_ids.projectIdInput.describe("Project ID (must be opened)"),
12
- label: zod.z.string().describe("Block label"),
13
- spec: zod.z.union([zod.z.object({
14
- type: zod.z.literal("from-registry-v2"),
15
- registryUrl: zod.z.string().describe("Registry URL"),
16
- id: zod.z.object({
17
- organization: zod.z.string(),
18
- name: zod.z.string(),
19
- version: zod.z.string()
20
- })
21
- }), zod.z.object({
22
- type: zod.z.literal("dev-v2"),
23
- folder: zod.z.string().describe("Path to block folder")
24
- })]).describe("Block pack specification")
25
- })
26
- }, async ({ projectId, label, spec }) => {
27
- const blockId = await (await ctx.getOpenedProject(projectId)).addBlock(label, spec, void 0, ctx.getAuthorMarker());
28
- return require_types.textResult({ blockId });
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.",
78
+ inputSchema: addBlockInput
79
+ }, async (input) => {
80
+ const ml = ctx.requireMl();
81
+ return await addBlock({
82
+ project: await ctx.getOpenedProject(input.projectId),
83
+ resolveKind: (kind, registryUrl, allowUnstable) => ml.blockRegistryProvider.getRegistry(registryUrl ?? centralBlockRegistryUrl()).resolveKind(kind, { allowUnstable }),
84
+ author: ctx.getAuthorMarker()
85
+ }, input);
29
86
  });
30
87
  server.registerTool("update_block", {
31
88
  title: "Update Block",
@@ -142,6 +199,7 @@ function registerBlockTools(server, ctx) {
142
199
  return require_types.textResult({ ok: true });
143
200
  });
144
201
  }
202
+ exports.addBlock = addBlock;
145
203
  exports.registerBlockTools = registerBlockTools;
146
204
 
147
205
  //# sourceMappingURL=blocks.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"blocks.cjs","names":["hints","z","projectIdInput","textResult","blockIdInput","errorResult"],"sources":["../../src/tools/blocks.ts"],"sourcesContent":["import type { McpServer } from \"@modelcontextprotocol/server\";\nimport type { BlockPackSpecAny } from \"@milaboratories/pl-middle-layer\";\nimport { z } from \"zod\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport type { ToolContext } from \"./types\";\nimport { errorResult, hints, textResult } from \"./types\";\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. Spec can be from-registry-v2 (for published blocks) or dev-v2 (for local dev blocks).\",\n inputSchema: 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(\"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 }),\n },\n async ({ projectId, label, spec }) => {\n const project = await ctx.getOpenedProject(projectId);\n const blockId = await project.addBlock(\n label,\n spec as BlockPackSpecAny,\n undefined,\n ctx.getAuthorMarker(),\n );\n return textResult({ blockId });\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":";;;;AAOA,SAAgB,mBAAmB,QAAmB,KAAwB;CAC5E,OAAO,aACL,aACA;EACE,OAAO;EACP,aAAaA,cAAAA,MAAM;EACnB,aACE;EACF,aAAaC,IAAAA,EAAE,OAAO;GACpB,WAAWC,YAAAA,eAAe,SAAS,6BAA6B;GAChE,OAAOD,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,aAAa;GACxC,MAAMA,IAAAA,EACH,MAAM,CACLA,IAAAA,EAAE,OAAO;IACP,MAAMA,IAAAA,EAAE,QAAQ,kBAAkB;IAClC,aAAaA,IAAAA,EAAE,OAAO,CAAC,CAAC,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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,OAAOF,cAAAA,WAAW,IAAI;CACxB,CACF;CAEA,OAAO,aACL,gBACA;EACE,OAAO;EACP,aAAaH,cAAAA,MAAM;EACnB,aAAa;EACb,aAAaC,IAAAA,EAAE,OAAO;GACpB,WAAWC,YAAAA,eAAe,SAAS,YAAY;GAC/C,SAASE,YAAAA,aAAa,SAAS,qBAAqB;EACtD,CAAC;CACH,GACA,OAAO,EAAE,WAAW,cAAc;EAChC,IAAI,CAAC,IAAI,UAAU,aACjB,OAAOC,cAAAA,YACL,+BACA,oMACF;EAEF,MAAM,IAAI,UAAU,YAAY,WAAW,OAAO;EAClD,OAAOF,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 (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: 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 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":";;;;;;;;AAWA,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;AA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AW,EAAE,IAAI,KAAK,CAAC;CAChC,CACF;AACF"}
@@ -1,31 +1,88 @@
1
1
  import { errorResult, hints, textResult } from "./types.js";
2
2
  import { blockIdInput, projectIdInput } from "./ids.js";
3
+ import { SUPPORTED_BLOCK_API, unsupportedBlockApiResult } from "./block-api.js";
3
4
  import { z } from "zod";
5
+ import { BlockKindRef, CentralBlockRegistry } from "@milaboratories/pl-middle-layer";
6
+ import { BlockInitParamsRejectedError } from "@milaboratories/pl-errors";
4
7
  // src/tools/blocks.ts
8
+ /** Where a kind is resolved when the caller names no registry. */
9
+ function centralBlockRegistryUrl() {
10
+ if (CentralBlockRegistry.type !== "remote-v2") throw new Error("The central block registry is expected to be a v2 remote registry.");
11
+ return CentralBlockRegistry.url;
12
+ }
13
+ function errorMessage(e) {
14
+ return e instanceof Error ? e.message : String(e);
15
+ }
16
+ const addBlockInput = z.object({
17
+ projectId: projectIdInput.describe("Project ID (must be opened)"),
18
+ label: z.string().describe("Block label"),
19
+ spec: z.union([
20
+ z.object({
21
+ type: z.literal("kind"),
22
+ kind: z.string().describe("Block kind reference \"<package name>@<version or range>\", e.g. \"@platforma-open/milaboratories.samples-and-data.kind@1.2.0\""),
23
+ registryUrl: z.string().optional().describe("Registry to resolve the kind in (default: the central block registry)"),
24
+ allowUnstable: z.boolean().optional().describe("Also consider blocks not published to the stable channel")
25
+ }),
26
+ z.object({
27
+ type: z.literal("from-registry-v2"),
28
+ registryUrl: z.string().describe("Registry URL"),
29
+ id: z.object({
30
+ organization: z.string(),
31
+ name: z.string(),
32
+ version: z.string()
33
+ })
34
+ }),
35
+ z.object({
36
+ type: z.literal("dev-v2"),
37
+ folder: z.string().describe("Path to block folder")
38
+ })
39
+ ]).describe("Which block to add"),
40
+ params: z.record(z.string(), z.unknown()).optional().describe("Initialization params of the block's kind. Omit for the default state."),
41
+ blockIds: z.record(z.string(), blockIdInput).optional().describe("Ids used inside `params` in place of block ids, each mapped to a block id of this project. Needed only when `params` do not already hold ids of this project."),
42
+ before: blockIdInput.optional().describe("ID of the block to insert the new block before (default: add at the end)")
43
+ });
44
+ /**
45
+ * Adds the block the input describes, started from its params when it carries them. Every way the
46
+ * block can be refused comes back as an error result saying nothing was created.
47
+ */
48
+ async function addBlock(deps, input) {
49
+ const { label, spec, params, blockIds, before } = input;
50
+ let blockPackSpec;
51
+ if (spec.type === "kind") try {
52
+ blockPackSpec = await deps.resolveKind(BlockKindRef.parse(spec.kind), spec.registryUrl, spec.allowUnstable ?? false);
53
+ } catch (e) {
54
+ return errorResult(`Kind "${spec.kind}" was not resolved to a block: ${errorMessage(e)}. Nothing was created.`, "Check the kind name and version. Pass allowUnstable: true if the block is not published to the stable channel, or registryUrl if it lives in another registry.");
55
+ }
56
+ else blockPackSpec = spec;
57
+ try {
58
+ const blockId = await deps.project.addBlock(label, blockPackSpec, before, deps.author, void 0, {
59
+ init: params === void 0 ? void 0 : {
60
+ params,
61
+ blockIds
62
+ },
63
+ requireModelAPIVersion: SUPPORTED_BLOCK_API
64
+ });
65
+ return textResult({ blockId });
66
+ } catch (e) {
67
+ const unsupported = unsupportedBlockApiResult(e);
68
+ if (unsupported) return unsupported;
69
+ if (e instanceof BlockInitParamsRejectedError) return errorResult(`The block did not accept the params: ${e.reason}. Nothing was created.`, "Fix the params and call add_block again. get_block_params on a configured block of the same kind shows the expected shape.");
70
+ throw e;
71
+ }
72
+ }
5
73
  function registerBlockTools(server, ctx) {
6
74
  server.registerTool("add_block", {
7
75
  title: "Add Block",
8
76
  annotations: hints.additive,
9
- description: "Add a block to an opened project. Spec can be from-registry-v2 (for published blocks) or dev-v2 (for local dev blocks).",
10
- inputSchema: z.object({
11
- projectId: projectIdInput.describe("Project ID (must be opened)"),
12
- label: z.string().describe("Block label"),
13
- spec: z.union([z.object({
14
- type: z.literal("from-registry-v2"),
15
- registryUrl: z.string().describe("Registry URL"),
16
- id: z.object({
17
- organization: z.string(),
18
- name: z.string(),
19
- version: z.string()
20
- })
21
- }), z.object({
22
- type: z.literal("dev-v2"),
23
- folder: z.string().describe("Path to block folder")
24
- })]).describe("Block pack specification")
25
- })
26
- }, async ({ projectId, label, spec }) => {
27
- const blockId = await (await ctx.getOpenedProject(projectId)).addBlock(label, spec, void 0, ctx.getAuthorMarker());
28
- return textResult({ blockId });
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.",
78
+ inputSchema: addBlockInput
79
+ }, async (input) => {
80
+ const ml = ctx.requireMl();
81
+ return await addBlock({
82
+ project: await ctx.getOpenedProject(input.projectId),
83
+ resolveKind: (kind, registryUrl, allowUnstable) => ml.blockRegistryProvider.getRegistry(registryUrl ?? centralBlockRegistryUrl()).resolveKind(kind, { allowUnstable }),
84
+ author: ctx.getAuthorMarker()
85
+ }, input);
29
86
  });
30
87
  server.registerTool("update_block", {
31
88
  title: "Update Block",
@@ -142,6 +199,6 @@ function registerBlockTools(server, ctx) {
142
199
  return textResult({ ok: true });
143
200
  });
144
201
  }
145
- export { registerBlockTools };
202
+ export { addBlock, registerBlockTools };
146
203
 
147
204
  //# sourceMappingURL=blocks.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"blocks.js","names":[],"sources":["../../src/tools/blocks.ts"],"sourcesContent":["import type { McpServer } from \"@modelcontextprotocol/server\";\nimport type { BlockPackSpecAny } from \"@milaboratories/pl-middle-layer\";\nimport { z } from \"zod\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport type { ToolContext } from \"./types\";\nimport { errorResult, hints, textResult } from \"./types\";\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. Spec can be from-registry-v2 (for published blocks) or dev-v2 (for local dev blocks).\",\n inputSchema: 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(\"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 }),\n },\n async ({ projectId, label, spec }) => {\n const project = await ctx.getOpenedProject(projectId);\n const blockId = await project.addBlock(\n label,\n spec as BlockPackSpecAny,\n undefined,\n ctx.getAuthorMarker(),\n );\n return textResult({ blockId });\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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,MAAM,OAAO,MAAM,IAAI,UAAU,aAAa,aAAa,cAAc,MAAM,OAAO;EACtF,OAAO,WAAW,IAAI;CACxB,CACF;CAEA,OAAO,aACL,gBACA;EACE,OAAO;EACP,aAAa,MAAM;EACnB,aAAa;EACb,aAAa,EAAE,OAAO;GACpB,WAAW,eAAe,SAAS,YAAY;GAC/C,SAAS,aAAa,SAAS,qBAAqB;EACtD,CAAC;CACH,GACA,OAAO,EAAE,WAAW,cAAc;EAChC,IAAI,CAAC,IAAI,UAAU,aACjB,OAAO,YACL,+BACA,oMACF;EAEF,MAAM,IAAI,UAAU,YAAY,WAAW,OAAO;EAClD,OAAO,WAAW,EAAE,IAAI,KAAK,CAAC;CAChC,CACF;AACF"}
1
+ {"version":3,"file":"blocks.js","names":[],"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 (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: 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 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":";;;;;;;;AAWA,SAAS,0BAAkC;CACzC,IAAI,qBAAqB,SAAS,aAChC,MAAM,IAAI,MAAM,oEAAoE;CACtF,OAAO,qBAAqB;AAC9B;AAEA,SAAS,aAAa,GAAoB;CACxC,OAAO,aAAa,QAAQ,EAAE,UAAU,OAAO,CAAC;AAClD;AAEA,MAAM,gBAAgB,EAAE,OAAO;CAC7B,WAAW,eAAe,SAAS,6BAA6B;CAChE,OAAO,EAAE,OAAO,CAAC,CAAC,SAAS,aAAa;CACxC,MAAM,EACH,MAAM;EACL,EAAE,OAAO;GACP,MAAM,EAAE,QAAQ,MAAM;GACtB,MAAM,EACH,OAAO,CAAC,CACR,SACC,iIAEF;GACF,aAAa,EACV,OAAO,CAAC,CACR,SAAS,CAAC,CACV,SAAS,uEAAuE;GACnF,eAAe,EACZ,QAAQ,CAAC,CACT,SAAS,CAA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AAE,WAAW,cAAc;EAChC,IAAI,CAAC,IAAI,UAAU,aACjB,OAAO,YACL,+BACA,oMACF;EAEF,MAAM,IAAI,UAAU,YAAY,WAAW,OAAO;EAClD,OAAO,WAAW,EAAE,IAAI,KAAK,CAAC;CAChC,CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"connection.cjs","names":["hints","textResult","errorResult","z"],"sources":["../../src/tools/connection.ts"],"sourcesContent":["import type { McpServer } from \"@modelcontextprotocol/server\";\nimport { z } from \"zod\";\nimport type { ToolContext } from \"./types\";\nimport { errorResult, hints, textResult } from \"./types\";\n\nexport function registerConnectionTools(server: McpServer, ctx: ToolContext): void {\n server.registerTool(\n \"get_connection_status\",\n {\n title: \"Get Connection Status\",\n annotations: hints.read,\n description:\n \"Get the connection status of the application: whether it is connected to a backend server, and to which address and user.\",\n },\n async () => {\n if (!ctx.callbacks.getConnectionStatus) {\n return textResult({ connected: !!ctx.getMl() });\n }\n return textResult(await ctx.callbacks.getConnectionStatus());\n },\n );\n\n server.registerTool(\n \"list_connections\",\n {\n title: \"List Saved Connections\",\n annotations: hints.read,\n description:\n \"List the server connections saved in the application. Use one of them with connect_to_server.\",\n },\n async () => {\n if (!ctx.callbacks.listConnections) {\n return errorResult(\n \"Connection management is not available.\",\n \"The desktop app integration may not support this feature.\",\n );\n }\n return textResult(await ctx.callbacks.listConnections());\n },\n );\n\n server.registerTool(\n \"connect_to_server\",\n {\n title: \"Connect to Server\",\n annotations: { ...hints.idempotent, openWorldHint: true },\n description: \"Connect to a Platforma server. Use list_connections to see saved servers.\",\n inputSchema: z.object({\n addr: z.string().describe(\"Server address (e.g. https://platforma.example.com:6346)\"),\n login: z.string().describe(\"Username\"),\n password: z.string().optional().describe(\"Password (uses saved token if omitted)\"),\n }),\n },\n async ({ addr, login, password }) => {\n if (!ctx.callbacks.connectToServer) {\n return errorResult(\n \"Failed to connect to Platforma Server.\",\n \"Check that provided URL is available and accepts connecitons.\",\n );\n }\n return textResult(await ctx.callbacks.connectToServer(addr, login, password));\n },\n );\n\n server.registerTool(\n \"disconnect\",\n {\n title: \"Disconnect\",\n annotations: hints.idempotent,\n description:\n \"Disconnect the application from the current backend server. Nothing on the server is deleted.\",\n },\n async () => {\n if (!ctx.callbacks.disconnect) {\n return errorResult(\n \"Failed to disconnect.\",\n \"More likely it's because connection is already closed. Could check it with 'get_connection_status' tool.\",\n );\n }\n await ctx.callbacks.disconnect();\n return textResult({ ok: true });\n },\n );\n}\n"],"mappings":";;;AAKA,SAAgB,wBAAwB,QAAmB,KAAwB;CACjF,OAAO,aACL,yBACA;EACE,OAAO;EACP,aAAaA,cAAAA,MAAM;EACnB,aACE;CACJ,GACA,YAAY;EACV,IAAI,CAAC,IAAI,UAAU,qBACjB,OAAOC,cAAAA,WAAW,EAAE,WAAW,CAAC,CAAC,IAAI,MAAM,EAAE,CAAC;EAEhD,OAAOA,cAAAA,WAAW,MAAM,IAAI,UAAU,oBAAoB,CAAC;CAC7D,CACF;CAEA,OAAO,aACL,oBACA;EACE,OAAO;EACP,aAAaD,cAAAA,MAAM;EACnB,aACE;CACJ,GACA,YAAY;EACV,IAAI,CAAC,IAAI,UAAU,iBACjB,OAAOE,cAAAA,YACL,2CACA,2DACF;EAEF,OAAOD,cAAAA,WAAW,MAAM,IAAI,UAAU,gBAAgB,CAAC;CACzD,CACF;CAEA,OAAO,aACL,qBACA;EACE,OAAO;EACP,aAAa;GAAE,GAAGD,cAAAA,MAAM;GAAY,eAAe;EAAK;EACxD,aAAa;EACb,aAAaG,IAAAA,EAAE,OAAO;GACpB,MAAMA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,0DAA0D;GACpF,OAAOA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,UAAU;GACrC,UAAUA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,wCAAwC;EACnF,CAAC;CACH,GACA,OAAO,EAAE,MAAM,OAAO,eAAe;EACnC,IAAI,CAAC,IAAI,UAAU,iBACjB,OAAOD,cAAAA,YACL,0CACA,+DACF;EAEF,OAAOD,cAAAA,WAAW,MAAM,IAAI,UAAU,gBAAgB,MAAM,OAAO,QAAQ,CAAC;CAC9E,CACF;CAEA,OAAO,aACL,cACA;EACE,OAAO;EACP,aAAaD,cAAAA,MAAM;EACnB,aACE;CACJ,GACA,YAAY;EACV,IAAI,CAAC,IAAI,UAAU,YACjB,OAAOE,cAAAA,YACL,yBACA,0GACF;EAEF,MAAM,IAAI,UAAU,WAAW;EAC/B,OAAOD,cAAAA,WAAW,EAAE,IAAI,KAAK,CAAC;CAChC,CACF;AACF"}
1
+ {"version":3,"file":"connection.cjs","names":["hints","textResult","errorResult","z"],"sources":["../../src/tools/connection.ts"],"sourcesContent":["import { z } from \"zod\";\nimport type { ToolContext, ToolRegistrar } from \"./types\";\nimport { errorResult, hints, textResult } from \"./types\";\n\nexport function registerConnectionTools(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"get_connection_status\",\n {\n title: \"Get Connection Status\",\n annotations: hints.read,\n description:\n \"Get the connection status of the application: whether it is connected to a backend server, and to which address and user.\",\n },\n async () => {\n if (!ctx.callbacks.getConnectionStatus) {\n return textResult({ connected: !!ctx.getMl() });\n }\n return textResult(await ctx.callbacks.getConnectionStatus());\n },\n );\n\n server.registerTool(\n \"list_connections\",\n {\n title: \"List Saved Connections\",\n annotations: hints.read,\n description:\n \"List the server connections saved in the application. Use one of them with connect_to_server.\",\n },\n async () => {\n if (!ctx.callbacks.listConnections) {\n return errorResult(\n \"Connection management is not available.\",\n \"The desktop app integration may not support this feature.\",\n );\n }\n return textResult(await ctx.callbacks.listConnections());\n },\n );\n\n server.registerTool(\n \"connect_to_server\",\n {\n title: \"Connect to Server\",\n annotations: { ...hints.idempotent, openWorldHint: true },\n description: \"Connect to a Platforma server. Use list_connections to see saved servers.\",\n inputSchema: z.object({\n addr: z.string().describe(\"Server address (e.g. https://platforma.example.com:6346)\"),\n login: z.string().describe(\"Username\"),\n password: z.string().optional().describe(\"Password (uses saved token if omitted)\"),\n }),\n },\n async ({ addr, login, password }) => {\n if (!ctx.callbacks.connectToServer) {\n return errorResult(\n \"Failed to connect to Platforma Server.\",\n \"Check that provided URL is available and accepts connecitons.\",\n );\n }\n return textResult(await ctx.callbacks.connectToServer(addr, login, password));\n },\n );\n\n server.registerTool(\n \"disconnect\",\n {\n title: \"Disconnect\",\n annotations: hints.idempotent,\n description:\n \"Disconnect the application from the current backend server. Nothing on the server is deleted.\",\n },\n async () => {\n if (!ctx.callbacks.disconnect) {\n return errorResult(\n \"Failed to disconnect.\",\n \"More likely it's because connection is already closed. Could check it with 'get_connection_status' tool.\",\n );\n }\n await ctx.callbacks.disconnect();\n return textResult({ ok: true });\n },\n );\n}\n"],"mappings":";;;AAIA,SAAgB,wBAAwB,QAAuB,KAAwB;CACrF,OAAO,aACL,yBACA;EACE,OAAO;EACP,aAAaA,cAAAA,MAAM;EACnB,aACE;CACJ,GACA,YAAY;EACV,IAAI,CAAC,IAAI,UAAU,qBACjB,OAAOC,cAAAA,WAAW,EAAE,WAAW,CAAC,CAAC,IAAI,MAAM,EAAE,CAAC;EAEhD,OAAOA,cAAAA,WAAW,MAAM,IAAI,UAAU,oBAAoB,CAAC;CAC7D,CACF;CAEA,OAAO,aACL,oBACA;EACE,OAAO;EACP,aAAaD,cAAAA,MAAM;EACnB,aACE;CACJ,GACA,YAAY;EACV,IAAI,CAAC,IAAI,UAAU,iBACjB,OAAOE,cAAAA,YACL,2CACA,2DACF;EAEF,OAAOD,cAAAA,WAAW,MAAM,IAAI,UAAU,gBAAgB,CAAC;CACzD,CACF;CAEA,OAAO,aACL,qBACA;EACE,OAAO;EACP,aAAa;GAAE,GAAGD,cAAAA,MAAM;GAAY,eAAe;EAAK;EACxD,aAAa;EACb,aAAaG,IAAAA,EAAE,OAAO;GACpB,MAAMA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,0DAA0D;GACpF,OAAOA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,UAAU;GACrC,UAAUA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,wCAAwC;EACnF,CAAC;CACH,GACA,OAAO,EAAE,MAAM,OAAO,eAAe;EACnC,IAAI,CAAC,IAAI,UAAU,iBACjB,OAAOD,cAAAA,YACL,0CACA,+DACF;EAEF,OAAOD,cAAAA,WAAW,MAAM,IAAI,UAAU,gBAAgB,MAAM,OAAO,QAAQ,CAAC;CAC9E,CACF;CAEA,OAAO,aACL,cACA;EACE,OAAO;EACP,aAAaD,cAAAA,MAAM;EACnB,aACE;CACJ,GACA,YAAY;EACV,IAAI,CAAC,IAAI,UAAU,YACjB,OAAOE,cAAAA,YACL,yBACA,0GACF;EAEF,MAAM,IAAI,UAAU,WAAW;EAC/B,OAAOD,cAAAA,WAAW,EAAE,IAAI,KAAK,CAAC;CAChC,CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"connection.js","names":[],"sources":["../../src/tools/connection.ts"],"sourcesContent":["import type { McpServer } from \"@modelcontextprotocol/server\";\nimport { z } from \"zod\";\nimport type { ToolContext } from \"./types\";\nimport { errorResult, hints, textResult } from \"./types\";\n\nexport function registerConnectionTools(server: McpServer, ctx: ToolContext): void {\n server.registerTool(\n \"get_connection_status\",\n {\n title: \"Get Connection Status\",\n annotations: hints.read,\n description:\n \"Get the connection status of the application: whether it is connected to a backend server, and to which address and user.\",\n },\n async () => {\n if (!ctx.callbacks.getConnectionStatus) {\n return textResult({ connected: !!ctx.getMl() });\n }\n return textResult(await ctx.callbacks.getConnectionStatus());\n },\n );\n\n server.registerTool(\n \"list_connections\",\n {\n title: \"List Saved Connections\",\n annotations: hints.read,\n description:\n \"List the server connections saved in the application. Use one of them with connect_to_server.\",\n },\n async () => {\n if (!ctx.callbacks.listConnections) {\n return errorResult(\n \"Connection management is not available.\",\n \"The desktop app integration may not support this feature.\",\n );\n }\n return textResult(await ctx.callbacks.listConnections());\n },\n );\n\n server.registerTool(\n \"connect_to_server\",\n {\n title: \"Connect to Server\",\n annotations: { ...hints.idempotent, openWorldHint: true },\n description: \"Connect to a Platforma server. Use list_connections to see saved servers.\",\n inputSchema: z.object({\n addr: z.string().describe(\"Server address (e.g. https://platforma.example.com:6346)\"),\n login: z.string().describe(\"Username\"),\n password: z.string().optional().describe(\"Password (uses saved token if omitted)\"),\n }),\n },\n async ({ addr, login, password }) => {\n if (!ctx.callbacks.connectToServer) {\n return errorResult(\n \"Failed to connect to Platforma Server.\",\n \"Check that provided URL is available and accepts connecitons.\",\n );\n }\n return textResult(await ctx.callbacks.connectToServer(addr, login, password));\n },\n );\n\n server.registerTool(\n \"disconnect\",\n {\n title: \"Disconnect\",\n annotations: hints.idempotent,\n description:\n \"Disconnect the application from the current backend server. Nothing on the server is deleted.\",\n },\n async () => {\n if (!ctx.callbacks.disconnect) {\n return errorResult(\n \"Failed to disconnect.\",\n \"More likely it's because connection is already closed. Could check it with 'get_connection_status' tool.\",\n );\n }\n await ctx.callbacks.disconnect();\n return textResult({ ok: true });\n },\n );\n}\n"],"mappings":";;;AAKA,SAAgB,wBAAwB,QAAmB,KAAwB;CACjF,OAAO,aACL,yBACA;EACE,OAAO;EACP,aAAa,MAAM;EACnB,aACE;CACJ,GACA,YAAY;EACV,IAAI,CAAC,IAAI,UAAU,qBACjB,OAAO,WAAW,EAAE,WAAW,CAAC,CAAC,IAAI,MAAM,EAAE,CAAC;EAEhD,OAAO,WAAW,MAAM,IAAI,UAAU,oBAAoB,CAAC;CAC7D,CACF;CAEA,OAAO,aACL,oBACA;EACE,OAAO;EACP,aAAa,MAAM;EACnB,aACE;CACJ,GACA,YAAY;EACV,IAAI,CAAC,IAAI,UAAU,iBACjB,OAAO,YACL,2CACA,2DACF;EAEF,OAAO,WAAW,MAAM,IAAI,UAAU,gBAAgB,CAAC;CACzD,CACF;CAEA,OAAO,aACL,qBACA;EACE,OAAO;EACP,aAAa;GAAE,GAAG,MAAM;GAAY,eAAe;EAAK;EACxD,aAAa;EACb,aAAa,EAAE,OAAO;GACpB,MAAM,EAAE,OAAO,CAAC,CAAC,SAAS,0DAA0D;GACpF,OAAO,EAAE,OAAO,CAAC,CAAC,SAAS,UAAU;GACrC,UAAU,EAAE,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,wCAAwC;EACnF,CAAC;CACH,GACA,OAAO,EAAE,MAAM,OAAO,eAAe;EACnC,IAAI,CAAC,IAAI,UAAU,iBACjB,OAAO,YACL,0CACA,+DACF;EAEF,OAAO,WAAW,MAAM,IAAI,UAAU,gBAAgB,MAAM,OAAO,QAAQ,CAAC;CAC9E,CACF;CAEA,OAAO,aACL,cACA;EACE,OAAO;EACP,aAAa,MAAM;EACnB,aACE;CACJ,GACA,YAAY;EACV,IAAI,CAAC,IAAI,UAAU,YACjB,OAAO,YACL,yBACA,0GACF;EAEF,MAAM,IAAI,UAAU,WAAW;EAC/B,OAAO,WAAW,EAAE,IAAI,KAAK,CAAC;CAChC,CACF;AACF"}
1
+ {"version":3,"file":"connection.js","names":[],"sources":["../../src/tools/connection.ts"],"sourcesContent":["import { z } from \"zod\";\nimport type { ToolContext, ToolRegistrar } from \"./types\";\nimport { errorResult, hints, textResult } from \"./types\";\n\nexport function registerConnectionTools(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"get_connection_status\",\n {\n title: \"Get Connection Status\",\n annotations: hints.read,\n description:\n \"Get the connection status of the application: whether it is connected to a backend server, and to which address and user.\",\n },\n async () => {\n if (!ctx.callbacks.getConnectionStatus) {\n return textResult({ connected: !!ctx.getMl() });\n }\n return textResult(await ctx.callbacks.getConnectionStatus());\n },\n );\n\n server.registerTool(\n \"list_connections\",\n {\n title: \"List Saved Connections\",\n annotations: hints.read,\n description:\n \"List the server connections saved in the application. Use one of them with connect_to_server.\",\n },\n async () => {\n if (!ctx.callbacks.listConnections) {\n return errorResult(\n \"Connection management is not available.\",\n \"The desktop app integration may not support this feature.\",\n );\n }\n return textResult(await ctx.callbacks.listConnections());\n },\n );\n\n server.registerTool(\n \"connect_to_server\",\n {\n title: \"Connect to Server\",\n annotations: { ...hints.idempotent, openWorldHint: true },\n description: \"Connect to a Platforma server. Use list_connections to see saved servers.\",\n inputSchema: z.object({\n addr: z.string().describe(\"Server address (e.g. https://platforma.example.com:6346)\"),\n login: z.string().describe(\"Username\"),\n password: z.string().optional().describe(\"Password (uses saved token if omitted)\"),\n }),\n },\n async ({ addr, login, password }) => {\n if (!ctx.callbacks.connectToServer) {\n return errorResult(\n \"Failed to connect to Platforma Server.\",\n \"Check that provided URL is available and accepts connecitons.\",\n );\n }\n return textResult(await ctx.callbacks.connectToServer(addr, login, password));\n },\n );\n\n server.registerTool(\n \"disconnect\",\n {\n title: \"Disconnect\",\n annotations: hints.idempotent,\n description:\n \"Disconnect the application from the current backend server. Nothing on the server is deleted.\",\n },\n async () => {\n if (!ctx.callbacks.disconnect) {\n return errorResult(\n \"Failed to disconnect.\",\n \"More likely it's because connection is already closed. Could check it with 'get_connection_status' tool.\",\n );\n }\n await ctx.callbacks.disconnect();\n return textResult({ ok: true });\n },\n );\n}\n"],"mappings":";;;AAIA,SAAgB,wBAAwB,QAAuB,KAAwB;CACrF,OAAO,aACL,yBACA;EACE,OAAO;EACP,aAAa,MAAM;EACnB,aACE;CACJ,GACA,YAAY;EACV,IAAI,CAAC,IAAI,UAAU,qBACjB,OAAO,WAAW,EAAE,WAAW,CAAC,CAAC,IAAI,MAAM,EAAE,CAAC;EAEhD,OAAO,WAAW,MAAM,IAAI,UAAU,oBAAoB,CAAC;CAC7D,CACF;CAEA,OAAO,aACL,oBACA;EACE,OAAO;EACP,aAAa,MAAM;EACnB,aACE;CACJ,GACA,YAAY;EACV,IAAI,CAAC,IAAI,UAAU,iBACjB,OAAO,YACL,2CACA,2DACF;EAEF,OAAO,WAAW,MAAM,IAAI,UAAU,gBAAgB,CAAC;CACzD,CACF;CAEA,OAAO,aACL,qBACA;EACE,OAAO;EACP,aAAa;GAAE,GAAG,MAAM;GAAY,eAAe;EAAK;EACxD,aAAa;EACb,aAAa,EAAE,OAAO;GACpB,MAAM,EAAE,OAAO,CAAC,CAAC,SAAS,0DAA0D;GACpF,OAAO,EAAE,OAAO,CAAC,CAAC,SAAS,UAAU;GACrC,UAAU,EAAE,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,wCAAwC;EACnF,CAAC;CACH,GACA,OAAO,EAAE,MAAM,OAAO,eAAe;EACnC,IAAI,CAAC,IAAI,UAAU,iBACjB,OAAO,YACL,0CACA,+DACF;EAEF,OAAO,WAAW,MAAM,IAAI,UAAU,gBAAgB,MAAM,OAAO,QAAQ,CAAC;CAC9E,CACF;CAEA,OAAO,aACL,cACA;EACE,OAAO;EACP,aAAa,MAAM;EACnB,aACE;CACJ,GACA,YAAY;EACV,IAAI,CAAC,IAAI,UAAU,YACjB,OAAO,YACL,yBACA,0GACF;EAEF,MAAM,IAAI,UAAU,WAAW;EAC/B,OAAO,WAAW,EAAE,IAAI,KAAK,CAAC;CAChC,CACF;AACF"}