@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.
- package/dist/index.d.ts +2 -1
- package/dist/instructions.cjs +27 -0
- package/dist/instructions.cjs.map +1 -0
- package/dist/instructions.js +27 -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 +43 -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 +42 -40
- package/dist/server.js.map +1 -1
- package/dist/tools/await.cjs +7 -4
- package/dist/tools/await.cjs.map +1 -1
- package/dist/tools/await.js +8 -5
- 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-state.cjs +17 -10
- package/dist/tools/block-state.cjs.map +1 -1
- package/dist/tools/block-state.js +18 -11
- package/dist/tools/block-state.js.map +1 -1
- package/dist/tools/blocks.cjs +55 -33
- package/dist/tools/blocks.cjs.map +1 -1
- package/dist/tools/blocks.js +56 -34
- 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 +23 -0
- package/src/server.test.ts +631 -0
- package/src/server.ts +63 -58
- package/src/tools/await.ts +9 -6
- package/src/tools/block-action-context.ts +9 -6
- package/src/tools/block-state.ts +21 -14
- package/src/tools/blocks.ts +58 -36
- 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/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
|
}
|
package/src/tools/projects.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
|
+
import { projectIdInput } from "./ids";
|
|
3
4
|
import type { ToolContext } from "./types";
|
|
4
|
-
import { textResult } from "./types";
|
|
5
|
+
import { hints, textResult } from "./types";
|
|
5
6
|
|
|
6
7
|
export function registerProjectTools(server: McpServer, ctx: ToolContext): void {
|
|
7
8
|
server.registerTool(
|
|
8
9
|
"list_projects",
|
|
9
|
-
{
|
|
10
|
+
{
|
|
11
|
+
title: "List Projects",
|
|
12
|
+
annotations: hints.read,
|
|
13
|
+
description: "List all projects with their IDs, labels, and status",
|
|
14
|
+
},
|
|
10
15
|
async () => {
|
|
11
16
|
const ml = ctx.requireMl();
|
|
12
17
|
await ml.projectList.refreshState();
|
|
@@ -26,8 +31,11 @@ export function registerProjectTools(server: McpServer, ctx: ToolContext): void
|
|
|
26
31
|
server.registerTool(
|
|
27
32
|
"create_project",
|
|
28
33
|
{
|
|
29
|
-
|
|
30
|
-
|
|
34
|
+
title: "Create Project",
|
|
35
|
+
annotations: hints.additive,
|
|
36
|
+
description:
|
|
37
|
+
"Create a new, empty project and return its ID. Call open_project before adding blocks to it.",
|
|
38
|
+
inputSchema: z.object({ label: z.string().describe("Project name") }),
|
|
31
39
|
},
|
|
32
40
|
async ({ label }) => {
|
|
33
41
|
const projectId = await ctx.requireMl().createProject({ label });
|
|
@@ -39,10 +47,12 @@ export function registerProjectTools(server: McpServer, ctx: ToolContext): void
|
|
|
39
47
|
server.registerTool(
|
|
40
48
|
"open_project",
|
|
41
49
|
{
|
|
50
|
+
title: "Open Project",
|
|
51
|
+
annotations: hints.idempotent,
|
|
42
52
|
description: "Open a project for editing. Required before working with blocks.",
|
|
43
|
-
inputSchema: {
|
|
44
|
-
projectId:
|
|
45
|
-
},
|
|
53
|
+
inputSchema: z.object({
|
|
54
|
+
projectId: projectIdInput.describe("Project ID from list_projects or create_project"),
|
|
55
|
+
}),
|
|
46
56
|
},
|
|
47
57
|
async ({ projectId }) => {
|
|
48
58
|
const entry = await ctx.resolveProject(projectId);
|
|
@@ -55,8 +65,11 @@ export function registerProjectTools(server: McpServer, ctx: ToolContext): void
|
|
|
55
65
|
server.registerTool(
|
|
56
66
|
"close_project",
|
|
57
67
|
{
|
|
58
|
-
|
|
59
|
-
|
|
68
|
+
title: "Close Project",
|
|
69
|
+
annotations: hints.idempotent,
|
|
70
|
+
description:
|
|
71
|
+
"Close an opened project, releasing its resources in the application. Nothing is deleted.",
|
|
72
|
+
inputSchema: z.object({ projectId: projectIdInput.describe("Project ID") }),
|
|
60
73
|
},
|
|
61
74
|
async ({ projectId }) => {
|
|
62
75
|
const entry = await ctx.resolveProject(projectId);
|
|
@@ -69,8 +82,10 @@ export function registerProjectTools(server: McpServer, ctx: ToolContext): void
|
|
|
69
82
|
server.registerTool(
|
|
70
83
|
"delete_project",
|
|
71
84
|
{
|
|
85
|
+
title: "Delete Project",
|
|
86
|
+
annotations: hints.destructive,
|
|
72
87
|
description: "Delete a project permanently. The project must be closed first.",
|
|
73
|
-
inputSchema: { projectId:
|
|
88
|
+
inputSchema: z.object({ projectId: projectIdInput.describe("Project ID") }),
|
|
74
89
|
},
|
|
75
90
|
async ({ projectId }) => {
|
|
76
91
|
const entry = await ctx.resolveProject(projectId);
|
package/src/tools/screenshot.ts
CHANGED
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
import { writeFile } from "node:fs/promises";
|
|
2
2
|
import { resolve } from "node:path";
|
|
3
|
-
import type { McpServer } from "@modelcontextprotocol/
|
|
3
|
+
import type { McpServer } from "@modelcontextprotocol/server";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import type { ToolContext } from "./types";
|
|
6
|
-
import { errorResult } from "./types";
|
|
6
|
+
import { errorResult, hints } from "./types";
|
|
7
7
|
|
|
8
8
|
export function registerScreenshotTool(server: McpServer, ctx: ToolContext): void {
|
|
9
9
|
server.registerTool(
|
|
10
10
|
"capture_screenshot",
|
|
11
11
|
{
|
|
12
|
+
title: "Capture Screenshot",
|
|
13
|
+
annotations: hints.additive,
|
|
12
14
|
description:
|
|
13
15
|
"Capture a screenshot of the current application window. Optionally save to a file.",
|
|
14
|
-
inputSchema: {
|
|
16
|
+
inputSchema: z.object({
|
|
15
17
|
savePath: z
|
|
16
18
|
.string()
|
|
17
19
|
.optional()
|
|
18
20
|
.describe(
|
|
19
21
|
"Absolute file path to save the screenshot as PNG. If omitted, returns the image inline only.",
|
|
20
22
|
),
|
|
21
|
-
},
|
|
23
|
+
}),
|
|
22
24
|
},
|
|
23
|
-
async ({ savePath }
|
|
25
|
+
async ({ savePath }) => {
|
|
24
26
|
if (!ctx.callbacks.captureScreenshot) {
|
|
25
27
|
return errorResult(
|
|
26
28
|
"Screenshot capture is not available.",
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { authorMarkerSource } from "./types";
|
|
3
|
+
|
|
4
|
+
test("author markers keep the id and count the version up from 1", () => {
|
|
5
|
+
const next = authorMarkerSource("mcp-1a2b3c4d");
|
|
6
|
+
expect([next(), next(), next()]).toEqual([
|
|
7
|
+
{ authorId: "mcp-1a2b3c4d", localVersion: 1 },
|
|
8
|
+
{ authorId: "mcp-1a2b3c4d", localVersion: 2 },
|
|
9
|
+
{ authorId: "mcp-1a2b3c4d", localVersion: 3 },
|
|
10
|
+
]);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test("two sources count separately", () => {
|
|
14
|
+
const first = authorMarkerSource("mcp-aaaaaaaa");
|
|
15
|
+
const second = authorMarkerSource("mcp-bbbbbbbb");
|
|
16
|
+
first();
|
|
17
|
+
expect(second()).toEqual({ authorId: "mcp-bbbbbbbb", localVersion: 1 });
|
|
18
|
+
expect(first()).toEqual({ authorId: "mcp-aaaaaaaa", localVersion: 2 });
|
|
19
|
+
});
|
package/src/tools/types.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type {
|
|
|
2
2
|
AuthorMarker,
|
|
3
3
|
MiddleLayer,
|
|
4
4
|
Project,
|
|
5
|
+
ProjectId,
|
|
5
6
|
ProjectListEntry,
|
|
6
7
|
} from "@milaboratories/pl-middle-layer";
|
|
7
8
|
import type { PlMcpServerCallbacks } from "../server";
|
|
@@ -11,13 +12,80 @@ export type { AuthorMarker };
|
|
|
11
12
|
export interface ToolContext {
|
|
12
13
|
getMl: () => MiddleLayer | null;
|
|
13
14
|
requireMl: () => MiddleLayer;
|
|
14
|
-
resolveProject: (projectId:
|
|
15
|
-
getOpenedProject: (projectId:
|
|
15
|
+
resolveProject: (projectId: ProjectId) => Promise<ProjectListEntry>;
|
|
16
|
+
getOpenedProject: (projectId: ProjectId) => Promise<Project>;
|
|
16
17
|
callbacks: PlMcpServerCallbacks;
|
|
17
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Returns the marker for the next write made through MCP. All writes of one server instance carry
|
|
20
|
+
* the same `authorId`, whichever client asked for them, and a `localVersion` that grows with
|
|
21
|
+
* every call.
|
|
22
|
+
*/
|
|
18
23
|
getAuthorMarker: () => AuthorMarker;
|
|
19
24
|
}
|
|
20
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Makes the author markers of one writer: every call returns a marker with `authorId` and the next
|
|
28
|
+
* `localVersion`, counted from 1.
|
|
29
|
+
*/
|
|
30
|
+
export function authorMarkerSource(authorId: string): () => AuthorMarker {
|
|
31
|
+
let localVersion = 0;
|
|
32
|
+
return () => ({ authorId, localVersion: ++localVersion });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The four behaviour hints of a tool, all stated. A client reads a missing hint as the worst case
|
|
37
|
+
* (not read-only, destructive, not idempotent, open world), so no tool leaves one out.
|
|
38
|
+
*/
|
|
39
|
+
export type ToolHints = {
|
|
40
|
+
/** The tool changes nothing. */
|
|
41
|
+
readOnlyHint: boolean;
|
|
42
|
+
/** The tool may replace or discard existing data or work, not only add to it. */
|
|
43
|
+
destructiveHint: boolean;
|
|
44
|
+
/** Calling the tool again with the same arguments changes nothing further. */
|
|
45
|
+
idempotentHint: boolean;
|
|
46
|
+
/** The tool reaches beyond the application and the backend it is connected to. */
|
|
47
|
+
openWorldHint: boolean;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/** The hint sets tools choose from. A tool that fits none spreads the nearest one and overrides. */
|
|
51
|
+
export const hints = {
|
|
52
|
+
/** Reads state; safe to call in parallel and to repeat. */
|
|
53
|
+
read: {
|
|
54
|
+
readOnlyHint: true,
|
|
55
|
+
destructiveHint: false,
|
|
56
|
+
idempotentHint: true,
|
|
57
|
+
openWorldHint: false,
|
|
58
|
+
},
|
|
59
|
+
/** Adds something or starts something; a second call does it again. Loses nothing. */
|
|
60
|
+
additive: {
|
|
61
|
+
readOnlyHint: false,
|
|
62
|
+
destructiveHint: false,
|
|
63
|
+
idempotentHint: false,
|
|
64
|
+
openWorldHint: false,
|
|
65
|
+
},
|
|
66
|
+
/** Puts the application into a state; a second call changes nothing. Loses nothing. */
|
|
67
|
+
idempotent: {
|
|
68
|
+
readOnlyHint: false,
|
|
69
|
+
destructiveHint: false,
|
|
70
|
+
idempotentHint: true,
|
|
71
|
+
openWorldHint: false,
|
|
72
|
+
},
|
|
73
|
+
/** Replaces or discards data, configuration or running work; a second call changes nothing more. */
|
|
74
|
+
destructive: {
|
|
75
|
+
readOnlyHint: false,
|
|
76
|
+
destructiveHint: true,
|
|
77
|
+
idempotentHint: true,
|
|
78
|
+
openWorldHint: false,
|
|
79
|
+
},
|
|
80
|
+
/** Acts on the application window or runs given code: the effect depends on what it hits. */
|
|
81
|
+
unpredictable: {
|
|
82
|
+
readOnlyHint: false,
|
|
83
|
+
destructiveHint: true,
|
|
84
|
+
idempotentHint: false,
|
|
85
|
+
openWorldHint: false,
|
|
86
|
+
},
|
|
87
|
+
} as const satisfies Record<string, ToolHints>;
|
|
88
|
+
|
|
21
89
|
export function textResult(data: unknown) {
|
|
22
90
|
return {
|
|
23
91
|
content: [{ type: "text" as const, text: JSON.stringify(data) }],
|
|
@@ -1,19 +1,22 @@
|
|
|
1
|
-
import type { McpServer } from "@modelcontextprotocol/
|
|
1
|
+
import type { McpServer } from "@modelcontextprotocol/server";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { projectIdInput, blockIdInput } from "./ids";
|
|
3
4
|
import type { ToolContext } from "./types";
|
|
4
|
-
import { errorResult, textResult } from "./types";
|
|
5
|
+
import { errorResult, hints, textResult } from "./types";
|
|
5
6
|
|
|
6
7
|
export function registerUIInteractionTools(server: McpServer, ctx: ToolContext): void {
|
|
7
8
|
server.registerTool(
|
|
8
9
|
"click",
|
|
9
10
|
{
|
|
11
|
+
title: "Click in the Application Window",
|
|
12
|
+
annotations: hints.unpredictable,
|
|
10
13
|
description:
|
|
11
14
|
"Click at coordinates (x, y) in the application window. Use capture_screenshot to find element positions.",
|
|
12
|
-
inputSchema: {
|
|
15
|
+
inputSchema: z.object({
|
|
13
16
|
x: z.number().describe("X coordinate"),
|
|
14
17
|
y: z.number().describe("Y coordinate"),
|
|
15
18
|
doubleClick: z.boolean().optional().describe("Double click"),
|
|
16
|
-
},
|
|
19
|
+
}),
|
|
17
20
|
},
|
|
18
21
|
async ({ x, y, doubleClick }) => {
|
|
19
22
|
if (!ctx.callbacks.sendInputEvent) {
|
|
@@ -38,10 +41,13 @@ export function registerUIInteractionTools(server: McpServer, ctx: ToolContext):
|
|
|
38
41
|
server.registerTool(
|
|
39
42
|
"type_text",
|
|
40
43
|
{
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
title: "Type Text",
|
|
45
|
+
annotations: hints.unpredictable,
|
|
46
|
+
description:
|
|
47
|
+
"Type text into the element that has focus in the application window. UI tool: not needed to configure blocks.",
|
|
48
|
+
inputSchema: z.object({
|
|
43
49
|
text: z.string().describe("Text to type"),
|
|
44
|
-
},
|
|
50
|
+
}),
|
|
45
51
|
},
|
|
46
52
|
async ({ text }) => {
|
|
47
53
|
if (!ctx.callbacks.sendInputEvent) {
|
|
@@ -62,8 +68,10 @@ export function registerUIInteractionTools(server: McpServer, ctx: ToolContext):
|
|
|
62
68
|
server.registerTool(
|
|
63
69
|
"press_key",
|
|
64
70
|
{
|
|
71
|
+
title: "Press Key",
|
|
72
|
+
annotations: hints.unpredictable,
|
|
65
73
|
description: "Press a keyboard key (Enter, Tab, Escape, Backspace, ArrowDown, ArrowUp, etc.)",
|
|
66
|
-
inputSchema: {
|
|
74
|
+
inputSchema: z.object({
|
|
67
75
|
key: z
|
|
68
76
|
.string()
|
|
69
77
|
.describe("Key name (e.g. 'Enter', 'Tab', 'Escape', 'Backspace', 'ArrowDown')"),
|
|
@@ -71,7 +79,7 @@ export function registerUIInteractionTools(server: McpServer, ctx: ToolContext):
|
|
|
71
79
|
.array(z.enum(["shift", "control", "alt", "meta"]))
|
|
72
80
|
.optional()
|
|
73
81
|
.describe("Modifier keys to hold"),
|
|
74
|
-
},
|
|
82
|
+
}),
|
|
75
83
|
},
|
|
76
84
|
async ({ key, modifiers }) => {
|
|
77
85
|
if (!ctx.callbacks.sendInputEvent) {
|
|
@@ -107,13 +115,16 @@ export function registerUIInteractionTools(server: McpServer, ctx: ToolContext):
|
|
|
107
115
|
server.registerTool(
|
|
108
116
|
"scroll",
|
|
109
117
|
{
|
|
110
|
-
|
|
111
|
-
|
|
118
|
+
title: "Scroll",
|
|
119
|
+
annotations: hints.additive,
|
|
120
|
+
description:
|
|
121
|
+
"Scroll the application window at a given position. UI tool: not needed to configure blocks.",
|
|
122
|
+
inputSchema: z.object({
|
|
112
123
|
x: z.number().describe("X coordinate to scroll at"),
|
|
113
124
|
y: z.number().describe("Y coordinate to scroll at"),
|
|
114
125
|
deltaX: z.number().optional().default(0).describe("Horizontal scroll amount"),
|
|
115
126
|
deltaY: z.number().describe("Vertical scroll amount (negative = up, positive = down)"),
|
|
116
|
-
},
|
|
127
|
+
}),
|
|
117
128
|
},
|
|
118
129
|
async ({ x, y, deltaX, deltaY }) => {
|
|
119
130
|
if (!ctx.callbacks.sendInputEvent) {
|
|
@@ -136,21 +147,21 @@ export function registerUIInteractionTools(server: McpServer, ctx: ToolContext):
|
|
|
136
147
|
server.registerTool(
|
|
137
148
|
"execute_js",
|
|
138
149
|
{
|
|
150
|
+
title: "Execute JavaScript",
|
|
151
|
+
annotations: { ...hints.unpredictable, openWorldHint: true },
|
|
139
152
|
description:
|
|
140
153
|
"Execute JavaScript in a renderer and return the result. By default runs in the topmost webContents (main app / topmost modal). Pass projectId + blockId to run inside that block's webview, where `window.platforma` is exposed and the driverKit (e.g. `window.platforma.lsDriver.getLocalFileHandle`) is callable. The block must already be open — call `select_block` first if needed.",
|
|
141
|
-
inputSchema: {
|
|
154
|
+
inputSchema: z.object({
|
|
142
155
|
code: z.string().describe("JavaScript code to execute"),
|
|
143
|
-
projectId:
|
|
144
|
-
.string()
|
|
156
|
+
projectId: projectIdInput
|
|
145
157
|
.optional()
|
|
146
158
|
.describe("Target project ID. Must be paired with blockId."),
|
|
147
|
-
blockId:
|
|
148
|
-
.string()
|
|
159
|
+
blockId: blockIdInput
|
|
149
160
|
.optional()
|
|
150
161
|
.describe(
|
|
151
162
|
"Target block ID. When provided with projectId, JS runs in that block's webview (where `window.platforma` is available).",
|
|
152
163
|
),
|
|
153
|
-
},
|
|
164
|
+
}),
|
|
154
165
|
},
|
|
155
166
|
async ({ code, projectId, blockId }) => {
|
|
156
167
|
if (!ctx.callbacks.executeJavaScript) {
|