@gtkx/mcp 1.0.0-rc.3 → 1.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/server.js CHANGED
@@ -5,8 +5,8 @@ import { createRequire } from "node:module";
5
5
  import { z } from "zod";
6
6
  import { AppRouter } from "./app-router.js";
7
7
  import { ConnectionRegistry } from "./connection-registry.js";
8
- import { DEFAULT_SOCKET_PATH, fireEventParams, queryParams, screenshotParams, treeParams, typeParams, widgetIdParams, } from "./protocol/schemas.js";
9
- import { buildReferenceTools, createReferenceProvider, registerReferenceResources } from "./reference.js";
8
+ import { DEFAULT_SOCKET_PATH, DEFAULT_SUBTREE_DEPTH, fireEventParams, MAX_SUBTREE_WIDGETS, queryParams, screenshotParams, treeParams, typeParams, widgetIdParams, widgetPropsParams, } from "./protocol/schemas.js";
9
+ import { buildReferenceTools, createReferenceProvider, registerReferenceResources, } from "./reference.js";
10
10
  import { SocketServer } from "./socket-server.js";
11
11
  import { defineTool, imageContent, registerTool, textContent } from "./tool.js";
12
12
  const require = createRequire(import.meta.url);
@@ -19,13 +19,28 @@ const WIDGET_ID_DESCRIPTION = "Widget ID obtained from `gtkx_get_widget_tree`, `
19
19
  const applicationIdShape = { applicationId: z.string().optional().describe(APPLICATION_ID_DESCRIPTION) };
20
20
  const widgetIdShape = {
21
21
  ...applicationIdShape,
22
- widgetId: widgetIdParams.shape.widgetId.describe(WIDGET_ID_DESCRIPTION),
22
+ ...describeParams(widgetIdParams.shape, { widgetId: WIDGET_ID_DESCRIPTION }),
23
+ };
24
+ const widgetPropsShape = {
25
+ ...applicationIdShape,
26
+ ...describeParams(widgetPropsParams.shape, {
27
+ widgetId: WIDGET_ID_DESCRIPTION,
28
+ properties: "GObject property names to read as well, in kebab-case or camelCase (\"current-breakpoint\" or " +
29
+ "\"currentBreakpoint\"). Omit for the summary alone.",
30
+ maxDepth: `How many levels of descendants to include: ${String(DEFAULT_SUBTREE_DEPTH)} by default, and 0 ` +
31
+ `for the widget on its own. At most ${String(MAX_SUBTREE_WIDGETS)} widgets come back whatever ` +
32
+ "the depth, and any widget whose own direct children were left out carries a `hiddenChildren` count.",
33
+ }),
23
34
  };
24
35
  const treeShape = {
25
36
  ...applicationIdShape,
26
- rootId: treeParams.shape.rootId.describe("Render only the subtree rooted at this widget ID (from a prior tree or query). Omit for the whole app."),
27
- maxDepth: treeParams.shape.maxDepth.describe("Limit how many levels deep to render; deeper descendants are summarized with a count. " +
28
- "Combine with rootId to drill in without dumping the whole tree."),
37
+ ...describeParams(treeParams.shape, {
38
+ rootId: "Render only the subtree rooted at this widget ID (from a prior tree or query). Omit for the " +
39
+ "whole app.",
40
+ maxDepth: "Limit how many levels deep to render, and 0 for the root widget on its own; deeper " +
41
+ "descendants are summarized with a count. Combine with rootId to drill in without dumping " +
42
+ "the whole tree.",
43
+ }),
29
44
  };
