@milaboratories/pl-mcp-server 53.0.0 → 54.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/README.md +36 -2
  2. package/dist/instructions.cjs +3 -2
  3. package/dist/instructions.cjs.map +1 -1
  4. package/dist/instructions.js +3 -2
  5. package/dist/instructions.js.map +1 -1
  6. package/dist/package.cjs +1 -1
  7. package/dist/package.js +1 -1
  8. package/dist/project-holds.cjs +72 -0
  9. package/dist/project-holds.cjs.map +1 -0
  10. package/dist/project-holds.js +72 -0
  11. package/dist/project-holds.js.map +1 -0
  12. package/dist/server-log.cjs +373 -0
  13. package/dist/server-log.cjs.map +1 -0
  14. package/dist/server-log.js +371 -0
  15. package/dist/server-log.js.map +1 -0
  16. package/dist/server.cjs +77 -22
  17. package/dist/server.cjs.map +1 -1
  18. package/dist/server.d.ts +31 -7
  19. package/dist/server.d.ts.map +1 -1
  20. package/dist/server.js +77 -23
  21. package/dist/server.js.map +1 -1
  22. package/dist/tools/await.cjs +59 -60
  23. package/dist/tools/await.cjs.map +1 -1
  24. package/dist/tools/await.js +60 -61
  25. package/dist/tools/await.js.map +1 -1
  26. package/dist/tools/block-action-context.cjs +11 -9
  27. package/dist/tools/block-action-context.cjs.map +1 -1
  28. package/dist/tools/block-action-context.js +11 -9
  29. package/dist/tools/block-action-context.js.map +1 -1
  30. package/dist/tools/block-params.cjs +4 -3
  31. package/dist/tools/block-params.cjs.map +1 -1
  32. package/dist/tools/block-params.js +4 -3
  33. package/dist/tools/block-params.js.map +1 -1
  34. package/dist/tools/block-state.cjs +46 -41
  35. package/dist/tools/block-state.cjs.map +1 -1
  36. package/dist/tools/block-state.js +47 -42
  37. package/dist/tools/block-state.js.map +1 -1
  38. package/dist/tools/blocks.cjs +30 -20
  39. package/dist/tools/blocks.cjs.map +1 -1
  40. package/dist/tools/blocks.js +30 -20
  41. package/dist/tools/blocks.js.map +1 -1
  42. package/dist/tools/connection.cjs.map +1 -1
  43. package/dist/tools/connection.js.map +1 -1
  44. package/dist/tools/data-query.cjs +111 -80
  45. package/dist/tools/data-query.cjs.map +1 -1
  46. package/dist/tools/data-query.js +114 -83
  47. package/dist/tools/data-query.js.map +1 -1
  48. package/dist/tools/ids.cjs +16 -0
  49. package/dist/tools/ids.cjs.map +1 -1
  50. package/dist/tools/ids.js +13 -1
  51. package/dist/tools/ids.js.map +1 -1
  52. package/dist/tools/logs.cjs +28 -26
  53. package/dist/tools/logs.cjs.map +1 -1
  54. package/dist/tools/logs.js +28 -26
  55. package/dist/tools/logs.js.map +1 -1
  56. package/dist/tools/ping.cjs.map +1 -1
  57. package/dist/tools/ping.js.map +1 -1
  58. package/dist/tools/projects.cjs +10 -27
  59. package/dist/tools/projects.cjs.map +1 -1
  60. package/dist/tools/projects.js +11 -28
  61. package/dist/tools/projects.js.map +1 -1
  62. package/dist/tools/sandbox.cjs +110 -8
  63. package/dist/tools/sandbox.cjs.map +1 -1
  64. package/dist/tools/sandbox.js +107 -9
  65. package/dist/tools/sandbox.js.map +1 -1
  66. package/dist/tools/screenshot.cjs +9 -1
  67. package/dist/tools/screenshot.cjs.map +1 -1
  68. package/dist/tools/screenshot.js +9 -1
  69. package/dist/tools/screenshot.js.map +1 -1
  70. package/dist/tools/types.cjs +29 -0
  71. package/dist/tools/types.cjs.map +1 -1
  72. package/dist/tools/types.js +27 -1
  73. package/dist/tools/types.js.map +1 -1
  74. package/dist/tools/ui-interaction.cjs.map +1 -1
  75. package/dist/tools/ui-interaction.js.map +1 -1
  76. package/package.json +6 -5
  77. package/src/instructions.ts +3 -2
  78. package/src/project-holds.test.ts +183 -0
  79. package/src/project-holds.ts +105 -0
  80. package/src/server-log.test.ts +871 -0
  81. package/src/server-log.ts +504 -0
  82. package/src/server.logging.test.ts +383 -0
  83. package/src/server.request-failure.test.ts +49 -0
  84. package/src/server.test.ts +15 -5
  85. package/src/server.ts +111 -26
  86. package/src/test/recording-logger.ts +33 -0
  87. package/src/tools/await.ts +96 -98
  88. package/src/tools/block-action-context.ts +16 -16
  89. package/src/tools/block-params.ts +6 -6
  90. package/src/tools/block-state.ts +61 -60
  91. package/src/tools/blocks.ts +49 -40
  92. package/src/tools/connection.ts +2 -3
  93. package/src/tools/data-query.ts +151 -108
  94. package/src/tools/ids.ts +22 -1
  95. package/src/tools/logs.ts +43 -43
  96. package/src/tools/ping.ts +2 -3
  97. package/src/tools/projects.ts +22 -45
  98. package/src/tools/sandbox.test.ts +183 -0
  99. package/src/tools/sandbox.ts +126 -10
  100. package/src/tools/screenshot.ts +15 -4
  101. package/src/tools/types.test.ts +4 -3
  102. package/src/tools/types.ts +73 -3
  103. package/src/tools/ui-interaction.ts +2 -3
