@milaboratories/pl-mcp-server 54.0.0 → 55.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 (208) hide show
  1. package/README.md +15 -25
  2. package/dist/_virtual/_rolldown/runtime.cjs +22 -0
  3. package/dist/agent-tables.cjs +116 -0
  4. package/dist/agent-tables.cjs.map +1 -0
  5. package/dist/agent-tables.js +115 -0
  6. package/dist/agent-tables.js.map +1 -0
  7. package/dist/instructions.cjs +15 -12
  8. package/dist/instructions.cjs.map +1 -1
  9. package/dist/instructions.js +15 -12
  10. package/dist/instructions.js.map +1 -1
  11. package/dist/package.cjs +1 -1
  12. package/dist/package.js +1 -1
  13. package/dist/project-holds.cjs +58 -8
  14. package/dist/project-holds.cjs.map +1 -1
  15. package/dist/project-holds.js +58 -8
  16. package/dist/project-holds.js.map +1 -1
  17. package/dist/project-list.cjs +16 -0
  18. package/dist/project-list.cjs.map +1 -0
  19. package/dist/project-list.js +16 -0
  20. package/dist/project-list.js.map +1 -0
  21. package/dist/server-log.cjs +40 -18
  22. package/dist/server-log.cjs.map +1 -1
  23. package/dist/server-log.js +40 -19
  24. package/dist/server-log.js.map +1 -1
  25. package/dist/server.cjs +48 -18
  26. package/dist/server.cjs.map +1 -1
  27. package/dist/server.d.ts +21 -20
  28. package/dist/server.d.ts.map +1 -1
  29. package/dist/server.js +48 -18
  30. package/dist/server.js.map +1 -1
  31. package/dist/tools/agent-tables.cjs +424 -0
  32. package/dist/tools/agent-tables.cjs.map +1 -0
  33. package/dist/tools/agent-tables.js +417 -0
  34. package/dist/tools/agent-tables.js.map +1 -0
  35. package/dist/tools/await.cjs +216 -73
  36. package/dist/tools/await.cjs.map +1 -1
  37. package/dist/tools/await.js +212 -75
  38. package/dist/tools/await.js.map +1 -1
  39. package/dist/tools/block-action-context.cjs +3 -0
  40. package/dist/tools/block-action-context.cjs.map +1 -1
  41. package/dist/tools/block-action-context.js +3 -0
  42. package/dist/tools/block-action-context.js.map +1 -1
  43. package/dist/tools/block-api.cjs +17 -2
  44. package/dist/tools/block-api.cjs.map +1 -1
  45. package/dist/tools/block-api.js +17 -3
  46. package/dist/tools/block-api.js.map +1 -1
  47. package/dist/tools/block-params.cjs +272 -4
  48. package/dist/tools/block-params.cjs.map +1 -1
  49. package/dist/tools/block-params.js +270 -6
  50. package/dist/tools/block-params.js.map +1 -1
  51. package/dist/tools/block-state.cjs +323 -42
  52. package/dist/tools/block-state.cjs.map +1 -1
  53. package/dist/tools/block-state.js +317 -46
  54. package/dist/tools/block-state.js.map +1 -1
  55. package/dist/tools/block-storage.cjs +153 -0
  56. package/dist/tools/block-storage.cjs.map +1 -0
  57. package/dist/tools/block-storage.js +147 -0
  58. package/dist/tools/block-storage.js.map +1 -0
  59. package/dist/tools/block-updates.cjs +405 -0
  60. package/dist/tools/block-updates.cjs.map +1 -0
  61. package/dist/tools/block-updates.js +397 -0
  62. package/dist/tools/block-updates.js.map +1 -0
  63. package/dist/tools/blocks.cjs +183 -70
  64. package/dist/tools/blocks.cjs.map +1 -1
  65. package/dist/tools/blocks.js +177 -70
  66. package/dist/tools/blocks.js.map +1 -1
  67. package/dist/tools/data-query.cjs +451 -113
  68. package/dist/tools/data-query.cjs.map +1 -1
  69. package/dist/tools/data-query.js +446 -118
  70. package/dist/tools/data-query.js.map +1 -1
  71. package/dist/tools/errors.cjs +21 -0
  72. package/dist/tools/errors.cjs.map +1 -0
  73. package/dist/tools/errors.js +20 -0
  74. package/dist/tools/errors.js.map +1 -0
  75. package/dist/tools/files.cjs +643 -0
  76. package/dist/tools/files.cjs.map +1 -0
  77. package/dist/tools/files.js +613 -0
  78. package/dist/tools/files.js.map +1 -0
  79. package/dist/tools/ids.cjs +56 -0
  80. package/dist/tools/ids.cjs.map +1 -1
  81. package/dist/tools/ids.js +51 -2
  82. package/dist/tools/ids.js.map +1 -1
  83. package/dist/tools/imports.cjs +195 -0
  84. package/dist/tools/imports.cjs.map +1 -0
  85. package/dist/tools/imports.js +186 -0
  86. package/dist/tools/imports.js.map +1 -0
  87. package/dist/tools/logs.cjs +98 -19
  88. package/dist/tools/logs.cjs.map +1 -1
  89. package/dist/tools/logs.js +95 -20
  90. package/dist/tools/logs.js.map +1 -1
  91. package/dist/tools/paging.cjs +27 -0
  92. package/dist/tools/paging.cjs.map +1 -0
  93. package/dist/tools/paging.js +26 -0
  94. package/dist/tools/paging.js.map +1 -0
  95. package/dist/tools/params-merge.cjs +106 -0
  96. package/dist/tools/params-merge.cjs.map +1 -0
  97. package/dist/tools/params-merge.js +106 -0
  98. package/dist/tools/params-merge.js.map +1 -0
  99. package/dist/tools/project-template.cjs +75 -0
  100. package/dist/tools/project-template.cjs.map +1 -0
  101. package/dist/tools/project-template.js +72 -0
  102. package/dist/tools/project-template.js.map +1 -0
  103. package/dist/tools/projects.cjs +66 -19
  104. package/dist/tools/projects.cjs.map +1 -1
  105. package/dist/tools/projects.js +66 -20
  106. package/dist/tools/projects.js.map +1 -1
  107. package/dist/tools/readiness.cjs +104 -0
  108. package/dist/tools/readiness.cjs.map +1 -0
  109. package/dist/tools/readiness.js +99 -0
  110. package/dist/tools/readiness.js.map +1 -0
  111. package/dist/tools/result-pool.cjs +260 -0
  112. package/dist/tools/result-pool.cjs.map +1 -0
  113. package/dist/tools/result-pool.js +252 -0
  114. package/dist/tools/result-pool.js.map +1 -0
  115. package/dist/tools/sandbox.cjs +112 -14
  116. package/dist/tools/sandbox.cjs.map +1 -1
  117. package/dist/tools/sandbox.js +110 -15
  118. package/dist/tools/sandbox.js.map +1 -1
  119. package/dist/tools/sdk-types.cjs +24 -0
  120. package/dist/tools/sdk-types.cjs.map +1 -0
  121. package/dist/tools/sdk-types.js +24 -0
  122. package/dist/tools/sdk-types.js.map +1 -0
  123. package/dist/tools/settle.cjs +155 -0
  124. package/dist/tools/settle.cjs.map +1 -0
  125. package/dist/tools/settle.js +148 -0
  126. package/dist/tools/settle.js.map +1 -0
  127. package/dist/tools/tokens.cjs +49 -8
  128. package/dist/tools/tokens.cjs.map +1 -1
  129. package/dist/tools/tokens.js +45 -9
  130. package/dist/tools/tokens.js.map +1 -1
  131. package/dist/tools/types.cjs +62 -11
  132. package/dist/tools/types.cjs.map +1 -1
  133. package/dist/tools/types.js +60 -12
  134. package/dist/tools/types.js.map +1 -1
  135. package/dist/tools/value-outline.cjs +119 -0
  136. package/dist/tools/value-outline.cjs.map +1 -0
  137. package/dist/tools/value-outline.js +117 -0
  138. package/dist/tools/value-outline.js.map +1 -0
  139. package/package.json +9 -8
  140. package/src/agent-tables.test.ts +246 -0
  141. package/src/agent-tables.ts +145 -0
  142. package/src/instructions.ts +15 -12
  143. package/src/project-holds.test.ts +179 -0
  144. package/src/project-holds.ts +114 -12
  145. package/src/project-list.test.ts +38 -0
  146. package/src/project-list.ts +25 -0
  147. package/src/server-log.test.ts +54 -1
  148. package/src/server-log.ts +49 -27
  149. package/src/server.logging.test.ts +38 -46
  150. package/src/server.test.ts +151 -17
  151. package/src/server.ts +62 -34
  152. package/src/tools/agent-tables.test.ts +650 -0
  153. package/src/tools/agent-tables.ts +673 -0
  154. package/src/tools/await.test.ts +287 -0
  155. package/src/tools/await.ts +393 -123
  156. package/src/tools/block-action-context.ts +3 -0
  157. package/src/tools/block-api.ts +19 -4
  158. package/src/tools/block-params.test.ts +828 -0
  159. package/src/tools/block-params.ts +623 -8
  160. package/src/tools/block-state.test.ts +480 -0
  161. package/src/tools/block-state.ts +659 -66
  162. package/src/tools/block-storage.test.ts +270 -0
  163. package/src/tools/block-storage.ts +195 -0
  164. package/src/tools/block-updates.test.ts +605 -0
  165. package/src/tools/block-updates.ts +751 -0
  166. package/src/tools/blocks.test.ts +169 -22
  167. package/src/tools/blocks.ts +336 -105
  168. package/src/tools/data-query.test.ts +641 -0
  169. package/src/tools/data-query.ts +807 -157
  170. package/src/tools/errors.test.ts +33 -0
  171. package/src/tools/errors.ts +23 -0
  172. package/src/tools/files.test.ts +842 -0
  173. package/src/tools/files.ts +990 -0
  174. package/src/tools/ids.test.ts +87 -0
  175. package/src/tools/ids.ts +67 -0
  176. package/src/tools/imports.ts +304 -0
  177. package/src/tools/logs.test.ts +70 -0
  178. package/src/tools/logs.ts +130 -21
  179. package/src/tools/paging.test.ts +39 -0
  180. package/src/tools/paging.ts +39 -0
  181. package/src/tools/params-merge.test.ts +274 -0
  182. package/src/tools/params-merge.ts +149 -0
  183. package/src/tools/project-template.test.ts +230 -0
  184. package/src/tools/project-template.ts +135 -0
  185. package/src/tools/projects.test.ts +122 -0
  186. package/src/tools/projects.ts +135 -25
  187. package/src/tools/readiness.test.ts +195 -0
  188. package/src/tools/readiness.ts +189 -0
  189. package/src/tools/result-pool.test.ts +377 -0
  190. package/src/tools/result-pool.ts +483 -0
  191. package/src/tools/sandbox.test.ts +128 -10
  192. package/src/tools/sandbox.ts +132 -18
  193. package/src/tools/sdk-types.ts +54 -0
  194. package/src/tools/settle.test.ts +340 -0
  195. package/src/tools/settle.ts +312 -0
  196. package/src/tools/tokens.ts +74 -9
  197. package/src/tools/types.ts +77 -12
  198. package/src/tools/value-outline.ts +143 -0
  199. package/dist/tools/screenshot.cjs +0 -44
  200. package/dist/tools/screenshot.cjs.map +0 -1
  201. package/dist/tools/screenshot.js +0 -44
  202. package/dist/tools/screenshot.js.map +0 -1
  203. package/dist/tools/ui-interaction.cjs +0 -140
  204. package/dist/tools/ui-interaction.cjs.map +0 -1
  205. package/dist/tools/ui-interaction.js +0 -140
  206. package/dist/tools/ui-interaction.js.map +0 -1
  207. package/src/tools/screenshot.ts +0 -61
  208. package/src/tools/ui-interaction.ts +0 -184