30
45
  const listAppsShape = {
31
46
  waitForApps: z
@@ -36,25 +51,48 @@ const listAppsShape = {
36
51
  };
37
52
  const queryWidgetsShape = {
38
53
  ...applicationIdShape,
39
- by: queryParams.shape.by.describe("Query type"),
40
- value: queryParams.shape.value.describe("Value to search for"),
41
- options: queryParams.shape.options.describe("Additional query options"),
54
+ ...describeParams(queryParams.shape, {
55
+ by: "Query type",
56
+ value: "Value to search for",
57
+ options: "Additional query options",
58
+ }),
42
59
  };
43
60
  const typeShape = {
44
- ...widgetIdShape,
45
- text: typeParams.shape.text.describe("Text to type"),
46
- clear: typeParams.shape.clear.describe("Clear existing text before typing"),
61
+ ...applicationIdShape,
62
+ ...describeParams(typeParams.shape, {
63
+ widgetId: WIDGET_ID_DESCRIPTION,
64
+ text: "Text to type",
65
+ clear: "Clear existing text before typing",
66
+ }),
47
67
  };
48
68
  const fireEventShape = {
49
- ...widgetIdShape,
50
- signal: fireEventParams.shape.signal.describe("GTK4 signal name to emit"),
51
- args: fireEventParams.shape.args.describe("Arguments to pass to the signal"),
69
+ ...applicationIdShape,
70
+ ...describeParams(fireEventParams.shape, {
71
+ widgetId: WIDGET_ID_DESCRIPTION,
72
+ signal: "GTK4 signal name to emit",
73
+ args: "Arguments to pass to the signal",
74
+ }),
52
75
  };
53
76
  const screenshotShape = {
54
77
  ...applicationIdShape,
55
- windowId: screenshotParams.shape.windowId.describe("Window ID to capture. If not specified, captures the first window."),
56
- path: screenshotParams.shape.path.describe("Absolute path to write the PNG to on the app's machine. If set, the screenshot is saved there " +
57
- "in addition to being returned."),
78
+ ...describeParams(screenshotParams.shape, {
79
+ windowId: "Window ID to capture. If not specified, captures the first window.",
80
+ path: "Absolute path to write the PNG to on the app's machine. If set, the screenshot is saved there " +
81
+ "in addition to being returned.",
82
+ }),
83
+ };
84
+ function describeParams(shape, descriptions) {
85
+ const described = Object.entries(shape).map(([key, schema]) => [
86
+ key,
87
+ schema.describe(descriptions[key]),
88
+ ]);
89
+ return Object.fromEntries(described);
90
+ }
91
+ const connectStdio = async (mcpServer, stop) => {
92
+ const transport = new StdioServerTransport();
93
+ process.stdin.on("end", () => void stop());
94
+ process.stdin.on("close", () => void stop());
95
+ await mcpServer.connect(transport);
58
96
  };
59
97
  const logSocketError = (event) => {
60
98
  const error = event.detail;
@@ -109,6 +147,28 @@ const screenshotTool = (appRouter) => defineTool({
109
147
  return imageContent(result.data, result.mimeType);
110
148
  },
111
149
  });
150
+ const widgetPropsTool = (appRouter) => defineTool({
151
+ name: "gtkx_get_widget_props",
152
+ title: "Get widget properties",
153
+ kind: "readOnly",
154
+ description: "Get a fixed summary of one widget by ID: type, accessible role, name, text, sensitivity, " +
155
+ "visibility, CSS classes, and the same summary for its descendants. The subtree is bounded " +
156
+ `twice: ${String(DEFAULT_SUBTREE_DEPTH)} levels deep unless \`maxDepth\` says otherwise, and ` +
157
+ `${String(MAX_SUBTREE_WIDGETS)} widgets in all, filled breadth first. Wherever either bound ` +
158
+ "cut a branch, that widget carries `hiddenChildren`, the count of its own direct children left " +
159
+ "out rather than of everything below them; call again with that widget's ID to drill in, or " +
160
+ "use `gtkx_get_widget_tree` for a wider map. Pass `properties` to read GObject properties too; " +
161
+ "they come back first in the payload, each under its canonical kebab-case name as " +
162
+ "`{type, value}`, where an enum or flags value is its GType value name, a 64-bit integer a " +
163
+ "decimal string, and an object its GType name plus `widgetId` when it is a widget. Asking for " +
164
+ "a property the widget does not have fails; a value that cannot be marshalled carries a `note` " +
165
+ "instead.",
166
+ inputSchema: widgetPropsShape,
167
+ handler: async ({ applicationId, ...params }) => {
168
+ const result = await appRouter.sendToApp(applicationId, "widget.getProps", params);
169
+ return textContent(JSON.stringify(result, null, 2));
170
+ },
171
+ });
112
172
  function buildInspectionTools(appRouter) {
113
173
  return [
114
174
  listAppsTool(appRouter),
@@ -132,26 +192,17 @@ function buildInspectionTools(appRouter) {
132
192
  name: "gtkx_query_widgets",
133
193
  title: "Query widgets",
134
194
  kind: "readOnly",
135
- description: "Find widgets by role, text, name, or label. Returns matching widgets with their IDs and properties.",
195
+ description: "Find widgets by role, text, name, or label. Returns each match with its ID and the same " +
196
+ "fixed summary `gtkx_get_widget_props` returns, with no descendants: a match that has " +
197
+ "children carries `hiddenChildren`, the count of its direct children left out. Read a " +
198
+ "match's subtree with `gtkx_get_widget_props` or `gtkx_get_widget_tree`.",
136
199
  inputSchema: queryWidgetsShape,
137
200
  handler: async ({ applicationId, ...params }) => {
138
201
  const result = await appRouter.sendToApp(applicationId, "widget.query", params);
139
202
  return textContent(JSON.stringify(result, null, 2));
140
203
  },
141
204
  }),
142
- defineTool({
143
- name: "gtkx_get_widget_props",
144
- title: "Get widget properties",
145
- kind: "readOnly",
146
- description: "Get a fixed summary of one widget by ID: type, accessible role, name, text, sensitivity, " +
147
- "visibility, CSS classes, and the full subtree of descendant widgets. It does not return " +
148
- "arbitrary GObject properties.",
149
- inputSchema: widgetIdShape,
150
- handler: async ({ applicationId, ...params }) => {
151
- const result = await appRouter.sendToApp(applicationId, "widget.getProps", params);
152
- return textContent(JSON.stringify(result, null, 2));
153
- },
154
- }),
205
+ widgetPropsTool(appRouter),
155
206
  screenshotTool(appRouter),
156
207
  ];
157
208
  }
@@ -161,7 +212,9 @@ function buildInteractionTools(appRouter) {
161
212
  name: "gtkx_click",
162
213
  title: "Click widget",
163
214
  kind: "action",
164
- description: "Click a widget. Works with buttons, checkboxes, and other interactive widgets.",
215
+ description: "Click a widget through userEvent.click, with no special case per widget. Works with " +
216
+ "buttons, checkboxes, switches, list and grid rows, tree expanders, and column headers: a " +
217
+ "row is selected, an expander toggles its row's expansion, and a header sorts its column.",
165
218
  inputSchema: widgetIdShape,
166
219
  handler: async ({ applicationId, ...params }) => {
167
220
  await appRouter.sendToApp(applicationId, "widget.click", params);
@@ -186,8 +239,8 @@ function buildInteractionTools(appRouter) {
186
239
  description: "Emit a GTK4 signal on a widget. Use this for custom interactions.",
187
240
  inputSchema: fireEventShape,
188
241
  handler: async ({ applicationId, ...params }) => {
189
- await appRouter.sendToApp(applicationId, "widget.fireEvent", params);
190
- return textContent("Fired event");
242
+ const result = await appRouter.sendToApp(applicationId, "widget.fireEvent", params);
243
+ return textContent(JSON.stringify(result, null, 2));
191
244
  },
192
245
  }),
193
246
  ];