@@ -1,14 +1,13 @@
1
- import type { McpServer } from "@modelcontextprotocol/server";
2
1
  import { deriveDataFromStorage } from "@platforma-sdk/model";
3
2
  import { ModelAPIVersionMismatchError } from "@milaboratories/pl-errors";
4
3
  import { z } from "zod";
5
4
  import { projectIdInput, blockIdInput } from "./ids";
6
- import type { ToolContext } from "./types";
5
+ import type { ToolContext, ToolRegistrar } from "./types";
7
6
  import { summarizeOutputs } from "./tokens";
8
7
  import { safeEval } from "./sandbox";
9
- import { errorResult, hints, textResult } from "./types";
8
+ import { errorResult, hints, textResult, transformFailedResult } from "./types";
10
9
 
11
- export function registerBlockStateTools(server: McpServer, ctx: ToolContext): void {
10
+ export function registerBlockStateTools(server: ToolRegistrar, ctx: ToolContext): void {
12
11
  server.registerTool(
13
12
  "get_project_overview",
14
13
  {
@@ -17,26 +16,27 @@ export function registerBlockStateTools(server: McpServer, ctx: ToolContext): vo
17
16
  description:
18
17
  "Get project overview with all blocks and their statuses (calculationStatus, canRun, stale, errors, upstreams/downstreams)",
19
18
  inputSchema: z.object({
20
- projectId: projectIdInput.describe("Project ID (must be opened)"),
19
+ projectId: projectIdInput.describe("Project ID"),
21
20
  }),
22
21
  },
23
22
  async ({ projectId }) => {
24
- const project = await ctx.getOpenedProject(projectId);
25
- const overview = await project.overview.getValue();
26
- if (!overview) return errorResult("Project overview not available yet.");
27
- return textResult({
28
- label: overview.meta.label,
29
- blocks: overview.blocks.map((b) => ({
30
- id: b.id,
31
- title: b.title ?? b.label,
32
- calculationStatus: b.calculationStatus,
33
- canRun: b.canRun,
34
- stale: b.stale,
35
- inputsValid: b.inputsValid,
36
- outputErrors: b.outputErrors,
37
- upstreams: b.upstreams,
38
- downstreams: b.downstreams,
39
- })),
23
+ return await ctx.withProject(projectId, async (project) => {
24
+ const overview = await project.overview.getValue();
25
+ if (!overview) return errorResult("Project overview not available yet.");
26
+ return textResult({
27
+ label: overview.meta.label,
28
+ blocks: overview.blocks.map((b) => ({
29
+ id: b.id,
30
+ title: b.title ?? b.label,
31
+ calculationStatus: b.calculationStatus,
32
+ canRun: b.canRun,
33
+ stale: b.stale,
34
+ inputsValid: b.inputsValid,
35
+ outputErrors: b.outputErrors,
36
+ upstreams: b.upstreams,
37
+ downstreams: b.downstreams,
38
+ })),
39
+ });
40
40
  });
41
41
  },
42
42
  );
@@ -73,27 +73,28 @@ export function registerBlockStateTools(server: McpServer, ctx: ToolContext): vo
73
73
  }),
74
74
  },
75
75
  async ({ projectId, blockId, transform, transformTimeout }) => {
76
- const project = await ctx.getOpenedProject(projectId);
77
- const state = await project.getBlockState(blockId).getValue();
78
- const data = deriveDataFromStorage(state.blockStorage);
79
- if (transform) {
80
- try {
81
- const result = await safeEval(
82
- transform,
83
- { data, outputs: state.outputs },
84
- transformTimeout,
85
- );
86
- return textResult(result);
87
- } catch (e: unknown) {
88
- return errorResult(
89
- `Transform failed: ${e instanceof Error ? e.message : String(e)}`,
90
- "Check your JS expression syntax. Available variables: data, outputs.",
91
- );
76
+ return await ctx.withProject(projectId, async (project) => {
77
+ const state = await project.getBlockState(blockId).getValue();
78
+ const data = deriveDataFromStorage(state.blockStorage);
79
+ if (transform) {
80
+ try {
81
+ const result = await safeEval(
82
+ transform,
83
+ { data, outputs: state.outputs },
84
+ transformTimeout,
85
+ );
86
+ return textResult(result);
87
+ } catch (e: unknown) {
88
+ return transformFailedResult(
89
+ e,
90
+ "Check your JS expression syntax. Available variables: data, outputs.",
91
+ );
92
+ }
92
93
  }
93
- }
94
- return textResult({
95
- data,
96
- outputs: summarizeOutputs(state.outputs as Record<string, unknown> | undefined),
94
+ return textResult({
95
+ data,
96
+ outputs: summarizeOutputs(state.outputs as Record<string, unknown> | undefined),
97
+ });
97
98
  });
98
99
  },
99
100
  );
@@ -111,27 +112,27 @@ export function registerBlockStateTools(server: McpServer, ctx: ToolContext): vo
111
112
  }),
112
113
  },