@@ -6,6 +6,7 @@ import type { Server as Listener } from "node:net";
6
6
  import { afterAll, beforeAll, describe, expect, test } from "vitest";
7
7
  import { version } from "../package.json";
8
8
  import type { McpSecret, PlMcpServerCallbacks } from "./server";
9
+ import { SERVER_INSTRUCTIONS } from "./instructions";
9
10
  import { PlMcpServer } from "./server";
10
11
 
11
12
  const secret = "0".repeat(32) as McpSecret;
@@ -73,11 +74,29 @@ describe.each(eras)("to a $era client", (era) => {
73
74
  expect(client.getServerVersion()).toMatchObject({ name: "pl", version });
74
75
  });
75
76
 
77
+ // Claude Code cuts instructions at 4096 characters. The text is kept under 3600 so that new
78
+ // tools fit; the test guards the cut and that headroom.
76
79
  test("sends instructions that fit the length clients keep", () => {
77
80
  const instructions = client.getInstructions() ?? "";
78
81
  expect(instructions).toContain("list_projects");
79
82
  expect(instructions.length).toBeGreaterThan(0);
80
83
  expect(instructions.length).toBeLessThanOrEqual(4096);
84
+ expect(SERVER_INSTRUCTIONS.length).toBeLessThan(3600);
85
+ });
86
+
87
+ test("say a block param takes its declared form and column tools take a columnId", () => {
88
+ expect(SERVER_INSTRUCTIONS).toContain(
89
+ "A block param takes the form get_block_contract declares: a column's `ref` for a PlRef " +
90
+ "object, its `columnId` for an id string, `valueIds` for picked values.",
91
+ );
92
+ expect(SERVER_INSTRUCTIONS).toContain(
93
+ "Tools that take a column (create_table, get_pool_column, get_column_values) take its " +
94
+ "`columnId`.",
95
+ );
96
+ expect(SERVER_INSTRUCTIONS).not.toMatch(/wherever a column is taken/);
97
+ expect(SERVER_INSTRUCTIONS).toMatch(
98
+ /\{__isRef: true, blockId, name\}, may be written by hand/,
99
+ );
81
100
  });