@@ -195,6 +248,35 @@ function buildInteractionTools(appRouter) {
195
248
  function buildTools(appRouter) {
196
249
  return [...buildInspectionTools(appRouter), ...buildInteractionTools(appRouter)];
197
250
  }
251
+ const registerTools = (mcpServer, appRouter, provider) => {
252
+ for (const tool of [...buildTools(appRouter), ...buildReferenceTools(provider)]) {
253
+ registerTool(mcpServer, tool);
254
+ }
255
+ };
256
+ async function stopServer(state) {
257
+ if (state.isStopped) {
258
+ return;
259
+ }
260
+ state.isStopped = true;
261
+ await state.socketServer.stop();
262
+ await state.mcpServer.close();
263
+ }
264
+ async function startServer(state) {
265
+ if (state.isStopped) {
266
+ throw new Error("createMcpServer: a stopped server cannot be started again");
267
+ }
268
+ await state.socketServer.start();
269
+ if (state.isStarted) {
270
+ return;
271
+ }
272
+ state.isStarted = true;
273
+ log.info(`socket server listening on ${state.socketPath}`);
274
+ await connectStdio(state.mcpServer, () => stopServer(state));
275
+ }
276
+ const createServerHandle = (socketServer, mcpServer, socketPath) => {
277
+ const state = { socketServer, mcpServer, socketPath, isStopped: false, isStarted: false };
278
+ return { start: () => startServer(state), stop: () => stopServer(state) };
279
+ };
198
280
  const createMcpServer = (options) => {
199
281
  const socketPath = options.socketPath ?? DEFAULT_SOCKET_PATH;
200
282
  const registry = new ConnectionRegistry();
@@ -209,29 +291,10 @@ const createMcpServer = (options) => {
209
291
  log.info(`app unregistered: ${event.detail}`);
210
292
  });
211
293
  const mcpServer = new McpServer({ name: "gtkx-mcp", version: options.version });
212
- const referenceProvider = createReferenceProvider(() => appRouter.getProjectRoot() ?? process.cwd());
213
- for (const tool of [...buildTools(appRouter), ...buildReferenceTools(referenceProvider)]) {
214
- registerTool(mcpServer, tool);
215
- }
294
+ const referenceProvider = createReferenceProvider({ getAppRoot: () => appRouter.getProjectRoot() });
295
+ registerTools(mcpServer, appRouter, referenceProvider);
216
296
  registerReferenceResources(mcpServer, referenceProvider);
217
- let isStopped = false;
218
- const stop = async () => {
219
- if (isStopped) {
220
- return;
221
- }
222
- isStopped = true;
223
- await socketServer.stop();
224
- await mcpServer.close();
225
- };
226
- const start = async () => {
227
- await socketServer.start();
228
- log.info(`socket server listening on ${socketPath}`);
229
- const transport = new StdioServerTransport();
230
- process.stdin.on("end", () => void stop());
231
- process.stdin.on("close", () => void stop());
232
- await mcpServer.connect(transport);
233
- };
234
- return { start, stop };
297
+ return createServerHandle(socketServer, mcpServer, socketPath);
235
298
  };
