@milaboratories/pl-mcp-server 52.0.0 → 52.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/dist/index.d.ts +2 -1
  2. package/dist/instructions.cjs +27 -0
  3. package/dist/instructions.cjs.map +1 -0
  4. package/dist/instructions.js +27 -0
  5. package/dist/instructions.js.map +1 -0
  6. package/dist/package.cjs +10 -0
  7. package/dist/package.cjs.map +1 -0
  8. package/dist/package.js +5 -0
  9. package/dist/package.js.map +1 -0
  10. package/dist/server.cjs +43 -41
  11. package/dist/server.cjs.map +1 -1
  12. package/dist/server.d.ts +15 -9
  13. package/dist/server.d.ts.map +1 -1
  14. package/dist/server.js +42 -40
  15. package/dist/server.js.map +1 -1
  16. package/dist/tools/await.cjs +7 -4
  17. package/dist/tools/await.cjs.map +1 -1
  18. package/dist/tools/await.js +8 -5
  19. package/dist/tools/await.js.map +1 -1
  20. package/dist/tools/block-action-context.cjs +7 -4
  21. package/dist/tools/block-action-context.cjs.map +1 -1
  22. package/dist/tools/block-action-context.js +8 -5
  23. package/dist/tools/block-action-context.js.map +1 -1
  24. package/dist/tools/block-state.cjs +17 -10
  25. package/dist/tools/block-state.cjs.map +1 -1
  26. package/dist/tools/block-state.js +18 -11
  27. package/dist/tools/block-state.js.map +1 -1
  28. package/dist/tools/blocks.cjs +55 -33
  29. package/dist/tools/blocks.cjs.map +1 -1
  30. package/dist/tools/blocks.js +56 -34
  31. package/dist/tools/blocks.js.map +1 -1
  32. package/dist/tools/connection.cjs +23 -6
  33. package/dist/tools/connection.cjs.map +1 -1
  34. package/dist/tools/connection.js +24 -7
  35. package/dist/tools/connection.js.map +1 -1
  36. package/dist/tools/data-query.cjs +14 -7
  37. package/dist/tools/data-query.cjs.map +1 -1
  38. package/dist/tools/data-query.js +15 -8
  39. package/dist/tools/data-query.js.map +1 -1
  40. package/dist/tools/ids.cjs +14 -0
  41. package/dist/tools/ids.cjs.map +1 -0
  42. package/dist/tools/ids.js +13 -0
  43. package/dist/tools/ids.js.map +1 -0
  44. package/dist/tools/logs.cjs +11 -6
  45. package/dist/tools/logs.cjs.map +1 -1
  46. package/dist/tools/logs.js +12 -7
  47. package/dist/tools/logs.js.map +1 -1
  48. package/dist/tools/ping.cjs +5 -1
  49. package/dist/tools/ping.cjs.map +1 -1
  50. package/dist/tools/ping.js +6 -2
  51. package/dist/tools/ping.js.map +1 -1
  52. package/dist/tools/projects.cjs +20 -7
  53. package/dist/tools/projects.cjs.map +1 -1
  54. package/dist/tools/projects.js +21 -8
  55. package/dist/tools/projects.js.map +1 -1
  56. package/dist/tools/screenshot.cjs +3 -1
  57. package/dist/tools/screenshot.cjs.map +1 -1
  58. package/dist/tools/screenshot.js +4 -2
  59. package/dist/tools/screenshot.js.map +1 -1
  60. package/dist/tools/types.cjs +51 -0
  61. package/dist/tools/types.cjs.map +1 -1
  62. package/dist/tools/types.js +50 -1
  63. package/dist/tools/types.js.map +1 -1
  64. package/dist/tools/ui-interaction.cjs +27 -13
  65. package/dist/tools/ui-interaction.cjs.map +1 -1
  66. package/dist/tools/ui-interaction.js +28 -14
  67. package/dist/tools/ui-interaction.js.map +1 -1
  68. package/package.json +11 -9
  69. package/src/index.ts +1 -0
  70. package/src/instructions.ts +23 -0
  71. package/src/server.test.ts +631 -0
  72. package/src/server.ts +63 -58
  73. package/src/tools/await.ts +9 -6
  74. package/src/tools/block-action-context.ts +9 -6
  75. package/src/tools/block-state.ts +21 -14
  76. package/src/tools/blocks.ts +58 -36
  77. package/src/tools/connection.ts +38 -17
  78. package/src/tools/data-query.ts +17 -10
  79. package/src/tools/ids.ts +11 -0
  80. package/src/tools/logs.ts +13 -8
  81. package/src/tools/ping.ts +14 -5
  82. package/src/tools/projects.ts +26 -11
  83. package/src/tools/screenshot.ts +7 -5
  84. package/src/tools/types.test.ts +19 -0
  85. package/src/tools/types.ts +71 -3
  86. package/src/tools/ui-interaction.ts +29 -18
