@gtkx/mcp 2.0.0-beta.1 → 2.0.0-beta.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +6 -169
  2. package/dist/app-router.d.ts +7 -7
  3. package/dist/app-router.d.ts.map +1 -1
  4. package/dist/app-router.js +63 -32
  5. package/dist/app-router.js.map +1 -1
  6. package/dist/connection-registry.d.ts +0 -1
  7. package/dist/connection-registry.d.ts.map +1 -1
  8. package/dist/connection-registry.js +0 -3
  9. package/dist/connection-registry.js.map +1 -1
  10. package/dist/internal.d.ts +2 -1
  11. package/dist/internal.d.ts.map +1 -1
  12. package/dist/internal.js +2 -1
  13. package/dist/internal.js.map +1 -1
  14. package/dist/protocol/schemas.d.ts +2 -7
  15. package/dist/protocol/schemas.d.ts.map +1 -1
  16. package/dist/protocol/schemas.js +1 -7
  17. package/dist/protocol/schemas.js.map +1 -1
  18. package/dist/reference.d.ts.map +1 -1
  19. package/dist/reference.js +32 -18
  20. package/dist/reference.js.map +1 -1
  21. package/dist/server.d.ts.map +1 -1
  22. package/dist/server.js +110 -62
  23. package/dist/server.js.map +1 -1
  24. package/dist/socket-path.d.ts +11 -0
  25. package/dist/socket-path.d.ts.map +1 -0
  26. package/dist/socket-path.js +74 -0
  27. package/dist/socket-path.js.map +1 -0
  28. package/dist/socket-server.d.ts +3 -1
  29. package/dist/socket-server.d.ts.map +1 -1
  30. package/dist/socket-server.js +48 -32
  31. package/dist/socket-server.js.map +1 -1
  32. package/dist/tool-filter.d.ts.map +1 -1
  33. package/dist/tool-filter.js +1 -3
  34. package/dist/tool-filter.js.map +1 -1
  35. package/package.json +22 -8
  36. package/src/app-router.ts +84 -39
  37. package/src/connection-registry.ts +0 -3
  38. package/src/internal.ts +4 -1
  39. package/src/protocol/schemas.ts +1 -14
  40. package/src/reference.ts +48 -19
  41. package/src/server.ts +133 -64
  42. package/src/socket-path.ts +103 -0
  43. package/src/socket-server.ts +61 -37
  44. package/src/tool-filter.ts +1 -4
package/dist/server.js CHANGED
@@ -1,15 +1,18 @@
1
1
  import { loadConfig } from "@gtkx/config";
2
- import { resolveMcpSettings } from "@gtkx/config/internal";
2
+ import { configDependenciesFor, resolveMcpSettings } from "@gtkx/config/internal";
3
3
  import { createLogger, installGracefulShutdown } from "@gtkx/utils";
4
4
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
5
5
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
6
+ import { existsSync } from "node:fs";
7
+ import { resolve } from "node:path";
6
8
  import { parseArgs } from "node:util";
7
9
  import { z } from "zod";
8
10
  import packageManifest from "../package.json" with { type: "json" };
9
11
  import { AppRouter } from "./app-router.js";
10
12
  import { ConnectionRegistry } from "./connection-registry.js";
11
- import { DEFAULT_SOCKET_PATH, DEFAULT_SUBTREE_DEPTH, fireEventParams, MAX_SUBTREE_WIDGETS, queryParams, screenshotParams, treeParams, typeParams, widgetIdParams, widgetPropsParams, } from "./protocol/schemas.js";
13
+ import { DEFAULT_SUBTREE_DEPTH, fireEventParams, MAX_SUBTREE_WIDGETS, queryParams, screenshotParams, treeParams, typeParams, widgetIdParams, widgetPropsParams, } from "./protocol/schemas.js";
12
14
  import { buildReferenceTools, createReferenceProvider, registerReferenceResources, } from "./reference.js";
15
+ import { resolveMcpSocketAddress } from "./socket-path.js";
13
16
  import { SocketServer } from "./socket-server.js";
14
17
  import { selectTools } from "./tool-filter.js";
15
18
  import { defineTool, imageContent, registerTool, textContent, textError } from "./tool.js";
@@ -18,17 +21,23 @@ const log = createLogger("mcp");
18
21
  const DEFAULT_SETTINGS = { tools: [], isReadOnly: false };
19
22
  const INSTRUCTIONS = "The widget tools drive a GTKX app running under `gtkx dev`: they read " +
20
23
  "its live widget tree, query it by accessible role and name, click and type, and capture screenshots. " +
21
- "They fail until an app is running, so start `gtkx dev` first. The reference tools answer from the " +
24
+ "They wait briefly for a starting app, so start `gtkx dev` before or alongside a widget request. " +
25
+ "The reference tools answer from the " +
22
26
  "bindings generated for a specific project, so they describe that project's GIR libraries rather than " +
23
- "GTK in general; prefer them over recalled GTK knowledge, which is usually C, PyGObject or GJS and " +
24
- "does not apply here.\n\n" +
27
+ "the GNOME platform in general; prefer them over recalled Adwaita or GTK knowledge, which is usually C, " +
28
+ "PyGObject or GJS and does not apply here.\n\n" +
25
29
  "Widget IDs are valid only while the widget is mounted. After a dialog closes, a list re-renders, or " +
26
30
  "fast refresh patches a component, re-read the tree or re-run the query instead of reusing an ID.";
27
- const APPLICATION_ID_DESCRIPTION = "Application ID to query. If not specified, uses the first connected app.";
31
+ const APPLICATION_ID_DESCRIPTION = "Application ID to query. If not specified, uses the first connected app. The tool waits briefly for the " +
32
+ "requested app to register.";
33
+ const APP_TIMEOUT_DESCRIPTION = "Milliseconds to wait for the requested app to register (default: 10000).";
28
34
  const WIDGET_ID_DESCRIPTION = "Widget ID obtained from `gtkx_get_widget_tree`, `gtkx_query_widgets`, or `gtkx_get_widget_props`. " +
29
35
  "IDs are scoped to a single app. An ID stays valid for as long as its widget is mounted and stops " +
30
36
  "resolving once the widget is unmounted.";