236
299
  async function main() {
237
300
  const server = createMcpServer({ version });
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,uBAAuB,EAAe,MAAM,aAAa,CAAC;AACjF,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAA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BAAuB,CAAC;QACpB,QAAQ,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE;KAChC,CAAC,CAAC;IAEH,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;AACzB,CAAC;AAED,OAAO,EAAE,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC","sourcesContent":["import { createLogger, installGracefulShutdown, type Logger } from \"@gtkx/utils\";\nimport { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\nimport { createRequire } from \"node:module\";\nimport { z } from \"zod\";\nimport type { ConnectionErrorEvent } from \"./transport.js\";\nimport { type AppRegisteredEvent, AppRouter, type AppUnregisteredEvent } from \"./app-router.js\";\nimport { ConnectionRegistry } from \"./connection-registry.js\";\nimport {\n type AppInfo,\n DEFAULT_SOCKET_PATH,\n fireEventParams,\n queryParams,\n screenshotParams,\n treeParams,\n typeParams,\n widgetIdParams,\n} from \"./protocol/schemas.js\";\nimport { buildReferenceTools, createReferenceProvider, registerReferenceResources } from \"./reference.js\";\nimport { SocketServer } from \"./socket-server.js\";\nimport { defineTool, imageContent, registerTool, textContent, type Tool } from \"./tool.js\";\n\ntype CreateMcpServerOptions = {\n socketPath?: string;\n version: string;\n};\n\ntype McpServerHandle = {\n start(): Promise<void>;\n stop(): Promise<void>;\n};\n\ntype AppWindow = { id: string; title: string | null };\ntype AppWithWindows = AppInfo & { windows?: AppWindow[] };\n\nconst require = createRequire(import.meta.url);\nconst { version } = require(\"../package.json\") as { version: string };\nconst log: Logger = createLogger(\"mcp\");\nconst APPLICATION_ID_DESCRIPTION = \"Application ID to query. If not specified, uses the first connected app.\";\n\nconst WIDGET_ID_DESCRIPTION =\n \"Widget ID obtained from `gtkx_get_widget_tree`, `gtkx_query_widgets`, or `gtkx_get_widget_props`. \" +\n \"IDs are scoped to a single app. An ID stays valid for as long as its widget is mounted and stops \" +\n \"resolving once the widget is unmounted.\";\n\nconst applicationIdShape = { applicationId: z.string().optional().describe(APPLICATION_ID_DESCRIPTION) };\n\nconst widgetIdShape = {\n ...applicationIdShape,\n widgetId: widgetIdParams.shape.widgetId.describe(WIDGET_ID_DESCRIPTION),\n};\n\nconst treeShape = {\n ...applicationIdShape,\n rootId: treeParams.shape.rootId.describe(\n \"Render only the subtree rooted at this widget ID (from a prior tree or query). Omit for the whole app.\",\n ),\n maxDepth: treeParams.shape.maxDepth.describe(\n \"Limit how many levels deep to render; deeper descendants are summarized with a count. \" +\n \"Combine with rootId to drill in without dumping the whole tree.\",\n ),\n};\n\nconst listAppsShape = {\n waitForApps: z\n .boolean()\n .optional()\n .describe(\n \"If true, wait for at least one app to register before returning. Useful when app is still starting.\",\n ),\n timeout: z.number().optional().describe(\"Timeout in milliseconds when waitForApps is true (default: 10000)\"),\n};\n\nconst queryWidgetsShape = {\n ...applicationIdShape,\n by: queryParams.shape.by.describe(\"Query type\"),\n value: queryParams.shape.value.describe(\"Value to search for\"),\n options: queryParams.shape.options.describe(\"Additional query options\"),\n};\n\nconst typeShape = {\n ...widgetIdShape,\n text: typeParams.shape.text.describe(\"Text to type\"),\n clear: typeParams.shape.clear.describe(\"Clear existing text before typing\"),\n};\n\nconst fireEventShape = {\n ...widgetIdShape,\n signal: fireEventParams.shape.signal.describe(\"GTK4 signal name to emit\"),\n args: fireEventParams.shape.args.describe(\"Arguments to pass to the signal\"),\n};\n\nconst screenshotShape = {\n ...applicationIdShape,\n windowId: screenshotParams.shape.windowId.describe(\n \"Window ID to capture. If not specified, captures the first window.\",\n ),\n path: screenshotParams.shape.path.describe(\n \"Absolute path to write the PNG to on the app's machine. If set, the screenshot is saved there \" +\n \"in addition to being returned.\",\n ),\n};\n\nconst logSocketError = (event: Event): void => {\n const error = (event as ConnectionErrorEvent).detail;\n const code = (error as NodeJS.ErrnoException).code;\n\n if (code === \"EPIPE\" || code === \"ECONNRESET\") {\n return;\n }\n\n log.error(`socket error: ${error.message}`);\n};\n\nconst appWithWindows = async (appRouter: AppRouter, app: AppInfo): Promise<AppWithWindows> => {\n try {\n const result = await appRouter.sendToApp<{ windows: AppWindow[] }>(\n app.applicationId,\n \"app.getWindows\",\n {},\n );\n\n return { ...app, windows: result.windows };\n } catch {\n return app;\n }\n};\n\nconst listAppsTool = (appRouter: AppRouter): Tool =>\n defineTool({\n name: \"gtkx_list_apps\",\n title: \"List apps\",\n kind: \"readOnly\",\n description: \"List all connected GTKX applications and their open windows.\",\n inputSchema: listAppsShape,\n handler: async ({ waitForApps, timeout }) => {\n if (waitForApps && !appRouter.hasConnectedApps()) {\n await appRouter.waitForApp(timeout);\n }\n\n const apps = appRouter.getApps();\n const appsWithWindows = await Promise.all(apps.map((app) => appWithWindows(appRouter, app)));\n\n return textContent(JSON.stringify(appsWithWindows, null, 2));\n },\n });\n\nconst screenshotTool = (appRouter: AppRouter): Tool =>\n defineTool({\n name: \"gtkx_take_screenshot\",\n title: \"Take screenshot\",\n kind: \"readOnly\",\n description:\n \"Capture a screenshot of a window. Returns base64-encoded PNG image data, and optionally writes \" +\n \"the PNG to `path` on the app's machine. You can't target widgets from a screenshot; use \" +\n \"`gtkx_get_widget_tree` to find widget IDs for interaction.\",\n inputSchema: screenshotShape,\n handler: async ({ applicationId, ...params }) => {\n const result = await appRouter.sendToApp<{ data: string; mimeType: string; savedPath?: string }>(\n applicationId,\n \"widget.screenshot\",\n params,\n );\n\n if (result.savedPath) {\n return {\n content: [\n { type: \"text\", text: `Screenshot saved to ${result.savedPath}` },\n { type: \"image\", data: result.data, mimeType: result.mimeType },\n ],\n };\n }\n\n return imageContent(result.data, result.mimeType);\n },\n });\n\nfunction buildInspectionTools(appRouter: AppRouter): Tool[] {\n return [\n listAppsTool(appRouter),\n defineTool({\n name: \"gtkx_get_widget_tree\",\n title: \"Widget tree\",\n kind: \"readOnly\",\n description:\n \"Get the widget hierarchy for a connected GTKX app. Returns a tree of widgets with their IDs, \" +\n \"types, roles, and properties. For large apps, pass `maxDepth` for a shallow overview and/or \" +\n \"`rootId` to render just one subtree instead of the whole (possibly truncated) tree.\",\n inputSchema: treeShape,\n handler: async ({ applicationId, rootId, maxDepth }) => {\n const result = await appRouter.sendToApp<{ tree: string }>(applicationId, \"widget.getTree\", {\n rootId,\n maxDepth,\n });\n\n return textContent(result.tree);\n },\n }),\n defineTool({\n name: \"gtkx_query_widgets\",\n title: \"Query widgets\",\n kind: \"readOnly\",\n description:\n \"Find widgets by role, text, name, or label. Returns matching widgets with their IDs and properties.\",\n inputSchema: queryWidgetsShape,\n handler: async ({ applicationId, ...params }) => {\n const result = await appRouter.sendToApp(applicationId, \"widget.query\", params);\n\n return textContent(JSON.stringify(result, null, 2));\n },\n }),\n defineTool({\n name: \"gtkx_get_widget_props\",\n title: \"Get widget properties\",\n kind: \"readOnly\",\n description:\n \"Get a fixed summary of one widget by ID: type, accessible role, name, text, sensitivity, \" +\n \"visibility, CSS classes, and the full subtree of descendant widgets. It does not return \" +\n \"arbitrary GObject properties.\",\n inputSchema: widgetIdShape,\n handler: async ({ applicationId, ...params }) => {\n const result = await appRouter.sendToApp(applicationId, \"widget.getProps\", params);\n\n return textContent(JSON.stringify(result, null, 2));\n },\n }),\n screenshotTool(appRouter),\n ];\n}\n\nfunction buildInteractionTools(appRouter: AppRouter): Tool[] {\n return [\n defineTool({\n name: \"gtkx_click\",\n title: \"Click widget\",\n kind: \"action\",\n description: \"Click a widget. Works with buttons, checkboxes, and other interactive widgets.\",\n inputSchema: widgetIdShape,\n handler: async ({ applicationId, ...params }) => {\n await appRouter.sendToApp(applicationId, \"widget.click\", params);\n\n return textContent(\"Clicked\");\n },\n }),\n defineTool({\n name: \"gtkx_type\",\n title: \"Type text\",\n kind: \"action\",\n description: \"Type text into an editable widget like Entry or TextView\",\n inputSchema: typeShape,\n handler: async ({ applicationId, ...params }) => {\n await appRouter.sendToApp(applicationId, \"widget.type\", params);\n\n return textContent(\"Typed text\");\n },\n }),\n defineTool({\n name: \"gtkx_fire_event\",\n title: \"Fire event\",\n kind: \"action\",\n description: \"Emit a GTK4 signal on a widget. Use this for custom interactions.\",\n inputSchema: fireEventShape,\n handler: async ({ applicationId, ...params }) => {\n await appRouter.sendToApp(applicationId, \"widget.fireEvent\", params);\n\n return textContent(\"Fired event\");\n },\n }),\n ];\n}\n\nfunction buildTools(appRouter: AppRouter): Tool[] {\n return [...buildInspectionTools(appRouter), ...buildInteractionTools(appRouter)];\n}\n\nconst createMcpServer = (options: CreateMcpServerOptions): McpServerHandle => {\n const socketPath = options.socketPath ?? DEFAULT_SOCKET_PATH;\n const registry = new ConnectionRegistry();\n const socketServer = new SocketServer(registry, socketPath);\n const appRouter = new AppRouter(registry);\n registry.addEventListener(\"error\", logSocketError);\n\n appRouter.addEventListener(\"appRegistered\", (event) => {\n const appInfo = (event as AppRegisteredEvent).detail;\n log.info(`app registered: ${appInfo.applicationId} (PID: ${String(appInfo.pid)})`);\n });\n\n appRouter.addEventListener(\"appUnregistered\", (event) => {\n log.info(`app unregistered: ${(event as AppUnregisteredEvent).detail}`);\n });\n\n const mcpServer = new McpServer({ name: \"gtkx-mcp\", version: options.version });\n const referenceProvider = createReferenceProvider(() => appRouter.getProjectRoot() ?? process.cwd());\n\n for (const tool of [...buildTools(appRouter), ...buildReferenceTools(referenceProvider)]) {\n registerTool(mcpServer, tool);\n }\n\n registerReferenceResources(mcpServer, referenceProvider);\n let isStopped = false;\n\n const stop = async (): Promise<void> => {\n if (isStopped) {\n return;\n }\n\n isStopped = true;\n await socketServer.stop();\n await mcpServer.close();\n };\n\n const start = async (): Promise<void> => {\n await socketServer.start();\n log.info(`socket server listening on ${socketPath}`);\n const transport = new StdioServerTransport();\n process.stdin.on(\"end\", () => void stop());\n process.stdin.on(\"close\", () => void stop());\n await mcpServer.connect(transport);\n };\n\n return { start, stop };\n};\n\nasync function main(): Promise<void> {\n const server = createMcpServer({ version });\n\n installGracefulShutdown({\n onSignal: () => server.stop(),\n });\n\n await server.start();\n}\n\nexport { log, createMcpServer, main };\n"]}
1
+ {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CAAC,IAAI,CAAC,mBAAmB,OAAO,CAAC,aAAa,UAAU,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACvF,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,gBAAgB,CAAC,iBAAiB,EAAE,CAAC,KAAK,EAAE,EAAE;QACpD,GAAG,CAAC,IAAI,CAAC,qBAAsB,KAA8B,CAAC,MAAM,EAAE,CAAC,CAAC;IAC5E,CAAC,CAAC,CAAC;IAEH,MAAM,SAAS,GAAG,IAAI,SAAS,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAChF,MAAM,iBAAiB,GAAG,uBAAuB,CAAC,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;IACpG,aAAa,CAAC,SAAS,EAAE,SAAS,EAAE,iBAAiB,CAAC,CAAC;IACvD,0BAA0B,CAAC,SAAS,EAAE,iBAAiB,CAAC,CAAC;IAEzD,OAAO,kBAAkB,CAAC,YAAY,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;AACnE,CAAC,CAAC;AAEF,KAAK,UAAU,IAAI;IACf,MAAM,MAAM,GAAG,eAAe,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC;IAE5C,uBAAuB,CAAC;QACpB,QAAQ,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE;KAChC,CAAC,CAAC;IAEH,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;AACzB,CAAC;AAED,OAAO,EAAE,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC","sourcesContent":["import { createLogger, installGracefulShutdown, type Logger } from \"@gtkx/utils\";\nimport { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\nimport { createRequire } from \"node:module\";\nimport { z } from \"zod\";\nimport type { ConnectionErrorEvent } from \"./transport.js\";\nimport { type AppRegisteredEvent, AppRouter, type AppUnregisteredEvent } from \"./app-router.js\";\nimport { ConnectionRegistry } from \"./connection-registry.js\";\nimport {\n type AppInfo,\n DEFAULT_SOCKET_PATH,\n DEFAULT_SUBTREE_DEPTH,\n fireEventParams,\n MAX_SUBTREE_WIDGETS,\n queryParams,\n screenshotParams,\n treeParams,\n typeParams,\n widgetIdParams,\n widgetPropsParams,\n} from \"./protocol/schemas.js\";\nimport {\n buildReferenceTools,\n createReferenceProvider,\n type ReferenceProvider,\n registerReferenceResources,\n} from \"./reference.js\";\nimport { SocketServer } from \"./socket-server.js\";\nimport { defineTool, imageContent, registerTool, textContent, type Tool } from \"./tool.js\";\n\ntype CreateMcpServerOptions = {\n socketPath?: string;\n version: string;\n};\n\ntype McpServerHandle = {\n start(): Promise<void>;\n stop(): Promise<void>;\n};\n\ntype ServerLifecycle = {\n socketServer: SocketServer;\n mcpServer: McpServer;\n socketPath: string;\n isStopped: boolean;\n isStarted: boolean;\n};\n\ntype AppWindow = { id: string; title: string | null };\ntype AppWithWindows = AppInfo & { windows?: AppWindow[] };\n\nconst require = createRequire(import.meta.url);\nconst { version } = require(\"../package.json\") as { version: string };\nconst log: Logger = createLogger(\"mcp\");\nconst APPLICATION_ID_DESCRIPTION = \"Application ID to query. If not specified, uses the first connected app.\";\n\nconst WIDGET_ID_DESCRIPTION =\n \"Widget ID obtained from `gtkx_get_widget_tree`, `gtkx_query_widgets`, or `gtkx_get_widget_props`. \" +\n \"IDs are scoped to a single app. An ID stays valid for as long as its widget is mounted and stops \" +\n \"resolving once the widget is unmounted.\";\n\nconst applicationIdShape = { applicationId: z.string().optional().describe(APPLICATION_ID_DESCRIPTION) };\n\nconst widgetIdShape = {\n ...applicationIdShape,\n ...describeParams(widgetIdParams.shape, { widgetId: WIDGET_ID_DESCRIPTION }),\n};\n\nconst widgetPropsShape = {\n ...applicationIdShape,\n ...describeParams(widgetPropsParams.shape, {\n widgetId: WIDGET_ID_DESCRIPTION,\n properties:\n \"GObject property names to read as well, in kebab-case or camelCase (\\\"current-breakpoint\\\" or \" +\n \"\\\"currentBreakpoint\\\"). Omit for the summary alone.\",\n maxDepth:\n `How many levels of descendants to include: ${String(DEFAULT_SUBTREE_DEPTH)} by default, and 0 ` +\n `for the widget on its own. At most ${String(MAX_SUBTREE_WIDGETS)} widgets come back whatever ` +\n \"the depth, and any widget whose own direct children were left out carries a `hiddenChildren` count.\",\n }),\n};\n\nconst treeShape = {\n ...applicationIdShape,\n ...describeParams(treeParams.shape, {\n rootId:\n \"Render only the subtree rooted at this widget ID (from a prior tree or query). Omit for the \" +\n \"whole app.\",\n maxDepth:\n \"Limit how many levels deep to render, and 0 for the root widget on its own; deeper \" +\n \"descendants are summarized with a count. Combine with rootId to drill in without dumping \" +\n \"the whole tree.\",\n }),\n};\n\nconst listAppsShape = {\n waitForApps: z\n .boolean()\n .optional()\n .describe(\n \"If true, wait for at least one app to register before returning. Useful when app is still starting.\",\n ),\n timeout: z.number().optional().describe(\"Timeout in milliseconds when waitForApps is true (default: 10000)\"),\n};\n\nconst queryWidgetsShape = {\n ...applicationIdShape,\n ...describeParams(queryParams.shape, {\n by: \"Query type\",\n value: \"Value to search for\",\n options: \"Additional query options\",\n }),\n};\n\nconst typeShape = {\n ...applicationIdShape,\n ...describeParams(typeParams.shape, {\n widgetId: WIDGET_ID_DESCRIPTION,\n text: \"Text to type\",\n clear: \"Clear existing text before typing\",\n }),\n};\n\nconst fireEventShape = {\n ...applicationIdShape,\n ...describeParams(fireEventParams.shape, {\n widgetId: WIDGET_ID_DESCRIPTION,\n signal: \"GTK4 signal name to emit\",\n args: \"Arguments to pass to the signal\",\n }),\n};\n\nconst screenshotShape = {\n ...applicationIdShape,\n ...describeParams(screenshotParams.shape, {\n windowId: \"Window ID to capture. If not specified, captures the first window.\",\n path:\n \"Absolute path to write the PNG to on the app's machine. If set, the screenshot is saved there \" +\n \"in addition to being returned.\",\n }),\n};\n\nfunction describeParams<Shape extends Record<string, z.ZodType>>(\n shape: Shape,\n descriptions: { [Key in keyof Shape]: string },\n): Shape {\n const described: [string, z.ZodType][] = Object.entries(shape).map(([key, schema]) => [\n key,\n schema.describe(descriptions[key as keyof Shape]),\n ]);\n\n return Object.fromEntries(described) as Shape;\n}\n\nconst connectStdio = async (mcpServer: McpServer, stop: () => Promise<void>): Promise<void> => {\n const transport = new StdioServerTransport();\n process.stdin.on(\"end\", () => void stop());\n process.stdin.on(\"close\", () => void stop());\n await mcpServer.connect(transport);\n};\n\nconst logSocketError = (event: Event): void => {\n const error = (event as ConnectionErrorEvent).detail;\n const code = (error as NodeJS.ErrnoException).code;\n\n if (code === \"EPIPE\" || code === \"ECONNRESET\") {\n return;\n }\n\n log.error(`socket error: ${error.message}`);\n};\n\nconst appWithWindows = async (appRouter: AppRouter, app: AppInfo): Promise<AppWithWindows> => {\n try {\n const result = await appRouter.sendToApp<{ windows: AppWindow[] }>(\n app.applicationId,\n \"app.getWindows\",\n {},\n );\n\n return { ...app, windows: result.windows };\n } catch {\n return app;\n }\n};\n\nconst listAppsTool = (appRouter: AppRouter): Tool =>\n defineTool({\n name: \"gtkx_list_apps\",\n title: \"List apps\",\n kind: \"readOnly\",\n description: \"List all connected GTKX applications and their open windows.\",\n inputSchema: listAppsShape,\n handler: async ({ waitForApps, timeout }) => {\n if (waitForApps && !appRouter.hasConnectedApps()) {\n await appRouter.waitForApp(timeout);\n }\n\n const apps = appRouter.getApps();\n const appsWithWindows = await Promise.all(apps.map((app) => appWithWindows(appRouter, app)));\n\n return textContent(JSON.stringify(appsWithWindows, null, 2));\n },\n });\n\nconst screenshotTool = (appRouter: AppRouter): Tool =>\n defineTool({\n name: \"gtkx_take_screenshot\",\n title: \"Take screenshot\",\n kind: \"readOnly\",\n description:\n \"Capture a screenshot of a window. Returns base64-encoded PNG image data, and optionally writes \" +\n \"the PNG to `path` on the app's machine. You can't target widgets from a screenshot; use \" +\n \"`gtkx_get_widget_tree` to find widget IDs for interaction.\",\n inputSchema: screenshotShape,\n handler: async ({ applicationId, ...params }) => {\n const result = await appRouter.sendToApp<{ data: string; mimeType: string; savedPath?: string }>(\n applicationId,\n \"widget.screenshot\",\n params,\n );\n\n if (result.savedPath) {\n return {\n content: [\n { type: \"text\", text: `Screenshot saved to ${result.savedPath}` },\n { type: \"image\", data: result.data, mimeType: result.mimeType },\n ],\n };\n }\n\n return imageContent(result.data, result.mimeType);\n },\n });\n\nconst widgetPropsTool = (appRouter: AppRouter): Tool =>\n defineTool({\n name: \"gtkx_get_widget_props\",\n title: \"Get widget properties\",\n kind: \"readOnly\",\n description:\n \"Get a fixed summary of one widget by ID: type, accessible role, name, text, sensitivity, \" +\n \"visibility, CSS classes, and the same summary for its descendants. The subtree is bounded \" +\n `twice: ${String(DEFAULT_SUBTREE_DEPTH)} levels deep unless \\`maxDepth\\` says otherwise, and ` +\n `${String(MAX_SUBTREE_WIDGETS)} widgets in all, filled breadth first. Wherever either bound ` +\n \"cut a branch, that widget carries `hiddenChildren`, the count of its own direct children left \" +\n \"out rather than of everything below them; call again with that widget's ID to drill in, or \" +\n \"use `gtkx_get_widget_tree` for a wider map. Pass `properties` to read GObject properties too; \" +\n \"they come back first in the payload, each under its canonical kebab-case name as \" +\n \"`{type, value}`, where an enum or flags value is its GType value name, a 64-bit integer a \" +\n \"decimal string, and an object its GType name plus `widgetId` when it is a widget. Asking for \" +\n \"a property the widget does not have fails; a value that cannot be marshalled carries a `note` \" +\n \"instead.\",\n inputSchema: widgetPropsShape,\n handler: async ({ applicationId, ...params }) => {\n const result = await appRouter.sendToApp(applicationId, \"widget.getProps\", params);\n\n return textContent(JSON.stringify(result, null, 2));\n },\n });\n\nfunction buildInspectionTools(appRouter: AppRouter): Tool[] {\n return [\n listAppsTool(appRouter),\n defineTool({\n name: \"gtkx_get_widget_tree\",\n title: \"Widget tree\",\n kind: \"readOnly\",\n description:\n \"Get the widget hierarchy for a connected GTKX app. Returns a tree of widgets with their IDs, \" +\n \"types, roles, and properties. For large apps, pass `maxDepth` for a shallow overview and/or \" +\n \"`rootId` to render just one subtree instead of the whole (possibly truncated) tree.\",\n inputSchema: treeShape,\n handler: async ({ applicationId, rootId, maxDepth }) => {\n const result = await appRouter.sendToApp<{ tree: string }>(applicationId, \"widget.getTree\", {\n rootId,\n maxDepth,\n });\n\n return textContent(result.tree);\n },\n }),\n defineTool({\n name: \"gtkx_query_widgets\",\n title: \"Query widgets\",\n kind: \"readOnly\",\n description:\n \"Find widgets by role, text, name, or label. Returns each match with its ID and the same \" +\n \"fixed summary `gtkx_get_widget_props` returns, with no descendants: a match that has \" +\n \"children carries `hiddenChildren`, the count of its direct children left out. Read a \" +\n \"match's subtree with `gtkx_get_widget_props` or `gtkx_get_widget_tree`.\",\n inputSchema: queryWidgetsShape,\n handler: async ({ applicationId, ...params }) => {\n const result = await appRouter.sendToApp(applicationId, \"widget.query\", params);\n\n return textContent(JSON.stringify(result, null, 2));\n },\n }),\n widgetPropsTool(appRouter),\n screenshotTool(appRouter),\n ];\n}\n\nfunction buildInteractionTools(appRouter: AppRouter): Tool[] {\n return [\n defineTool({\n name: \"gtkx_click\",\n title: \"Click widget\",\n kind: \"action\",\n description:\n \"Click a widget through userEvent.click, with no special case per widget. Works with \" +\n \"buttons, checkboxes, switches, list and grid rows, tree expanders, and column headers: a \" +\n \"row is selected, an expander toggles its row's expansion, and a header sorts its column.\",\n inputSchema: widgetIdShape,\n handler: async ({ applicationId, ...params }) => {\n await appRouter.sendToApp(applicationId, \"widget.click\", params);\n\n return textContent(\"Clicked\");\n },\n }),\n defineTool({\n name: \"gtkx_type\",\n title: \"Type text\",\n kind: \"action\",\n description: \"Type text into an editable widget like Entry or TextView\",\n inputSchema: typeShape,\n handler: async ({ applicationId, ...params }) => {\n await appRouter.sendToApp(applicationId, \"widget.type\", params);\n\n return textContent(\"Typed text\");\n },\n }),\n defineTool({\n name: \"gtkx_fire_event\",\n title: \"Fire event\",\n kind: \"action\",\n description: \"Emit a GTK4 signal on a widget. Use this for custom interactions.\",\n inputSchema: fireEventShape,\n handler: async ({ applicationId, ...params }) => {\n const result = await appRouter.sendToApp(applicationId, \"widget.fireEvent\", params);\n\n return textContent(JSON.stringify(result, null, 2));\n },\n }),\n ];\n}\n\nfunction buildTools(appRouter: AppRouter): Tool[] {\n return [...buildInspectionTools(appRouter), ...buildInteractionTools(appRouter)];\n}\n\nconst registerTools = (mcpServer: McpServer, appRouter: AppRouter, provider: ReferenceProvider): void => {\n for (const tool of [...buildTools(appRouter), ...buildReferenceTools(provider)]) {\n registerTool(mcpServer, tool);\n }\n};\n\nasync function stopServer(state: ServerLifecycle): Promise<void> {\n if (state.isStopped) {\n return;\n }\n\n state.isStopped = true;\n await state.socketServer.stop();\n await state.mcpServer.close();\n}\n\nasync function startServer(state: ServerLifecycle): Promise<void> {\n if (state.isStopped) {\n throw new Error(\"createMcpServer: a stopped server cannot be started again\");\n }\n\n await state.socketServer.start();\n\n if (state.isStarted) {\n return;\n }\n\n state.isStarted = true;\n log.info(`socket server listening on ${state.socketPath}`);\n await connectStdio(state.mcpServer, () => stopServer(state));\n}\n\nconst createServerHandle = (socketServer: SocketServer, mcpServer: McpServer, socketPath: string): McpServerHandle => {\n const state: ServerLifecycle = { socketServer, mcpServer, socketPath, isStopped: false, isStarted: false };\n\n return { start: () => startServer(state), stop: () => stopServer(state) };\n};\n\nconst createMcpServer = (options: CreateMcpServerOptions): McpServerHandle => {\n const socketPath = options.socketPath ?? DEFAULT_SOCKET_PATH;\n const registry = new ConnectionRegistry();\n const socketServer = new SocketServer(registry, socketPath);\n const appRouter = new AppRouter(registry);\n registry.addEventListener(\"error\", logSocketError);\n\n appRouter.addEventListener(\"appRegistered\", (event) => {\n const appInfo = (event as AppRegisteredEvent).detail;\n log.info(`app registered: ${appInfo.applicationId} (PID: ${String(appInfo.pid)})`);\n });\n\n appRouter.addEventListener(\"appUnregistered\", (event) => {\n log.info(`app unregistered: ${(event as AppUnregisteredEvent).detail}`);\n });\n\n const mcpServer = new McpServer({ name: \"gtkx-mcp\", version: options.version });\n const referenceProvider = createReferenceProvider({ getAppRoot: () => appRouter.getProjectRoot() });\n registerTools(mcpServer, appRouter, referenceProvider);\n registerReferenceResources(mcpServer, referenceProvider);\n\n return createServerHandle(socketServer, mcpServer, socketPath);\n};\n\nasync function main(): Promise<void> {\n const server = createMcpServer({ version });\n\n installGracefulShutdown({\n onSignal: () => server.stop(),\n });\n\n await server.start();\n}\n\nexport { log, createMcpServer, main };\n"]}
@@ -1,11 +1,20 @@
1
1
  import type { ConnectionRegistry } from "./connection-registry.js";
