@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
@@ -14,7 +14,11 @@ function registerScreenshotTool(server, ctx) {
14
14
  const base64Png = await ctx.callbacks.captureScreenshot();
15
15
  if (savePath) {
16
16
  const absPath = resolve(savePath);
17
- await writeFile(absPath, Buffer.from(base64Png, "base64"), { flag: "wx" });
17
+ try {
18
+ await writeFile(absPath, Buffer.from(base64Png, "base64"), { flag: "wx" });
19
+ } catch (e) {
20
+ return saveFailedResult(e);
21
+ }
18
22
  return { content: [{
19
23
  type: "image",
20
24
  data: base64Png,
@@ -31,6 +35,10 @@ function registerScreenshotTool(server, ctx) {
31
35
  }] };
32
36
  });
33
37
  }
38
+ /** The result of a screenshot that could not be saved: the error of the file system, as it is. */
39
+ function saveFailedResult(error) {
40
+ return errorResult(`Could not save the screenshot: ${error instanceof Error ? error.message : String(error)}`, "Check that the folder exists and is writable and that no file exists at the path; the screenshot is not overwritten.");
41
+ }
34
42
  export { registerScreenshotTool };
35
43
 
36
44
  //# sourceMappingURL=screenshot.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"screenshot.js","names":[],"sources":["../../src/tools/screenshot.ts"],"sourcesContent":["import { writeFile } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nimport type { McpServer } from \"@modelcontextprotocol/server\";\nimport { z } from \"zod\";\nimport type { ToolContext } from \"./types\";\nimport { errorResult, hints } from \"./types\";\n\nexport function registerScreenshotTool(server: McpServer, ctx: ToolContext): void {\n server.registerTool(\n \"capture_screenshot\",\n {\n title: \"Capture Screenshot\",\n annotations: hints.additive,\n description:\n \"Capture a screenshot of the current application window. Optionally save to a file.\",\n inputSchema: z.object({\n savePath: z\n .string()\n .optional()\n .describe(\n \"Absolute file path to save the screenshot as PNG. If omitted, returns the image inline only.\",\n ),\n }),\n },\n async ({ savePath }) => {\n if (!ctx.callbacks.captureScreenshot) {\n return errorResult(\n \"Screenshot capture is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n const base64Png = await ctx.callbacks.captureScreenshot();\n\n if (savePath) {\n const absPath = resolve(savePath);\n await writeFile(absPath, Buffer.from(base64Png, \"base64\"), { flag: \"wx\" });\n return {\n content: [\n { type: \"image\" as const, data: base64Png, mimeType: \"image/png\" },\n { type: \"text\" as const, text: `Screenshot saved to ${absPath}` },\n ],\n };\n }\n\n return {\n content: [{ type: \"image\" as const, data: base64Png, mimeType: \"image/png\" }],\n };\n },\n );\n}\n"],"mappings":";;;;;AAOA,SAAgB,uBAAuB,QAAmB,KAAwB;CAChF,OAAO,aACL,sBACA;EACE,OAAO;EACP,aAAa,MAAM;EACnB,aACE;EACF,aAAa,EAAE,OAAO,EACpB,UAAU,EACP,OAAO,CAAC,CACR,SAAS,CAAC,CACV,SACC,8FACF,EACJ,CAAC;CACH,GACA,OAAO,EAAE,eAAe;EACtB,IAAI,CAAC,IAAI,UAAU,mBACjB,OAAO,YACL,wCACA,qJACF;EAEF,MAAM,YAAY,MAAM,IAAI,UAAU,kBAAkB;EAExD,IAAI,UAAU;GACZ,MAAM,UAAU,QAAQ,QAAQ;GAChC,MAAM,UAAU,SAAS,OAAO,KAAK,WAAW,QAAQ,GAAG,EAAE,MAAM,KAAK,CAAC;GACzE,OAAO,EACL,SAAS,CACP;IAAE,MAAM;IAAkB,MAAM;IAAW,UAAU;GAAY,GACjE;IAAE,MAAM;IAAiB,MAAM,uBAAuB;GAAU,CAClE,EACF;EACF;EAEA,OAAO,EACL,SAAS,CAAC;GAAE,MAAM;GAAkB,MAAM;GAAW,UAAU;EAAY,CAAC,EAC9E;CACF,CACF;AACF"}
1
+ {"version":3,"file":"screenshot.js","names":[],"sources":["../../src/tools/screenshot.ts"],"sourcesContent":["import { writeFile } from \"node:fs/promises\";\nimport { resolve } from \"node:path\";\nimport { z } from \"zod\";\nimport type { ToolContext, ToolRegistrar } from \"./types\";\nimport { errorResult, hints } from \"./types\";\n\nexport function registerScreenshotTool(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"capture_screenshot\",\n {\n title: \"Capture Screenshot\",\n annotations: hints.additive,\n description:\n \"Capture a screenshot of the current application window. Optionally save to a file.\",\n inputSchema: z.object({\n savePath: z\n .string()\n .optional()\n .describe(\n \"Absolute file path to save the screenshot as PNG. If omitted, returns the image inline only.\",\n ),\n }),\n },\n async ({ savePath }) => {\n if (!ctx.callbacks.captureScreenshot) {\n return errorResult(\n \"Screenshot capture is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n const base64Png = await ctx.callbacks.captureScreenshot();\n\n if (savePath) {\n const absPath = resolve(savePath);\n try {\n await writeFile(absPath, Buffer.from(base64Png, \"base64\"), { flag: \"wx\" });\n } catch (e: unknown) {\n return saveFailedResult(e);\n }\n return {\n content: [\n { type: \"image\" as const, data: base64Png, mimeType: \"image/png\" },\n { type: \"text\" as const, text: `Screenshot saved to ${absPath}` },\n ],\n };\n }\n\n return {\n content: [{ type: \"image\" as const, data: base64Png, mimeType: \"image/png\" }],\n };\n },\n );\n}\n\n/** The result of a screenshot that could not be saved: the error of the file system, as it is. */\nfunction saveFailedResult(error: unknown) {\n return errorResult(\n `Could not save the screenshot: ${error instanceof Error ? error.message : String(error)}`,\n \"Check that the folder exists and is writable and that no file exists at the path; the screenshot is not overwritten.\",\n );\n}\n"],"mappings":";;;;;AAMA,SAAgB,uBAAuB,QAAuB,KAAwB;CACpF,OAAO,aACL,sBACA;EACE,OAAO;EACP,aAAa,MAAM;EACnB,aACE;EACF,aAAa,EAAE,OAAO,EACpB,UAAU,EACP,OAAO,CAAC,CACR,SAAS,CAAC,CACV,SACC,8FACF,EACJ,CAAC;CACH,GACA,OAAO,EAAE,eAAe;EACtB,IAAI,CAAC,IAAI,UAAU,mBACjB,OAAO,YACL,wCACA,qJACF;EAEF,MAAM,YAAY,MAAM,IAAI,UAAU,kBAAkB;EAExD,IAAI,UAAU;GACZ,MAAM,UAAU,QAAQ,QAAQ;GAChC,IAAI;IACF,MAAM,UAAU,SAAS,OAAO,KAAK,WAAW,QAAQ,GAAG,EAAE,MAAM,KAAK,CAAC;GAC3E,SAAS,GAAY;IACnB,OAAO,iBAAiB,CAAC;GAC3B;GACA,OAAO,EACL,SAAS,CACP;IAAE,MAAM;IAAkB,MAAM;IAAW,UAAU;GAAY,GACjE;IAAE,MAAM;IAAiB,MAAM,uBAAuB;GAAU,CAClE,EACF;EACF;EAEA,OAAO,EACL,SAAS,CAAC;GAAE,MAAM;GAAkB,MAAM;GAAW,UAAU;EAAY,CAAC,EAC9E;CACF,CACF;AACF;;AAGA,SAAS,iBAAiB,OAAgB;CACxC,OAAO,YACL,kCAAkC,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,KACvF,sHACF;AACF"}
@@ -64,9 +64,38 @@ function errorResult(message, hint) {
64
64
  isError: true
65
65
  };
66
66
  }
67
+ /** The results made by {@link timedOutResult}. */
68
+ const timedOutResults = /* @__PURE__ */ new WeakSet();
69
+ /**
70
+ * Returns the result of a tool that waited for something and ran out of time: the JSON of `data`
71
+ * with `timedOut: true` in front. It is not an error result, the caller is expected to wait again.
72
+ * The server's log recognises such a result with {@link isTimedOutResult}.
73
+ */
74
+ function timedOutResult(data) {
75
+ const result = textResult({
76
+ timedOut: true,
77
+ ...data
78
+ });
79
+ timedOutResults.add(result);
80
+ return result;
81
+ }
82
+ /** Whether `result` was made by {@link timedOutResult}. */
83
+ function isTimedOutResult(result) {
84
+ return typeof result === "object" && result !== null && timedOutResults.has(result);
85
+ }
86
+ /**
87
+ * Returns the error result of a tool whose `transform` failed: `Transform failed: ` and the whole
88
+ * error, then `hint`. The agent needs the whole error to fix its expression.
89
+ */
90
+ function transformFailedResult(error, hint) {
91
+ return errorResult(`Transform failed: ${error instanceof Error ? error.message : String(error)}`, hint);
92
+ }
67
93
  exports.authorMarkerSource = authorMarkerSource;
68
94
  exports.errorResult = errorResult;
69
95
  exports.hints = hints;
96
+ exports.isTimedOutResult = isTimedOutResult;
70
97
  exports.textResult = textResult;
98
+ exports.timedOutResult = timedOutResult;
99
+ exports.transformFailedResult = transformFailedResult;
71
100
 