113
114
  async ({ projectId, blockId, data }) => {
114
- const project = await ctx.getOpenedProject(projectId);
115
+ return await ctx.withProject(projectId, async (project) => {
116
+ // V1 state shape: { args, uiState } — callers may pass either the full state
117
+ // or just the args object. Unwrap once for both V2 and V1 paths.
118
+ const value = data.args ?? data;
115
119
 
116
- // V1 state shape: { args, uiState } — callers may pass either the full state
117
- // or just the args object. Unwrap once for both V2 and V1 paths.
118
- const value = data.args ?? data;
119
-
120
- // Try V2 (BlockModelV3 storage facade) first, fall back to V1 (legacy setBlockArgs).
121
- try {
122
- await project.mutateBlockStorage(
123
- blockId,
124
- { operation: "update-block-data", value },
125
- ctx.getAuthorMarker(),
126
- );
127
- } catch (e: unknown) {
128
- if (e instanceof ModelAPIVersionMismatchError) {
129
- await project.setBlockArgs(blockId, value, ctx.getAuthorMarker());
130
- } else {
131
- throw e;
120
+ // Try V2 (BlockModelV3 storage facade) first, fall back to V1 (legacy setBlockArgs).
121
+ try {
122
+ await project.mutateBlockStorage(
123
+ blockId,
124
+ { operation: "update-block-data", value },
125
+ ctx.getAuthorMarker(),
126
+ );
127
+ } catch (e: unknown) {
128
+ if (e instanceof ModelAPIVersionMismatchError) {
129
+ await project.setBlockArgs(blockId, value, ctx.getAuthorMarker());
130
+ } else {
131
+ throw e;
132
+ }
132
133
  }
133
- }
134
- return textResult({ ok: true });
134
+ return textResult({ ok: true });
135
+ });
135
136
  },
136
137
  );
137
138
  }
@@ -1,11 +1,10 @@
1
- import type { McpServer } from "@modelcontextprotocol/server";
2
1
  import type { BlockPackSpecAny, Project } from "@milaboratories/pl-middle-layer";
3
2
  import { BlockKindRef, CentralBlockRegistry } from "@milaboratories/pl-middle-layer";
4
3
  import { BlockInitParamsRejectedError } from "@milaboratories/pl-errors";
5
4
  import type { BlockKindReference } from "@platforma-sdk/model";
6
5
  import { z } from "zod";
7
6
  import { projectIdInput, blockIdInput } from "./ids";
