@milaboratories/pl-mcp-server 52.0.0 → 53.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.
- package/dist/index.d.ts +2 -1
- package/dist/instructions.cjs +28 -0
- package/dist/instructions.cjs.map +1 -0
- package/dist/instructions.js +28 -0
- package/dist/instructions.js.map +1 -0
- package/dist/package.cjs +10 -0
- package/dist/package.cjs.map +1 -0
- package/dist/package.js +5 -0
- package/dist/package.js.map +1 -0
- package/dist/server.cjs +45 -41
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.ts +15 -9
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +44 -40
- package/dist/server.js.map +1 -1
- package/dist/tools/await.cjs +8 -5
- package/dist/tools/await.cjs.map +1 -1
- package/dist/tools/await.js +9 -6
- package/dist/tools/await.js.map +1 -1
- package/dist/tools/block-action-context.cjs +7 -4
- package/dist/tools/block-action-context.cjs.map +1 -1
- package/dist/tools/block-action-context.js +8 -5
- package/dist/tools/block-action-context.js.map +1 -1
- package/dist/tools/block-api.cjs +23 -0
- package/dist/tools/block-api.cjs.map +1 -0
- package/dist/tools/block-api.js +22 -0
- package/dist/tools/block-api.js.map +1 -0
- package/dist/tools/block-params.cjs +21 -0
- package/dist/tools/block-params.cjs.map +1 -0
- package/dist/tools/block-params.js +21 -0
- package/dist/tools/block-params.js.map +1 -0
- package/dist/tools/block-state.cjs +18 -11
- package/dist/tools/block-state.cjs.map +1 -1
- package/dist/tools/block-state.js +19 -12
- package/dist/tools/block-state.js.map +1 -1
- package/dist/tools/blocks.cjs +130 -50
- package/dist/tools/blocks.cjs.map +1 -1
- package/dist/tools/blocks.js +131 -52
- package/dist/tools/blocks.js.map +1 -1
- package/dist/tools/connection.cjs +23 -6
- package/dist/tools/connection.cjs.map +1 -1
- package/dist/tools/connection.js +24 -7
- package/dist/tools/connection.js.map +1 -1
- package/dist/tools/data-query.cjs +14 -7
- package/dist/tools/data-query.cjs.map +1 -1
- package/dist/tools/data-query.js +15 -8
- package/dist/tools/data-query.js.map +1 -1
- package/dist/tools/ids.cjs +14 -0
- package/dist/tools/ids.cjs.map +1 -0
- package/dist/tools/ids.js +13 -0
- package/dist/tools/ids.js.map +1 -0
- package/dist/tools/logs.cjs +11 -6
- package/dist/tools/logs.cjs.map +1 -1
- package/dist/tools/logs.js +12 -7
- package/dist/tools/logs.js.map +1 -1
- package/dist/tools/ping.cjs +5 -1
- package/dist/tools/ping.cjs.map +1 -1
- package/dist/tools/ping.js +6 -2
- package/dist/tools/ping.js.map +1 -1
- package/dist/tools/projects.cjs +20 -7
- package/dist/tools/projects.cjs.map +1 -1
- package/dist/tools/projects.js +21 -8
- package/dist/tools/projects.js.map +1 -1
- package/dist/tools/screenshot.cjs +3 -1
- package/dist/tools/screenshot.cjs.map +1 -1
- package/dist/tools/screenshot.js +4 -2
- package/dist/tools/screenshot.js.map +1 -1
- package/dist/tools/types.cjs +51 -0
- package/dist/tools/types.cjs.map +1 -1
- package/dist/tools/types.js +50 -1
- package/dist/tools/types.js.map +1 -1
- package/dist/tools/ui-interaction.cjs +27 -13
- package/dist/tools/ui-interaction.cjs.map +1 -1
- package/dist/tools/ui-interaction.js +28 -14
- package/dist/tools/ui-interaction.js.map +1 -1
- package/package.json +11 -9
- package/src/index.ts +1 -0
- package/src/instructions.ts +24 -0
- package/src/server.test.ts +633 -0
- package/src/server.ts +65 -58
- package/src/tools/await.ts +9 -6
- package/src/tools/block-action-context.ts +9 -6
- package/src/tools/block-api.ts +24 -0
- package/src/tools/block-params.ts +30 -0
- package/src/tools/block-state.ts +21 -14
- package/src/tools/blocks.test.ts +148 -0
- package/src/tools/blocks.ts +216 -65
- package/src/tools/connection.ts +38 -17
- package/src/tools/data-query.ts +17 -10
- package/src/tools/ids.ts +11 -0
- package/src/tools/logs.ts +13 -8
- package/src/tools/ping.ts +14 -5
- package/src/tools/projects.ts +26 -11
- package/src/tools/screenshot.ts +7 -5
- package/src/tools/types.test.ts +19 -0
- package/src/tools/types.ts +71 -3
- package/src/tools/ui-interaction.ts +29 -18
package/src/tools/blocks.ts
CHANGED
|
@@ -1,57 +1,191 @@
|
|
|
1
|
-
import type { McpServer } from "@modelcontextprotocol/
|
|
2
|
-
import type { BlockPackSpecAny } from "@milaboratories/pl-middle-layer";
|
|
1
|
+
import type { McpServer } from "@modelcontextprotocol/server";
|
|
2
|
+
import type { BlockPackSpecAny, Project } from "@milaboratories/pl-middle-layer";
|
|
3
|
+
import { BlockKindRef, CentralBlockRegistry } from "@milaboratories/pl-middle-layer";
|
|
4
|
+
import { BlockInitParamsRejectedError } from "@milaboratories/pl-errors";
|
|
5
|
+
import type { BlockKindReference } from "@platforma-sdk/model";
|
|
3
6
|
import { z } from "zod";
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
7
|
+
import { projectIdInput, blockIdInput } from "./ids";
|
|
8
|
+
import type { AuthorMarker, ToolContext } from "./types";
|
|
9
|
+
import { errorResult, hints, textResult } from "./types";
|
|
10
|
+
import { SUPPORTED_BLOCK_API, unsupportedBlockApiResult } from "./block-api";
|
|
11
|
+
|
|
12
|
+
/** Where a kind is resolved when the caller names no registry. */
|
|
13
|
+
function centralBlockRegistryUrl(): string {
|
|
14
|
+
if (CentralBlockRegistry.type !== "remote-v2")
|
|
15
|
+
throw new Error("The central block registry is expected to be a v2 remote registry.");
|
|
16
|
+
return CentralBlockRegistry.url;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function errorMessage(e: unknown): string {
|
|
20
|
+
return e instanceof Error ? e.message : String(e);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const addBlockInput = z.object({
|
|
24
|
+
projectId: projectIdInput.describe("Project ID (must be opened)"),
|
|
25
|
+
label: z.string().describe("Block label"),
|
|
26
|
+
spec: z
|
|
27
|
+
.union([
|
|
28
|
+
z.object({
|
|
29
|
+
type: z.literal("kind"),
|
|
30
|
+
kind: z
|
|
31
|
+
.string()
|
|
32
|
+
.describe(
|
|
33
|
+
'Block kind reference "<package name>@<version or range>", ' +
|
|
34
|
+
'e.g. "@platforma-open/milaboratories.samples-and-data.kind@1.2.0"',
|
|
35
|
+
),
|
|
36
|
+
registryUrl: z
|
|
37
|
+
.string()
|
|
38
|
+
.optional()
|
|
39
|
+
.describe("Registry to resolve the kind in (default: the central block registry)"),
|
|
40
|
+
allowUnstable: z
|
|
41
|
+
.boolean()
|
|
42
|
+
.optional()
|
|
43
|
+
.describe("Also consider blocks not published to the stable channel"),
|
|
44
|
+
}),
|
|
45
|
+
z.object({
|
|
46
|
+
type: z.literal("from-registry-v2"),
|
|
47
|
+
registryUrl: z.string().describe("Registry URL"),
|
|
48
|
+
id: z.object({
|
|
49
|
+
organization: z.string(),
|
|
50
|
+
name: z.string(),
|
|
51
|
+
version: z.string(),
|
|
52
|
+
}),
|
|
53
|
+
}),
|
|
54
|
+
z.object({
|
|
55
|
+
type: z.literal("dev-v2"),
|
|
56
|
+
folder: z.string().describe("Path to block folder"),
|
|
57
|
+
}),
|
|
58
|
+
])
|
|
59
|
+
.describe("Which block to add"),
|
|
60
|
+
params: z
|
|
61
|
+
.record(z.string(), z.unknown())
|
|
62
|
+
.optional()
|
|
63
|
+
.describe("Initialization params of the block's kind. Omit for the default state."),
|
|
64
|
+
blockIds: z
|
|
65
|
+
.record(z.string(), blockIdInput)
|
|
66
|
+
.optional()
|
|
67
|
+
.describe(
|
|
68
|
+
"Ids used inside `params` in place of block ids, each mapped to a block id of this " +
|
|
69
|
+
"project. Needed only when `params` do not already hold ids of this project.",
|
|
70
|
+
),
|
|
71
|
+
before: blockIdInput
|
|
72
|
+
.optional()
|
|
73
|
+
.describe("ID of the block to insert the new block before (default: add at the end)"),
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
/** Input of the `add_block` tool. */
|
|
77
|
+
export type AddBlockInput = z.infer<typeof addBlockInput>;
|
|
78
|
+
|
|
79
|
+
/** What `add_block` needs from the application. */
|
|
80
|
+
export type AddBlockDeps = {
|
|
81
|
+
project: Pick<Project, "addBlock">;
|
|
82
|
+
/** Resolves a kind reference to the block implementing it; throws when there is none. */
|
|
83
|
+
resolveKind: (
|
|
84
|
+
kind: BlockKindReference,
|
|
85
|
+
registryUrl: string | undefined,
|
|
86
|
+
allowUnstable: boolean,
|
|
87
|
+
) => Promise<BlockPackSpecAny>;
|
|
88
|
+
author: AuthorMarker;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Adds the block the input describes, started from its params when it carries them. Every way the
|
|
93
|
+
* block can be refused comes back as an error result saying nothing was created.
|
|
94
|
+
*/
|
|
95
|
+
export async function addBlock(deps: AddBlockDeps, input: AddBlockInput) {
|
|
96
|
+
const { label, spec, params, blockIds, before } = input;
|
|
97
|
+
|
|
98
|
+
let blockPackSpec: BlockPackSpecAny;
|
|
99
|
+
if (spec.type === "kind") {
|
|
100
|
+
try {
|
|
101
|
+
blockPackSpec = await deps.resolveKind(
|
|
102
|
+
BlockKindRef.parse(spec.kind),
|
|
103
|
+
spec.registryUrl,
|
|
104
|
+
spec.allowUnstable ?? false,
|
|
105
|
+
);
|
|
106
|
+
} catch (e: unknown) {
|
|
107
|
+
return errorResult(
|
|
108
|
+
`Kind "${spec.kind}" was not resolved to a block: ${errorMessage(e)}. Nothing was created.`,
|
|
109
|
+
"Check the kind name and version. Pass allowUnstable: true if the block is not " +
|
|
110
|
+
"published to the stable channel, or registryUrl if it lives in another registry.",
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
blockPackSpec = spec;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
try {
|
|
118
|
+
const blockId = await deps.project.addBlock(
|
|
119
|
+
label,
|
|
120
|
+
blockPackSpec,
|
|
121
|
+
before,
|
|
122
|
+
deps.author,
|
|
123
|
+
undefined,
|
|
124
|
+
{
|
|
125
|
+
init: params === undefined ? undefined : { params, blockIds },
|
|
126
|
+
requireModelAPIVersion: SUPPORTED_BLOCK_API,
|
|
127
|
+
},
|
|
128
|
+
);
|
|
129
|
+
return textResult({ blockId });
|
|
130
|
+
} catch (e: unknown) {
|
|
131
|
+
const unsupported = unsupportedBlockApiResult(e);
|
|
132
|
+
if (unsupported) return unsupported;
|
|
133
|
+
if (e instanceof BlockInitParamsRejectedError)
|
|
134
|
+
return errorResult(
|
|
135
|
+
`The block did not accept the params: ${e.reason}. Nothing was created.`,
|
|
136
|
+
"Fix the params and call add_block again. get_block_params on a configured block " +
|
|
137
|
+
"of the same kind shows the expected shape.",
|
|
138
|
+
);
|
|
139
|
+
throw e;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
6
142
|
|
|
7
143
|
export function registerBlockTools(server: McpServer, ctx: ToolContext): void {
|
|
8
144
|
server.registerTool(
|
|
9
145
|
"add_block",
|
|
10
146
|
{
|
|
147
|
+
title: "Add Block",
|
|
148
|
+
annotations: hints.additive,
|
|
11
149
|
description:
|
|
12
|
-
"Add a block to an opened project
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
version: z.string(),
|
|
25
|
-
}),
|
|
26
|
-
}),
|
|
27
|
-
z.object({
|
|
28
|
-
type: z.literal("dev-v2"),
|
|
29
|
-
folder: z.string().describe("Path to block folder"),
|
|
30
|
-
}),
|
|
31
|
-
])
|
|
32
|
-
.describe("Block pack specification"),
|
|
33
|
-
},
|
|
150
|
+
"Add a block to an opened project, optionally configured from initialization params.\n\n" +
|
|
151
|
+
"`spec` names the block: `kind` (a block kind reference, resolved to the newest block " +
|
|
152
|
+
"implementing it), `from-registry-v2` (an exact published block) or `dev-v2` (a local dev " +
|
|
153
|
+
"block folder).\n\n" +
|
|
154
|
+
"`params` are the initialization params of the block's kind: the block's own model checks " +
|
|
155
|
+
"them and builds its initial state from them. Without `params` the block starts in its " +
|
|
156
|
+
"default state. get_block_params shows the params of an existing block.\n\n" +
|
|
157
|
+
"References to other blocks inside `params` must hold real block ids of this project, " +
|
|
158
|
+
"copied from tool results. Params copied from another project or a template hold other " +
|
|
159
|
+
"ids: map each of them to a block of this project with `blockIds`.\n\n" +
|
|
160
|
+
"Only blocks on the current block API can be added. On any error nothing is created.",
|
|
161
|
+
inputSchema: addBlockInput,
|
|
34
162
|
},
|
|
35
|
-
async (
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
163
|
+
async (input) => {
|
|
164
|
+
const ml = ctx.requireMl();
|
|
165
|
+
return await addBlock(
|
|
166
|
+
{
|
|
167
|
+
project: await ctx.getOpenedProject(input.projectId),
|
|
168
|
+
resolveKind: (kind, registryUrl, allowUnstable) =>
|
|
169
|
+
ml.blockRegistryProvider
|
|
170
|
+
.getRegistry(registryUrl ?? centralBlockRegistryUrl())
|
|
171
|
+
.resolveKind(kind, { allowUnstable }),
|
|
172
|
+
author: ctx.getAuthorMarker(),
|
|
173
|
+
},
|
|
174
|
+
input,
|
|
42
175
|
);
|
|
43
|
-
return textResult({ blockId });
|
|
44
176
|
},
|
|
45
177
|
);
|
|
46
178
|
|
|
47
179
|
server.registerTool(
|
|
48
180
|
"update_block",
|
|
49
181
|
{
|
|
182
|
+
title: "Update Block",
|
|
183
|
+
annotations: hints.destructive,
|
|
50
184
|
description:
|
|
51
185
|
"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:
|
|
54
|
-
blockId:
|
|
186
|
+
inputSchema: z.object({
|
|
187
|
+
projectId: projectIdInput.describe("Project ID (must be opened)"),
|
|
188
|
+
blockId: blockIdInput.describe("Block ID to update"),
|
|
55
189
|
spec: z
|
|
56
190
|
.union([
|
|
57
191
|
z.object({
|
|
@@ -73,7 +207,7 @@ export function registerBlockTools(server: McpServer, ctx: ToolContext): void {
|
|
|
73
207
|
.boolean()
|
|
74
208
|
.optional()
|
|
75
209
|
.describe("Reset block arguments to initial values (default: false)"),
|
|
76
|
-
},
|
|
210
|
+
}),
|
|
77
211
|
},
|
|
78
212
|
async ({ projectId, blockId, spec, resetArgs }) => {
|
|
79
213
|
const project = await ctx.getOpenedProject(projectId);
|
|
@@ -90,11 +224,14 @@ export function registerBlockTools(server: McpServer, ctx: ToolContext): void {
|
|
|
90
224
|
server.registerTool(
|
|
91
225
|
"remove_block",
|
|
92
226
|
{
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
227
|
+
title: "Remove Block",
|
|
228
|
+
annotations: hints.destructive,
|
|
229
|
+
description:
|
|
230
|
+
"Remove a block from an opened project, with its configuration and results. Blocks below that refer to it are left with a missing reference.",
|
|
231
|
+
inputSchema: z.object({
|
|
232
|
+
projectId: projectIdInput.describe("Project ID"),
|
|
233
|
+
blockId: blockIdInput.describe("Block ID to remove"),
|
|
234
|
+
}),
|
|
98
235
|
},
|
|
99
236
|
async ({ projectId, blockId }) => {
|
|
100
237
|
const project = await ctx.getOpenedProject(projectId);
|
|
@@ -106,11 +243,15 @@ export function registerBlockTools(server: McpServer, ctx: ToolContext): void {
|
|
|
106
243
|
server.registerTool(
|
|
107
244
|
"run_block",
|
|
108
245
|
{
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
246
|
+
title: "Run Block",
|
|
247
|
+
// Starts work like an additive tool, but replaces results and stops blocks computing below.
|
|
248
|
+
annotations: { ...hints.additive, destructiveHint: true },
|
|
249
|
+
description:
|
|
250
|
+
"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.",
|
|
251
|
+
inputSchema: z.object({
|
|
252
|
+
projectId: projectIdInput.describe("Project ID"),
|
|
253
|
+
blockId: blockIdInput.describe("Block ID to run"),
|
|
254
|
+
}),
|
|
114
255
|
},
|
|
115
256
|
async ({ projectId, blockId }) => {
|
|
116
257
|
const project = await ctx.getOpenedProject(projectId);
|
|
@@ -122,11 +263,13 @@ export function registerBlockTools(server: McpServer, ctx: ToolContext): void {
|
|
|
122
263
|
server.registerTool(
|
|
123
264
|
"stop_block",
|
|
124
265
|
{
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
266
|
+
title: "Stop Block",
|
|
267
|
+
annotations: hints.destructive,
|
|
268
|
+
description: "Stop the computation of a running block. Use run_block to start it again.",
|
|
269
|
+
inputSchema: z.object({
|
|
270
|
+
projectId: projectIdInput.describe("Project ID"),
|
|
271
|
+
blockId: blockIdInput.describe("Block ID to stop"),
|
|
272
|
+
}),
|
|
130
273
|
},
|
|
131
274
|
async ({ projectId, blockId }) => {
|
|
132
275
|
const project = await ctx.getOpenedProject(projectId);
|
|
@@ -138,11 +281,13 @@ export function registerBlockTools(server: McpServer, ctx: ToolContext): void {
|
|
|
138
281
|
server.registerTool(
|
|
139
282
|
"reorder_blocks",
|
|
140
283
|
{
|
|
284
|
+
title: "Reorder Blocks",
|
|
285
|
+
annotations: hints.destructive,
|
|
141
286
|
description: "Reorder blocks in a project. Must provide ALL block IDs in the desired order.",
|
|
142
|
-
inputSchema: {
|
|
143
|
-
projectId:
|
|
144
|
-
blockIds: z.array(
|
|
145
|
-
},
|
|
287
|
+
inputSchema: z.object({
|
|
288
|
+
projectId: projectIdInput.describe("Project ID"),
|
|
289
|
+
blockIds: z.array(blockIdInput).describe("All block IDs in the desired order"),
|
|
290
|
+
}),
|
|
146
291
|
},
|
|
147
292
|
async ({ projectId, blockIds }) => {
|
|
148
293
|
const project = await ctx.getOpenedProject(projectId);
|
|
@@ -154,14 +299,16 @@ export function registerBlockTools(server: McpServer, ctx: ToolContext): void {
|
|
|
154
299
|
server.registerTool(
|
|
155
300
|
"list_available_blocks",
|
|
156
301
|
{
|
|
302
|
+
title: "List Available Blocks",
|
|
303
|
+
annotations: hints.read,
|
|
157
304
|
description:
|
|
158
305
|
"List available blocks from configured registries. Optional query to filter by name.",
|
|
159
|
-
inputSchema: {
|
|
306
|
+
inputSchema: z.object({
|
|
160
307
|
query: z
|
|
161
308
|
.string()
|
|
162
309
|
.optional()
|
|
163
310
|
.describe("Filter blocks by name (case-insensitive substring match)"),
|
|
164
|
-
},
|
|
311
|
+
}),
|
|
165
312
|
},
|
|
166
313
|
async ({ query }) => {
|
|
167
314
|
if (!ctx.callbacks.listAvailableBlocks) {
|
|
@@ -178,14 +325,16 @@ export function registerBlockTools(server: McpServer, ctx: ToolContext): void {
|
|
|
178
325
|
server.registerTool(
|
|
179
326
|
"get_block_info",
|
|
180
327
|
{
|
|
328
|
+
title: "Get Block Info",
|
|
329
|
+
annotations: hints.read,
|
|
181
330
|
description:
|
|
182
331
|
"Get detailed info about a specific block package from the registry. Use list_available_blocks first to find the block.",
|
|
183
|
-
inputSchema: {
|
|
332
|
+
inputSchema: z.object({
|
|
184
333
|
registryUrl: z.string().describe("Registry URL (from list_available_blocks)"),
|
|
185
334
|
organization: z.string().describe("Organization name"),
|
|
186
335
|
name: z.string().describe("Block package name"),
|
|
187
336
|
version: z.string().describe("Block version"),
|
|
188
|
-
},
|
|
337
|
+
}),
|
|
189
338
|
},
|
|
190
339
|
async ({ registryUrl, organization, name, version }) => {
|
|
191
340
|
if (!ctx.callbacks.getBlockInfo) {
|
|
@@ -202,11 +351,13 @@ export function registerBlockTools(server: McpServer, ctx: ToolContext): void {
|
|
|
202
351
|
server.registerTool(
|
|
203
352
|
"select_block",
|
|
204
353
|
{
|
|
354
|
+
title: "Show Block in the Application",
|
|
355
|
+
annotations: hints.idempotent,
|
|
205
356
|
description: "Navigate the desktop UI to show a specific block's interface",
|
|
206
|
-
inputSchema: {
|
|
207
|
-
projectId:
|
|
208
|
-
blockId:
|
|
209
|
-
},
|
|
357
|
+
inputSchema: z.object({
|
|
358
|
+
projectId: projectIdInput.describe("Project ID"),
|
|
359
|
+
blockId: blockIdInput.describe("Block ID to display"),
|
|
360
|
+
}),
|
|
210
361
|
},
|
|
211
362
|
async ({ projectId, blockId }) => {
|
|
212
363
|
if (!ctx.callbacks.selectBlock) {
|
package/src/tools/connection.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import type { McpServer } from "@modelcontextprotocol/
|
|
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
|
-
{
|
|
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
|
-
{
|
|
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://
|
|
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(
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
}
|
package/src/tools/data-query.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { McpServer } from "@modelcontextprotocol/
|
|
1
|
+
import type { McpServer } from "@modelcontextprotocol/server";
|
|
2
2
|
import type {
|
|
3
3
|
PFrameHandle,
|
|
4
4
|
PTableHandle,
|
|
@@ -12,9 +12,10 @@ import {
|
|
|
12
12
|
PFrameDriver,
|
|
13
13
|
} from "@milaboratories/pl-model-common";
|
|
14
14
|
import { z } from "zod";
|
|
15
|
+
import { projectIdInput, blockIdInput } from "./ids";
|
|
15
16
|
import type { ToolContext } from "./types";
|
|
16
17
|
import { safeEval } from "./sandbox";
|
|
17
|
-
import { errorResult, textResult } from "./types";
|
|
18
|
+
import { errorResult, hints, textResult } from "./types";
|
|
18
19
|
|
|
19
20
|
const HEX_HASH_RE = /^[a-f0-9]{64}$/;
|
|
20
21
|
|
|
@@ -122,19 +123,21 @@ export function registerDataQueryTools(server: McpServer, ctx: ToolContext): voi
|
|
|
122
123
|
server.registerTool(
|
|
123
124
|
"get_block_outputs",
|
|
124
125
|
{
|
|
126
|
+
title: "Get Block Outputs",
|
|
127
|
+
annotations: hints.read,
|
|
125
128
|
description:
|
|
126
129
|
"Get block output values as a JSON map. " +
|
|
127
130
|
"PFrame/PTable handles are resolved inline to summaries with column specs and row counts. " +
|
|
128
131
|
"Use this to discover block results and available data before querying tables.",
|
|
129
|
-
inputSchema: {
|
|
130
|
-
projectId:
|
|
131
|
-
blockId:
|
|
132
|
+
inputSchema: z.object({
|
|
133
|
+
projectId: projectIdInput.describe("Project ID"),
|
|
134
|
+
blockId: blockIdInput.describe("Block ID"),
|
|
132
135
|
maxColumns: z
|
|
133
136
|
.number()
|
|
134
137
|
.optional()
|
|
135
138
|
.default(30)
|
|
136
139
|
.describe("Max columns to show per PFrame/PTable summary (default 30)."),
|
|
137
|
-
},
|
|
140
|
+
}),
|
|
138
141
|
},
|
|
139
142
|
async ({ projectId, blockId, maxColumns }) => {
|
|
140
143
|
const project = await ctx.getOpenedProject(projectId);
|
|
@@ -165,13 +168,15 @@ export function registerDataQueryTools(server: McpServer, ctx: ToolContext): voi
|
|
|
165
168
|
server.registerTool(
|
|
166
169
|
"list_columns",
|
|
167
170
|
{
|
|
171
|
+
title: "List Columns",
|
|
172
|
+
annotations: hints.read,
|
|
168
173
|
description:
|
|
169
174
|
"List all columns in a PFrame with their specs. Use get_block_outputs first to find the PFrame handle.",
|
|
170
|
-
inputSchema: {
|
|
175
|
+
inputSchema: z.object({
|
|
171
176
|
pFrameHandle: z
|
|
172
177
|
.string()
|
|
173
178
|
.describe("PFrame handle (64-char hex hash from get_block_outputs)"),
|
|
174
|
-
},
|
|
179
|
+
}),
|
|
175
180
|
},
|
|
176
181
|
async ({ pFrameHandle }) => {
|
|
177
182
|
const pFrameDriver = ctx.requireMl().internalDriverKit.pFrameDriver;
|
|
@@ -196,10 +201,12 @@ export function registerDataQueryTools(server: McpServer, ctx: ToolContext): voi
|
|
|
196
201
|
server.registerTool(
|
|
197
202
|
"query_table",
|
|
198
203
|
{
|
|
204
|
+
title: "Query Table",
|
|
205
|
+
annotations: hints.read,
|
|
199
206
|
description:
|
|
200
207
|
"Query data from a PTable. Returns rows as arrays of values. Use get_block_outputs first to find the PTable handle. " +
|
|
201
208
|
"Use `transform` to process results server-side and return only what you need.",
|
|
202
|
-
inputSchema: {
|
|
209
|
+
inputSchema: z.object({
|
|
203
210
|
pTableHandle: z
|
|
204
211
|
.string()
|
|
205
212
|
.describe("PTable handle (64-char hex hash from get_block_outputs)"),
|
|
@@ -229,7 +236,7 @@ export function registerDataQueryTools(server: McpServer, ctx: ToolContext): voi
|
|
|
229
236
|
.optional()
|
|
230
237
|
.default(5000)
|
|
231
238
|
.describe("Timeout in ms for transform evaluation (default 5000)."),
|
|
232
|
-
},
|
|
239
|
+
}),
|
|
233
240
|
},
|
|
234
241
|
async ({ pTableHandle, columns, offset, limit, maxLimit, transform, transformTimeout }) => {
|
|
235
242
|
const pFrameDriver = ctx.requireMl().internalDriverKit.pFrameDriver;
|
package/src/tools/ids.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { asBlockId, asProjectId } from "@milaboratories/pl-model-common";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A project id argument of a tool. The agent sends a string; the tool receives a `ProjectId`.
|
|
6
|
+
* Each tool adds its own description.
|
|
7
|
+
*/
|
|
8
|
+
export const projectIdInput = z.string().transform(asProjectId);
|
|
9
|
+
|
|
10
|
+
/** A block id argument of a tool. The agent sends a string; the tool receives a `BlockId`. */
|
|
11
|
+
export const blockIdInput = z.string().transform(asBlockId);
|
package/src/tools/logs.ts
CHANGED
|
@@ -1,25 +1,28 @@
|
|
|
1
|
-
import type { McpServer } from "@modelcontextprotocol/
|
|
1
|
+
import type { McpServer } from "@modelcontextprotocol/server";
|
|
2
2
|
import { isAnyLogHandle } from "@milaboratories/pl-model-common";
|
|
3
3
|
import type { AnyLogHandle } from "@milaboratories/pl-model-common";
|
|
4
4
|
import { z } from "zod";
|
|
5
|
+
import { projectIdInput, blockIdInput } from "./ids";
|
|
5
6
|
import type { ToolContext } from "./types";
|
|
6
|
-
import { errorResult, textResult } from "./types";
|
|
7
|
+
import { errorResult, hints, textResult } from "./types";
|
|
7
8
|
|
|
8
9
|
export function registerLogTools(server: McpServer, ctx: ToolContext): void {
|
|
9
10
|
server.registerTool(
|
|
10
11
|
"get_block_logs",
|
|
11
12
|
{
|
|
13
|
+
title: "Get Block Logs",
|
|
14
|
+
annotations: hints.read,
|
|
12
15
|
description:
|
|
13
16
|
"Read execution logs for a block. Extracts log handles from block outputs and reads log content. Returns logs keyed by sample/run ID.",
|
|
14
|
-
inputSchema: {
|
|
15
|
-
projectId:
|
|
16
|
-
blockId:
|
|
17
|
+
inputSchema: z.object({
|
|
18
|
+
projectId: projectIdInput.describe("Project ID"),
|
|
19
|
+
blockId: blockIdInput.describe("Block ID"),
|
|
17
20
|
lines: z.number().optional().default(100).describe("Number of lines per log (default 100)"),
|
|
18
21
|
sampleId: z
|
|
19
22
|
.string()
|
|
20
23
|
.optional()
|
|
21
24
|
.describe("Specific sample/key to read logs for (reads all if omitted)"),
|
|
22
|
-
},
|
|
25
|
+
}),
|
|
23
26
|
},
|
|
24
27
|
async ({ projectId, blockId, lines, sampleId }) => {
|
|
25
28
|
const project = await ctx.getOpenedProject(projectId);
|
|
@@ -77,11 +80,13 @@ export function registerLogTools(server: McpServer, ctx: ToolContext): void {
|
|
|
77
80
|
server.registerTool(
|
|
78
81
|
"get_app_log",
|
|
79
82
|
{
|
|
83
|
+
title: "Get Application Log",
|
|
84
|
+
annotations: hints.read,
|
|
80
85
|
description: "Read recent lines from the application log. Useful for debugging errors.",
|
|
81
|
-
inputSchema: {
|
|
86
|
+
inputSchema: z.object({
|
|
82
87
|
lines: z.number().optional().default(50).describe("Number of lines to return (default 50)"),
|
|
83
88
|
search: z.string().optional().describe("Filter lines containing this substring"),
|
|
84
|
-
},
|
|
89
|
+
}),
|
|
85
90
|
},
|
|
86
91
|
async ({ lines, search }) => {
|
|
87
92
|
if (!ctx.callbacks.readAppLog) {
|
package/src/tools/ping.ts
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
|
-
import type { McpServer } from "@modelcontextprotocol/
|
|
1
|
+
import type { McpServer } from "@modelcontextprotocol/server";
|
|
2
2
|
import type { ToolContext } from "./types";
|
|
3
|
-
import { textResult } from "./types";
|
|
3
|
+
import { hints, textResult } from "./types";
|
|
4
4
|
|
|
5
5
|
export function registerPingTool(server: McpServer, ctx: ToolContext): void {
|
|
6
|
-
server.registerTool(
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
server.registerTool(
|
|
7
|
+
"ping",
|
|
8
|
+
{
|
|
9
|
+
title: "Ping",
|
|
10
|
+
annotations: hints.read,
|
|
11
|
+
description:
|
|
12
|
+
"Check that the MCP server responds. Returns `connected`: whether the application is connected to a backend server. Needs no connection.",
|
|
13
|
+
},
|
|
14
|
+
async () => {
|
|
15
|
+
return textResult({ status: "ok", connected: !!ctx.getMl() });
|
|
16
|
+
},
|
|
17
|
+
);
|
|
9
18
|
}
|