72
101
  //# sourceMappingURL=types.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.cjs","names":[],"sources":["../../src/tools/types.ts"],"sourcesContent":["import type {\n AuthorMarker,\n MiddleLayer,\n Project,\n ProjectId,\n ProjectListEntry,\n} from \"@milaboratories/pl-middle-layer\";\nimport type { PlMcpServerCallbacks } from \"../server\";\n\nexport type { AuthorMarker };\n\nexport interface ToolContext {\n getMl: () => MiddleLayer | null;\n requireMl: () => MiddleLayer;\n resolveProject: (projectId: ProjectId) => Promise<ProjectListEntry>;\n getOpenedProject: (projectId: ProjectId) => Promise<Project>;\n callbacks: PlMcpServerCallbacks;\n /**\n * Returns the marker for the next write made through MCP. All writes of one server instance carry\n * the same `authorId`, whichever client asked for them, and a `localVersion` that grows with\n * every call.\n */\n getAuthorMarker: () => AuthorMarker;\n}\n\n/**\n * Makes the author markers of one writer: every call returns a marker with `authorId` and the next\n * `localVersion`, counted from 1.\n */\nexport function authorMarkerSource(authorId: string): () => AuthorMarker {\n let localVersion = 0;\n return () => ({ authorId, localVersion: ++localVersion });\n}\n\n/**\n * The four behaviour hints of a tool, all stated. A client reads a missing hint as the worst case\n * (not read-only, destructive, not idempotent, open world), so no tool leaves one out.\n */\nexport type ToolHints = {\n /** The tool changes nothing. */\n readOnlyHint: boolean;\n /** The tool may replace or discard existing data or work, not only add to it. */\n destructiveHint: boolean;\n /** Calling the tool again with the same arguments changes nothing further. */\n idempotentHint: boolean;\n /** The tool reaches beyond the application and the backend it is connected to. */\n openWorldHint: boolean;\n};\n\n/** The hint sets tools choose from. A tool that fits none spreads the nearest one and overrides. */\nexport const hints = {\n /** Reads state; safe to call in parallel and to repeat. */\n read: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n },\n /** Adds something or starts something; a second call does it again. Loses nothing. */\n additive: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: false,\n openWorldHint: false,\n },\n /** Puts the application into a state; a second call changes nothing. Loses nothing. */\n idempotent: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n },\n /** Replaces or discards data, configuration or running work; a second call changes nothing more. */\n destructive: {\n readOnlyHint: false,\n destructiveHint: true,\n idempotentHint: true,\n openWorldHint: false,\n },\n /** Acts on the application window or runs given code: the effect depends on what it hits. */\n unpredictable: {\n readOnlyHint: false,\n destructiveHint: true,\n idempotentHint: false,\n openWorldHint: false,\n },\n} as const satisfies Record<string, ToolHints>;\n\nexport function textResult(data: unknown) {\n return {\n content: [{ type: \"text\" as const, text: JSON.stringify(data) }],\n };\n}\n\n/** Return an MCP error result with an actionable hint for the AI agent. */\nexport function errorResult(message: string, hint?: string) {\n const text = hint ? `${message}\\n\\nHint: ${hint}` : message;\n return {\n content: [{ type: \"text\" as const, text }],\n isError: true,\n };\n}\n"],"mappings":";;;;;AA6BA,SAAgB,mBAAmB,UAAsC;CACvE,IAAI,eAAe;CACnB,cAAc;EAAE;EAAU,cAAc,EAAE;CAAa;AACzD;;AAkBA,MAAa,QAAQ;;CAEnB,MAAM;EACJ,cAAc;EACd,iBAAiB;EACjB,gBAAgB;EAChB,eAAe;CACjB;;CAEA,UAAU;EACR,cAAc;EACd,iBAAiB;EACjB,gBAAgB;EAChB,eAAe;CACjB;;CAEA,YAAY;EACV,cAAc;EACd,iBAAiB;EACjB,gBAAgB;EAChB,eAAe;CACjB;;CAEA,aAAa;EACX,cAAc;EACd,iBAAiB;EACjB,gBAAgB;EAChB,eAAe;CACjB;;CAEA,eAAe;EACb,cAAc;EACd,iBAAiB;EACjB,gBAAgB;EAChB,eAAe;CACjB;AACF;AAEA,SAAgB,WAAW,MAAe;CACxC,OAAO,EACL,SAAS,CAAC;EAAE,MAAM;EAAiB,MAAM,KAAK,UAAU,IAAI;CAAE,CAAC,EACjE;AACF;;AAGA,SAAgB,YAAY,SAAiB,MAAe;CAE1D,OAAO;EACL,SAAS,CAAC;GAAE,MAAM;GAAiB,MAFxB,OAAO,GAAG,QAAQ,YAAY,SAAS;EAEV,CAAC;EACzC,SAAS;CACX;AACF"}
1
+ {"version":3,"file":"types.cjs","names":[],"sources":["../../src/tools/types.ts"],"sourcesContent":["import type {\n AuthorMarker,\n MiddleLayer,\n Project,\n ProjectHolder,\n ProjectId,\n ProjectListEntry,\n} from \"@milaboratories/pl-middle-layer\";\nimport type {\n Icon,\n RegisteredTool,\n ScopeChallengeHandler,\n StandardSchemaWithJSON,\n ToolAnnotations,\n ToolCallback,\n} from \"@modelcontextprotocol/server\";\nimport type { McpInstanceId, PlMcpServerCallbacks } from \"../server\";\n\nexport type { AuthorMarker };\n\nexport interface ToolContext {\n getMl: () => MiddleLayer | null;\n requireMl: () => MiddleLayer;\n resolveProject: (projectId: ProjectId) => Promise<ProjectListEntry>;\n /**\n * Runs `fn` on the project, loading it when it is not loaded. The server holds the project\n * while `fn` runs, so neither the application nor anyone else can unload it under the call.\n */\n withProject: <T>(projectId: ProjectId, fn: (project: Project) => Promise<T>) => Promise<T>;\n /** The holder of this server's holds, as the middle layer's `projectHolders` lists them. */\n projectHolder: ProjectHolder;\n callbacks: PlMcpServerCallbacks;\n /**\n * Returns the marker for the next write made through MCP. All writes of one server instance carry\n * the same `authorId`, whichever client asked for them, and a `localVersion` that grows with\n * every call.\n */\n getAuthorMarker: () => AuthorMarker;\n}\n\n/**\n * What a tool is registered with: the `registerTool` of an `McpServer`, in its form that takes\n * schemas. The `register*Tools` functions get this and not the server, so that every tool they\n * register goes through whatever the server put around the registration (the call log).\n */\nexport interface ToolRegistrar {\n registerTool<\n OutputArgs extends StandardSchemaWithJSON,\n InputArgs extends StandardSchemaWithJSON | undefined = undefined,\n >(\n name: string,\n config: {\n title?: string;\n description?: string;\n inputSchema?: InputArgs;\n outputSchema?: OutputArgs;\n annotations?: ToolAnnotations;\n icons?: Icon[];\n scopeChallenge?: ScopeChallengeHandler;\n _meta?: Record<string, unknown>;\n },\n cb: ToolCallback<InputArgs>,\n ): RegisteredTool;\n}\n\n/**\n * Makes the author markers of one writer: every call returns a marker with `authorId` and the next\n * `localVersion`, counted from 1.\n */\nexport function authorMarkerSource(authorId: McpInstanceId): () => AuthorMarker {\n let localVersion = 0;\n return () => ({ authorId, localVersion: ++localVersion });\n}\n\n/**\n * The four behaviour hints of a tool, all stated. A client reads a missing hint as the worst case\n * (not read-only, destructive, not idempotent, open world), so no tool leaves one out.\n */\nexport type ToolHints = {\n /** The tool changes nothing. */\n readOnlyHint: boolean;\n /** The tool may replace or discard existing data or work, not only add to it. */\n destructiveHint: boolean;\n /** Calling the tool again with the same arguments changes nothing further. */\n idempotentHint: boolean;\n /** The tool reaches beyond the application and the backend it is connected to. */\n openWorldHint: boolean;\n};\n\n/** The hint sets tools choose from. A tool that fits none spreads the nearest one and overrides. */\nexport const hints = {\n /** Reads state; safe to call in parallel and to repeat. */\n read: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n },\n /** Adds something or starts something; a second call does it again. Loses nothing. */\n additive: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: false,\n openWorldHint: false,\n },\n /** Puts the application into a state; a second call changes nothing. Loses nothing. */\n idempotent: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n },\n /** Replaces or discards data, configuration or running work; a second call changes nothing more. */\n destructive: {\n readOnlyHint: false,\n destructiveHint: true,\n idempotentHint: true,\n openWorldHint: false,\n },\n /** Acts on the application window or runs given code: the effect depends on what it hits. */\n unpredictable: {\n readOnlyHint: false,\n destructiveHint: true,\n idempotentHint: false,\n openWorldHint: false,\n },\n} as const satisfies Record<string, ToolHints>;\n\nexport function textResult(data: unknown) {\n return {\n content: [{ type: \"text\" as const, text: JSON.stringify(data) }],\n };\n}\n\n/** Return an MCP error result with an actionable hint for the AI agent. */\nexport function errorResult(message: string, hint?: string) {\n const text = hint ? `${message}\\n\\nHint: ${hint}` : message;\n return {\n content: [{ type: \"text\" as const, text }],\n isError: true,\n };\n}\n\n/** The results made by {@link timedOutResult}. */\nconst timedOutResults = new WeakSet<object>();\n\n/**\n * Returns the result of a tool that waited for something and ran out of time: the JSON of `data`\n * with `timedOut: true` in front. It is not an error result, the caller is expected to wait again.\n * The server's log recognises such a result with {@link isTimedOutResult}.\n */\nexport function timedOutResult(data: Record<string, unknown>) {\n const result = textResult({ timedOut: true, ...data });\n timedOutResults.add(result);\n return result;\n}\n\n/** Whether `result` was made by {@link timedOutResult}. */\nexport function isTimedOutResult(result: unknown): boolean {\n return typeof result === \"object\" && result !== null && timedOutResults.has(result);\n}\n\n/**\n * Returns the error result of a tool whose `transform` failed: `Transform failed: ` and the whole\n * error, then `hint`. The agent needs the whole error to fix its expression.\n */\nexport function transformFailedResult(error: unknown, hint: string) {\n return errorResult(\n `Transform failed: ${error instanceof Error ? error.message : String(error)}`,\n hint,\n );\n}\n"],"mappings":";;;;;AAqEA,SAAgB,mBAAmB,UAA6C;CAC9E,IAAI,eAAe;CACnB,cAAc;EAAE;EAAU,cAAc,EAAE;CAAa;AACzD;;AAkBA,MAAa,QAAQ;;CAEnB,MAAM;EACJ,cAAc;EACd,iBAAiB;EACjB,gBAAgB;EAChB,eAAe;CACjB;;CAEA,UAAU;EACR,cAAc;EACd,iBAAiB;EACjB,gBAAgB;EAChB,eAAe;CACjB;;CAEA,YAAY;EACV,cAAc;EACd,iBAAiB;EACjB,gBAAgB;EAChB,eAAe;CACjB;;CAEA,aAAa;EACX,cAAc;EACd,iBAAiB;EACjB,gBAAgB;EAChB,eAAe;CACjB;;CAEA,eAAe;EACb,cAAc;EACd,iBAAiB;EACjB,gBAAgB;EAChB,eAAe;CACjB;AACF;AAEA,SAAgB,WAAW,MAAe;CACxC,OAAO,EACL,SAAS,CAAC;EAAE,MAAM;EAAiB,MAAM,KAAK,UAAU,IAAI;CAAE,CAAC,EACjE;AACF;;AAGA,SAAgB,YAAY,SAAiB,MAAe;CAE1D,OAAO;EACL,SAAS,CAAC;GAAE,MAAM;GAAiB,MAFxB,OAAO,GAAG,QAAQ,YAAY,SAAS;EAEV,CAAC;EACzC,SAAS;CACX;AACF;;AAGA,MAAM,kCAAkB,IAAI,QAAgB;;;;;;AAO5C,SAAgB,eAAe,MAA+B;CAC5D,MAAM,SAAS,WAAW;EAAE,UAAU;EAAM,GAAG;CAAK,CAAC;CACrD,gBAAgB,IAAI,MAAM;CAC1B,OAAO;AACT;;AAGA,SAAgB,iBAAiB,QAA0B;CACzD,OAAO,OAAO,WAAW,YAAY,WAAW,QAAQ,gBAAgB,IAAI,MAAM;AACpF;;;;;AAMA,SAAgB,sBAAsB,OAAgB,MAAc;CAClE,OAAO,YACL,qBAAqB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,KAC1E,IACF;AACF"}
@@ -64,6 +64,32 @@ function errorResult(message, hint) {
64
64
  isError: true
65
65
  };