package/src/server.ts CHANGED
@@ -1,10 +1,13 @@
1
- import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
- import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
1
+ import { toNodeHandler } from "@modelcontextprotocol/node";
2
+ import { createMcpHandler, McpServer, type McpHttpHandler } from "@modelcontextprotocol/server";
3
3
  import { createServer, type IncomingMessage, type Server, type ServerResponse } from "node:http";
4
4
  import { randomUUID } from "node:crypto";
5
5
  import type { MiddleLayer } from "@milaboratories/pl-middle-layer";
6
- import type { Branded } from "@milaboratories/pl-model-common";
6
+ import type { BlockId, Branded, ProjectId } from "@milaboratories/pl-model-common";
7
+ import { version } from "../package.json";
8
+ import { SERVER_INSTRUCTIONS } from "./instructions";
7
9
  import type { ToolContext } from "./tools/types";
10
+ import { authorMarkerSource } from "./tools/types";
8
11
  import { registerPingTool } from "./tools/ping";
9
12
  import { registerConnectionTools } from "./tools/connection";
10
13
  import { registerProjectTools } from "./tools/projects";
@@ -18,10 +21,10 @@ import { registerScreenshotTool } from "./tools/screenshot";
18
21
  import { registerUIInteractionTools } from "./tools/ui-interaction";
19
22
 