82
101
 
83
102
  test("names in the instructions are tools the server has", () => {
@@ -96,12 +115,32 @@ describe.each(eras)("to a $era client", (era) => {
96
115
  expect(said).not.toMatch(/open_project|close_project|\bopened\b|must be open/i);
97
116
  });
98
117
 
118
+ // A pool column's leaf id fits a block field of that form; a discovered id is not offered.
119
+ test("the result pool is not ruled out for configuring a block", () => {
120
+ const pool = tools.find((tool) => tool.name === "list_pool_columns")?.description ?? "";
121
+ for (const said of [client.getInstructions() ?? "", pool]) {
122
+ expect(said).not.toMatch(/not to configure a block|To configure a block/);
123
+ expect(said).toContain("own option outputs");
124
+ expect(said).toMatch(
125
+ /`?ref`?, or its `?columnId`? when it has a `?ref`?, fits a block field/,
126
+ );
127
+ }
128
+ });
129
+
99
130
  test("says its set of tools does not change", () => {
100
131
  expect(client.getServerCapabilities()?.tools).toEqual({ listChanged: false });
101
132
  });
102
133
  });
103
134
 
104
135
  describe("every tool", () => {
136
+ // Claude Code cuts tool descriptions it shows upfront at 4096 characters.
137
+ test("has a description that fits the length clients keep", () => {
138
+ const tooLong = tools
139
+ .filter((tool) => (tool.description ?? "").length > 4096)
140
+ .map((tool) => tool.name);
141
+ expect(tooLong).toEqual([]);
142
+ });
143
+
105
144
  test("has a title and a description that says what it is for", () => {
106
145
  const lacking = tools
107
146
  .filter((tool) => !tool.title || (tool.description ?? "").length < 40)
@@ -144,43 +183,46 @@ describe.each(eras)("to a $era client", (era) => {
144
183
  "await_block_done",
145
184
  "get_app_log",
146
185
  "get_block_action_context",
186
+ "get_block_contract",
147
187
  "get_block_info",
148
188
  "get_block_logs",
149
189
  "get_block_outputs",
150
190
  "get_block_params",
151
191
  "get_block_state",
192
+ "get_column_values",
152
193
  "get_connection_status",
194
+ "get_file_handles",
195
+ "get_pool_column",
153
196
  "get_project_overview",
154
197
  "list_available_blocks",
198
+ "list_block_updates",
155
199
  "list_columns",
156
200
  "list_connections",
201
+ "list_files",
202
+ "list_pool_columns",
157
203
  "list_projects",
158
204
  "ping",
159
205
  "query_table",
206
+ "read_file",
160
207
  ]);
161
208
  });
162
209
 
163
210
  test("destructive tools", () => {
164
211
  expect(namesWhere((tool) => tool.annotations?.destructiveHint)).toEqual([
165
- "click",
166
212
  "delete_project",
167
- "execute_js",
168
- "press_key",
169
213
  "remove_block",
170
214
  "reorder_blocks",
171
215
  "run_block",
172
216
  "set_block_data",
217
+ "set_block_params",
173
218
  "stop_block",
174
- "type_text",
175
219
  "update_block",
220
+ "update_blocks",
176
221
  ]);
177
222
  });
178
223
 
179
224
  test("open-world tools", () => {
180
- expect(namesWhere((tool) => tool.annotations?.openWorldHint)).toEqual([
181
- "connect_to_server",
182
- "execute_js",
183
- ]);
225
+ expect(namesWhere((tool) => tool.annotations?.openWorldHint)).toEqual(["connect_to_server"]);
184
226
  });
185
227
  });