66
66
  }
67
- export { authorMarkerSource, errorResult, hints, textResult };
67
+ /** The results made by {@link timedOutResult}. */
68
+ const timedOutResults = /* @__PURE__ */ new WeakSet();
69
+ /**
70
+ * Returns the result of a tool that waited for something and ran out of time: the JSON of `data`
71
+ * with `timedOut: true` in front. It is not an error result, the caller is expected to wait again.
72
+ * The server's log recognises such a result with {@link isTimedOutResult}.
73
+ */
74
+ function timedOutResult(data) {
75
+ const result = textResult({
76
+ timedOut: true,
77
+ ...data
78
+ });
79
+ timedOutResults.add(result);
80
+ return result;
81
+ }
82
+ /** Whether `result` was made by {@link timedOutResult}. */
83
+ function isTimedOutResult(result) {
84
+ return typeof result === "object" && result !== null && timedOutResults.has(result);
85
+ }
86
+ /**
87
+ * Returns the error result of a tool whose `transform` failed: `Transform failed: ` and the whole
88
+ * error, then `hint`. The agent needs the whole error to fix its expression.
89
+ */
90
+ function transformFailedResult(error, hint) {
91
+ return errorResult(`Transform failed: ${error instanceof Error ? error.message : String(error)}`, hint);
92
+ }
93
+ export { authorMarkerSource, errorResult, hints, isTimedOutResult, textResult, timedOutResult, transformFailedResult };
68
94
 
