@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
@@ -0,0 +1,383 @@
1
+ import { tmpdir } from "node:os";
2
+ import { join } from "node:path";
3
+ import { Client, StreamableHTTPClientTransport } from "@modelcontextprotocol/client";
4
+ import { afterEach, describe, expect, test } from "vitest";
5
+ import type { McpSecret, PlMcpServerCallbacks, PlMcpServerOptions } from "./server";
6
+ import { PlMcpServer } from "./server";
7
+ import type { RecordingLogger } from "./test/recording-logger";
8
+ import { recordingLogger } from "./test/recording-logger";
9
+
10
+ const secret = "5ec7e75ec7e75ec7e75ec7e75ec7e7aa" as McpSecret;
11
+
12
+ /** The two ways a client talks to the server; see `server.test.ts`. */
13
+ const eras = [
14
+ { era: "modern", mode: { pin: "2026-07-28" } },
15
+ { era: "legacy", mode: "legacy" },
16
+ ] as const;
17
+
18
+ type Era = (typeof eras)[number];
19
+ type CallToolResult = Awaited<ReturnType<Client["callTool"]>>;
20
+
21
+ const started: { server: PlMcpServer; clients: Client[] }[] = [];
22
+
23
+ afterEach(async () => {
24
+ for (const { server, clients } of started.splice(0)) {
25
+ for (const client of clients) await client.close();
26
+ await server.stop();
27
+ }
28
+ });
29
+
30
+ /** A running server with no backend behind it. Stopped after the test, unless it stops it itself. */
31
+ async function start(options: Partial<PlMcpServerOptions> = {}) {
32
+ const server = new PlMcpServer({ port: 0, secret, ...options });
33
+ const entry: (typeof started)[number] = { server, clients: [] };
34
+ started.push(entry);
35
+ await server.start();
36
+ const connect = async ({ mode }: Era = eras[0]): Promise<Client> => {
37
+ const client = new Client(
38
+ { name: "test-client", version: "1.0.0" },
39
+ { versionNegotiation: { mode } },
40
+ );
41
+ entry.clients.push(client);
42
+ await client.connect(new StreamableHTTPClientTransport(new URL(server.url)));
43
+ return client;
44
+ };
45
+ return { server, connect };
46
+ }
47
+
48
+ /** A running server that writes to a recording logger. */
49
+ async function startLogged(callbacks?: PlMcpServerCallbacks) {
50
+ const recorded: RecordingLogger = recordingLogger();
51
+ return { ...(await start({ logger: recorded.logger, callbacks })), ...recorded };
52
+ }
53
+
54
+ /** The lines about tool calls, without the server's own. */
55
+ function callLines(recorded: Pick<RecordingLogger, "lines">) {
56
+ return recorded.lines.filter((line) => line.text.startsWith("mcp-call"));
57
+ }
58
+
59
+ const port = (server: PlMcpServer): string => new URL(server.url).port;
60
+
61
+ /** Headers of a request the MCP handler refuses and reports: its body is not JSON. */
62
+ const notJson = { "Content-Type": "text/plain" };
63
+
64
+ describe.each(eras)("a tool call of a $era client", (era) => {
65
+ test("that succeeds is written as one info line", async () => {
66
+ const { connect, lines } = await startLogged();
67
+ const client = await connect(era);
68
+
69
+ const result = await client.callTool({ name: "ping", arguments: {} });
70
+
71
+ await client.close();
72
+
73
+ expect(result.isError).not.toBe(true);
74
+ // Nothing but the start of the server and the call: an ordinary session of a client of either
75
+ // era, from connecting to closing, makes the MCP handler report no error.
76
+ expect(lines.slice(1)).toEqual([
77
+ {
78
+ level: "info",
79
+ text: expect.stringMatching(
80
+ /^mcp-call call=mcp-[0-9a-f]{8}#1 tool=ping argsBytes=0 ms=\d+ outcome=ok resultBytes=\d+ inflight=0$/,
81
+ ),
82
+ },
83
+ ]);
84
+ });
85
+
86
+ test("that throws is written with the error the client was not shown", async () => {
87
+ const { connect, lines } = await startLogged();
88
+ const client = await connect(era);
89
+
90
+ const result = await client.callTool({
91
+ name: "set_block_data",
92
+ arguments: { projectId: "p-1", blockId: "b-1", data: { numbers: [1, 2, 3] } },
93
+ });
94
+
95
+ // The client gets the message only.
96
+ expect(result.isError).toBe(true);
97
+ expect(result.content).toEqual([
98
+ { type: "text", text: "Not connected to a server. Use connect_to_server first." },
99
+ ]);
100
+ const [info, error, ...rest] = callLines({ lines });
101
+ expect(rest).toEqual([]);
102
+ expect(info).toEqual({
103
+ level: "info",
104
+ text: expect.stringMatching(
105
+ /^mcp-call call=mcp-[0-9a-f]{8}#1 tool=set_block_data project=p-1 block=b-1 argsBytes=\d+ ms=\d+ outcome=thrown resultBytes=0 inflight=0$/,
106
+ ),
107
+ });
108
+ expect(error?.level).toBe("error");
109
+ expect(error?.text).toMatch(
110
+ /^mcp-call-failed call=mcp-[0-9a-f]{8}#1 tool=set_block_data project=p-1 block=b-1 outcome=thrown argKeys=projectId,blockId,data error="Not connected to a server\. Use connect_to_server first\."\nError: Not connected to a server\. Use connect_to_server first\.\n\s+at .*requireMl/,
111
+ );
112
+ });
113
+
114
+ test("that returns an error is written with the text of the error", async () => {
115
+ const { connect, lines } = await startLogged();
116
+ const client = await connect(era);
117
+
118
+ const result = await client.callTool({ name: "capture_screenshot", arguments: {} });
119
+
120
+ expect(result.isError).toBe(true);
121
+ const text = JSON.stringify(result.content);
122
+ const [info, error, ...rest] = callLines({ lines });
123
+ expect(rest).toEqual([]);
124
+ expect(info?.text).toMatch(/ tool=capture_screenshot argsBytes=\d+ ms=\d+ outcome=error /);
125
+ expect(error?.level).toBe("error");
126
+ const [head, ...details] = (error?.text ?? "").split("\n");
127
+ expect(head).toMatch(
128
+ /^mcp-call-failed call=\S+ tool=capture_screenshot outcome=error argKeys=/,
129
+ );
130
+ expect(text).toContain(JSON.stringify(details.join("\n")).slice(1, -1));
131
+ });
132
+ });
133
+
134
+ describe("the arguments of a call", () => {
135
+ const password = "correct-horse-battery-staple";
136
+
137
+ test("are written as names and sizes; a password never reaches the log", async () => {
138
+ const seen: (string | undefined)[] = [];
139
+ const { connect, lines, everything } = await startLogged({
140
+ connectToServer: async (_addr, login, given) => {
141
+ seen.push(given);
142
+ throw new Error(`login ${login} with ${given} refused`);
143
+ },
144
+ });
145
+ const client = await connect();
146
+
147
+ const result = await client.callTool({
148
+ name: "connect_to_server",
149
+ arguments: { addr: "https://pl.example.org:6345", login: "someone@example.org", password },
150
+ });
151
+
152
+ // The handler did get the password; the log did not.
153
+ expect(result.isError).toBe(true);
154
+ expect(seen).toEqual([password]);
155
+ expect(callLines({ lines }).map((line) => line.level)).toEqual(["info", "error"]);
156
+ const written = everything();
157
+ expect(written).not.toContain(password);
158
+ expect(written).toContain("argKeys=addr,login,password");
159
+ expect(written).toContain("login someone@example.org with <secret> refused");
160
+ });
161
+ });
162
+
163
+ describe("a screenshot that cannot be saved", () => {
164
+ test("is reported with the error of the file system, to the agent and in the log", async () => {
165
+ const { connect, lines, at } = await startLogged({
166
+ captureScreenshot: async () => Buffer.from("not a png").toString("base64"),
167
+ });
168
+ const client = await connect();
169
+ const folder = join(tmpdir(), `missing-folder-${process.pid}-${Date.now()}`);
170
+
171
+ const result = await client.callTool({
172
+ name: "capture_screenshot",
173
+ arguments: { savePath: join(folder, "result.png") },
174
+ });
175
+
176
+ expect(result.isError).toBe(true);
177
+ expect(result.content).toEqual([
178
+ {
179
+ type: "text",
180
+ text: expect.stringMatching(/^Could not save the screenshot: ENOENT: .*result\.png/),
181
+ },
182
+ ]);
183
+ expect(callLines({ lines }).map((line) => line.level)).toEqual(["info", "error"]);
184
+ expect(at("error")[0]).toContain("ENOENT");
185
+ });
186
+ });
187
+
188
+ describe("the tools of the server", () => {
189
+ /** Arguments that pass a tool's schema where plain values are enough for it. */
190
+ function sampleArguments(schema: {
191
+ properties?: Record<string, unknown>;
192
+ required?: string[];
193
+ }): Record<string, unknown> {
194
+ const samples: Record<string, unknown> = { string: "x", number: 1, integer: 1, boolean: false };
195
+ const args: Record<string, unknown> = {};
196
+ for (const name of schema.required ?? []) {
197
+ const property = schema.properties?.[name];
198
+ const type =
199
+ typeof property === "object" && property !== null && "type" in property
200
+ ? property.type
201
+ : undefined;
202
+ args[name] = typeof type === "string" && type in samples ? samples[type] : {};
203
+ }
204
+ return args;
205
+ }
206
+
207
+ const text = (result: CallToolResult): string => JSON.stringify(result.content);
208
+
209
+ test("are all logged: every call that reaches a handler writes its line", async () => {
210
+ const { connect, lines } = await startLogged();
211
+ const client = await connect();
212
+ const { tools } = await client.listTools();
213
+
214
+ const reached: string[] = [];
215
+ const refused: string[] = [];
216
+ for (const tool of tools) {
217
+ const result = await client.callTool({
218
+ name: tool.name,
219
+ arguments: sampleArguments(tool.inputSchema),
220
+ });
221
+ if (text(result).includes("Input validation error")) refused.push(tool.name);
222
+ else reached.push(tool.name);
223
+ }
224
+
225
+ const logged = callLines({ lines })
226
+ .filter((line) => line.level === "info")
227
+ .map((line) => / tool=(\S+) /.exec(line.text)?.[1]);
228
+ expect(logged).toEqual(reached);
229
+ // Only the tools whose arguments are more than plain values are not reached this way.
230
+ expect(refused).toEqual(["add_block", "update_block", "reorder_blocks"]);
231
+ expect(reached).toHaveLength(tools.length - 3);
232
+ });
233
+
234
+ test("a call refused before its handler writes no line", async () => {
235
+ const { connect, lines } = await startLogged();
236
+ const client = await connect();
237
+
238
+ const result = await client.callTool({
239
+ name: "get_project_overview",
240
+ arguments: { projectId: 5 },
241
+ });
242
+
243
+ expect(text(result)).toContain("Input validation error");
244
+ expect(callLines({ lines })).toEqual([]);
245
+ });
246
+ });
247
+
248
+ describe("calls of one server", () => {
249
+ test("share one counter and one instance id, across clients and requests", async () => {
250
+ const { connect, lines } = await startLogged();
251
+ const [modern, legacy] = await Promise.all(eras.map((era) => connect(era)));
252
+
253
+ await modern?.callTool({ name: "ping", arguments: {} });
254
+ await legacy?.callTool({ name: "ping", arguments: {} });
255
+ await modern?.callTool({ name: "ping", arguments: {} });
256
+
257
+ const ids = callLines({ lines }).map((line) => /call=(mcp-[0-9a-f]{8})#(\d+) /.exec(line.text));
258
+ expect(ids.map((id) => id?.[2])).toEqual(["1", "2", "3"]);
259
+ expect(new Set(ids.map((id) => id?.[1])).size).toBe(1);
260
+ });
261
+
262
+ test("served at the same time say how many were in flight", async () => {
263
+ const release: (() => void)[] = [];
264
+ const { connect, lines } = await startLogged({
265
+ // Holds every call of `get_connection_status` until the test lets it go.
266
+ getConnectionStatus: () =>
267
+ new Promise((resolve) => release.push(() => resolve({ connected: false }))),
268
+ });
269
+ const client = await connect();
270
+
271
+ const calls = [1, 2, 3].map(() =>
272
+ client.callTool({ name: "get_connection_status", arguments: {} }),
273
+ );
274
+ await expect.poll(() => release.length).toBe(3);
275
+ for (const letGo of release) letGo();
276
+ await Promise.all(calls);
277
+
278
+ const inFlight = callLines({ lines }).map((line) => / inflight=(\d+)/.exec(line.text)?.[1]);
279
+ expect(inFlight.toSorted()).toEqual(["0", "1", "2"]);
280
+ });
281
+ });
282
+
283
+ describe("a logger that throws", () => {
284
+ test("changes no answer of the server", async () => {
285
+ const fail = () => {
286
+ throw new Error("the log file is gone");
287
+ };
288
+ const { connect: connectBroken } = await start({
289
+ logger: { info: fail, warn: fail, error: fail },
290
+ });
291
+ const { connect: connectSilent } = await start();
292
+ const broken = await connectBroken();
293
+ const silent = await connectSilent();
294
+
295
+ for (const call of [
296
+ { name: "ping", arguments: {} },
297
+ { name: "capture_screenshot", arguments: {} },
298
+ { name: "get_project_overview", arguments: { projectId: "p-1" } },
299
+ { name: "get_project_overview", arguments: { projectId: 5 } },
300
+ ]) {
301
+ const answer = await broken.callTool(call);
302
+ expect(answer).toEqual(await silent.callTool(call));
303
+ expect(answer.content).not.toEqual([]);
304
+ }
305
+ expect((await broken.listTools()).tools).toEqual((await silent.listTools()).tools);
306
+ });
307
+ });
308
+
309
+ describe("a server given no logger", () => {
310
+ test("answers the same as one that logs", async () => {
311
+ const logged = await startLogged();
312
+ const { connect } = await start();
313
+ const withLog = await logged.connect();
314
+ const without = await connect();
315
+
316
+ for (const call of [
317
+ { name: "ping", arguments: {} },
318
+ { name: "capture_screenshot", arguments: {} },
319
+ { name: "get_project_overview", arguments: { projectId: "p-1" } },
320
+ ])
321
+ expect(await without.callTool(call)).toEqual(await withLog.callTool(call));
322
+ expect(callLines(logged)).toHaveLength(5);
323
+ });
324
+ });
325
+
326
+ describe("the server's own lines", () => {
327
+ test("say when it started and stopped, with the port and without the secret", async () => {
328
+ const { server, connect, lines } = await startLogged();
329
+ const listeningOn = port(server);
330
+ const client = await connect();
331
+ await client.callTool({ name: "ping", arguments: {} });
332
+ await client.close();
333
+ await server.stop();
334
+
335
+ expect(lines[0]).toEqual({
336
+ level: "info",
337
+ text: expect.stringMatching(
338
+ new RegExp(
339
+ `^mcp-server-start id=mcp-[0-9a-f]{8} port=${listeningOn} ` +
340
+ `url="http://127\\.0\\.0\\.1:${listeningOn}/<secret>/mcp" version=\\d+\\.\\d+\\.\\d+$`,
341
+ ),
342
+ ),
343
+ });
344
+ expect(lines.at(-1)).toEqual({
345
+ level: "info",
346
+ text: expect.stringMatching(
347
+ new RegExp(`^mcp-server-stop id=mcp-[0-9a-f]{8} port=${listeningOn} calls=1 inflight=0$`),
348
+ ),
349
+ });
350
+ });
351
+
352
+ test("never hold the secret, whatever was asked of the server", async () => {
353
+ const { server, connect, lines, everything } = await startLogged();
354
+ const client = await connect();
355
+
356
+ await client.callTool({ name: "ping", arguments: {} });
357
+ await client.callTool({ name: "get_project_overview", arguments: { projectId: secret } });
358
+ await client.callTool({ name: "capture_screenshot", arguments: {} });
359
+ await fetch(server.url, { method: "POST", headers: notJson, body: "ping" });
360
+ await fetch(server.url, { method: "GET" });
361
+ await client.close();
362
+ await server.stop();
363
+
364
+ expect(lines.length).toBeGreaterThanOrEqual(7);
365
+ expect(server.url).toContain(secret);
366
+ expect(everything()).not.toContain(secret);
367
+ });
368
+ });
369
+
370
+ describe("a failure outside a tool handler", () => {
371
+ test("that the MCP handler reports reaches the logger", async () => {
372
+ const { server, at } = await startLogged();
373
+
374
+ const answer = await fetch(server.url, { method: "POST", headers: notJson, body: "ping" });
375
+
376
+ expect(answer.status).toBe(415);
377
+ expect(at("error")).toEqual([
378
+ expect.stringMatching(
379
+ /^mcp-sdk-error id=mcp-[0-9a-f]{8} error="Unsupported Media Type: [^"]+"\nError: Unsupported Media Type: .*\n\s+at /,
380
+ ),
381
+ ]);
382
+ });
383
+ });
@@ -0,0 +1,49 @@
1
+ import { expect, test, vi } from "vitest";
2
+ import type { McpSecret } from "./server";
3
+ import { PlMcpServer } from "./server";
4
+ import { recordingLogger } from "./test/recording-logger";
5
+
6
+ // The part of the server that turns an HTTP request into an MCP exchange, made to fail the way
7
+ // nothing in the server's own code does: outside the MCP handler, which reports its own failures.
8
+ vi.mock("@modelcontextprotocol/node", () => ({
9
+ toNodeHandler: () => async () => {
10
+ throw new Error("Cannot read the request", { cause: new Error("socket closed") });
11
+ },
12
+ }));
13
+
14
+ const secret = "5ec7e75ec7e75ec7e75ec7e75ec7e7aa" as McpSecret;
15
+
16
+ test("a request that fails outside the MCP handler is answered 500 and written to the log", async () => {
17
+ const { logger, lines, everything } = recordingLogger();
18
+ const server = new PlMcpServer({ port: 0, secret, logger });
19
+ await server.start();
20
+ try {
21
+ const answer = await fetch(server.url, { method: "POST", body: "{}" });
22
+
23
+ expect(answer.status).toBe(500);
24
+ expect(await answer.json()).toEqual({ error: "Internal Server Error" });
25
+ expect(lines.filter((line) => line.level === "error")).toEqual([
26
+ {
27
+ level: "error",
28
+ text: expect.stringMatching(
29
+ /^mcp-request-failed id=mcp-[0-9a-f]{8} method=POST status=500 error="Cannot read the request"\nError: Cannot read the request\n\s+at [^]*\n\s+\[cause\]: Error: socket closed\n\s+at /,
30
+ ),
31
+ },
32
+ ]);
33
+ expect(everything()).not.toContain(secret);
34
+ } finally {
35
+ await server.stop();
36
+ }
37
+ });
38
+
39
+ test("without a logger the same request is answered 500 all the same", async () => {
40
+ const server = new PlMcpServer({ port: 0, secret });
41
+ await server.start();
42
+ try {
43
+ const answer = await fetch(server.url, { method: "POST", body: "{}" });
44
+
45
+ expect(answer.status).toBe(500);
46
+ } finally {
47
+ await server.stop();
48
+ }
49
+ });
@@ -75,7 +75,7 @@ describe.each(eras)("to a $era client", (era) => {
75
75
 
76
76
  test("sends instructions that fit the length clients keep", () => {
77
77
  const instructions = client.getInstructions() ?? "";
78
- expect(instructions).toContain("open_project");
78
+ expect(instructions).toContain("list_projects");
79
79
  expect(instructions.length).toBeGreaterThan(0);
80
80
  expect(instructions.length).toBeLessThanOrEqual(4096);
81
81
  });
@@ -87,6 +87,15 @@ describe.each(eras)("to a $era client", (era) => {
87
87
  expect(mentioned.filter((name) => !known.has(name))).toEqual([]);
88
88
  });
89
89
 
90
+ // A project is loaded by whatever tool needs it; an agent is never asked to open one.
91
+ test("nothing it says asks for a project to be opened", () => {
92
+ const said = [
93
+ client.getInstructions() ?? "",
94
+ ...tools.map((tool) => JSON.stringify(tool)),
95
+ ].join("\n");
96
+ expect(said).not.toMatch(/open_project|close_project|\bopened\b|must be open/i);
97
+ });
98
+
90
99
  test("says its set of tools does not change", () => {
91
100
  expect(client.getServerCapabilities()?.tools).toEqual({ listChanged: false });
92
101
  });
@@ -183,7 +192,6 @@ describe.each(eras)("to a $era client", (era) => {
183
192
  "await_block_done",
184
193
  "capture_screenshot",
185
194
  "click",
186
- "close_project",
187
195
  "connect_to_server",
188
196
  "create_project",
189
197
  "delete_project",
@@ -202,7 +210,6 @@ describe.each(eras)("to a $era client", (era) => {
202
210
  "list_columns",
203
211
  "list_connections",
204
212
  "list_projects",
205
- "open_project",
206
213
  "ping",
207
214
  "press_key",
208
215
  "query_table",
@@ -229,7 +236,7 @@ describe.each(eras)("to a $era client", (era) => {
229
236
 
230
237
  test("required arguments are the ones without `optional` or a default", () => {
231
238
  expect(inputSchemaOf("add_block").required).toEqual(["projectId", "label", "spec"]);
232
- expect(inputSchemaOf("open_project").required).toEqual(["projectId"]);
239
+ expect(inputSchemaOf("get_project_overview").required).toEqual(["projectId"]);
233
240
  });
234
241
 
235
242
  test("an optional argument keeps its description", () => {
@@ -251,7 +258,10 @@ describe.each(eras)("to a $era client", (era) => {
251
258
  });
252
259
 
253
260
  test("arguments of the wrong type are refused before the tool runs", async () => {
254
- const result = await client.callTool({ name: "open_project", arguments: { projectId: 5 } });
261
+ const result = await client.callTool({
262
+ name: "get_project_overview",
263
+ arguments: { projectId: 5 },
264
+ });
255
265
  expect(result.isError).toBe(true);
256
266
  expect(JSON.stringify(result.content)).toContain("Input validation error");
257
267
  });