186
228
 
@@ -190,38 +232,45 @@ describe.each(eras)("to a $era client", (era) => {
190
232
  expect(tools.map((tool) => tool.name).toSorted()).toEqual([
191
233
  "add_block",
192
234
  "await_block_done",
193
- "capture_screenshot",
194
- "click",
195
235
  "connect_to_server",
196
236
  "create_project",
237
+ "create_table",
197
238
  "delete_project",
198
239
  "disconnect",
199
- "execute_js",
240
+ "drop_table",
241
+ "export_project_template",
200
242
  "get_app_log",
201
243
  "get_block_action_context",
244
+ "get_block_contract",
202
245
  "get_block_info",
203
246
  "get_block_logs",
204
247
  "get_block_outputs",
205
248
  "get_block_params",
206
249
  "get_block_state",
250
+ "get_column_values",
207
251
  "get_connection_status",
252
+ "get_file_handles",
253
+ "get_pool_column",
208
254
  "get_project_overview",
209
255
  "list_available_blocks",
256
+ "list_block_updates",
210
257
  "list_columns",
211
258
  "list_connections",
259
+ "list_files",
260
+ "list_pool_columns",
212
261
  "list_projects",
213
262
  "ping",
214
- "press_key",
215
263
  "query_table",
264
+ "read_file",
216
265
  "remove_block",
217
266
  "reorder_blocks",
218
267
  "run_block",
219
- "scroll",
220
268
  "select_block",
221
269
  "set_block_data",
270
+ "set_block_params",
222
271
  "stop_block",
223
- "type_text",
224
272
  "update_block",
273
+ "update_blocks",
225
274
  ]);
226
275
  });