69
95
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":[],"sources":["../../src/tools/types.ts"],"sourcesContent":["import type {\n AuthorMarker,\n MiddleLayer,\n Project,\n ProjectId,\n ProjectListEntry,\n} from \"@milaboratories/pl-middle-layer\";\nimport type { PlMcpServerCallbacks } from \"../server\";\n\nexport type { AuthorMarker };\n\nexport interface ToolContext {\n getMl: () => MiddleLayer | null;\n requireMl: () => MiddleLayer;\n resolveProject: (projectId: ProjectId) => Promise<ProjectListEntry>;\n getOpenedProject: (projectId: ProjectId) => Promise<Project>;\n callbacks: PlMcpServerCallbacks;\n /**\n * Returns the marker for the next write made through MCP. All writes of one server instance carry\n * the same `authorId`, whichever client asked for them, and a `localVersion` that grows with\n * every call.\n */\n getAuthorMarker: () => AuthorMarker;\n}\n\n/**\n * Makes the author markers of one writer: every call returns a marker with `authorId` and the next\n * `localVersion`, counted from 1.\n */\nexport function authorMarkerSource(authorId: string): () => AuthorMarker {\n let localVersion = 0;\n return () => ({ authorId, localVersion: ++localVersion });\n}\n\n/**\n * The four behaviour hints of a tool, all stated. A client reads a missing hint as the worst case\n * (not read-only, destructive, not idempotent, open world), so no tool leaves one out.\n */\nexport type ToolHints = {\n /** The tool changes nothing. */\n readOnlyHint: boolean;\n /** The tool may replace or discard existing data or work, not only add to it. */\n destructiveHint: boolean;\n /** Calling the tool again with the same arguments changes nothing further. */\n idempotentHint: boolean;\n /** The tool reaches beyond the application and the backend it is connected to. */\n openWorldHint: boolean;\n};\n\n/** The hint sets tools choose from. A tool that fits none spreads the nearest one and overrides. */\nexport const hints = {\n /** Reads state; safe to call in parallel and to repeat. */\n read: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n },\n /** Adds something or starts something; a second call does it again. Loses nothing. */\n additive: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: false,\n openWorldHint: false,\n },\n /** Puts the application into a state; a second call changes nothing. Loses nothing. */\n idempotent: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n },\n /** Replaces or discards data, configuration or running work; a second call changes nothing more. */\n destructive: {\n readOnlyHint: false,\n destructiveHint: true,\n idempotentHint: true,\n openWorldHint: false,\n },\n /** Acts on the application window or runs given code: the effect depends on what it hits. */\n unpredictable: {\n readOnlyHint: false,\n destructiveHint: true,\n idempotentHint: false,\n openWorldHint: false,\n },\n} as const satisfies Record<string, ToolHints>;\n\nexport function textResult(data: unknown) {\n return {\n content: [{ type: \"text\" as const, text: JSON.stringify(data) }],\n };\n}\n\n/** Return an MCP error result with an actionable hint for the AI agent. */\nexport function errorResult(message: string, hint?: string) {\n const text = hint ? `${message}\\n\\nHint: ${hint}` : message;\n return {\n content: [{ type: \"text\" as const, text }],\n isError: true,\n };\n}\n"],"mappings":";;;;;AA6BA,SAAgB,mBAAmB,UAAsC;CACvE,IAAI,eAAe;CACnB,cAAc;EAAE;EAAU,cAAc,EAAE;CAAa;AACzD;;AAkBA,MAAa,QAAQ;;CAEnB,MAAM;EACJ,cAAc;EACd,iBAAiB;EACjB,gBAAgB;EAChB,eAAe;CACjB;;CAEA,UAAU;EACR,cAAc;EACd,iBAAiB;EACjB,gBAAgB;EAChB,eAAe;CACjB;;CAEA,YAAY;EACV,cAAc;EACd,iBAAiB;EACjB,gBAAgB;EAChB,eAAe;CACjB;;CAEA,aAAa;EACX,cAAc;EACd,iBAAiB;EACjB,gBAAgB;EAChB,eAAe;CACjB;;CAEA,eAAe;EACb,cAAc;EACd,iBAAiB;EACjB,gBAAgB;EAChB,eAAe;CACjB;AACF;AAEA,SAAgB,WAAW,MAAe;CACxC,OAAO,EACL,SAAS,CAAC;EAAE,MAAM;EAAiB,MAAM,KAAK,UAAU,IAAI;CAAE,CAAC,EACjE;AACF;;AAGA,SAAgB,YAAY,SAAiB,MAAe;CAE1D,OAAO;EACL,SAAS,CAAC;GAAE,MAAM;GAAiB,MAFxB,OAAO,GAAG,QAAQ,YAAY,SAAS;EAEV,CAAC;EACzC,SAAS;CACX;AACF"}
1
+ {"version":3,"file":"types.js","names":[],"sources":["../../src/tools/types.ts"],"sourcesContent":["import type {\n AuthorMarker,\n MiddleLayer,\n Project,\n ProjectHolder,\n ProjectId,\n ProjectListEntry,\n} from \"@milaboratories/pl-middle-layer\";\nimport type {\n Icon,\n RegisteredTool,\n ScopeChallengeHandler,\n StandardSchemaWithJSON,\n ToolAnnotations,\n ToolCallback,\n} from \"@modelcontextprotocol/server\";\nimport type { McpInstanceId, PlMcpServerCallbacks } from \"../server\";\n\nexport type { AuthorMarker };\n\nexport interface ToolContext {\n getMl: () => MiddleLayer | null;\n requireMl: () => MiddleLayer;\n resolveProject: (projectId: ProjectId) => Promise<ProjectListEntry>;\n /**\n * Runs `fn` on the project, loading it when it is not loaded. The server holds the project\n * while `fn` runs, so neither the application nor anyone else can unload it under the call.\n */\n withProject: <T>(projectId: ProjectId, fn: (project: Project) => Promise<T>) => Promise<T>;\n /** The holder of this server's holds, as the middle layer's `projectHolders` lists them. */\n projectHolder: ProjectHolder;\n callbacks: PlMcpServerCallbacks;\n /**\n * Returns the marker for the next write made through MCP. All writes of one server instance carry\n * the same `authorId`, whichever client asked for them, and a `localVersion` that grows with\n * every call.\n */\n getAuthorMarker: () => AuthorMarker;\n}\n\n/**\n * What a tool is registered with: the `registerTool` of an `McpServer`, in its form that takes\n * schemas. The `register*Tools` functions get this and not the server, so that every tool they\n * register goes through whatever the server put around the registration (the call log).\n */\nexport interface ToolRegistrar {\n registerTool<\n OutputArgs extends StandardSchemaWithJSON,\n InputArgs extends StandardSchemaWithJSON | undefined = undefined,\n >(\n name: string,\n config: {\n title?: string;\n description?: string;\n inputSchema?: InputArgs;\n outputSchema?: OutputArgs;\n annotations?: ToolAnnotations;\n icons?: Icon[];\n scopeChallenge?: ScopeChallengeHandler;\n _meta?: Record<string, unknown>;\n },\n cb: ToolCallback<InputArgs>,\n ): RegisteredTool;\n}\n\n/**\n * Makes the author markers of one writer: every call returns a marker with `authorId` and the next\n * `localVersion`, counted from 1.\n */\nexport function authorMarkerSource(authorId: McpInstanceId): () => AuthorMarker {\n let localVersion = 0;\n return () => ({ authorId, localVersion: ++localVersion });\n}\n\n/**\n * The four behaviour hints of a tool, all stated. A client reads a missing hint as the worst case\n * (not read-only, destructive, not idempotent, open world), so no tool leaves one out.\n */\nexport type ToolHints = {\n /** The tool changes nothing. */\n readOnlyHint: boolean;\n /** The tool may replace or discard existing data or work, not only add to it. */\n destructiveHint: boolean;\n /** Calling the tool again with the same arguments changes nothing further. */\n idempotentHint: boolean;\n /** The tool reaches beyond the application and the backend it is connected to. */\n openWorldHint: boolean;\n};\n\n/** The hint sets tools choose from. A tool that fits none spreads the nearest one and overrides. */\nexport const hints = {\n /** Reads state; safe to call in parallel and to repeat. */\n read: {\n readOnlyHint: true,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n },\n /** Adds something or starts something; a second call does it again. Loses nothing. */\n additive: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: false,\n openWorldHint: false,\n },\n /** Puts the application into a state; a second call changes nothing. Loses nothing. */\n idempotent: {\n readOnlyHint: false,\n destructiveHint: false,\n idempotentHint: true,\n openWorldHint: false,\n },\n /** Replaces or discards data, configuration or running work; a second call changes nothing more. */\n destructive: {\n readOnlyHint: false,\n destructiveHint: true,\n idempotentHint: true,\n openWorldHint: false,\n },\n /** Acts on the application window or runs given code: the effect depends on what it hits. */\n unpredictable: {\n readOnlyHint: false,\n destructiveHint: true,\n idempotentHint: false,\n openWorldHint: false,\n },\n} as const satisfies Record<string, ToolHints>;\n\nexport function textResult(data: unknown) {\n return {\n content: [{ type: \"text\" as const, text: JSON.stringify(data) }],\n };\n}\n\n/** Return an MCP error result with an actionable hint for the AI agent. */\nexport function errorResult(message: string, hint?: string) {\n const text = hint ? `${message}\\n\\nHint: ${hint}` : message;\n return {\n content: [{ type: \"text\" as const, text }],\n isError: true,\n };\n}\n\n/** The results made by {@link timedOutResult}. */\nconst timedOutResults = new WeakSet<object>();\n\n/**\n * Returns the result of a tool that waited for something and ran out of time: the JSON of `data`\n * with `timedOut: true` in front. It is not an error result, the caller is expected to wait again.\n * The server's log recognises such a result with {@link isTimedOutResult}.\n */\nexport function timedOutResult(data: Record<string, unknown>) {\n const result = textResult({ timedOut: true, ...data });\n timedOutResults.add(result);\n return result;\n}\n\n/** Whether `result` was made by {@link timedOutResult}. */\nexport function isTimedOutResult(result: unknown): boolean {\n return typeof result === \"object\" && result !== null && timedOutResults.has(result);\n}\n\n/**\n * Returns the error result of a tool whose `transform` failed: `Transform failed: ` and the whole\n * error, then `hint`. The agent needs the whole error to fix its expression.\n */\nexport function transformFailedResult(error: unknown, hint: string) {\n return errorResult(\n `Transform failed: ${error instanceof Error ? error.message : String(error)}`,\n hint,\n );\n}\n"],"mappings":";;;;;AAqEA,SAAgB,mBAAmB,UAA6C;CAC9E,IAAI,eAAe;CACnB,cAAc;EAAE;EAAU,cAAc,EAAE;CAAa;AACzD;;AAkBA,MAAa,QAAQ;;CAEnB,MAAM;EACJ,cAAc;EACd,iBAAiB;EACjB,gBAAgB;EAChB,eAAe;CACjB;;CAEA,UAAU;EACR,cAAc;EACd,iBAAiB;EACjB,gBAAgB;EAChB,eAAe;CACjB;;CAEA,YAAY;EACV,cAAc;EACd,iBAAiB;EACjB,gBAAgB;EAChB,eAAe;CACjB;;CAEA,aAAa;EACX,cAAc;EACd,iBAAiB;EACjB,gBAAgB;EAChB,eAAe;CACjB;;CAEA,eAAe;EACb,cAAc;EACd,iBAAiB;EACjB,gBAAgB;EAChB,eAAe;CACjB;AACF;AAEA,SAAgB,WAAW,MAAe;CACxC,OAAO,EACL,SAAS,CAAC;EAAE,MAAM;EAAiB,MAAM,KAAK,UAAU,IAAI;CAAE,CAAC,EACjE;AACF;;AAGA,SAAgB,YAAY,SAAiB,MAAe;CAE1D,OAAO;EACL,SAAS,CAAC;GAAE,MAAM;GAAiB,MAFxB,OAAO,GAAG,QAAQ,YAAY,SAAS;EAEV,CAAC;EACzC,SAAS;CACX;AACF;;AAGA,MAAM,kCAAkB,IAAI,QAAgB;;;;;;AAO5C,SAAgB,eAAe,MAA+B;CAC5D,MAAM,SAAS,WAAW;EAAE,UAAU;EAAM,GAAG;CAAK,CAAC;CACrD,gBAAgB,IAAI,MAAM;CAC1B,OAAO;AACT;;AAGA,SAAgB,iBAAiB,QAA0B;CACzD,OAAO,OAAO,WAAW,YAAY,WAAW,QAAQ,gBAAgB,IAAI,MAAM;AACpF;;;;;AAMA,SAAgB,sBAAsB,OAAgB,MAAc;CAClE,OAAO,YACL,qBAAqB,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK,KAC1E,IACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"ui-interaction.cjs","names":["hints","z","errorResult","textResult","projectIdInput","blockIdInput"],"sources":["../../src/tools/ui-interaction.ts"],"sourcesContent":["import type { McpServer } from \"@modelcontextprotocol/server\";\nimport { z } from \"zod\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport type { ToolContext } from \"./types\";\nimport { errorResult, hints, textResult } from \"./types\";\n\nexport function registerUIInteractionTools(server: McpServer, ctx: ToolContext): void {\n server.registerTool(\n \"click\",\n {\n title: \"Click in the Application Window\",\n annotations: hints.unpredictable,\n description:\n \"Click at coordinates (x, y) in the application window. Use capture_screenshot to find element positions.\",\n inputSchema: z.object({\n x: z.number().describe(\"X coordinate\"),\n y: z.number().describe(\"Y coordinate\"),\n doubleClick: z.boolean().optional().describe(\"Double click\"),\n }),\n },\n async ({ x, y, doubleClick }) => {\n if (!ctx.callbacks.sendInputEvent) {\n return errorResult(\n \"UI interaction is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n const clickCount = doubleClick ? 2 : 1;\n await ctx.callbacks.sendInputEvent({\n type: \"mouseDown\",\n x,\n y,\n button: \"left\",\n clickCount,\n });\n await ctx.callbacks.sendInputEvent({ type: \"mouseUp\", x, y, button: \"left\", clickCount });\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"type_text\",\n {\n title: \"Type Text\",\n annotations: hints.unpredictable,\n description:\n \"Type text into the element that has focus in the application window. UI tool: not needed to configure blocks.\",\n inputSchema: z.object({\n text: z.string().describe(\"Text to type\"),\n }),\n },\n async ({ text }) => {\n if (!ctx.callbacks.sendInputEvent) {\n return errorResult(\n \"UI interaction is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n for (const char of text) {\n await ctx.callbacks.sendInputEvent({ type: \"keyDown\", keyCode: char });\n await ctx.callbacks.sendInputEvent({ type: \"char\", keyCode: char });\n await ctx.callbacks.sendInputEvent({ type: \"keyUp\", keyCode: char });\n }\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"press_key\",\n {\n title: \"Press Key\",\n annotations: hints.unpredictable,\n description: \"Press a keyboard key (Enter, Tab, Escape, Backspace, ArrowDown, ArrowUp, etc.)\",\n inputSchema: z.object({\n key: z\n .string()\n .describe(\"Key name (e.g. 'Enter', 'Tab', 'Escape', 'Backspace', 'ArrowDown')\"),\n modifiers: z\n .array(z.enum([\"shift\", \"control\", \"alt\", \"meta\"]))\n .optional()\n .describe(\"Modifier keys to hold\"),\n }),\n },\n async ({ key, modifiers }) => {\n if (!ctx.callbacks.sendInputEvent) {\n return errorResult(\n \"UI interaction is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n await ctx.callbacks.sendInputEvent({\n type: \"keyDown\",\n keyCode: key,\n ...(modifiers && {\n shift: modifiers.includes(\"shift\"),\n control: modifiers.includes(\"control\"),\n alt: modifiers.includes(\"alt\"),\n meta: modifiers.includes(\"meta\"),\n }),\n });\n await ctx.callbacks.sendInputEvent({\n type: \"keyUp\",\n keyCode: key,\n ...(modifiers && {\n shift: modifiers.includes(\"shift\"),\n control: modifiers.includes(\"control\"),\n alt: modifiers.includes(\"alt\"),\n meta: modifiers.includes(\"meta\"),\n }),\n });\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"scroll\",\n {\n title: \"Scroll\",\n annotations: hints.additive,\n description:\n \"Scroll the application window at a given position. UI tool: not needed to configure blocks.\",\n inputSchema: z.object({\n x: z.number().describe(\"X coordinate to scroll at\"),\n y: z.number().describe(\"Y coordinate to scroll at\"),\n deltaX: z.number().optional().default(0).describe(\"Horizontal scroll amount\"),\n deltaY: z.number().describe(\"Vertical scroll amount (negative = up, positive = down)\"),\n }),\n },\n async ({ x, y, deltaX, deltaY }) => {\n if (!ctx.callbacks.sendInputEvent) {\n return errorResult(\n \"UI interaction is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n await ctx.callbacks.sendInputEvent({\n type: \"mouseWheel\",\n x,\n y,\n deltaX: deltaX ?? 0,\n deltaY,\n });\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"execute_js\",\n {\n title: \"Execute JavaScript\",\n annotations: { ...hints.unpredictable, openWorldHint: true },\n description:\n \"Execute JavaScript in a renderer and return the result. By default runs in the topmost webContents (main app / topmost modal). Pass projectId + blockId to run inside that block's webview, where `window.platforma` is exposed and the driverKit (e.g. `window.platforma.lsDriver.getLocalFileHandle`) is callable. The block must already be open — call `select_block` first if needed.\",\n inputSchema: z.object({\n code: z.string().describe(\"JavaScript code to execute\"),\n projectId: projectIdInput\n .optional()\n .describe(\"Target project ID. Must be paired with blockId.\"),\n blockId: blockIdInput\n .optional()\n .describe(\n \"Target block ID. When provided with projectId, JS runs in that block's webview (where `window.platforma` is available).\",\n ),\n }),\n },\n async ({ code, projectId, blockId }) => {\n if (!ctx.callbacks.executeJavaScript) {\n return errorResult(\n \"JS execution is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n if ((projectId === undefined) !== (blockId === undefined)) {\n return errorResult(\n \"projectId and blockId must be provided together.\",\n \"Either pass both to target a specific block's webview, or pass neither to run in the topmost webContents.\",\n );\n }\n const target =\n projectId !== undefined && blockId !== undefined ? { projectId, blockId } : undefined;\n const result = await ctx.callbacks.executeJavaScript(code, target);\n return textResult(result);\n },\n );\n}\n"],"mappings":";;;;AAMA,SAAgB,2BAA2B,QAAmB,KAAwB;CACpF,OAAO,aACL,SACA;EACE,OAAO;EACP,aAAaA,cAAAA,MAAM;EACnB,aACE;EACF,aAAaC,IAAAA,EAAE,OAAO;GACpB,GAAGA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,cAAc;GACrC,GAAGA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,cAAc;GACrC,aAAaA,IAAAA,EAAE,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,cAAc;EAC7D,CAAC;CACH,GACA,OAAO,EAAE,GAAG,GAAG,kBAAkB;EAC/B,IAAI,CAAC,IAAI,UAAU,gBACjB,OAAOC,cAAAA,YACL,oCACA,qJACF;EAEF,MAAM,aAAa,cAAc,IAAI;EACrC,MAAM,IAAI,UAAU,eAAe;GACjC,MAAM;GACN;GAC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AA4B;GACtD,WAAWG,YAAAA,eACR,SAAS,CAAC,CACV,SAAS,iDAAiD;GAC7D,SAASC,YAAAA,aACN,SAAS,CAAC,CACV,SACC,yHACF;EACJ,CAAC;CACH,GACA,OAAO,EAAE,MAAM,WAAW,cAAc;EACtC,IAAI,CAAC,IAAI,UAAU,mBACjB,OAAOH,cAAAA,YACL,kCACA,qJACF;EAEF,IAAK,cAAc,KAAA,OAAgB,YAAY,KAAA,IAC7C,OAAOA,cAAAA,YACL,oDACA,2GACF;EAEF,MAAM,SACJ,cAAc,KAAA,KAAa,YAAY,KAAA,IAAY;GAAE;GAAW;EAAQ,IAAI,KAAA;EAC9E,MAAM,SAAS,MAAM,IAAI,UAAU,kBAAkB,MAAM,MAAM;EACjE,OAAOC,cAAAA,WAAW,MAAM;CAC1B,CACF;AACF"}
1
+ {"version":3,"file":"ui-interaction.cjs","names":["hints","z","errorResult","textResult","projectIdInput","blockIdInput"],"sources":["../../src/tools/ui-interaction.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport type { ToolContext, ToolRegistrar } from \"./types\";\nimport { errorResult, hints, textResult } from \"./types\";\n\nexport function registerUIInteractionTools(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"click\",\n {\n title: \"Click in the Application Window\",\n annotations: hints.unpredictable,\n description:\n \"Click at coordinates (x, y) in the application window. Use capture_screenshot to find element positions.\",\n inputSchema: z.object({\n x: z.number().describe(\"X coordinate\"),\n y: z.number().describe(\"Y coordinate\"),\n doubleClick: z.boolean().optional().describe(\"Double click\"),\n }),\n },\n async ({ x, y, doubleClick }) => {\n if (!ctx.callbacks.sendInputEvent) {\n return errorResult(\n \"UI interaction is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n const clickCount = doubleClick ? 2 : 1;\n await ctx.callbacks.sendInputEvent({\n type: \"mouseDown\",\n x,\n y,\n button: \"left\",\n clickCount,\n });\n await ctx.callbacks.sendInputEvent({ type: \"mouseUp\", x, y, button: \"left\", clickCount });\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"type_text\",\n {\n title: \"Type Text\",\n annotations: hints.unpredictable,\n description:\n \"Type text into the element that has focus in the application window. UI tool: not needed to configure blocks.\",\n inputSchema: z.object({\n text: z.string().describe(\"Text to type\"),\n }),\n },\n async ({ text }) => {\n if (!ctx.callbacks.sendInputEvent) {\n return errorResult(\n \"UI interaction is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n for (const char of text) {\n await ctx.callbacks.sendInputEvent({ type: \"keyDown\", keyCode: char });\n await ctx.callbacks.sendInputEvent({ type: \"char\", keyCode: char });\n await ctx.callbacks.sendInputEvent({ type: \"keyUp\", keyCode: char });\n }\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"press_key\",\n {\n title: \"Press Key\",\n annotations: hints.unpredictable,\n description: \"Press a keyboard key (Enter, Tab, Escape, Backspace, ArrowDown, ArrowUp, etc.)\",\n inputSchema: z.object({\n key: z\n .string()\n .describe(\"Key name (e.g. 'Enter', 'Tab', 'Escape', 'Backspace', 'ArrowDown')\"),\n modifiers: z\n .array(z.enum([\"shift\", \"control\", \"alt\", \"meta\"]))\n .optional()\n .describe(\"Modifier keys to hold\"),\n }),\n },\n async ({ key, modifiers }) => {\n if (!ctx.callbacks.sendInputEvent) {\n return errorResult(\n \"UI interaction is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n await ctx.callbacks.sendInputEvent({\n type: \"keyDown\",\n keyCode: key,\n ...(modifiers && {\n shift: modifiers.includes(\"shift\"),\n control: modifiers.includes(\"control\"),\n alt: modifiers.includes(\"alt\"),\n meta: modifiers.includes(\"meta\"),\n }),\n });\n await ctx.callbacks.sendInputEvent({\n type: \"keyUp\",\n keyCode: key,\n ...(modifiers && {\n shift: modifiers.includes(\"shift\"),\n control: modifiers.includes(\"control\"),\n alt: modifiers.includes(\"alt\"),\n meta: modifiers.includes(\"meta\"),\n }),\n });\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"scroll\",\n {\n title: \"Scroll\",\n annotations: hints.additive,\n description:\n \"Scroll the application window at a given position. UI tool: not needed to configure blocks.\",\n inputSchema: z.object({\n x: z.number().describe(\"X coordinate to scroll at\"),\n y: z.number().describe(\"Y coordinate to scroll at\"),\n deltaX: z.number().optional().default(0).describe(\"Horizontal scroll amount\"),\n deltaY: z.number().describe(\"Vertical scroll amount (negative = up, positive = down)\"),\n }),\n },\n async ({ x, y, deltaX, deltaY }) => {\n if (!ctx.callbacks.sendInputEvent) {\n return errorResult(\n \"UI interaction is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n await ctx.callbacks.sendInputEvent({\n type: \"mouseWheel\",\n x,\n y,\n deltaX: deltaX ?? 0,\n deltaY,\n });\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"execute_js\",\n {\n title: \"Execute JavaScript\",\n annotations: { ...hints.unpredictable, openWorldHint: true },\n description:\n \"Execute JavaScript in a renderer and return the result. By default runs in the topmost webContents (main app / topmost modal). Pass projectId + blockId to run inside that block's webview, where `window.platforma` is exposed and the driverKit (e.g. `window.platforma.lsDriver.getLocalFileHandle`) is callable. The block must already be open — call `select_block` first if needed.\",\n inputSchema: z.object({\n code: z.string().describe(\"JavaScript code to execute\"),\n projectId: projectIdInput\n .optional()\n .describe(\"Target project ID. Must be paired with blockId.\"),\n blockId: blockIdInput\n .optional()\n .describe(\n \"Target block ID. When provided with projectId, JS runs in that block's webview (where `window.platforma` is available).\",\n ),\n }),\n },\n async ({ code, projectId, blockId }) => {\n if (!ctx.callbacks.executeJavaScript) {\n return errorResult(\n \"JS execution is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n if ((projectId === undefined) !== (blockId === undefined)) {\n return errorResult(\n \"projectId and blockId must be provided together.\",\n \"Either pass both to target a specific block's webview, or pass neither to run in the topmost webContents.\",\n );\n }\n const target =\n projectId !== undefined && blockId !== undefined ? { projectId, blockId } : undefined;\n const result = await ctx.callbacks.executeJavaScript(code, target);\n return textResult(result);\n },\n );\n}\n"],"mappings":";;;;AAKA,SAAgB,2BAA2B,QAAuB,KAAwB;CACxF,OAAO,aACL,SACA;EACE,OAAO;EACP,aAAaA,cAAAA,MAAM;EACnB,aACE;EACF,aAAaC,IAAAA,EAAE,OAAO;GACpB,GAAGA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,cAAc;GACrC,GAAGA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,cAAc;GACrC,aAAaA,IAAAA,EAAE,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,cAAc;EAC7D,CAAC;CACH,GACA,OAAO,EAAE,GAAG,GAAG,kBAAkB;EAC/B,IAAI,CAAC,IAAI,UAAU,gBACjB,OAAOC,cAAAA,YACL,oCACA,qJACF;EAEF,MAAM,aAAa,cAAc,IAAI;EACrC,MAAM,IAAI,UAAU,eAAe;GACjC,MAAM;GACN;GACA;GACA,QAAQ;GACR;EACF,CAAC;EACD,MAAM,IAAI,UAAU,eAAe;GAAE,MAAM;GAAW;GAAG;GAAG,QAAQ;GAAQ;EAAW,CAAC;EACxF,OAAOC,cAAAA,WAAW,EAAE,IAAI,KAAK,CAAC;CAChC,CACF;CAEA,OAAO,aACL,aACA;EACE,OAAO;EACP,aAAaH,cAAAA,MAAM;EACnB,aACE;EACF,aAAaC,IAAAA,EAAE,OAAO,EACpB,MAAMA,IAAAA,EAAE,OAAO,CAAC,CAAC,SAAS,cAAc,EAC1C,CAAC;CACH,GACA,OAAO,EAAE,WAAW;EAClB,IAAI,CAAC,IAAI,UAAU,gBACjB,OAAOC,cAAAA,YACL,oCACA,qJAC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kBAAkB,MAAM,MAAM;EACjE,OAAOC,cAAAA,WAAW,MAAM;CAC1B,CACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"ui-interaction.js","names":[],"sources":["../../src/tools/ui-interaction.ts"],"sourcesContent":["import type { McpServer } from \"@modelcontextprotocol/server\";\nimport { z } from \"zod\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport type { ToolContext } from \"./types\";\nimport { errorResult, hints, textResult } from \"./types\";\n\nexport function registerUIInteractionTools(server: McpServer, ctx: ToolContext): void {\n server.registerTool(\n \"click\",\n {\n title: \"Click in the Application Window\",\n annotations: hints.unpredictable,\n description:\n \"Click at coordinates (x, y) in the application window. Use capture_screenshot to find element positions.\",\n inputSchema: z.object({\n x: z.number().describe(\"X coordinate\"),\n y: z.number().describe(\"Y coordinate\"),\n doubleClick: z.boolean().optional().describe(\"Double click\"),\n }),\n },\n async ({ x, y, doubleClick }) => {\n if (!ctx.callbacks.sendInputEvent) {\n return errorResult(\n \"UI interaction is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n const clickCount = doubleClick ? 2 : 1;\n await ctx.callbacks.sendInputEvent({\n type: \"mouseDown\",\n x,\n y,\n button: \"left\",\n clickCount,\n });\n await ctx.callbacks.sendInputEvent({ type: \"mouseUp\", x, y, button: \"left\", clickCount });\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"type_text\",\n {\n title: \"Type Text\",\n annotations: hints.unpredictable,\n description:\n \"Type text into the element that has focus in the application window. UI tool: not needed to configure blocks.\",\n inputSchema: z.object({\n text: z.string().describe(\"Text to type\"),\n }),\n },\n async ({ text }) => {\n if (!ctx.callbacks.sendInputEvent) {\n return errorResult(\n \"UI interaction is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n for (const char of text) {\n await ctx.callbacks.sendInputEvent({ type: \"keyDown\", keyCode: char });\n await ctx.callbacks.sendInputEvent({ type: \"char\", keyCode: char });\n await ctx.callbacks.sendInputEvent({ type: \"keyUp\", keyCode: char });\n }\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"press_key\",\n {\n title: \"Press Key\",\n annotations: hints.unpredictable,\n description: \"Press a keyboard key (Enter, Tab, Escape, Backspace, ArrowDown, ArrowUp, etc.)\",\n inputSchema: z.object({\n key: z\n .string()\n .describe(\"Key name (e.g. 'Enter', 'Tab', 'Escape', 'Backspace', 'ArrowDown')\"),\n modifiers: z\n .array(z.enum([\"shift\", \"control\", \"alt\", \"meta\"]))\n .optional()\n .describe(\"Modifier keys to hold\"),\n }),\n },\n async ({ key, modifiers }) => {\n if (!ctx.callbacks.sendInputEvent) {\n return errorResult(\n \"UI interaction is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n await ctx.callbacks.sendInputEvent({\n type: \"keyDown\",\n keyCode: key,\n ...(modifiers && {\n shift: modifiers.includes(\"shift\"),\n control: modifiers.includes(\"control\"),\n alt: modifiers.includes(\"alt\"),\n meta: modifiers.includes(\"meta\"),\n }),\n });\n await ctx.callbacks.sendInputEvent({\n type: \"keyUp\",\n keyCode: key,\n ...(modifiers && {\n shift: modifiers.includes(\"shift\"),\n control: modifiers.includes(\"control\"),\n alt: modifiers.includes(\"alt\"),\n meta: modifiers.includes(\"meta\"),\n }),\n });\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"scroll\",\n {\n title: \"Scroll\",\n annotations: hints.additive,\n description:\n \"Scroll the application window at a given position. UI tool: not needed to configure blocks.\",\n inputSchema: z.object({\n x: z.number().describe(\"X coordinate to scroll at\"),\n y: z.number().describe(\"Y coordinate to scroll at\"),\n deltaX: z.number().optional().default(0).describe(\"Horizontal scroll amount\"),\n deltaY: z.number().describe(\"Vertical scroll amount (negative = up, positive = down)\"),\n }),\n },\n async ({ x, y, deltaX, deltaY }) => {\n if (!ctx.callbacks.sendInputEvent) {\n return errorResult(\n \"UI interaction is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n await ctx.callbacks.sendInputEvent({\n type: \"mouseWheel\",\n x,\n y,\n deltaX: deltaX ?? 0,\n deltaY,\n });\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"execute_js\",\n {\n title: \"Execute JavaScript\",\n annotations: { ...hints.unpredictable, openWorldHint: true },\n description:\n \"Execute JavaScript in a renderer and return the result. By default runs in the topmost webContents (main app / topmost modal). Pass projectId + blockId to run inside that block's webview, where `window.platforma` is exposed and the driverKit (e.g. `window.platforma.lsDriver.getLocalFileHandle`) is callable. The block must already be open — call `select_block` first if needed.\",\n inputSchema: z.object({\n code: z.string().describe(\"JavaScript code to execute\"),\n projectId: projectIdInput\n .optional()\n .describe(\"Target project ID. Must be paired with blockId.\"),\n blockId: blockIdInput\n .optional()\n .describe(\n \"Target block ID. When provided with projectId, JS runs in that block's webview (where `window.platforma` is available).\",\n ),\n }),\n },\n async ({ code, projectId, blockId }) => {\n if (!ctx.callbacks.executeJavaScript) {\n return errorResult(\n \"JS execution is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n if ((projectId === undefined) !== (blockId === undefined)) {\n return errorResult(\n \"projectId and blockId must be provided together.\",\n \"Either pass both to target a specific block's webview, or pass neither to run in the topmost webContents.\",\n );\n }\n const target =\n projectId !== undefined && blockId !== undefined ? { projectId, blockId } : undefined;\n const result = await ctx.callbacks.executeJavaScript(code, target);\n return textResult(result);\n },\n );\n}\n"],"mappings":";;;;AAMA,SAAgB,2BAA2B,QAAmB,KAAwB;CACpF,OAAO,aACL,SACA;EACE,OAAO;EACP,aAAa,MAAM;EACnB,aACE;EACF,aAAa,EAAE,OAAO;GACpB,GAAG,EAAE,OAAO,CAAC,CAAC,SAAS,cAAc;GACrC,GAAG,EAA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AAe,eAAe;EAAK;EAC3D,aACE;EACF,aAAa,EAAE,OAAO;GACpB,MAAM,EAAE,OAAO,CAAC,CAAC,SAAS,4BAA4B;GACtD,WAAW,eACR,SAAS,CAAC,CACV,SAAS,iDAAiD;GAC7D,SAAS,aACN,SAAS,CAAC,CACV,SACC,yHACF;EACJ,CAAC;CACH,GACA,OAAO,EAAE,MAAM,WAAW,cAAc;EACtC,IAAI,CAAC,IAAI,UAAU,mBACjB,OAAO,YACL,kCACA,qJACF;EAEF,IAAK,cAAc,KAAA,OAAgB,YAAY,KAAA,IAC7C,OAAO,YACL,oDACA,2GACF;EAEF,MAAM,SACJ,cAAc,KAAA,KAAa,YAAY,KAAA,IAAY;GAAE;GAAW;EAAQ,IAAI,KAAA;EAC9E,MAAM,SAAS,MAAM,IAAI,UAAU,kBAAkB,MAAM,MAAM;EACjE,OAAO,WAAW,MAAM;CAC1B,CACF;AACF"}
1
+ {"version":3,"file":"ui-interaction.js","names":[],"sources":["../../src/tools/ui-interaction.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { projectIdInput, blockIdInput } from \"./ids\";\nimport type { ToolContext, ToolRegistrar } from \"./types\";\nimport { errorResult, hints, textResult } from \"./types\";\n\nexport function registerUIInteractionTools(server: ToolRegistrar, ctx: ToolContext): void {\n server.registerTool(\n \"click\",\n {\n title: \"Click in the Application Window\",\n annotations: hints.unpredictable,\n description:\n \"Click at coordinates (x, y) in the application window. Use capture_screenshot to find element positions.\",\n inputSchema: z.object({\n x: z.number().describe(\"X coordinate\"),\n y: z.number().describe(\"Y coordinate\"),\n doubleClick: z.boolean().optional().describe(\"Double click\"),\n }),\n },\n async ({ x, y, doubleClick }) => {\n if (!ctx.callbacks.sendInputEvent) {\n return errorResult(\n \"UI interaction is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n const clickCount = doubleClick ? 2 : 1;\n await ctx.callbacks.sendInputEvent({\n type: \"mouseDown\",\n x,\n y,\n button: \"left\",\n clickCount,\n });\n await ctx.callbacks.sendInputEvent({ type: \"mouseUp\", x, y, button: \"left\", clickCount });\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"type_text\",\n {\n title: \"Type Text\",\n annotations: hints.unpredictable,\n description:\n \"Type text into the element that has focus in the application window. UI tool: not needed to configure blocks.\",\n inputSchema: z.object({\n text: z.string().describe(\"Text to type\"),\n }),\n },\n async ({ text }) => {\n if (!ctx.callbacks.sendInputEvent) {\n return errorResult(\n \"UI interaction is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n for (const char of text) {\n await ctx.callbacks.sendInputEvent({ type: \"keyDown\", keyCode: char });\n await ctx.callbacks.sendInputEvent({ type: \"char\", keyCode: char });\n await ctx.callbacks.sendInputEvent({ type: \"keyUp\", keyCode: char });\n }\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"press_key\",\n {\n title: \"Press Key\",\n annotations: hints.unpredictable,\n description: \"Press a keyboard key (Enter, Tab, Escape, Backspace, ArrowDown, ArrowUp, etc.)\",\n inputSchema: z.object({\n key: z\n .string()\n .describe(\"Key name (e.g. 'Enter', 'Tab', 'Escape', 'Backspace', 'ArrowDown')\"),\n modifiers: z\n .array(z.enum([\"shift\", \"control\", \"alt\", \"meta\"]))\n .optional()\n .describe(\"Modifier keys to hold\"),\n }),\n },\n async ({ key, modifiers }) => {\n if (!ctx.callbacks.sendInputEvent) {\n return errorResult(\n \"UI interaction is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n await ctx.callbacks.sendInputEvent({\n type: \"keyDown\",\n keyCode: key,\n ...(modifiers && {\n shift: modifiers.includes(\"shift\"),\n control: modifiers.includes(\"control\"),\n alt: modifiers.includes(\"alt\"),\n meta: modifiers.includes(\"meta\"),\n }),\n });\n await ctx.callbacks.sendInputEvent({\n type: \"keyUp\",\n keyCode: key,\n ...(modifiers && {\n shift: modifiers.includes(\"shift\"),\n control: modifiers.includes(\"control\"),\n alt: modifiers.includes(\"alt\"),\n meta: modifiers.includes(\"meta\"),\n }),\n });\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"scroll\",\n {\n title: \"Scroll\",\n annotations: hints.additive,\n description:\n \"Scroll the application window at a given position. UI tool: not needed to configure blocks.\",\n inputSchema: z.object({\n x: z.number().describe(\"X coordinate to scroll at\"),\n y: z.number().describe(\"Y coordinate to scroll at\"),\n deltaX: z.number().optional().default(0).describe(\"Horizontal scroll amount\"),\n deltaY: z.number().describe(\"Vertical scroll amount (negative = up, positive = down)\"),\n }),\n },\n async ({ x, y, deltaX, deltaY }) => {\n if (!ctx.callbacks.sendInputEvent) {\n return errorResult(\n \"UI interaction is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n await ctx.callbacks.sendInputEvent({\n type: \"mouseWheel\",\n x,\n y,\n deltaX: deltaX ?? 0,\n deltaY,\n });\n return textResult({ ok: true });\n },\n );\n\n server.registerTool(\n \"execute_js\",\n {\n title: \"Execute JavaScript\",\n annotations: { ...hints.unpredictable, openWorldHint: true },\n description:\n \"Execute JavaScript in a renderer and return the result. By default runs in the topmost webContents (main app / topmost modal). Pass projectId + blockId to run inside that block's webview, where `window.platforma` is exposed and the driverKit (e.g. `window.platforma.lsDriver.getLocalFileHandle`) is callable. The block must already be open — call `select_block` first if needed.\",\n inputSchema: z.object({\n code: z.string().describe(\"JavaScript code to execute\"),\n projectId: projectIdInput\n .optional()\n .describe(\"Target project ID. Must be paired with blockId.\"),\n blockId: blockIdInput\n .optional()\n .describe(\n \"Target block ID. When provided with projectId, JS runs in that block's webview (where `window.platforma` is available).\",\n ),\n }),\n },\n async ({ code, projectId, blockId }) => {\n if (!ctx.callbacks.executeJavaScript) {\n return errorResult(\n \"JS execution is not available.\",\n \"Make sure the MCP server is running inside Platforma Desktop and MCP connected properly. If everything is fine check Electron logs with get_app_log\",\n );\n }\n if ((projectId === undefined) !== (blockId === undefined)) {\n return errorResult(\n \"projectId and blockId must be provided together.\",\n \"Either pass both to target a specific block's webview, or pass neither to run in the topmost webContents.\",\n );\n }\n const target =\n projectId !== undefined && blockId !== undefined ? { projectId, blockId } : undefined;\n const result = await ctx.callbacks.executeJavaScript(code, target);\n return textResult(result);\n },\n );\n}\n"],"mappings":";;;;AAKA,SAAgB,2BAA2B,QAAuB,KAAwB;CACxF,OAAO,aACL,SACA;EACE,OAAO;EACP,aAAa,MAAM;EACnB,aACE;EACF,aAAa,EAAE,OAAO;GACpB,GAAG,EAAE,OAAO,CAAC,CAAC,SAAS,cAAc;GACrC,GAAG,EAAE,OAAO,CAAC,CAAC,SAAS,cAAc;GACrC,aAAa,EAAE,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,cAAc;EAC7D,CAAC;CACH,GACA,OAAO,EAAE,GAAG,GAAG,kBAAkB;EAC/B,IAAI,CAAC,IAAI,UAAU,gBACjB,OAAO,YACL,oCACA,qJACF;EAEF,MAAM,aAAa,cAAc,IAAI;EACrC,MAAM,IAAI,UAAU,eAAe;GACjC,MAAM;GACN;GACA;GACA,QAAQ;GACR;EACF,CAAC;EACD,MAAM,IAAI,UAAU,eAAe;GAAE,MAAM;GAAW;GAAG;GAAG,QAAQ;GAAQ;EAAW,CAAC;EACxF,OAAO,WAAW,EAAE,IAAI,KAAK,CAAC;CAChC,CACF;CAEA,OAAO,aACL,aACA;EACE,OAAO;EACP,aAAa,MAAM;EACnB,aACE;EACF,aAAa,EAAE,OAAO,EACpB,MAAM,EAAE,OAAO,CAAC,CAAC,SAAS,cAAc,EAC1C,CAAC;CACH,GACA,OAAO,EAAE,WAAW;EAClB,IAAI,CAAC,IAAI,UAAU,gBACjB,OAAO,YACL,oCACA,qJACF;EAEF,KAAK,MAAM,QAAQ,MAAM;GACvB,MAAM,IAAI,UAAU,eAAe;IAAE,MAA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D,QAAQ,EAAE,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,0BAA0B;GAC5E,QAAQ,EAAE,OAAO,CAAC,CAAC,SAAS,yDAAyD;EACvF,CAAC;CACH,GACA,OAAO,EAAE,GAAG,GAAG,QAAQ,aAAa;EAClC,IAAI,CAAC,IAAI,UAAU,gBACjB,OAAO,YACL,oCACA,qJACF;EAEF,MAAM,IAAI,UAAU,eAAe;GACjC,MAAM;GACN;GACA;GACA,QAAQ,UAAU;GAClB;EACF,CAAC;EACD,OAAO,WAAW,EAAE,IAAI,KAAK,CAAC;CAChC,CACF;CAEA,OAAO,aACL,cACA;EACE,OAAO;EACP,aAAa;GAAE,GAAG,MAAM;GAAe,eAAe;EAAK;EAC3D,aACE;EACF,aAAa,EAAE,OAAO;GACpB,MAAM,EAAE,OAAO,CAAC,CAAC,SAAS,4BAA4B;GACtD,WAAW,eACR,SAAS,CAAC,CACV,SAAS,iDAAiD;GAC7D,SAAS,aACN,SAAS,CAAC,CACV,SACC,yHACF;EACJ,CAAC;CACH,GACA,OAAO,EAAE,MAAM,WAAW,cAAc;EACtC,IAAI,CAAC,IAAI,UAAU,mBACjB,OAAO,YACL,kCACA,qJACF;EAEF,IAAK,cAAc,KAAA,OAAgB,YAAY,KAAA,IAC7C,OAAO,YACL,oDACA,2GACF;EAEF,MAAM,SACJ,cAAc,KAAA,KAAa,YAAY,KAAA,IAAY;GAAE;GAAW;EAAQ,IAAI,KAAA;EAC9E,MAAM,SAAS,MAAM,IAAI,UAAU,kBAAkB,MAAM,MAAM;EACjE,OAAO,WAAW,MAAM;CAC1B,CACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@milaboratories/pl-mcp-server",
3
- "version": "53.0.0",
3
+ "version": "54.0.0",
4
4
  "description": "MCP server for Platforma Desktop",
5
5
  "keywords": [],
6
6
  "license": "UNLICENSED",
@@ -19,6 +19,7 @@
19
19
  }