31
- const applicationIdShape = { applicationId: z.string().optional().describe(APPLICATION_ID_DESCRIPTION) };
37
+ const applicationIdShape = {
38
+ applicationId: z.string().optional().describe(APPLICATION_ID_DESCRIPTION),
39
+ appTimeout: z.number().int().nonnegative().optional().describe(APP_TIMEOUT_DESCRIPTION),
40
+ };
32
41
  const widgetIdShape = {
33
42
  ...applicationIdShape,
34
43
  ...describeParams(widgetIdParams.shape, { widgetId: WIDGET_ID_DESCRIPTION }),
@@ -81,7 +90,7 @@ const fireEventShape = {
81
90
  ...applicationIdShape,
82
91
  ...describeParams(fireEventParams.shape, {
83
92
  widgetId: WIDGET_ID_DESCRIPTION,
84
- signal: "GTK4 signal name to emit",
93
+ signal: "GObject signal name to emit",
85
94
  args: "Arguments to pass to the signal",
86
95
  }),
87
96
  };
@@ -95,9 +104,8 @@ const screenshotShape = {
95
104
  returnImage: z
96
105
  .boolean()
97
106
  .optional()
98
- .describe("Whether to return the PNG as image content, true by default. Pass false together with `path` " +
99
- "to save the screenshot and get back only where it landed, which keeps the image out of the " +
100
- "conversation until something actually needs to look at it."),
107
+ .describe("Return the PNG as image content (default: true). Set false with `path` to save the image " +
108
+ "and return only its file location."),
101
109
  };
102
110
  function describeParams(shape, descriptions) {
103
111
  const described = Object.entries(shape).map(([key, schema]) => [
@@ -133,11 +141,12 @@ const listAppsTool = (appRouter) => defineTool({
133
141
  name: "gtkx_list_apps",
134
142
  title: "List apps",
135
143
  kind: "readOnly",
136
- description: "List all connected GTKX applications and their open windows.",
144
+ description: "List connected GTKX applications and their open windows. " +
145
+ "Returns the current snapshot immediately unless waitForApps is true.",
137
146
  inputSchema: listAppsShape,
138
147
  handler: async ({ waitForApps, timeout }) => {
139
148
  if (waitForApps && !appRouter.hasConnectedApps()) {
140
- await appRouter.waitForApp(timeout);
149
+ await appRouter.waitForApp(undefined, timeout);
141
150
  }
142
151
  const apps = appRouter.getApps();
143
152
  const appsWithWindows = await Promise.all(apps.map((app) => appWithWindows(appRouter, app)));
@@ -165,8 +174,8 @@ const screenshotTool = (appRouter) => defineTool({
165
174
  "the PNG to `path` on the app's machine. You can't target widgets from a screenshot; use " +
166
175
  "`gtkx_get_widget_tree` to find widget IDs for interaction.",
167
176
  inputSchema: screenshotShape,
168
- handler: async ({ applicationId, returnImage, ...params }) => {
169
- const result = await appRouter.sendToApp(applicationId, "widget.screenshot", params);
177
+ handler: async ({ applicationId, appTimeout, returnImage, ...params }) => {
178
+ const result = await appRouter.sendToApp(applicationId, "widget.screenshot", params, appTimeout);
170
179
  return screenshotResult(result, returnImage !== false);
171
180
  },
172
181
  });
@@ -174,21 +183,17 @@ const widgetPropsTool = (appRouter) => defineTool({
174
183
  name: "gtkx_get_widget_props",
175
184
  title: "Get widget properties",
176
185
  kind: "readOnly",
177
- description: "Get a fixed summary of one widget by ID: type, accessible role, name, text, sensitivity, " +
178
- "visibility, CSS classes, and the same summary for its descendants. The subtree is bounded " +
179
- `twice: ${String(DEFAULT_SUBTREE_DEPTH)} levels deep unless \`maxDepth\` says otherwise, and ` +
180
- `${String(MAX_SUBTREE_WIDGETS)} widgets in all, filled breadth first. Wherever either bound ` +
181
- "cut a branch, that widget carries `hiddenChildren`, the count of its own direct children left " +
182
- "out rather than of everything below them; call again with that widget's ID to drill in, or " +
183
- "use `gtkx_get_widget_tree` for a wider map. Pass `properties` to read GObject properties too; " +
184
- "they come back first in the payload, each under its canonical kebab-case name as " +
185
- "`{type, value}`, where an enum or flags value is its GType value name, a 64-bit integer a " +
186
- "decimal string, and an object its GType name plus `widgetId` when it is a widget. Asking for " +
187
- "a property the widget does not have fails; a value that cannot be marshalled carries a `note` " +
188
- "instead.",
186
+ description: "Read a widget's type, accessible role, name, text, sensitivity, visibility, CSS classes, " +
187
+ `and descendants. Defaults to ${String(DEFAULT_SUBTREE_DEPTH)} levels; \`maxDepth\` changes ` +
188
+ `the depth. Results contain at most ${String(MAX_SUBTREE_WIDGETS)} widgets, in breadth-first ` +
189
+ "order. `hiddenChildren` counts omitted direct children; query that widget's ID to expand it. " +
190
+ "Use `gtkx_get_widget_tree` for an overview. Requested GObject `properties` appear first, " +
191
+ "keyed by canonical kebab-case name with `{type, value}`. Enum/flags values use GType value " +
192
+ "names, 64-bit integers use decimal strings, and objects use their GType name plus `widgetId` " +
193
+ "for widgets. Unknown properties fail; values that cannot be converted include a `note`.",
189
194
  inputSchema: widgetPropsShape,
190
- handler: async ({ applicationId, ...params }) => {
191
- const result = await appRouter.sendToApp(applicationId, "widget.getProps", params);
195
+ handler: async ({ applicationId, appTimeout, ...params }) => {
196
+ const result = await appRouter.sendToApp(applicationId, "widget.getProps", params, appTimeout);
192
197
  return textContent(JSON.stringify(result, null, 2));
193
198
  },
194
199
  });
@@ -203,11 +208,11 @@ function buildInspectionTools(appRouter) {
203
208
  "types, roles, and properties. For large apps, pass `maxDepth` for a shallow overview and/or " +
204
209
  "`rootId` to render just one subtree instead of the whole (possibly truncated) tree.",
205
210
  inputSchema: treeShape,
206
- handler: async ({ applicationId, rootId, maxDepth }) => {
211
+ handler: async ({ applicationId, appTimeout, rootId, maxDepth }) => {
207
212
  const result = await appRouter.sendToApp(applicationId, "widget.getTree", {
208
213
  rootId,
209
214
  maxDepth,
210
- });
215
+ }, appTimeout);
211
216
  return textContent(result.tree);
212
217
  },
213
218
  }),
@@ -220,8 +225,8 @@ function buildInspectionTools(appRouter) {
220
225
  "children carries `hiddenChildren`, the count of its direct children left out. Read a " +
221
226
  "match's subtree with `gtkx_get_widget_props` or `gtkx_get_widget_tree`.",
222
227
  inputSchema: queryWidgetsShape,
223
- handler: async ({ applicationId, ...params }) => {
224
- const result = await appRouter.sendToApp(applicationId, "widget.query", params);
228
+ handler: async ({ applicationId, appTimeout, ...params }) => {
229
+ const result = await appRouter.sendToApp(applicationId, "widget.query", params, appTimeout);
225
230
  return textContent(JSON.stringify(result, null, 2));
226
231
  },
227
232
  }),
@@ -235,12 +240,12 @@ function buildInteractionTools(appRouter) {
235
240
  name: "gtkx_click",
236
241
  title: "Click widget",
237
242
  kind: "action",
238
- description: "Click a widget through userEvent.click, with no special case per widget. Works with " +
243
+ description: "Click a widget through userEvent.click. Works with " +
239
244
  "buttons, checkboxes, switches, list and grid rows, tree expanders, and column headers: a " +
240
245
  "row is selected, an expander toggles its row's expansion, and a header sorts its column.",
241
246
  inputSchema: widgetIdShape,
242
- handler: async ({ applicationId, ...params }) => {
243
- await appRouter.sendToApp(applicationId, "widget.click", params);
247
+ handler: async ({ applicationId, appTimeout, ...params }) => {
248
+ await appRouter.sendToApp(applicationId, "widget.click", params, appTimeout);
244
249
  return textContent("Clicked");
245
250
  },
246
251
  }),
@@ -250,8 +255,8 @@ function buildInteractionTools(appRouter) {
250
255
  kind: "action",
251
256
  description: "Type text into an editable widget like Entry or TextView",
252
257
  inputSchema: typeShape,
253
- handler: async ({ applicationId, ...params }) => {
254
- await appRouter.sendToApp(applicationId, "widget.type", params);
258
+ handler: async ({ applicationId, appTimeout, ...params }) => {
259
+ await appRouter.sendToApp(applicationId, "widget.type", params, appTimeout);
255
260
  return textContent("Typed text");
256
261
  },
257
262
  }),
@@ -259,10 +264,10 @@ function buildInteractionTools(appRouter) {
259
264
  name: "gtkx_fire_event",
260
265
  title: "Fire event",
261
266
  kind: "action",
262
- description: "Emit a GTK4 signal on a widget. Use this for custom interactions.",
267
+ description: "Emit a GObject signal on a widget. Use this for custom interactions.",
263
268
  inputSchema: fireEventShape,
264
- handler: async ({ applicationId, ...params }) => {
265
- const result = await appRouter.sendToApp(applicationId, "widget.fireEvent", params);
269
+ handler: async ({ applicationId, appTimeout, ...params }) => {
270
+ const result = await appRouter.sendToApp(applicationId, "widget.fireEvent", params, appTimeout);
266
271
  return textContent(JSON.stringify(result, null, 2));
267
272
  },
268
273
  }),
@@ -280,34 +285,74 @@ const registerTools = (mcpServer, appRouter, provider, settings) => {
280
285
  registerTool(mcpServer, tool);
281
286
  }
282
287
  };
283
- async function stopServer(state) {
284
- if (state.isStopped) {
285
- return;
288
+ const stoppedServerError = () => new Error("createMcpServer: a stopped server cannot be started again");
289
+ const wasStopRequested = (state) => state.isStopRequested;
290
+ function stopServer(state) {
291
+ if (state.shutdown !== null) {
292
+ return state.shutdown;
286
293
  }
287
- state.isStopped = true;
288
- await state.socketServer.stop();
289
- await state.mcpServer.close();
294
+ state.isStopRequested = true;
295
+ state.appRouter.dispose();
296
+ const startup = state.startup;
297
+ const shutdown = (async () => {
298
+ if (startup !== null) {
299
+ await Promise.allSettled([startup]);
300
+ }
301
+ await state.socketServer.stop();
302
+ await state.mcpServer.close();
303
+ })();
304
+ state.shutdown = shutdown;
305
+ return shutdown;
290
306
  }
291
- async function startServer(state) {
292
- if (state.isStopped) {
293
- throw new Error("createMcpServer: a stopped server cannot be started again");
307
+ function startServer(state) {
308
+ if (wasStopRequested(state)) {
309
+ return Promise.reject(stoppedServerError());
294
310
  }
295
- await state.socketServer.start();
296
- if (state.isStarted) {
297
- return;
311
+ if (state.startup !== null) {
312
+ return state.startup;
298
313
  }
299
- state.isStarted = true;
300
- log.info(`socket server listening on ${state.socketPath}`);
301
- await connectStdio(state.mcpServer, () => stopServer(state));
314
+ const startup = (async () => {
315
+ try {
316
+ await state.socketServer.start();
317
+ if (wasStopRequested(state)) {
318
+ return;
319
+ }
320
+ log.info(`socket server listening on ${state.socketPath}`);
321
+ await connectStdio(state.mcpServer, () => stopServer(state));
322
+ }
323
+ catch (error) {
324
+ if (!wasStopRequested(state)) {
325
+ state.isStopRequested = true;
326
+ state.appRouter.dispose();
327
+ await state.socketServer.stop();
328
+ await state.mcpServer.close();
329
+ }
330
+ throw error;
331
+ }
332
+ })();
333
+ state.startup = startup;
334
+ return startup;
302
335
  }
303
- const createServerHandle = (socketServer, mcpServer, socketPath) => {
304
- const state = { socketServer, mcpServer, socketPath, isStopped: false, isStarted: false };
336
+ const createServerHandle = (socketServer, mcpServer, appRouter, socketPath) => {
337
+ const state = {
338
+ socketServer,
339
+ mcpServer,
340
+ appRouter,
341
+ socketPath,
342
+ isStopRequested: false,
343
+ startup: null,
344
+ shutdown: null,
345
+ };
305
346
  return { start: () => startServer(state), stop: () => stopServer(state) };
306
347
  };
307
348
  const createMcpServer = (options) => {
308
- const socketPath = options.socketPath ?? DEFAULT_SOCKET_PATH;
349
+ const socketAddress = resolveMcpSocketAddress(options.socketPath);
350
+ const socketPath = socketAddress.path;
351
+ if (socketAddress.fallbackDirectory !== null) {
352
+ log.warn(`MCP socket path exceeds the safe Unix byte budget; using private fallback ${socketPath}`);
353
+ }
309
354
  const registry = new ConnectionRegistry();
310
- const socketServer = new SocketServer(registry, socketPath);
355
+ const socketServer = new SocketServer(registry, socketAddress);
311
356
  const appRouter = new AppRouter(registry);
312
357
  registry.addEventListener("error", logSocketError);
313
358
  appRouter.addEventListener("appRegistered", (event) => {
@@ -321,14 +366,17 @@ const createMcpServer = (options) => {
321
366
  const referenceProvider = createReferenceProvider({ getAppRoot: () => appRouter.getProjectRoot() });
322
367
  registerTools(mcpServer, appRouter, referenceProvider, options.settings ?? DEFAULT_SETTINGS);
323
368
  registerReferenceResources(mcpServer, referenceProvider);
324
- return createServerHandle(socketServer, mcpServer, socketPath);
369
+ return createServerHandle(socketServer, mcpServer, appRouter, socketPath);
325
370
  };
326
371
  const configuredSettings = async (cwd) => {
327
372
  try {
328
373
  const { config } = await loadConfig(cwd);
329
374
  return resolveMcpSettings(config);
330
375
  }
331
- catch {
376
+ catch (error) {
377
+ if (configDependenciesFor(error).some((path) => existsSync(resolve(cwd, path)))) {
378
+ throw error;
379
+ }
332
380
  return DEFAULT_SETTINGS;
333
381
  }
334
382
  };
@@ -1 +1 @@
1
- {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAoB,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAAE,YAAY,EAAE,uBAAuB,EAAe,MAAM,aAAa,CAAC;AACjF,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,eAAe,MAAM,iBAAiB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AACpE,OAAO,EAA2B,SAAS,EAA6B,MAAM,iBAAiB,CAAC;AAChG,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAEH,mBAAmB,EACnB,qBAAqB,EACrB,eAAe,EACf,mBAAmB,EACnB,WAAW,EACX,gBAAgB,EAChB,UAAU,EACV,UAAU,EACV,cAAc,EACd,iBAAiB,GACpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAC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AAa,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAEnF,OAAO;QACH,GAAG,CAAC,KAAK,KAAK,SAAS,IAAI,EAAE,KAAK,EAAE,CAAC;QACrC,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,KAAK,SAAS,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,WAAW,CAAC,EAAE,CAAC;KAChF,CAAC;AACN,CAAC,CAAC;AAEF,KAAK,UAAU,IAAI,CAAC,UAAyB,EAAE;IAC3C,MAAM,QAAQ,GAAG,MAAM,eAAe,CAAC,OAAO,CAAC,CAAC;IAChD,MAAM,MAAM,GAAG,eAAe,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC;IAEtD,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,IAAI,EAAE,IAAI,IAAI,YAAY,EAAE,eAAe,EAAE,CAAC","sourcesContent":["import type { CallToolResult } from \"@modelcontextprotocol/sdk/types.js\";\nimport { loadConfig } from \"@gtkx/config\";\nimport { type McpSettings, resolveMcpSettings } from \"@gtkx/config/internal\";\nimport { createLogger, installGracefulShutdown, type Logger } from \"@gtkx/utils\";\nimport { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\nimport { parseArgs } from \"node:util\";\nimport { z } from \"zod\";\nimport type { ConnectionErrorEvent } from \"./transport.js\";\nimport packageManifest from \"../package.json\" with { type: \"json\" };\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 { selectTools } from \"./tool-filter.js\";\nimport { defineTool, imageContent, registerTool, textContent, textError, type Tool } from \"./tool.js\";\n\ntype CreateMcpServerOptions = {\n socketPath?: string;\n version: string;\n settings?: McpSettings;\n};\n\ntype ServerOptions = {\n cwd?: string;\n tools?: string[];\n isReadOnly?: boolean;\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 { version } = packageManifest;\nconst log: Logger = createLogger(\"mcp\");\nconst DEFAULT_SETTINGS: McpSettings = { tools: [], isReadOnly: false };\n\nconst INSTRUCTIONS =\n \"The widget tools drive a GTKX app running under `gtkx dev`: they read \" +\n \"its live widget tree, query it by accessible role and name, click and type, and capture screenshots. \" +\n \"They fail until an app is running, so start `gtkx dev` first. The reference tools answer from the \" +\n \"bindings generated for a specific project, so they describe that project's GIR libraries rather than \" +\n \"GTK in general; prefer them over recalled GTK knowledge, which is usually C, PyGObject or GJS and \" +\n \"does not apply here.\\n\\n\" +\n \"Widget IDs are valid only while the widget is mounted. After a dialog closes, a list re-renders, or \" +\n \"fast refresh patches a component, re-read the tree or re-run the query instead of reusing an ID.\";\n\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 returnImage: z\n .boolean()\n .optional()\n .describe(\n \"Whether to return the PNG as image content, true by default. Pass false together with `path` \" +\n \"to save the screenshot and get back only where it landed, which keeps the image out of the \" +\n \"conversation until something actually needs to look at it.\",\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 screenshotResult = (\n result: { data: string; mimeType: string; savedPath?: string },\n shouldReturnImage: boolean,\n): CallToolResult => {\n if (result.savedPath === undefined) {\n return shouldReturnImage\n ? imageContent(result.data, result.mimeType)\n : textError(\n \"Nothing to return: `returnImage` was false and no `path` was given, so the screenshot was \" +\n \"neither saved nor returned. Pass `path` to save it, or leave `returnImage` unset.\",\n );\n }\n\n const saved = { type: \"text\", text: `Screenshot saved to ${result.savedPath}` } as const;\n\n if (!shouldReturnImage) {\n return { content: [saved] };\n }\n\n return { content: [saved, { type: \"image\", data: result.data, mimeType: result.mimeType }] };\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, returnImage, ...params }) => {\n const result = await appRouter.sendToApp<{ data: string; mimeType: string; savedPath?: string }>(\n applicationId,\n \"widget.screenshot\",\n params,\n );\n\n return screenshotResult(result, returnImage !== false);\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 = (\n mcpServer: McpServer,\n appRouter: AppRouter,\n provider: ReferenceProvider,\n settings: McpSettings,\n): void => {\n const tools = selectTools([...buildTools(appRouter), ...buildReferenceTools(provider)], settings);\n\n if (tools.length === 0) {\n log.warn(\"no tools matched the configured filter; the server is registering none\");\n }\n\n for (const tool of tools) {\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 }, { instructions: INSTRUCTIONS });\n const referenceProvider = createReferenceProvider({ getAppRoot: () => appRouter.getProjectRoot() });\n registerTools(mcpServer, appRouter, referenceProvider, options.settings ?? DEFAULT_SETTINGS);\n registerReferenceResources(mcpServer, referenceProvider);\n\n return createServerHandle(socketServer, mcpServer, socketPath);\n};\n\nconst configuredSettings = async (cwd: string): Promise<McpSettings> => {\n try {\n const { config } = await loadConfig(cwd);\n\n return resolveMcpSettings(config);\n } catch {\n return DEFAULT_SETTINGS;\n }\n};\n\nconst resolveSettings = async (options: ServerOptions): Promise<McpSettings> => {\n const configured = await configuredSettings(options.cwd ?? process.cwd());\n\n return {\n tools: options.tools ?? configured.tools,\n isReadOnly: options.isReadOnly ?? configured.isReadOnly,\n };\n};\n\nconst splitPatterns = (values: string[]): string[] =>\n values.flatMap((value) => value.split(\",\")).map((value) => value.trim()).filter((value) => value.length > 0);\n\nconst parseServerArgs = (argv: string[]): ServerOptions => {\n const { values } = parseArgs({\n args: argv,\n options: {\n tools: { type: \"string\", multiple: true },\n \"read-only\": { type: \"boolean\" },\n },\n allowPositionals: false,\n });\n\n const tools = values.tools === undefined ? undefined : splitPatterns(values.tools);\n\n return {\n ...(tools !== undefined && { tools }),\n ...(values[\"read-only\"] !== undefined && { isReadOnly: values[\"read-only\"] }),\n };\n};\n\nasync function main(options: ServerOptions = {}): Promise<void> {\n const settings = await resolveSettings(options);\n const server = createMcpServer({ version, settings });\n\n installGracefulShutdown({\n onSignal: () => server.stop(),\n });\n\n await server.start();\n}\n\nexport { log, main, main as runMcpServer, parseServerArgs };\n"]}
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,qBAAqB,EAAoB,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AACpG,OAAO,EAAE,YAAY,EAAE,uBAAuB,EAAe,MAAM,aAAa,CAAC;AACjF,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,eAAe,MAAM,iBAAiB,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AACpE,OAAO,EAA2B,SAAS,EAA6B,MAAM,iBAAiB,CAAC;AACh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AACN,CAAC,CAAC;AAEF,KAAK,UAAU,IAAI,CAAC,UAAyB,EAAE;IAC3C,MAAM,QAAQ,GAAG,MAAM,eAAe,CAAC,OAAO,CAAC,CAAC;IAChD,MAAM,MAAM,GAAG,eAAe,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,CAAC;IAEtD,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,IAAI,EAAE,IAAI,IAAI,YAAY,EAAE,eAAe,EAAE,CAAC","sourcesContent":["import type { CallToolResult } from \"@modelcontextprotocol/sdk/types.js\";\nimport { loadConfig } from \"@gtkx/config\";\nimport { configDependenciesFor, type McpSettings, resolveMcpSettings } from \"@gtkx/config/internal\";\nimport { createLogger, installGracefulShutdown, type Logger } from \"@gtkx/utils\";\nimport { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\nimport { existsSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport { parseArgs } from \"node:util\";\nimport { z } from \"zod\";\nimport type { ConnectionErrorEvent } from \"./transport.js\";\nimport packageManifest from \"../package.json\" with { type: \"json\" };\nimport { type AppRegisteredEvent, AppRouter, type AppUnregisteredEvent } from \"./app-router.js\";\nimport { ConnectionRegistry } from \"./connection-registry.js\";\nimport {\n type AppInfo,\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 { resolveMcpSocketAddress } from \"./socket-path.js\";\nimport { SocketServer } from \"./socket-server.js\";\nimport { selectTools } from \"./tool-filter.js\";\nimport { defineTool, imageContent, registerTool, textContent, textError, type Tool } from \"./tool.js\";\n\ntype CreateMcpServerOptions = {\n socketPath?: string;\n version: string;\n settings?: McpSettings;\n};\n\ntype ServerOptions = {\n cwd?: string;\n tools?: string[];\n isReadOnly?: boolean;\n};\n\ntype McpServerHandle = {\n start(): Promise<void>;\n stop(): Promise<void>;\n};\n\ntype ServerLifecycle = {\n socketServer: SocketServer;\n mcpServer: McpServer;\n appRouter: AppRouter;\n socketPath: string;\n isStopRequested: boolean;\n startup: Promise<void> | null;\n shutdown: Promise<void> | null;\n};\n\ntype AppWindow = { id: string; title: string | null };\ntype AppWithWindows = AppInfo & { windows?: AppWindow[] };\n\nconst { version } = packageManifest;\nconst log: Logger = createLogger(\"mcp\");\nconst DEFAULT_SETTINGS: McpSettings = { tools: [], isReadOnly: false };\n\nconst INSTRUCTIONS =\n \"The widget tools drive a GTKX app running under `gtkx dev`: they read \" +\n \"its live widget tree, query it by accessible role and name, click and type, and capture screenshots. \" +\n \"They wait briefly for a starting app, so start `gtkx dev` before or alongside a widget request. \" +\n \"The reference tools answer from the \" +\n \"bindings generated for a specific project, so they describe that project's GIR libraries rather than \" +\n \"the GNOME platform in general; prefer them over recalled Adwaita or GTK knowledge, which is usually C, \" +\n \"PyGObject or GJS and does not apply here.\\n\\n\" +\n \"Widget IDs are valid only while the widget is mounted. After a dialog closes, a list re-renders, or \" +\n \"fast refresh patches a component, re-read the tree or re-run the query instead of reusing an ID.\";\n\nconst APPLICATION_ID_DESCRIPTION =\n \"Application ID to query. If not specified, uses the first connected app. The tool waits briefly for the \" +\n \"requested app to register.\";\n\nconst APP_TIMEOUT_DESCRIPTION = \"Milliseconds to wait for the requested app to register (default: 10000).\";\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 = {\n applicationId: z.string().optional().describe(APPLICATION_ID_DESCRIPTION),\n appTimeout: z.number().int().nonnegative().optional().describe(APP_TIMEOUT_DESCRIPTION),\n};\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: \"GObject 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 returnImage: z\n .boolean()\n .optional()\n .describe(\n \"Return the PNG as image content (default: true). Set false with `path` to save the image \" +\n \"and return only its file location.\",\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:\n \"List connected GTKX applications and their open windows. \" +\n \"Returns the current snapshot immediately unless waitForApps is true.\",\n inputSchema: listAppsShape,\n handler: async ({ waitForApps, timeout }) => {\n if (waitForApps && !appRouter.hasConnectedApps()) {\n await appRouter.waitForApp(undefined, 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 screenshotResult = (\n result: { data: string; mimeType: string; savedPath?: string },\n shouldReturnImage: boolean,\n): CallToolResult => {\n if (result.savedPath === undefined) {\n return shouldReturnImage\n ? imageContent(result.data, result.mimeType)\n : textError(\n \"Nothing to return: `returnImage` was false and no `path` was given, so the screenshot was \" +\n \"neither saved nor returned. Pass `path` to save it, or leave `returnImage` unset.\",\n );\n }\n\n const saved = { type: \"text\", text: `Screenshot saved to ${result.savedPath}` } as const;\n\n if (!shouldReturnImage) {\n return { content: [saved] };\n }\n\n return { content: [saved, { type: \"image\", data: result.data, mimeType: result.mimeType }] };\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, appTimeout, returnImage, ...params }) => {\n const result = await appRouter.sendToApp<{ data: string; mimeType: string; savedPath?: string }>(\n applicationId,\n \"widget.screenshot\",\n params,\n appTimeout,\n );\n\n return screenshotResult(result, returnImage !== false);\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 \"Read a widget's type, accessible role, name, text, sensitivity, visibility, CSS classes, \" +\n `and descendants. Defaults to ${String(DEFAULT_SUBTREE_DEPTH)} levels; \\`maxDepth\\` changes ` +\n `the depth. Results contain at most ${String(MAX_SUBTREE_WIDGETS)} widgets, in breadth-first ` +\n \"order. `hiddenChildren` counts omitted direct children; query that widget's ID to expand it. \" +\n \"Use `gtkx_get_widget_tree` for an overview. Requested GObject `properties` appear first, \" +\n \"keyed by canonical kebab-case name with `{type, value}`. Enum/flags values use GType value \" +\n \"names, 64-bit integers use decimal strings, and objects use their GType name plus `widgetId` \" +\n \"for widgets. Unknown properties fail; values that cannot be converted include a `note`.\",\n inputSchema: widgetPropsShape,\n handler: async ({ applicationId, appTimeout, ...params }) => {\n const result = await appRouter.sendToApp(applicationId, \"widget.getProps\", params, appTimeout);\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, appTimeout, rootId, maxDepth }) => {\n const result = await appRouter.sendToApp<{ tree: string }>(applicationId, \"widget.getTree\", {\n rootId,\n maxDepth,\n }, appTimeout);\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, appTimeout, ...params }) => {\n const result = await appRouter.sendToApp(applicationId, \"widget.query\", params, appTimeout);\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. 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, appTimeout, ...params }) => {\n await appRouter.sendToApp(applicationId, \"widget.click\", params, appTimeout);\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, appTimeout, ...params }) => {\n await appRouter.sendToApp(applicationId, \"widget.type\", params, appTimeout);\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 GObject signal on a widget. Use this for custom interactions.\",\n inputSchema: fireEventShape,\n handler: async ({ applicationId, appTimeout, ...params }) => {\n const result = await appRouter.sendToApp(applicationId, \"widget.fireEvent\", params, appTimeout);\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 = (\n mcpServer: McpServer,\n appRouter: AppRouter,\n provider: ReferenceProvider,\n settings: McpSettings,\n): void => {\n const tools = selectTools([...buildTools(appRouter), ...buildReferenceTools(provider)], settings);\n\n if (tools.length === 0) {\n log.warn(\"no tools matched the configured filter; the server is registering none\");\n }\n\n for (const tool of tools) {\n registerTool(mcpServer, tool);\n }\n};\n\nconst stoppedServerError = (): Error => new Error(\"createMcpServer: a stopped server cannot be started again\");\n\nconst wasStopRequested = (state: ServerLifecycle): boolean => state.isStopRequested;\n\nfunction stopServer(state: ServerLifecycle): Promise<void> {\n if (state.shutdown !== null) {\n return state.shutdown;\n }\n\n state.isStopRequested = true;\n state.appRouter.dispose();\n const startup = state.startup;\n const shutdown = (async (): Promise<void> => {\n if (startup !== null) {\n await Promise.allSettled([startup]);\n }\n\n await state.socketServer.stop();\n await state.mcpServer.close();\n })();\n\n state.shutdown = shutdown;\n\n return shutdown;\n}\n\nfunction startServer(state: ServerLifecycle): Promise<void> {\n if (wasStopRequested(state)) {\n return Promise.reject(stoppedServerError());\n }\n\n if (state.startup !== null) {\n return state.startup;\n }\n\n const startup = (async (): Promise<void> => {\n try {\n await state.socketServer.start();\n\n if (wasStopRequested(state)) {\n return;\n }\n\n log.info(`socket server listening on ${state.socketPath}`);\n await connectStdio(state.mcpServer, () => stopServer(state));\n } catch (error) {\n if (!wasStopRequested(state)) {\n state.isStopRequested = true;\n state.appRouter.dispose();\n await state.socketServer.stop();\n await state.mcpServer.close();\n }\n\n throw error;\n }\n })();\n\n state.startup = startup;\n\n return startup;\n}\n\nconst createServerHandle = (\n socketServer: SocketServer,\n mcpServer: McpServer,\n appRouter: AppRouter,\n socketPath: string,\n): McpServerHandle => {\n const state: ServerLifecycle = {\n socketServer,\n mcpServer,\n appRouter,\n socketPath,\n isStopRequested: false,\n startup: null,\n shutdown: null,\n };\n\n return { start: () => startServer(state), stop: () => stopServer(state) };\n};\n\nconst createMcpServer = (options: CreateMcpServerOptions): McpServerHandle => {\n const socketAddress = resolveMcpSocketAddress(options.socketPath);\n const socketPath = socketAddress.path;\n\n if (socketAddress.fallbackDirectory !== null) {\n log.warn(`MCP socket path exceeds the safe Unix byte budget; using private fallback ${socketPath}`);\n }\n\n const registry = new ConnectionRegistry();\n const socketServer = new SocketServer(registry, socketAddress);\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 }, { instructions: INSTRUCTIONS });\n const referenceProvider = createReferenceProvider({ getAppRoot: () => appRouter.getProjectRoot() });\n registerTools(mcpServer, appRouter, referenceProvider, options.settings ?? DEFAULT_SETTINGS);\n registerReferenceResources(mcpServer, referenceProvider);\n\n return createServerHandle(socketServer, mcpServer, appRouter, socketPath);\n};\n\nconst configuredSettings = async (cwd: string): Promise<McpSettings> => {\n try {\n const { config } = await loadConfig(cwd);\n\n return resolveMcpSettings(config);\n } catch (error) {\n if (configDependenciesFor(error).some((path) => existsSync(resolve(cwd, path)))) {\n throw error;\n }\n\n return DEFAULT_SETTINGS;\n }\n};\n\nconst resolveSettings = async (options: ServerOptions): Promise<McpSettings> => {\n const configured = await configuredSettings(options.cwd ?? process.cwd());\n\n return {\n tools: options.tools ?? configured.tools,\n isReadOnly: options.isReadOnly ?? configured.isReadOnly,\n };\n};\n\nconst splitPatterns = (values: string[]): string[] =>\n values.flatMap((value) => value.split(\",\")).map((value) => value.trim()).filter((value) => value.length > 0);\n\nconst parseServerArgs = (argv: string[]): ServerOptions => {\n const { values } = parseArgs({\n args: argv,\n options: {\n tools: { type: \"string\", multiple: true },\n \"read-only\": { type: \"boolean\" },\n },\n allowPositionals: false,\n });\n\n const tools = values.tools === undefined ? undefined : splitPatterns(values.tools);\n\n return {\n ...(tools !== undefined && { tools }),\n ...(values[\"read-only\"] !== undefined && { isReadOnly: values[\"read-only\"] }),\n };\n};\n\nasync function main(options: ServerOptions = {}): Promise<void> {\n const settings = await resolveSettings(options);\n const server = createMcpServer({ version, settings });\n\n installGracefulShutdown({\n onSignal: () => server.stop(),\n });\n\n await server.start();\n}\n\nexport { log, main, main as runMcpServer, parseServerArgs };\n"]}
@@ -0,0 +1,11 @@
1
+ type McpSocketAddress = {
2
+ path: string;
3
+ fallbackDirectory: string | null;
4
+ };
5
+ declare const MCP_SOCKET_PATH_ENV = "GTKX_MCP_SOCKET_PATH";
6
+ declare const resolveMcpSocketAddress: (providedPath?: string) => McpSocketAddress;
7
+ declare const resolveMcpSocketPath: (providedPath?: string) => string;
8
+ declare const prepareMcpSocketAddress: (address: McpSocketAddress) => void;
9
+ declare const cleanupMcpSocketAddress: (address: McpSocketAddress) => void;
10
+ export { cleanupMcpSocketAddress, MCP_SOCKET_PATH_ENV, prepareMcpSocketAddress, resolveMcpSocketAddress, resolveMcpSocketPath, type McpSocketAddress, };
11
+ //# sourceMappingURL=socket-path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"socket-path.d.ts","sourceRoot":"","sources":["../src/socket-path.ts"],"names":[],"mappings":"AAKA,KAAK,gBAAgB,GAAG;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,iBAAiB,EAAE,MAAM,GAAG,IAAI,CAAC;CACpC,CAAC;AAEF,QAAA,MAAM,mBAAmB,yBAAyB,CAAC;AAsDnD,QAAA,MAAM,uBAAuB,GAAI,eAAe,MAAM,KAAG,gBAMxD,CAAC;AAEF,QAAA,MAAM,oBAAoB,GAAI,eAAe,MAAM,KAAG,MAAoD,CAAC;AAE3G,QAAA,MAAM,uBAAuB,GAAI,SAAS,gBAAgB,KAAG,IAI5D,CAAC;AAEF,QAAA,MAAM,uBAAuB,GAAI,SAAS,gBAAgB,KAAG,IAa5D,CAAC;AAEF,OAAO,EACH,uBAAuB,EACvB,mBAAmB,EACnB,uBAAuB,EACvB,uBAAuB,EACvB,oBAAoB,EACpB,KAAK,gBAAgB,GACxB,CAAC"}
@@ -0,0 +1,74 @@
1
+ import { createHash } from "node:crypto";
2
+ import { lstatSync, mkdirSync, rmdirSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ const MCP_SOCKET_PATH_ENV = "GTKX_MCP_SOCKET_PATH";
6
+ const SOCKET_NAME = "gtkx-mcp.sock";
7
+ const SOCKET_PATH_BYTE_LIMIT = 100;
8
+ const SHORT_SOCKET_ROOT = "/tmp";
9
+ const socketCandidate = () => process.env[MCP_SOCKET_PATH_ENV] ?? join(process.env.XDG_RUNTIME_DIR ?? tmpdir(), SOCKET_NAME);
10
+ const currentUserId = () => {
11
+ const getuid = process.getuid;
12
+ if (getuid === undefined) {
13
+ throw new Error("GTKX MCP Unix sockets require a platform with user IDs");
14
+ }
15
+ return getuid();
16
+ };
17
+ const verifyPrivateDirectory = (directory, userId) => {
18
+ const entry = lstatSync(directory);
19
+ if (!entry.isDirectory() || entry.uid !== userId || (entry.mode & 0o777) !== 0o700) {
20
+ throw new Error(`GTKX MCP fallback socket directory is not private: ${directory}`);
21
+ }
22
+ };
23
+ const ensurePrivateDirectory = (directory, userId) => {
24
+ try {
25
+ mkdirSync(directory, { mode: 0o700 });
26
+ }
27
+ catch (error) {
28
+ if (error.code !== "EEXIST") {
29
+ throw error;
30
+ }
31
+ }
32
+ verifyPrivateDirectory(directory, userId);
33
+ };
34
+ const fallbackAddress = (candidate) => {
35
+ const userId = currentUserId();
36
+ const digest = createHash("sha256").update(candidate).digest("hex").slice(0, 24);
37
+ const fallbackDirectory = join(SHORT_SOCKET_ROOT, `gtkx-mcp-${String(userId)}-${digest}`);
38
+ try {
39
+ verifyPrivateDirectory(fallbackDirectory, userId);
40
+ }
41
+ catch (error) {
42
+ if (error.code !== "ENOENT") {
43
+ throw error;
44
+ }
45
+ }
46
+ return { path: join(fallbackDirectory, "socket"), fallbackDirectory };
47
+ };
48
+ const resolveMcpSocketAddress = (providedPath) => {
49
+ const candidate = providedPath ?? socketCandidate();
50
+ return Buffer.byteLength(candidate) <= SOCKET_PATH_BYTE_LIMIT
51
+ ? { path: candidate, fallbackDirectory: null }
52
+ : fallbackAddress(candidate);
53
+ };
54
+ const resolveMcpSocketPath = (providedPath) => resolveMcpSocketAddress(providedPath).path;
55
+ const prepareMcpSocketAddress = (address) => {
56
+ if (address.fallbackDirectory !== null) {
57
+ ensurePrivateDirectory(address.fallbackDirectory, currentUserId());
58
+ }
59
+ };
60
+ const cleanupMcpSocketAddress = (address) => {
61
+ const directory = address.fallbackDirectory;
62
+ if (directory === null) {
63
+ return;
64
+ }
65
+ try {
66
+ verifyPrivateDirectory(directory, currentUserId());
67
+ rmdirSync(directory);
68
+ }
69
+ catch {
70
+ return;
71
+ }
72
+ };
73
+ export { cleanupMcpSocketAddress, MCP_SOCKET_PATH_ENV, prepareMcpSocketAddress, resolveMcpSocketAddress, resolveMcpSocketPath, };
74
+ //# sourceMappingURL=socket-path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"socket-path.js","sourceRoot":"","sources":["../src/socket-path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAC1D,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAOjC,MAAM,mBAAmB,GAAG,sBAAsB,CAAC;AACnD,MAAM,WAAW,GAAG,eAAe,CAAC;AACpC,MAAM,sBAAsB,GAAG,GAAG,CAAC;AACnC,MAAM,iBAAiB,GAAG,MAAM,CAAC;AAEjC,MAAM,eAAe,GAAG,GAAW,EAAE,CACjC,OAAO,CAAC,GAAG,CAAC,mBAAmB,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,MAAM,EAAE,EAAE,WAAW,CAAC,CAAC;AAEnG,MAAM,aAAa,GAAG,GAAW,EAAE;IAC/B,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAE9B,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAC9E,CAAC;I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AuB,EACvB,mBAAmB,EACnB,uBAAuB,EACvB,uBAAuB,EACvB,oBAAoB,GAEvB,CAAC","sourcesContent":["import { createHash } from \"node:crypto\";\nimport { lstatSync, mkdirSync, rmdirSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\n\ntype McpSocketAddress = {\n path: string;\n fallbackDirectory: string | null;\n};\n\nconst MCP_SOCKET_PATH_ENV = \"GTKX_MCP_SOCKET_PATH\";\nconst SOCKET_NAME = \"gtkx-mcp.sock\";\nconst SOCKET_PATH_BYTE_LIMIT = 100;\nconst SHORT_SOCKET_ROOT = \"/tmp\";\n\nconst socketCandidate = (): string =>\n process.env[MCP_SOCKET_PATH_ENV] ?? join(process.env.XDG_RUNTIME_DIR ?? tmpdir(), SOCKET_NAME);\n\nconst currentUserId = (): number => {\n const getuid = process.getuid;\n\n if (getuid === undefined) {\n throw new Error(\"GTKX MCP Unix sockets require a platform with user IDs\");\n }\n\n return getuid();\n};\n\nconst verifyPrivateDirectory = (directory: string, userId: number): void => {\n const entry = lstatSync(directory);\n\n if (!entry.isDirectory() || entry.uid !== userId || (entry.mode & 0o777) !== 0o700) {\n throw new Error(`GTKX MCP fallback socket directory is not private: ${directory}`);\n }\n};\n\nconst ensurePrivateDirectory = (directory: string, userId: number): void => {\n try {\n mkdirSync(directory, { mode: 0o700 });\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"EEXIST\") {\n throw error;\n }\n }\n\n verifyPrivateDirectory(directory, userId);\n};\n\nconst fallbackAddress = (candidate: string): McpSocketAddress => {\n const userId = currentUserId();\n const digest = createHash(\"sha256\").update(candidate).digest(\"hex\").slice(0, 24);\n const fallbackDirectory = join(SHORT_SOCKET_ROOT, `gtkx-mcp-${String(userId)}-${digest}`);\n\n try {\n verifyPrivateDirectory(fallbackDirectory, userId);\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code !== \"ENOENT\") {\n throw error;\n }\n }\n\n return { path: join(fallbackDirectory, \"socket\"), fallbackDirectory };\n};\n\nconst resolveMcpSocketAddress = (providedPath?: string): McpSocketAddress => {\n const candidate = providedPath ?? socketCandidate();\n\n return Buffer.byteLength(candidate) <= SOCKET_PATH_BYTE_LIMIT\n ? { path: candidate, fallbackDirectory: null }\n : fallbackAddress(candidate);\n};\n\nconst resolveMcpSocketPath = (providedPath?: string): string => resolveMcpSocketAddress(providedPath).path;\n\nconst prepareMcpSocketAddress = (address: McpSocketAddress): void => {\n if (address.fallbackDirectory !== null) {\n ensurePrivateDirectory(address.fallbackDirectory, currentUserId());\n }\n};\n\nconst cleanupMcpSocketAddress = (address: McpSocketAddress): void => {\n const directory = address.fallbackDirectory;\n\n if (directory === null) {\n return;\n }\n\n try {\n verifyPrivateDirectory(directory, currentUserId());\n rmdirSync(directory);\n } catch {\n return;\n }\n};\n\nexport {\n cleanupMcpSocketAddress,\n MCP_SOCKET_PATH_ENV,\n prepareMcpSocketAddress,\n resolveMcpSocketAddress,\n resolveMcpSocketPath,\n type McpSocketAddress,\n};\n"]}
@@ -1,11 +1,13 @@
1
1
  import type { ConnectionRegistry } from "./connection-registry.js";
2
+ import { type McpSocketAddress } from "./socket-path.js";
2
3
  declare class SocketServer {
3
4
  private server;
4
5
  private socketPath;
5
6
  private registry;
7
+ private address;
6
8
  private boundInode;
7
9
  private startup;
8
- constructor(registry: ConnectionRegistry, socketPath?: string);
10
+ constructor(registry: ConnectionRegistry, address?: McpSocketAddress);
9
11
  private listen;
10
12
  private listenPrivately;
11
13
  private bind;
@@ -1 +1 @@
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;AA0PnE,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,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;AACnE,OAAO,EAEH,KAAK,gBAAgB,EAGxB,MAAM,kBAAkB,CAAC;AAyO1B,cAAM,YAAY;IACd,OAAO,CAAC,MAAM,CAA2B;IACzC,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,QAAQ,CAAqB;IACrC,OAAO,CAAC,OAAO,CAAmB;IAClC,OAAO,CAAC,UAAU,CAAuB;IACzC,OAAO,CAAC,OAAO,CAA8B;gBAEjC,QAAQ,EAAE,kBAAkB,EAAE,OAAO,GAAE,gBAA4C;IAM/F,OAAO,CAAC,MAAM;YAoBA,eAAe;YASf,IAAI;IAgClB,OAAO,CAAC,IAAI;YAWE,aAAa;YASb,OAAO;IAmBf,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAetB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAW9B;AAED,OAAO,EAAE,YAAY,EAAE,CAAC"}