227
276
 
@@ -248,13 +297,44 @@ describe.each(eras)("to a $era client", (era) => {
248
297
  test("a default is advertised", () => {
249
298
  expect(inputSchemaOf("await_block_done").properties?.timeout).toMatchObject({
250
299
  type: "number",
251
- default: 120000,
300
+ default: 50000,
252
301
  });
253
302
  });
254
303
 
255
304
  test("a tool without arguments takes an empty object", () => {
256
305
  expect(inputSchemaOf("ping")).toEqual({ type: "object", properties: {} });
257
306
  });
307
+
308
+ // Every schema is sent to the agent at the start of each session. A sub-schema used at several
309
+ // places is inlined at each of them unless it has an id, which once made list_pool_columns
310
+ // 40,817 characters and create_table 12,757. The largest schemas are create_table at about
311
+ // 6,300 characters and list_pool_columns at about 4,500; 8,000 leaves them room to grow by a few
312
+ // arguments, while an inlined selector or filter tree (several times larger) does not fit.
313
+ test("no argument schema is larger than 8,000 characters", () => {
314
+ const large = tools
315
+ .map((tool) => ({ name: tool.name, size: JSON.stringify(tool.inputSchema).length }))
316
+ .filter(({ size }) => size > 8000);
317
+ expect(large).toEqual([]);
318
+ });
319
+
320
+ test("a shared sub-schema is sent once, under `$defs`, and every reference resolves", () => {
321
+ const defs = inputSchemaOf("list_pool_columns").$defs;
322
+ expect(Object.keys(defs ?? {})).toEqual(
323
+ expect.arrayContaining(["ColumnSelector", "RelaxedColumnSelector"]),
324
+ );
325
+ expect(Object.keys(inputSchemaOf("create_table").$defs ?? {})).toEqual(
326
+ expect.arrayContaining(["TableFilter", "TableColumnRef", "ColumnId"]),
327
+ );
328
+ for (const tool of tools) {
329
+ const json = JSON.stringify(tool.inputSchema);
330
+ const refs = [...json.matchAll(/"\$ref":"#\/\$defs\/([^"]+)"/g)].map((m) => m[1]);
331
+ const known = Object.keys(tool.inputSchema.$defs ?? {});
332
+ expect({ tool: tool.name, missing: refs.filter((r) => !known.includes(r)) }).toEqual({
333
+ tool: tool.name,
334
+ missing: [],
335
+ });
336
+ }
337
+ });
258
338
  });
259
339
 