20
23
  export interface PlMcpServerCallbacks {
21
- onProjectCreated?: (projectId: string) => void | Promise<void>;
22
- onProjectOpened?: (projectId: string) => void | Promise<void>;
23
- onProjectClosed?: (projectId: string) => void | Promise<void>;
24
- onProjectDeleted?: (projectId: string) => void | Promise<void>;
24
+ onProjectCreated?: (projectId: ProjectId) => void | Promise<void>;
25
+ onProjectOpened?: (projectId: ProjectId) => void | Promise<void>;
26
+ onProjectClosed?: (projectId: ProjectId) => void | Promise<void>;
27
+ onProjectDeleted?: (projectId: ProjectId) => void | Promise<void>;
25
28
  /** Capture the current application window as a PNG screenshot. Returns base64-encoded PNG. */
26
29
  captureScreenshot?: () => Promise<string>;
27
30
  /** Send an input event to the application window. */
@@ -34,12 +37,12 @@ export interface PlMcpServerCallbacks {
34
37
  */
35
38
  executeJavaScript?: (
36
39
  code: string,
37
- target?: { projectId: string; blockId: string },
40
+ target?: { projectId: ProjectId; blockId: BlockId },
38
41
  ) => Promise<unknown>;
39
42
  /** List available blocks from all configured registries. */
40
43
  listAvailableBlocks?: (query?: string) => Promise<unknown[]>;
41
44
  /** Navigate the desktop UI to show a specific block. */
42
- selectBlock?: (projectId: string, blockId: string) => Promise<void>;
45
+ selectBlock?: (projectId: ProjectId, blockId: BlockId) => Promise<void>;
43
46
  /** Read recent lines from the application log. */
44
47
  readAppLog?: (lines: number, search?: string) => Promise<string>;
45
48
  /** List saved server connections. */
@@ -95,13 +98,27 @@ export class PlMcpServer {
95
98
  private readonly secret: McpSecret;
96
99
  private readonly callbacks: PlMcpServerCallbacks;
97
100
  private httpServer: Server | undefined;
98
- private readonly transports = new Map<string, StreamableHTTPServerTransport>();
101
+ /** Serves the MCP requests of the running HTTP server. */
102
+ private handler: McpHttpHandler | undefined;
103
+ /**
104
+ * What the tools work with. One per server instance, so every write made through MCP carries the
105
+ * same author id, whichever client and connection it came from.
106
+ */
107
+ private readonly toolContext: ToolContext;
99
108
 
100
109
  constructor(options: PlMcpServerOptions) {
101
110
  this.ml = options.middleLayer ?? null;
102
111
  this.port = options.port;
103
112
  this.secret = options.secret;
104
113
  this.callbacks = options.callbacks ?? {};
114
+ this.toolContext = {
115
+ getMl: () => this.ml,
116
+ requireMl: () => this.requireMl(),
117
+ resolveProject: (id) => this.resolveProject(id),
118
+ getOpenedProject: (id) => this.getOpenedProject(id),
119
+ callbacks: this.callbacks,
120
+ getAuthorMarker: authorMarkerSource(`mcp-${randomUUID().slice(0, 8)}`),
121
+ };
105
122
  }
106
123
 
107
124
  /** Set or update the MiddleLayer instance (e.g. after connecting to a server). */
@@ -120,7 +137,18 @@ export class PlMcpServer {
120
137
 
121
138
  const expectedPath = `/${this.secret}/mcp`;
122
139
 
123
- this.httpServer = createServer(async (req: IncomingMessage, res: ServerResponse) => {
140
+ // Nothing is kept between requests: every request is answered by an MCP server made for it.
141
+ // Clients of the 2025 protocol revisions are served the same way, without a session.
142
+ const handler = createMcpHandler(() => this.createMcpServer(), {
143
+ // A tool can hold a request for minutes (a wait for a block). Answering as an event stream
144
+ // with keep-alives is what keeps a client from timing out while it waits for the headers;
145
+ // without this a 2026-07-28 request gets one JSON body, and no bytes until the tool returns.
146
+ responseMode: "sse",
147
+ });
148
+ const serveMcp = toNodeHandler(handler);
149
+ this.handler = handler;
150
+
151
+ const requestHandler = async (req: IncomingMessage, res: ServerResponse): Promise<void> => {
124
152
  try {
125
153
  // Origin validation — only allow localhost
126
154
  if (req.headers.origin !== undefined) {
@@ -145,41 +173,18 @@ export class PlMcpServer {
145
173
  return;
146
174
  }
147
175
 
148
- // Route to existing session transport
149
- const sessionId = req.headers["mcp-session-id"] as string | undefined;
150
- if (sessionId && this.transports.has(sessionId)) {
151
- await this.transports.get(sessionId)!.handleRequest(req, res);
152
- return;
153
- }
154
-
155
- // New session — create transport and connect MCP server
156
- const transport = new StreamableHTTPServerTransport({
157
- sessionIdGenerator: () => randomUUID(),
158
- });
159
- transport.onclose = () => {
160
- const sid = transport.sessionId;
161
- if (sid) this.transports.delete(sid);
162
- };
163
-
164
- const server = this.createMcpServer();
165
- await server.connect(transport);
166
- await transport.handleRequest(req, res);
167
-
168
- const sid = transport.sessionId;
169
- if (sid) this.transports.set(sid, transport);
176
+ await serveMcp(req, res);
170
177
  } catch {
171
178
  if (!res.headersSent) {
172
179
  res.writeHead(500, { "Content-Type": "application/json" });
173
180
  res.end(JSON.stringify({ error: "Internal Server Error" }));
174
181
  }
175
182
  }
176
- });
183
+ };
184
+
185
+ this.httpServer = createServer(requestHandler);
177
186
 
178
187
  const maxRetries = 10;
179
- const requestHandler = this.httpServer.listeners("request")[0] as (
180
- req: IncomingMessage,
181
- res: ServerResponse,
182
- ) => void;
183
188
  for (let attempt = 0; attempt < maxRetries; attempt++) {
184
189
  const server = this.httpServer;
185
190
  try {
@@ -205,44 +210,44 @@ export class PlMcpServer {
205
210
  this.port++;
206
211
  continue;
207
212
  }
213
+ // Nothing is listening: leave the instance as it was before the call, so that `stop()`
214
+ // has nothing to close and a later `start()` is not refused as already running.
215
+ this.httpServer = undefined;
216
+ this.handler = undefined;
208
217
  throw err;
209
218
  }
210
219
  }
211
220
  }
212
221
 
213
222
  async stop(): Promise<void> {
214
- for (const transport of this.transports.values()) {
215
- await transport.close();
216
- }
217
- this.transports.clear();
223
+ const handler = this.handler;
224
+ this.handler = undefined;
225
+ await handler?.close();
218
226
 
219
227
  const server = this.httpServer;
220
228
  if (server) {
221
229
  await new Promise<void>((resolve, reject) => {
222
230
  server.close((err) => (err ? reject(err) : resolve()));
231
+ // Requests still being answered would keep the server open until they finish, and a
232
+ // request waiting for a block can take long.
233
+ server.closeAllConnections();
223
234
  });
224
235
  this.httpServer = undefined;
225
236
  }
226
237
  }
227
238
 
228
239
  private createMcpServer(): McpServer {
229
- const sessionId = randomUUID().slice(0, 8);
230
- const server = new McpServer({ name: "pl", version: "0.1.0" }, { capabilities: { tools: {} } });
231
- this.registerTools(server, sessionId);
240
+ const server = new McpServer(
241
+ { name: "pl", title: "Platforma", version },
242
+ // The set of tools never changes while the server runs.
243
+ { capabilities: { tools: { listChanged: false } }, instructions: SERVER_INSTRUCTIONS },
244
+ );
245
+ this.registerTools(server);
232
246
  return server;
233
247
  }
234
248
 
235
- private registerTools(server: McpServer, sessionId: string): void {
236
- const authorId = `mcp-${sessionId}`;
237
- let localVersion = 0;
238
- const ctx: ToolContext = {
239
- getMl: () => this.ml,
240
- requireMl: () => this.requireMl(),
241
- resolveProject: (id) => this.resolveProject(id),
242
- getOpenedProject: (id) => this.getOpenedProject(id),
243
- callbacks: this.callbacks,
244
- getAuthorMarker: () => ({ authorId, localVersion: ++localVersion }),
245
- };
249
+ private registerTools(server: McpServer): void {
250
+ const ctx = this.toolContext;
246
251
  registerPingTool(server, ctx);
247
252
  registerConnectionTools(server, ctx);
248
253
  registerProjectTools(server, ctx);
@@ -263,7 +268,7 @@ export class PlMcpServer {
263
268
  }
264
269
 
265
270
  /** Resolves a project from the list by its projectId. */
266
- private async resolveProject(projectId: string) {
271
+ private async resolveProject(projectId: ProjectId) {
267
272
  const ml = this.requireMl();
268
273
  await ml.projectList.refreshState();
269
274
  const projects = await ml.projectList.awaitStableValue();
@@ -273,7 +278,7 @@ export class PlMcpServer {
273
278
  }
274
279
 
275
280
  /** Gets an opened project by projectId. */
276
- private async getOpenedProject(projectId: string) {
281
+ private async getOpenedProject(projectId: ProjectId) {
277
282
  const ml = this.requireMl();
278
283
  const entry = await this.resolveProject(projectId);
279
284
  return ml.getOpenedProject(entry.id);
@@ -1,23 +1,26 @@
1
- import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
1
+ import type { McpServer } from "@modelcontextprotocol/server";
2
2
  import { isTimeoutError } from "@milaboratories/pl-middle-layer";
3
3
  import { deriveDataFromStorage } from "@platforma-sdk/model";
4
4
  import { z } from "zod";
5
+ import { projectIdInput, blockIdInput } from "./ids";
5
6
  import type { ToolContext } from "./types";
6
7
  import { summarizeOutputs } from "./tokens";
7
8
  import { safeEval } from "./sandbox";
8
- import { errorResult, textResult } from "./types";
9
+ import { errorResult, hints, textResult } from "./types";
9
10
 
10
11
  export function registerAwaitTools(server: McpServer, ctx: ToolContext): void {
11
12
  server.registerTool(
12
13
  "await_block_done",
13
14
  {
15
+ title: "Wait for Block",
16
+ annotations: hints.read,
14
17
  description:
15
18
  "Wait for a block to finish computation and outputs to stabilize. " +
16
19
  "Returns block status, data, and concise output summary with token estimates. " +
17
20
  "Use `transform` to extract specific data server-side on completion.",
18
- inputSchema: {
19
- projectId: z.string().describe("Project ID"),
20
- blockId: z.string().describe("Block ID to wait for"),
21
+ inputSchema: z.object({
22
+ projectId: projectIdInput.describe("Project ID"),
23
+ blockId: blockIdInput.describe("Block ID to wait for"),
21
24
  timeout: z.number().optional().default(120000).describe("Timeout in ms (default 120000)"),
22
25
  transform: z
23
26
  .string()
@@ -32,7 +35,7 @@ export function registerAwaitTools(server: McpServer, ctx: ToolContext): void {
32
35
  .optional()
33
36
  .default(5000)
34
37
  .describe("Timeout in ms for transform evaluation (default 5000)."),
35
- },
38
+ }),
36
39
  },
37
40
  async ({ projectId, blockId, timeout, transform, transformTimeout }) => {
38
41
  const project = await ctx.getOpenedProject(projectId);
@@ -1,8 +1,9 @@
1
- import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
1
+ import type { McpServer } from "@modelcontextprotocol/server";
2
2
  import type { BlockActionContextNode } from "@milaboratories/pl-middle-layer";
3
3
  import { z } from "zod";
4
+ import { projectIdInput, blockIdInput } from "./ids";
4
5
  import type { ToolContext } from "./types";
5
- import { errorResult, textResult } from "./types";
6
+ import { errorResult, hints, textResult } from "./types";
6
7
 
7
8
  /** An action context tree node as the tool returns it: cut to the requested depth and history. */
8
9
  export type LimitedBlockActionContextNode = Omit<BlockActionContextNode, "children"> & {
@@ -60,6 +61,8 @@ export function registerBlockActionContextTools(server: McpServer, ctx: ToolCont
60
61
  server.registerTool(
61
62
  "get_block_action_context",
62
63
  {
64
+ title: "Get Block Action Context",
65
+ annotations: hints.read,
63
66
  description:
64
67
  "Get the block action context tree of a block run: one node per template render, each with its baggage " +
65
68
  "(name, block-pack, block-id, run-id), the render it belongs to (resource), its action transition in time order " +
@@ -68,9 +71,9 @@ export function registerBlockActionContextTools(server: McpServer, ctx: ToolCont
68
71
  "The result is cut to maxDepth levels and the latest maxTransitions per node; a node with " +
69
72
  "childrenOmitted or transitionsOmitted has more. Pass its contextId to read below it. " +
70
73
  "Reads the current state; call again to refresh.",
71
- inputSchema: {
72
- projectId: z.string().describe("Project ID (must be opened)"),
73
- blockId: z.string().describe("Block ID"),
74
+ inputSchema: z.object({
75
+ projectId: projectIdInput.describe("Project ID (must be opened)"),
76
+ blockId: blockIdInput.describe("Block ID"),
74
77
  mode: z
75
78
  .enum(["prod", "staging"])
76
79
  .optional()
@@ -93,7 +96,7 @@ export function registerBlockActionContextTools(server: McpServer, ctx: ToolCont
93
96
  .optional()
94
97
  .default(20)
95
98
  .describe("Latest transitions to include per node (default 20)"),
96
- },
99
+ }),
97
100
  },
98
101
  async ({ projectId, blockId, mode, contextId, maxDepth, maxTransitions }) => {
99
102
  const project = await ctx.getOpenedProject(projectId);
@@ -1,21 +1,24 @@
1
- import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
1
+ import type { McpServer } from "@modelcontextprotocol/server";
2
2
  import { deriveDataFromStorage } from "@platforma-sdk/model";
3
3
  import { ModelAPIVersionMismatchError } from "@milaboratories/pl-errors";
4
4
  import { z } from "zod";
5
+ import { projectIdInput, blockIdInput } from "./ids";
5
6
  import type { ToolContext } from "./types";
6
7
  import { summarizeOutputs } from "./tokens";
7
8
  import { safeEval } from "./sandbox";
8
- import { errorResult, textResult } from "./types";
9
+ import { errorResult, hints, textResult } from "./types";
9
10
 
10
11
  export function registerBlockStateTools(server: McpServer, ctx: ToolContext): void {
11
12
  server.registerTool(
12
13
  "get_project_overview",
13
14
  {
15
+ title: "Get Project Overview",
16
+ annotations: hints.read,
14
17
  description:
15
18
  "Get project overview with all blocks and their statuses (calculationStatus, canRun, stale, errors, upstreams/downstreams)",
16
- inputSchema: {
17
- projectId: z.string().describe("Project ID (must be opened)"),
18
- },
19
+ inputSchema: z.object({
20
+ projectId: projectIdInput.describe("Project ID (must be opened)"),
21
+ }),
19
22
  },
20
23
  async ({ projectId }) => {
21
24
  const project = await ctx.getOpenedProject(projectId);
@@ -41,6 +44,8 @@ export function registerBlockStateTools(server: McpServer, ctx: ToolContext): vo
41
44
  server.registerTool(
42
45
  "get_block_state",
43
46
  {
47
+ title: "Get Block State",
48
+ annotations: hints.read,
44
49
  description:
45
50
  "Get block state. Returns block args (data) and a concise output summary with token estimates by default. " +
46
51
  "Use `transform` to extract specific data server-side without loading full outputs into context.\n\n" +
@@ -49,9 +54,9 @@ export function registerBlockStateTools(server: McpServer, ctx: ToolContext): vo
49
54
  "- `outputs.logs?.value` — get one specific output value\n" +
50
55
  "- `data` — get only block args\n" +
51
56
  "- `({ preset: outputs.preset?.value, qc: outputs.qc?.value })` — get specific outputs",
52
- inputSchema: {
53
- projectId: z.string().describe("Project ID"),
54
- blockId: z.string().describe("Block ID"),
57
+ inputSchema: z.object({
58
+ projectId: projectIdInput.describe("Project ID"),
59
+ blockId: blockIdInput.describe("Block ID"),
55
60
  transform: z
56
61
  .string()
57
62
  .optional()
@@ -65,7 +70,7 @@ export function registerBlockStateTools(server: McpServer, ctx: ToolContext): vo
65
70
  .optional()
66
71
  .default(5000)
67
72
  .describe("Timeout in ms for transform evaluation (default 5000)."),
68
- },
73
+ }),
69
74
  },
70
75
  async ({ projectId, blockId, transform, transformTimeout }) => {
71
76
  const project = await ctx.getOpenedProject(projectId);
@@ -96,12 +101,14 @@ export function registerBlockStateTools(server: McpServer, ctx: ToolContext): vo
96
101
  server.registerTool(
97
102
  "set_block_data",
98
103
  {
104
+ title: "Set Block Data",
105
+ annotations: hints.destructive,
99
106
  description: "Set the user-facing data of a block (triggers args derivation and staging)",
100
- inputSchema: {
101
- projectId: z.string().describe("Project ID"),
102
- blockId: z.string().describe("Block ID"),
103
- data: z.record(z.unknown()).describe("Block data object"),
104
- },
107
+ inputSchema: z.object({
108
+ projectId: projectIdInput.describe("Project ID"),
109
+ blockId: blockIdInput.describe("Block ID"),
110
+ data: z.record(z.string(), z.unknown()).describe("Block data object"),
111
+ }),
105
112
  },
106
113
  async ({ projectId, blockId, data }) => {
107
114
  const project = await ctx.getOpenedProject(projectId);
@@ -1,17 +1,20 @@
1
- import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
1
+ import type { McpServer } from "@modelcontextprotocol/server";
2
2
  import type { BlockPackSpecAny } from "@milaboratories/pl-middle-layer";
3
3
  import { z } from "zod";
4
+ import { projectIdInput, blockIdInput } from "./ids";
4
5
  import type { ToolContext } from "./types";
5
- import { errorResult, textResult } from "./types";
6
+ import { errorResult, hints, textResult } from "./types";
6
7
 
7
8
  export function registerBlockTools(server: McpServer, ctx: ToolContext): void {
8
9
  server.registerTool(
9
10
  "add_block",
10
11
  {
12
+ title: "Add Block",
13
+ annotations: hints.additive,
11
14
  description:
12
15
  "Add a block to an opened project. Spec can be from-registry-v2 (for published blocks) or dev-v2 (for local dev blocks).",
13
- inputSchema: {
14
- projectId: z.string().describe("Project ID (must be opened)"),
16
+ inputSchema: z.object({
17
+ projectId: projectIdInput.describe("Project ID (must be opened)"),
15
18
  label: z.string().describe("Block label"),
16
19
  spec: z
17
20
  .union([
@@ -30,7 +33,7 @@ export function registerBlockTools(server: McpServer, ctx: ToolContext): void {
30
33
  }),
31
34
  ])
32
35
  .describe("Block pack specification"),
33
- },
36
+ }),
34
37
  },
35
38
  async ({ projectId, label, spec }) => {
36
39
  const project = await ctx.getOpenedProject(projectId);
@@ -47,11 +50,13 @@ export function registerBlockTools(server: McpServer, ctx: ToolContext): void {
47
50
  server.registerTool(
48
51
  "update_block",
49
52
  {
53
+ title: "Update Block",
54
+ annotations: hints.destructive,
50
55
  description:
51
56
  "Update an existing block's pack (reload from registry or dev folder). Use after rebuilding a dev block to pick up changes without removing/re-adding it.",
52
- inputSchema: {
53
- projectId: z.string().describe("Project ID (must be opened)"),
54
- blockId: z.string().describe("Block ID to update"),
57
+ inputSchema: z.object({
58
+ projectId: projectIdInput.describe("Project ID (must be opened)"),
59
+ blockId: blockIdInput.describe("Block ID to update"),
55
60
  spec: z
56
61
  .union([
57
62
  z.object({
@@ -73,7 +78,7 @@ export function registerBlockTools(server: McpServer, ctx: ToolContext): void {
73
78
  .boolean()
74
79
  .optional()
75
80
  .describe("Reset block arguments to initial values (default: false)"),
76
- },
81
+ }),
77
82
  },
78
83
  async ({ projectId, blockId, spec, resetArgs }) => {
79
84
  const project = await ctx.getOpenedProject(projectId);
@@ -90,11 +95,14 @@ export function registerBlockTools(server: McpServer, ctx: ToolContext): void {
90
95
  server.registerTool(
91
96
  "remove_block",
92
97
  {
93
- description: "Remove a block from an opened project",
94
- inputSchema: {
95
- projectId: z.string().describe("Project ID"),
96
- blockId: z.string().describe("Block ID to remove"),
97
- },
98
+ title: "Remove Block",
99
+ annotations: hints.destructive,
100
+ description:
101
+ "Remove a block from an opened project, with its configuration and results. Blocks below that refer to it are left with a missing reference.",
102
+ inputSchema: z.object({
103
+ projectId: projectIdInput.describe("Project ID"),
104
+ blockId: blockIdInput.describe("Block ID to remove"),
105
+ }),
98
106
  },
99
107
  async ({ projectId, blockId }) => {
100
108
  const project = await ctx.getOpenedProject(projectId);
@@ -106,11 +114,15 @@ export function registerBlockTools(server: McpServer, ctx: ToolContext): void {
106
114
  server.registerTool(
107
115
  "run_block",
108
116
  {
109
- description: "Run a block. Stale upstream blocks are started automatically.",
110
- inputSchema: {
111
- projectId: z.string().describe("Project ID"),
112
- blockId: z.string().describe("Block ID to run"),
113
- },
117
+ title: "Run Block",
118
+ // Starts work like an additive tool, but replaces results and stops blocks computing below.
119
+ annotations: { ...hints.additive, destructiveHint: true },
120
+ description:
121
+ "Run a block. Stale upstream blocks are started automatically. A run replaces the previous results of each block it starts; downstream blocks that are still computing are stopped and their unfinished work is lost.",
122
+ inputSchema: z.object({
123
+ projectId: projectIdInput.describe("Project ID"),
124
+ blockId: blockIdInput.describe("Block ID to run"),
125
+ }),
114
126
  },
115
127
  async ({ projectId, blockId }) => {
116
128
  const project = await ctx.getOpenedProject(projectId);
@@ -122,11 +134,13 @@ export function registerBlockTools(server: McpServer, ctx: ToolContext): void {
122
134
  server.registerTool(
123
135
  "stop_block",
124
136
  {
125
- description: "Stop a running block",
126
- inputSchema: {
127
- projectId: z.string().describe("Project ID"),
128
- blockId: z.string().describe("Block ID to stop"),
129
- },
137
+ title: "Stop Block",
138
+ annotations: hints.destructive,
139
+ description: "Stop the computation of a running block. Use run_block to start it again.",
140
+ inputSchema: z.object({
141
+ projectId: projectIdInput.describe("Project ID"),
142
+ blockId: blockIdInput.describe("Block ID to stop"),
143
+ }),
130
144
  },
131
145
  async ({ projectId, blockId }) => {
132
146
  const project = await ctx.getOpenedProject(projectId);
@@ -138,11 +152,13 @@ export function registerBlockTools(server: McpServer, ctx: ToolContext): void {
138
152
  server.registerTool(
139
153
  "reorder_blocks",
140
154
  {
155
+ title: "Reorder Blocks",
156
+ annotations: hints.destructive,
141
157
  description: "Reorder blocks in a project. Must provide ALL block IDs in the desired order.",
142
- inputSchema: {
143
- projectId: z.string().describe("Project ID"),
144
- blockIds: z.array(z.string()).describe("All block IDs in the desired order"),
145
- },
158
+ inputSchema: z.object({
159
+ projectId: projectIdInput.describe("Project ID"),
160
+ blockIds: z.array(blockIdInput).describe("All block IDs in the desired order"),
161
+ }),
146
162
  },
147
163
  async ({ projectId, blockIds }) => {
148
164
  const project = await ctx.getOpenedProject(projectId);
@@ -154,14 +170,16 @@ export function registerBlockTools(server: McpServer, ctx: ToolContext): void {
154
170
  server.registerTool(
155
171
  "list_available_blocks",
156
172
  {
173
+ title: "List Available Blocks",
174
+ annotations: hints.read,
157
175
  description:
158
176
  "List available blocks from configured registries. Optional query to filter by name.",
159
- inputSchema: {
177
+ inputSchema: z.object({
160
178
  query: z
161
179
  .string()
162
180
  .optional()
163
181
  .describe("Filter blocks by name (case-insensitive substring match)"),
164
- },
182
+ }),
165
183
  },
166
184
  async ({ query }) => {
167
185
  if (!ctx.callbacks.listAvailableBlocks) {
@@ -178,14 +196,16 @@ export function registerBlockTools(server: McpServer, ctx: ToolContext): void {
178
196
  server.registerTool(
179
197
  "get_block_info",
180
198
  {
199
+ title: "Get Block Info",
200
+ annotations: hints.read,
181
201
  description:
182
202
  "Get detailed info about a specific block package from the registry. Use list_available_blocks first to find the block.",
183
- inputSchema: {
203
+ inputSchema: z.object({
184
204
  registryUrl: z.string().describe("Registry URL (from list_available_blocks)"),
185
205
  organization: z.string().describe("Organization name"),
186
206
  name: z.string().describe("Block package name"),
187
207
  version: z.string().describe("Block version"),
188
- },
208
+ }),
189
209
  },
190
210
  async ({ registryUrl, organization, name, version }) => {
191
211
  if (!ctx.callbacks.getBlockInfo) {
@@ -202,11 +222,13 @@ export function registerBlockTools(server: McpServer, ctx: ToolContext): void {
202
222
  server.registerTool(
203
223
  "select_block",
204
224
  {
225
+ title: "Show Block in the Application",
226
+ annotations: hints.idempotent,
205
227
  description: "Navigate the desktop UI to show a specific block's interface",
206
- inputSchema: {
207
- projectId: z.string().describe("Project ID"),
208
- blockId: z.string().describe("Block ID to display"),
209
- },
228
+ inputSchema: z.object({
229
+ projectId: projectIdInput.describe("Project ID"),
230
+ blockId: blockIdInput.describe("Block ID to display"),
231
+ }),
210
232
  },
211
233
  async ({ projectId, blockId }) => {
212
234
  if (!ctx.callbacks.selectBlock) {
@@ -1,12 +1,17 @@
1
- import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
1
+ import type { McpServer } from "@modelcontextprotocol/server";
2
2
  import { z } from "zod";
3
3
  import type { ToolContext } from "./types";
4
- import { errorResult, textResult } from "./types";
4
+ import { errorResult, hints, textResult } from "./types";
5
5
 
6
6
  export function registerConnectionTools(server: McpServer, ctx: ToolContext): void {
7
7
  server.registerTool(
8
8
  "get_connection_status",
9
- { description: "Get current server connection status" },
9
+ {
10
+ title: "Get Connection Status",
11
+ annotations: hints.read,
12
+ description:
13
+ "Get the connection status of the application: whether it is connected to a backend server, and to which address and user.",
14
+ },
10
15
  async () => {
11
16
  if (!ctx.callbacks.getConnectionStatus) {
12
17
  return textResult({ connected: !!ctx.getMl() });
@@ -17,7 +22,12 @@ export function registerConnectionTools(server: McpServer, ctx: ToolContext): vo
17
22
 
18
23
  server.registerTool(
19
24
  "list_connections",
20
- { description: "List saved server connections" },
25
+ {
26
+ title: "List Saved Connections",
27
+ annotations: hints.read,
28
+ description:
29
+ "List the server connections saved in the application. Use one of them with connect_to_server.",
30
+ },
21
31
  async () => {
22
32
  if (!ctx.callbacks.listConnections) {
23
33
  return errorResult(
@@ -32,12 +42,14 @@ export function registerConnectionTools(server: McpServer, ctx: ToolContext): vo
32
42
  server.registerTool(
33
43
  "connect_to_server",
34
44
  {
45
+ title: "Connect to Server",
46
+ annotations: { ...hints.idempotent, openWorldHint: true },
35
47
  description: "Connect to a Platforma server. Use list_connections to see saved servers.",
36
- inputSchema: {
37
- addr: z.string().describe("Server address (e.g. https://pl6.demo2.platforma.bio:6346)"),
48
+ inputSchema: z.object({
49
+ addr: z.string().describe("Server address (e.g. https://platforma.example.com:6346)"),
38
50
  login: z.string().describe("Username"),
39
51
  password: z.string().optional().describe("Password (uses saved token if omitted)"),
40
- },
52
+ }),
41
53
  },
42
54
  async ({ addr, login, password }) => {
43
55
  if (!ctx.callbacks.connectToServer) {
@@ -50,14 +62,23 @@ export function registerConnectionTools(server: McpServer, ctx: ToolContext): vo
50
62
  },
51
63
  );
52
64
 
53
- server.registerTool("disconnect", { description: "Disconnect from current server" }, async () => {
54
- if (!ctx.callbacks.disconnect) {
55
- return errorResult(
56
- "Failed to disconnect.",
57
- "More likely it's because connection is already closed. Could check it with 'get_connection_status' tool.",
58
- );
59
- }
60
- await ctx.callbacks.disconnect();
61
- return textResult({ ok: true });
62
- });
65
+ server.registerTool(
66
+ "disconnect",
67
+ {
68
+ title: "Disconnect",
69
+ annotations: hints.idempotent,
70
+ description:
71
+ "Disconnect the application from the current backend server. Nothing on the server is deleted.",
72
+ },
73
+ async () => {
74
+ if (!ctx.callbacks.disconnect) {
75
+ return errorResult(
76
+ "Failed to disconnect.",
77
+ "More likely it's because connection is already closed. Could check it with 'get_connection_status' tool.",
78
+ );
79
+ }
80
+ await ctx.callbacks.disconnect();
81
+ return textResult({ ok: true });
82
+ },
83
+ );
63
84
  }