20
20
  },
21
21
  "dependencies": {
22
+ "@milaboratories/helpers": "1.14.7",
22
23
  "@modelcontextprotocol/node": "^2.1.2",
23
24
  "@modelcontextprotocol/server": "^2.4.0",
24
25
  "quickjs-emscripten": "npm:@milaboratories-poc/quickjs-emscripten@0.32.1-bytecode.1",
@@ -27,12 +28,12 @@
27
28
  "devDependencies": {
28
29
  "@milaboratories/build-configs": "2.0.3",
29
30
  "@milaboratories/pl-errors": "1.5.0",
30
- "@milaboratories/pl-middle-layer": "2.9.0",
31
+ "@milaboratories/pl-middle-layer": "2.10.0",
31
32
  "@milaboratories/pl-model-common": "1.60.0",
32
33
  "@milaboratories/ts-builder": "1.8.0",
33
34
  "@milaboratories/ts-configs": "1.4.1",
34
35
  "@modelcontextprotocol/client": "^2.4.0",
35
- "@platforma-sdk/model": "1.96.1",
36
+ "@platforma-sdk/model": "1.96.4",
36
37
  "@types/node": "~24.19.2",
37
38
  "@vitest/coverage-istanbul": "^4.1.12",
38
39
  "shx": "^0.4.0",
@@ -40,8 +41,8 @@
40
41
  "vitest": "^4.1.12"
41
42
  },
42
43
  "peerDependencies": {
43
- "@milaboratories/pl-middle-layer": ">=2.9.0",
44
- "@platforma-sdk/model": ">=1.96.1"
44
+ "@milaboratories/pl-middle-layer": ">=2.10.0",
45
+ "@platforma-sdk/model": ">=1.96.4"
45
46
  },
46
47
  "engines": {
47
48
  "node": ">=24"
@@ -10,7 +10,7 @@ export const SERVER_INSTRUCTIONS = `Platforma Desktop: build and run data analys
10
10
 
11
11
  Order of work:
12
12
  1. Connection: get_connection_status. If not connected: list_connections, then connect_to_server.
13
- 2. Project: list_projects or create_project, then open_project. Every block tool needs an opened project.
13
+ 2. Project: list_projects finds a project, create_project makes a new one. Every tool that works on a project takes its projectId.
14
14
  3. Add blocks: list_available_blocks finds a block; add_block adds it, with params to configure it at creation. Add blocks in the order the data flows.
15
15
  4. Configure a block: get_block_state returns the block's data and outputs. Change the data and write the whole object back with set_block_data. The choices a block offers for its inputs (datasets, columns of blocks above) are in its outputs: get_block_outputs.
16
16
  5. Check and run: get_project_overview shows for each block whether its inputs are valid and whether it can run. run_block starts a block together with the stale blocks above it; await_block_done waits for it.
@@ -21,4 +21,5 @@ Rules:
21
21
  - set_block_data replaces the block's data: send the whole object, not the changed part.
22
22
  - Changing a block's data can make its results, and the results of blocks that read them, stale until they run again.
23
23
  - Only blocks on the current block API can be added.
24
- - capture_screenshot, click, type_text, press_key, scroll, execute_js and select_block drive the application window. They are for testing the application; configuring and running blocks does not need them.`;
24
+ - select_block shows a block to the user in the application; use it only when the user asks to be shown something.
25
+ - capture_screenshot, click, type_text, press_key, scroll and execute_js drive the application window. They are for testing the application; configuring and running blocks does not need them.`;
@@ -0,0 +1,183 @@
1
+ import type { ProjectHolder, ProjectId } from "@milaboratories/pl-middle-layer";
2
+ import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
3
+ import type { Hold, HoldSource, KeptHoldRelease } from "./project-holds";
4
+ import { ProjectHolds } from "./project-holds";
5
+
6
+ const P1 = "p1" as ProjectId;
7
+ const P2 = "p2" as ProjectId;
8
+ const HOLDER = "mcp:test" as ProjectHolder;
9
+ const IDLE_MS = 1_000;
10
+
11
+ type FakeProject = { id: ProjectId };
12
+
13
+ /** A middle layer that only counts holds. */
14
+ class FakeSource implements HoldSource<FakeProject> {
15
+ readonly live = new Set<FakeHold>();
16
+ acquired = 0;
17
+
18
+ async acquireProject(id: ProjectId, holder: ProjectHolder): Promise<FakeHold> {
19
+ expect(holder).toBe(HOLDER);
20
+ this.acquired++;
21
+ const hold = new FakeHold(this, { id });
22
+ this.live.add(hold);
23
+ return hold;
24
+ }
25
+
26
+ holds(id: ProjectId): number {
27
+ return [...this.live].filter((h) => h.project.id === id).length;
28
+ }
29
+ }
30
+
31
+ class FakeHold implements Hold<FakeProject> {
32
+ private readonly controller = new AbortController();
33
+ constructor(
34
+ private readonly source: FakeSource,
35
+ readonly project: FakeProject,
36
+ ) {}
37
+ get signal(): AbortSignal {
38
+ return this.controller.signal;
39
+ }
40
+ get ended(): boolean {
41
+ return this.controller.signal.aborted;
42
+ }
43
+ async release(): Promise<void> {
44
+ this.end("released");
45
+ }
46
+ /** Ends the hold the way the middle layer does on a delete or a close. */
47
+ end(reason: string): void {
48
+ if (this.ended) return;
49
+ this.source.live.delete(this);
50
+ this.controller.abort(reason);
51
+ }
52
+ }
53
+
54
+ function deferred(): { promise: Promise<void>; resolve: () => void } {
55
+ let resolve = () => {};
56
+ const promise = new Promise<void>((res) => {
57
+ resolve = res;
58
+ });
59
+ return { promise, resolve };
60
+ }
61
+
62
+ describe("ProjectHolds", () => {
63
+ let source: FakeSource;
64
+ let released: [ProjectId, KeptHoldRelease][];
65
+ let holds: ProjectHolds<FakeProject>;
66
+
67
+ beforeEach(() => {
68
+ vi.useFakeTimers();
69
+ source = new FakeSource();
70
+ released = [];
71
+ holds = new ProjectHolds<FakeProject>({
72
+ holder: HOLDER,
73
+ idleMs: IDLE_MS,
74
+ onRelease: (id, reason) => released.push([id, reason]),
75
+ });
76
+ });
77
+
78
+ afterEach(() => {
79
+ vi.useRealTimers();
80
+ });
81
+
82
+ test("every call holds the project while it runs, and one hold is kept after", async () => {
83
+ const gates = [deferred(), deferred(), deferred()];
84
+ const calls = gates.map((gate) =>
85
+ holds.use(source, P1, async (project) => {
86
+ await gate.promise;
87
+ return project.id;
88
+ }),
89
+ );
90
+ await vi.waitFor(() => expect(source.holds(P1)).toBe(3));
91
+
92
+ // The first call to end leaves its hold as the kept one.
93
+ gates[0].resolve();
94
+ await calls[0];
95
+ expect(source.holds(P1)).toBe(3);
96
+
97
+ // Later calls give theirs back.
98
+ gates[1].resolve();
99
+ await calls[1];
100
+ expect(source.holds(P1)).toBe(2);
101
+
102
+ gates[2].resolve();
103
+ expect(await Promise.all(calls)).toEqual([P1, P1, P1]);
104
+ expect(source.holds(P1)).toBe(1);
105
+ });
106
+
107
+ test("the kept hold is released after the idle time, which every call restarts", async () => {
108
+ await holds.use(source, P1, async () => {});
109
+ await vi.advanceTimersByTimeAsync(IDLE_MS - 100);
110
+ await holds.use(source, P1, async () => {});
111
+ await vi.advanceTimersByTimeAsync(IDLE_MS - 100);
112
+ expect(source.holds(P1)).toBe(1);
113
+
114
+ await vi.advanceTimersByTimeAsync(200);
115
+ expect(source.holds(P1)).toBe(0);
116
+ expect(released).toEqual([[P1, "idle"]]);
117
+ });
118
+
119
+ test("a call running past the idle time keeps the project held", async () => {
120
+ await holds.use(source, P1, async () => {});
121
+ const gate = deferred();
122
+ const long = holds.use(source, P1, () => gate.promise);
123
+ await vi.waitFor(() => expect(source.holds(P1)).toBe(2));
124
+ await vi.advanceTimersByTimeAsync(IDLE_MS * 3);
125
+ expect(source.holds(P1)).toBe(1);
126
+
127
+ gate.resolve();
128
+ await long;
129
+ expect(source.holds(P1)).toBe(1);
130
+ });
131
+
132
+ test("releaseAll gives back every kept hold", async () => {
133
+ await holds.use(source, P1, async () => {});
134
+ await holds.use(source, P2, async () => {});
135
+ expect(source.live.size).toBe(2);
136
+ holds.releaseAll();
137
+ expect(source.live.size).toBe(0);
138
+ });
139
+
140
+ test("a call running across releaseAll gives its hold back when it ends", async () => {
141
+ const gate = deferred();
142
+ const running = holds.use(source, P1, () => gate.promise);
143
+ await vi.waitFor(() => expect(source.holds(P1)).toBe(1));
144
+ holds.releaseAll();
145
+ expect(source.holds(P1)).toBe(1);
146
+
147
+ gate.resolve();
148
+ await running;
149
+ expect(source.holds(P1)).toBe(0);
150
+
151
+ // Calls after it keep their hold again.
152
+ await holds.use(source, P1, async () => {});
153
+ expect(source.holds(P1)).toBe(1);
154
+ });
155
+
156
+ test("a call whose acquire was in flight at releaseAll keeps nothing", async () => {
157
+ const slow = deferred();
158
+ const acquire = source.acquireProject.bind(source);
159
+ source.acquireProject = async (id, holder) => {
160
+ await slow.promise;
161
+ return await acquire(id, holder);
162
+ };
163
+ const running = holds.use(source, P1, async () => {});
164
+ holds.releaseAll();
165
+ slow.resolve();
166
+ await running;
167
+ expect(source.live.size).toBe(0);
168
+ });
169
+
170
+ test("a kept hold the middle layer ends is forgotten", async () => {
171
+ await holds.use(source, P1, async () => {});
172
+ for (const hold of source.live) hold.end("deleted");
173
+ await vi.advanceTimersByTimeAsync(IDLE_MS * 2);
174
+ expect(released).toEqual([]);
175
+ });
176
+
177
+ test("a call whose hold ended during it keeps nothing", async () => {
178
+ await holds.use(source, P1, async () => {
179
+ for (const hold of source.live) hold.end("deleted");
180
+ });
181
+ expect(source.live.size).toBe(0);
182
+ });
183
+ });
@@ -0,0 +1,105 @@
1
+ import type { ProjectHolder, ProjectId } from "@milaboratories/pl-middle-layer";
2
+
3
+ /** A hold on a loaded project, as {@link ProjectHolds} uses it: the middle layer's `ProjectHandle`. */
4
+ export interface Hold<P> {
5
+ readonly project: P;
6
+ readonly signal: AbortSignal;
7
+ readonly ended: boolean;
8
+ release(): Promise<void>;
9
+ }
10
+
11
+ /** Where holds come from: the middle layer, or a fake of it in tests. */
12
+ export interface HoldSource<P> {
13
+ acquireProject(id: ProjectId, holder: ProjectHolder): Promise<Hold<P>>;
14
+ }
15
+
16
+ /** Why {@link ProjectHolds} gave a kept hold back. */
17
+ export type KeptHoldRelease = "idle" | "release-all";
18
+
19
+ export interface ProjectHoldsOptions {
20
+ /** The holder every hold is taken under. */
21
+ holder: ProjectHolder;
22
+ /** How long a project stays held after the last call on it ended. */
23
+ idleMs: number;
24
+ /** Told about every kept hold given back. */
25
+ onRelease?: (id: ProjectId, reason: KeptHoldRelease) => void;
26
+ }
27
+
28
+ type Kept<P> = { hold: Hold<P>; timer: NodeJS.Timeout };
29
+
30
+ /**
31
+ * The MCP server's holds on projects.
32
+ *
33
+ * Every call takes a hold of its own for as long as it runs, so nobody else's release can destroy
34
+ * the project under it. When the call ends, one hold per project is kept for `idleMs` more, so a
35
+ * run of calls on a project does not load it again for each call; the idle time restarts with
36
+ * every call. A kept hold the middle layer ends (the project was deleted, the middle layer closed)
37
+ * is forgotten.
38
+ */
39
+ export class ProjectHolds<P> {
40
+ private readonly kept = new Map<ProjectId, Kept<P>>();
41
+ /** Counts {@link releaseAll}: a call that started before the last one keeps nothing. */
42
+ private generation = 0;
43
+
44
+ constructor(private readonly options: ProjectHoldsOptions) {}
45
+
46
+ /** Runs `fn` on the project while holding it. */
47
+ async use<T>(source: HoldSource<P>, id: ProjectId, fn: (project: P) => Promise<T>): Promise<T> {
48
+ const generation = this.generation;
49
+ const hold = await source.acquireProject(id, this.options.holder);
50
+ try {
51
+ return await fn(hold.project);
52
+ } finally {
53
+ if (generation === this.generation) this.keep(id, hold);
54
+ else void hold.release();
55
+ }
56
+ }
57
+
58
+ /**
59
+ * Gives back every kept hold. Holds of calls still running are given back when those calls end,
60
+ * not kept.
61
+ */
62
+ releaseAll(): void {
63
+ this.generation++;
64
+ for (const id of this.kept.keys()) this.release(id, "release-all");
65
+ }
66
+
67
+ /** Makes the hold of a finished call the kept one, or gives it back when one is kept already. */
68
+ private keep(id: ProjectId, hold: Hold<P>): void {
69
+ if (hold.ended) return;
70
+
71
+ const kept = this.kept.get(id);
72
+ if (kept !== undefined) {
73
+ void hold.release();
74
+ kept.timer.refresh();
75
+ return;
76
+ }
77
+
78
+ const entry: Kept<P> = {
79
+ hold,
80
+ timer: setTimeout(() => {
81
+ if (this.kept.get(id) === entry) this.release(id, "idle");
82
+ }, this.options.idleMs),
83
+ };
84
+ entry.timer.unref();
85
+ hold.signal.addEventListener(
86
+ "abort",
87
+ () => {
88
+ if (this.kept.get(id) !== entry) return;
89
+ clearTimeout(entry.timer);
90
+ this.kept.delete(id);
91
+ },
92
+ { once: true },
93
+ );
94
+ this.kept.set(id, entry);
95
+ }
96
+
97
+ private release(id: ProjectId, reason: KeptHoldRelease): void {
98
+ const entry = this.kept.get(id);
99
+ if (entry === undefined) return;
100
+ clearTimeout(entry.timer);
101
+ this.kept.delete(id);
102
+ void entry.hold.release();
103
+ this.options.onRelease?.(id, reason);
104
+ }
105
+ }