260
340
  test("arguments of the wrong type are refused before the tool runs", async () => {
@@ -615,7 +695,7 @@ describe("stopping the server", () => {
615
695
  });
616
696
  const callbacks: PlMcpServerCallbacks = {
617
697
  // A tool that never answers, as a wait for a block that never finishes would.
618
- captureScreenshot: () => {
698
+ readAppLog: () => {
619
699
  reached();
620
700
  return new Promise<string>(() => {});
621
701
  },
@@ -626,7 +706,7 @@ describe("stopping the server", () => {
626
706
  await busy.start();
627
707
  client = await connect(busy, era);
628
708
 
629
- const call = client.callTool({ name: "capture_screenshot", arguments: {} });
709
+ const call = client.callTool({ name: "get_app_log", arguments: {} });
630
710
  const callFailed = call.then(
631
711
  () => false,
632
712
  () => true,
@@ -641,3 +721,57 @@ describe("stopping the server", () => {
641
721
  }
642
722
  });
643
723
  });
724
+
725
+ describe("get_block_info", () => {
726
+ async function callWith(args: Record<string, unknown>): Promise<{
727
+ registries: string[];
728
+ isError: boolean | undefined;
729
+ }> {
730
+ const registries: string[] = [];
731
+ const callbacks: PlMcpServerCallbacks = {
732
+ getBlockInfo: async (registry) => {
733
+ registries.push(registry);
734
+ return { ok: true };
735
+ },
736
+ };
737
+ const withInfo = new PlMcpServer({ port: 0, secret, callbacks });
738
+ let client: Client | undefined;
739
+ try {
740
+ await withInfo.start();
741
+ client = await connect(withInfo, eras[0]);
742
+ const result = await client.callTool({
743
+ name: "get_block_info",
744
+ arguments: { organization: "org", name: "block", version: "1.0.0", ...args },
745
+ });
746
+ return { registries, isError: result.isError as boolean | undefined };
747
+ } finally {
748
+ await client?.close();
749
+ await withInfo.stop();
750
+ }
751
+ }
752
+
753
+ test("passes `registryId` to the application as it is", async () => {
754
+ expect(await callWith({ registryId: "central" })).toEqual({
755
+ registries: ["central"],
756
+ isError: undefined,
757
+ });
758
+ });
759
+
760
+ test("still takes the deprecated `registryUrl`", async () => {
761
+ expect(await callWith({ registryUrl: "https://registry.test/" })).toEqual({
762
+ registries: ["https://registry.test/"],
763
+ isError: undefined,
764
+ });
765
+ });
766
+
767
+ test("`registryId` wins when both are given", async () => {
768
+ expect(await callWith({ registryId: "central", registryUrl: "other" })).toEqual({
769
+ registries: ["central"],
770
+ isError: undefined,
771
+ });
772
+ });
773
+
774
+ test("without either it is an error and the application is not asked", async () => {
775
+ expect(await callWith({})).toEqual({ registries: [], isError: true });
776
+ });
777
+ });
package/src/server.ts CHANGED
@@ -7,8 +7,10 @@ import { asProjectHolder } from "@milaboratories/pl-middle-layer";
7
7
  import type { MiddleLayer, Project } from "@milaboratories/pl-middle-layer";
8
8
  import type { BlockId, Branded, ProjectId } from "@milaboratories/pl-model-common";
9
9
  import { version } from "../package.json";
10
+ import { AgentTables, projectHoldsWithTables } from "./agent-tables";
10
11
  import { SERVER_INSTRUCTIONS } from "./instructions";
11
- import { ProjectHolds } from "./project-holds";
12
+ import type { ProjectHolds } from "./project-holds";
13
+ import { findListedProject } from "./project-list";
12
14
  import type { TxCounters } from "./server-log";
13
15
  import { ServerLog } from "./server-log";
14
16
  import type { ToolContext, ToolRegistrar } from "./tools/types";
@@ -17,32 +19,25 @@ import { registerPingTool } from "./tools/ping";
17
19
  import { registerConnectionTools } from "./tools/connection";
18
20
  import { registerProjectTools } from "./tools/projects";
19
21
  import { registerBlockTools } from "./tools/blocks";
22
+ import { registerBlockUpdateTools } from "./tools/block-updates";
20
23
  import { registerBlockParamsTools } from "./tools/block-params";
21
24
  import { registerBlockStateTools } from "./tools/block-state";
22
25
  import { registerBlockActionContextTools } from "./tools/block-action-context";
23
26
  import { registerAwaitTools } from "./tools/await";
24
27
  import { registerLogTools } from "./tools/logs";
25
28
  import { registerDataQueryTools } from "./tools/data-query";
26
- import { registerScreenshotTool } from "./tools/screenshot";
27
- import { registerUIInteractionTools } from "./tools/ui-interaction";
29
+ import { registerFileTools } from "./tools/files";
30
+ import { registerResultPoolTools } from "./tools/result-pool";
31
+ import {
32
+ AGENT_TABLE_IDLE_MS,
33
+ MAX_AGENT_TABLES,
34
+ registerAgentTableTools,
35
+ } from "./tools/agent-tables";
36
+ import { pendingUploadsOfProject } from "./tools/imports";
28
37
 
29
38
  export interface PlMcpServerCallbacks {
30
39
  onProjectCreated?: (projectId: ProjectId) => void | Promise<void>;
31
40
  onProjectDeleted?: (projectId: ProjectId) => void | Promise<void>;
32
- /** Capture the current application window as a PNG screenshot. Returns base64-encoded PNG. */
33
- captureScreenshot?: () => Promise<string>;
34
- /** Send an input event to the application window. */
35
- sendInputEvent?: (event: unknown) => Promise<void>;
36
- /**
37
- * Execute JavaScript in a renderer and return the result.
38
- * With no `target`, runs in the topmost webContents (usually the main app).
39
- * With `target`, runs in the specified block's webview (where `window.platforma` is
40
- * exposed) — the block must already be loaded (e.g. via `select_block`).
41
- */
42
- executeJavaScript?: (
43
- code: string,
44
- target?: { projectId: ProjectId; blockId: BlockId },
45
- ) => Promise<unknown>;
46
41
  /** List available blocks from all configured registries. */
47
42
  listAvailableBlocks?: (query?: string) => Promise<unknown[]>;
48
43
  /** Show a block to the user: the application's window navigates to it. */
@@ -66,9 +61,12 @@ export interface PlMcpServerCallbacks {
66
61
  }>;
67
62
  /** Disconnect from current server. */
68
63
  disconnect?: () => Promise<void>;
69
- /** Get detailed info about a specific block package. */
64
+ /**
65
+ * Get detailed info about a specific block package. `registry` is what the agent gave: the
66
+ * `registryId` list_available_blocks returns, or the address of a remote registry.
67
+ */
70
68
  getBlockInfo?: (
71
- registryUrl: string,
69
+ registry: string,
72
70
  organization: string,
73
71
  name: string,
74
72
  version: string,
@@ -115,7 +113,10 @@ export interface PlMcpServerOptions {
115
113
  /**
116
114
  * How long, in milliseconds, the server keeps holding a project after the last tool call on it
117
115
  * ended. Holding keeps the project loaded, so the next call does not load it again; the price is
118
- * the project's maintenance loop running meanwhile. Default {@link DEFAULT_PROJECT_IDLE_RELEASE_MS}.
116
+ * the project's maintenance loop running meanwhile. A project whose blocks still have files to
117
+ * upload is held on while the uploads move; after 5 idle times in a row with no byte uploaded
118
+ * (15 minutes at the default) it is let go, and the log says so. Default
119
+ * {@link DEFAULT_PROJECT_IDLE_RELEASE_MS}.
119
120
  */
120
121
  projectIdleReleaseMs?: number;
121
122
  }
@@ -140,6 +141,14 @@ export class PlMcpServer {
140
141
  private readonly log: ServerLog | undefined;
141
142
  /** The server's holds on the projects its tools work on. */
142
143
  private readonly holds: ProjectHolds<Project>;
144
+ /**
145
+ * The tables agents built with create_table. A table goes with the server's hold on its
146
+ * project, at the latest.
147
+ */
148
+ private readonly agentTables = new AgentTables({
149
+ idleMs: AGENT_TABLE_IDLE_MS,
150
+ maxTables: MAX_AGENT_TABLES,
151
+ });
143
152
 
144
153
  constructor(options: PlMcpServerOptions) {
145
154
  this.ml = options.middleLayer ?? null;
@@ -160,17 +169,28 @@ export class PlMcpServer {
160
169
  // Every hold the server takes carries this label, so the middle layer can tell them from the
161
170
  // holds of the application and of other servers.
162
171
  const projectHolder = asProjectHolder(`mcp:${instanceId}`);
163
- this.holds = new ProjectHolds<Project>({
172
+ // The agent tables of a project go with the server's hold on it, but not under a call still
173
+ // running on the project.
174
+ this.holds = projectHoldsWithTables<Project>(this.agentTables, {
164
175
  holder: projectHolder,
165
176
  idleMs: options.projectIdleReleaseMs ?? DEFAULT_PROJECT_IDLE_RELEASE_MS,
166
177
  onRelease: (projectId, reason) => this.log?.projectReleased(projectId, reason),
178
+ // Q-002: an upload runs only while its project is loaded, so a project with files still
179
+ // uploading stays held after the agent's last call, while the uploads move.
180
+ pendingWork: async (_projectId, project) => {
181
+ const uploads = await pendingUploadsOfProject(project);
182
+ return { count: uploads.count, progress: uploads.bytesProcessed };
183
+ },
184
+ onKeep: (projectId, reason, pending) => this.log?.projectKept(projectId, reason, pending),
167
185
  });
168
186
  this.toolContext = {
169
187
  getMl: () => this.ml,
170
188
  requireMl: () => this.requireMl(),
171
189
  resolveProject: (id) => this.resolveProject(id),
172
190
  withProject: (id, fn) => this.withProject(id, fn),
191
+ agentTables: this.agentTables,
173
192
  projectHolder,
193
+ callsInFlight: (projectId) => this.holds.callsInFlight(projectId),
174
194
  callbacks: this.callbacks,
175
195
  getAuthorMarker: authorMarkerSource(instanceId),
176
196
  };
@@ -182,7 +202,10 @@ export class PlMcpServer {
182
202
  */
183
203
  setMiddleLayer(ml: MiddleLayer | null | undefined) {
184
204
  const next = ml ?? null;
185
- if (next !== this.ml) this.holds.releaseAll();
205
+ if (next !== this.ml) {
206
+ this.holds.releaseAll();
207
+ this.agentTables.releaseAll();
208
+ }
186
209
  this.ml = next;
187
210
  }
188
211
 
@@ -286,6 +309,7 @@ export class PlMcpServer {
286
309
 
287
310
  async stop(): Promise<void> {
288
311
  this.holds.releaseAll();
312
+ this.agentTables.releaseAll();
289
313
  const handler = this.handler;
290
314
  this.handler = undefined;
291
315
  await handler?.close();
@@ -332,27 +356,29 @@ export class PlMcpServer {
332
356
  return this.ml;
333
357
  }
334
358
 
335
- /** Resolves a project from the list by its projectId. */
336
- private async resolveProject(projectId: ProjectId) {
337
- const ml = this.requireMl();
338
- await ml.projectList.refreshState();
339
- const projects = await ml.projectList.awaitStableValue();
340
- const entry = projects.find((p) => p.id === projectId);
359
+ /**
360
+ * Resolves a project from the list by its projectId: the list as the middle layer last read it,
361
+ * read again from the backend only when the project is not in it (see {@link findListedProject}).
362
+ */
363
+ private async resolveProject(projectId: ProjectId, ml: MiddleLayer = this.requireMl()) {
364
+ const entry = await findListedProject(ml.projectList, projectId);
341
365
  if (!entry) throw new Error(`Project ${projectId} not found`);
342
366
  return entry;
343
367
  }
344
368
 
345
369
  /**
346
370
  * Runs `fn` on the project, loading it when nobody holds it. The project is held while `fn`
347
- * runs, so nothing else can destroy it under the call, and for the idle time after.
371
+ * runs, so nothing else can destroy it under the call, and for the idle time after. `fn` is
372
+ * also given the middle layer the project is of.
348
373
  */
349
374
  private async withProject<T>(
350
375
  projectId: ProjectId,
351
- fn: (project: Project) => Promise<T>,
376
+ fn: (project: Project, ml: MiddleLayer) => Promise<T>,
352
377
  ): Promise<T> {
378
+ // The project and what `fn` is given of the middle layer come from the same one.
353
379
  const ml = this.requireMl();
354
- const entry = await this.resolveProject(projectId);
355
- return await this.holds.use(ml, entry.id, fn);
380
+ const entry = await this.resolveProject(projectId, ml);
381
+ return await this.holds.use(ml, entry.id, (project) => fn(project, ml));
356
382
  }
357
383
  }
358
384
 
@@ -362,12 +388,14 @@ function registerAllTools(tools: ToolRegistrar, ctx: ToolContext): void {
362
388
  registerConnectionTools(tools, ctx);
363
389
  registerProjectTools(tools, ctx);
364
390
  registerBlockTools(tools, ctx);
391
+ registerBlockUpdateTools(tools, ctx);
365
392
  registerBlockParamsTools(tools, ctx);
366
393
  registerBlockStateTools(tools, ctx);
367
394
  registerBlockActionContextTools(tools, ctx);
368
395
  registerAwaitTools(tools, ctx);
369
396
  registerLogTools(tools, ctx);
370
397
  registerDataQueryTools(tools, ctx);
371
- registerScreenshotTool(tools, ctx);
372
- registerUIInteractionTools(tools, ctx);
398
+ registerFileTools(tools, ctx);
399
+ registerResultPoolTools(tools, ctx);
400
+ registerAgentTableTools(tools, ctx);
373
401
  }