@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/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) {
|