8
- import type { AuthorMarker, ToolContext } from "./types";
7
+ import type { AuthorMarker, ToolContext, ToolRegistrar } from "./types";
9
8
  import { errorResult, hints, textResult } from "./types";
10
9
  import { SUPPORTED_BLOCK_API, unsupportedBlockApiResult } from "./block-api";
11
10
 
@@ -21,7 +20,7 @@ function errorMessage(e: unknown): string {
21
20
  }
22
21
 
23
22
  const addBlockInput = z.object({
24
- projectId: projectIdInput.describe("Project ID (must be opened)"),
23
+ projectId: projectIdInput.describe("Project ID"),
25
24
  label: z.string().describe("Block label"),
26
25
  spec: z
27
26
  .union([
@@ -140,14 +139,14 @@ export async function addBlock(deps: AddBlockDeps, input: AddBlockInput) {
140
139
  }
141
140
  }
142
141
 
143
- export function registerBlockTools(server: McpServer, ctx: ToolContext): void {
142
+ export function registerBlockTools(server: ToolRegistrar, ctx: ToolContext): void {
144
143
  server.registerTool(
145
144
  "add_block",
146
145
  {
147
146
  title: "Add Block",
148
147
  annotations: hints.additive,
149
148
  description:
150
- "Add a block to an opened project, optionally configured from initialization params.\n\n" +
149
+ "Add a block to a project, optionally configured from initialization params.\n\n" +
151
150
  "`spec` names the block: `kind` (a block kind reference, resolved to the newest block " +
152
151
  "implementing it), `from-registry-v2` (an exact published block) or `dev-v2` (a local dev " +
153
152
  "block folder).\n\n" +
@@ -162,16 +161,20 @@ export function registerBlockTools(server: McpServer, ctx: ToolContext): void {
162
161
  },
163
162
  async (input) => {
164
163
  const ml = ctx.requireMl();
165
- return await addBlock(
166
- {
167
- project: await ctx.getOpenedProject(input.projectId),
168
- resolveKind: (kind, registryUrl, allowUnstable) =>
169
- ml.blockRegistryProvider
170
- .getRegistry(registryUrl ?? centralBlockRegistryUrl())
171
- .resolveKind(kind, { allowUnstable }),
172
- author: ctx.getAuthorMarker(),
173
- },
174
- input,
164
+ return await ctx.withProject(
165
+ input.projectId,
166
+ async (project) =>
167
+ await addBlock(
168
+ {
169
+ project,
170
+ resolveKind: (kind, registryUrl, allowUnstable) =>
171
+ ml.blockRegistryProvider
172
+ .getRegistry(registryUrl ?? centralBlockRegistryUrl())
173
+ .resolveKind(kind, { allowUnstable }),
174
+ author: ctx.getAuthorMarker(),
175
+ },
176
+ input,
177
+ ),
175
178
  );
176
179
  },
177
180
  );
@@ -184,7 +187,7 @@ export function registerBlockTools(server: McpServer, ctx: ToolContext): void {
184
187
  description:
185
188
  "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.",
186
189
  inputSchema: z.object({
187
- projectId: projectIdInput.describe("Project ID (must be opened)"),
190
+ projectId: projectIdInput.describe("Project ID"),
188
191
  blockId: blockIdInput.describe("Block ID to update"),
189
192
  spec: z
190
193
  .union([
@@ -210,14 +213,15 @@ export function registerBlockTools(server: McpServer, ctx: ToolContext): void {
210
213
  }),
211
214
  },
212
215
  async ({ projectId, blockId, spec, resetArgs }) => {
213
- const project = await ctx.getOpenedProject(projectId);
214
- await project.updateBlockPack(
215
- blockId,
216
- spec as BlockPackSpecAny,
217
- resetArgs ?? false,
218
- ctx.getAuthorMarker(),
219
- );
220
- return textResult({ ok: true });
216
+ return await ctx.withProject(projectId, async (project) => {
217
+ await project.updateBlockPack(
218
+ blockId,
219
+ spec as BlockPackSpecAny,
220
+ resetArgs ?? false,
221
+ ctx.getAuthorMarker(),
222
+ );
223
+ return textResult({ ok: true });
224
+ });
221
225
  },
222
226
  );
223
227
 
@@ -227,16 +231,17 @@ export function registerBlockTools(server: McpServer, ctx: ToolContext): void {
227
231
  title: "Remove Block",
228
232
  annotations: hints.destructive,
229
233
  description:
230
- "Remove a block from an opened project, with its configuration and results. Blocks below that refer to it are left with a missing reference.",
234
+ "Remove a block from a project, with its configuration and results. Blocks below that refer to it are left with a missing reference.",
231
235
  inputSchema: z.object({
232
236
  projectId: projectIdInput.describe("Project ID"),
233
237
  blockId: blockIdInput.describe("Block ID to remove"),
234
238
  }),
235
239
  },
236
240
  async ({ projectId, blockId }) => {
237
- const project = await ctx.getOpenedProject(projectId);
238
- await project.deleteBlock(blockId, ctx.getAuthorMarker());
239
- return textResult({ ok: true });
241
+ return await ctx.withProject(projectId, async (project) => {
242
+ await project.deleteBlock(blockId, ctx.getAuthorMarker());
243
+ return textResult({ ok: true });
244
+ });
240
245
  },
241
246
  );
242
247
 
@@ -254,9 +259,10 @@ export function registerBlockTools(server: McpServer, ctx: ToolContext): void {
254
259
  }),
255
260
  },
256
261
  async ({ projectId, blockId }) => {
257
- const project = await ctx.getOpenedProject(projectId);
258
- await project.runBlock(blockId);
259
- return textResult({ ok: true });
262
+ return await ctx.withProject(projectId, async (project) => {
263
+ await project.runBlock(blockId);
264
+ return textResult({ ok: true });
265
+ });
260
266
  },
261
267
  );
262
268
 
@@ -272,9 +278,10 @@ export function registerBlockTools(server: McpServer, ctx: ToolContext): void {
272
278
  }),
273
279
  },
274
280
  async ({ projectId, blockId }) => {
275
- const project = await ctx.getOpenedProject(projectId);
276
- await project.stopBlock(blockId);
277
- return textResult({ ok: true });
281
+ return await ctx.withProject(projectId, async (project) => {
282
+ await project.stopBlock(blockId);
283
+ return textResult({ ok: true });
284
+ });
278
285
  },
279
286
  );
280
287
 
@@ -290,9 +297,10 @@ export function registerBlockTools(server: McpServer, ctx: ToolContext): void {
290
297
  }),
291
298
  },