2
+ declare const withClaimLock: <T>(socketPath: string, action: () => Promise<T> | T) => Promise<T>;
2
3
  declare class SocketServer {
3
4
  private server;
4
5
  private socketPath;
5
6
  private registry;
7
+ private boundInode;
8
+ private startup;
6
9
  constructor(registry: ConnectionRegistry, socketPath?: string);
10
+ private listen;
11
+ private listenPrivately;
12
+ private bind;
13
+ private open;
14
+ private settleStartup;
15
+ private release;
7
16
  start(): Promise<void>;
8
17
  stop(): Promise<void>;
9
18
  }
10
- export { SocketServer };
19
+ export { SocketServer, withClaimLock };
11
20
  //# sourceMappingURL=socket-server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"socket-server.d.ts","sourceRoot":"","sources":["../src/socket-server.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAiCnE,cAAM,YAAY;IACd,OAAO,CAAC,MAAM,CAA2B;IACzC,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,QAAQ,CAAqB;gBAEzB,QAAQ,EAAE,kBAAkB,EAAE,UAAU,GAAE,MAA4B;IAK5E,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA0BtB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAmB9B;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}
1
+ {"version":3,"file":"socket-server.d.ts","sourceRoot":"","sources":["../src/socket-server.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AA+EnE,QAAA,MAAM,aAAa,GAAU,CAAC,EAAE,YAAY,MAAM,EAAE,QAAQ,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,KAAG,OAAO,CAAC,CAAC,CAY3F,CAAC;AA+JF,cAAM,YAAY;IACd,OAAO,CAAC,MAAM,CAA2B;IACzC,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,QAAQ,CAAqB;IACrC,OAAO,CAAC,UAAU,CAAuB;IACzC,OAAO,CAAC,OAAO,CAA8B;gBAEjC,QAAQ,EAAE,kBAAkB,EAAE,UAAU,GAAE,MAA4B;IAKlF,OAAO,CAAC,MAAM;YAoBA,eAAe;YASf,IAAI;IAclB,OAAO,CAAC,IAAI;YAIE,aAAa;YASb,OAAO;IASf,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAetB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAa9B;AAED,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,CAAC"}