292
299
  async ({ projectId, blockIds }) => {
293
- const project = await ctx.getOpenedProject(projectId);
294
- await project.reorderBlocks(blockIds);
295
- return textResult({ ok: true });
300
+ return await ctx.withProject(projectId, async (project) => {
301
+ await project.reorderBlocks(blockIds);
302
+ return textResult({ ok: true });
303
+ });
296
304
  },
297
305
  );
298
306
 
@@ -353,7 +361,9 @@ export function registerBlockTools(server: McpServer, ctx: ToolContext): void {
353
361
  {
354
362
  title: "Show Block in the Application",
355
363
  annotations: hints.idempotent,
356
- description: "Navigate the desktop UI to show a specific block's interface",
364
+ description:
365
+ "Show a block to the user in the application: the application's window opens the block. " +
366
+ "Use it only when the user asks to be shown something; working with blocks does not need it.",
357
367
  inputSchema: z.object({
358
368
  projectId: projectIdInput.describe("Project ID"),
359
369
  blockId: blockIdInput.describe("Block ID to display"),
@@ -362,8 +372,7 @@ export function registerBlockTools(server: McpServer, ctx: ToolContext): void {
362
372
  async ({ projectId, blockId }) => {
363
373
  if (!ctx.callbacks.selectBlock) {
364
374
  return errorResult(
365
- "Failed to select the block.",
366
- "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.",
375
+ "Failed to show the block: this server is not running inside the desktop application.",
367
376
  );
368
377
  }
369
378
  await ctx.callbacks.selectBlock(projectId, blockId);
@@ -1,9 +1,8 @@
1
- import type { McpServer } from "@modelcontextprotocol/server";
2
1
  import { z } from "zod";
3
- import type { ToolContext } from "./types";
2
+ import type { ToolContext, ToolRegistrar } from "./types";
4
3
  import { errorResult, hints, textResult } from "./types";
5
4
 
6
- export function registerConnectionTools(server: McpServer, ctx: ToolContext): void {
5
+ export function registerConnectionTools(server: ToolRegistrar, ctx: ToolContext): void {
7
6
  server.registerTool(
8
7
  "get_connection_status",
9
8
  {