@gtkx/mcp 2.0.0-beta.2 → 2.0.0-beta.4

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.
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAGA,OAAO,EAAyC,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AAsCjF,KAAK,aAAa,GAAG;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAqBF,QAAA,MAAM,GAAG,EAAE,MAA4B,CAAC;AA0exC,QAAA,MAAM,eAAe,GAAI,MAAM,MAAM,EAAE,KAAG,aAgBzC,CAAC;AAEF,iBAAe,IAAI,CAAC,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAS9D;AAED,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,IAAI,YAAY,EAAE,eAAe,EAAE,CAAC"}
1
+ {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAGA,OAAO,EAAyC,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AAsCjF,KAAK,aAAa,GAAG;IACjB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAqBF,QAAA,MAAM,GAAG,EAAE,MAA4B,CAAC;AA4exC,QAAA,MAAM,eAAe,GAAI,MAAM,MAAM,EAAE,KAAG,aAgBzC,CAAC;AAEF,iBAAe,IAAI,CAAC,OAAO,GAAE,aAAkB,GAAG,OAAO,CAAC,IAAI,CAAC,CAS9D;AAED,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,IAAI,YAAY,EAAE,eAAe,EAAE,CAAC"}
package/dist/server.js CHANGED
@@ -140,7 +140,8 @@ const listAppsTool = (appRouter) => defineTool({
140
140
  name: "gtkx_list_apps",
141
141
  title: "List apps",
142
142
  kind: "readOnly",
143
- description: "List all connected GTKX applications and their open windows.",
143
+ description: "List connected GTKX applications and their open windows. " +
144
+ "Returns the current snapshot immediately unless waitForApps is true.",
144
145
  inputSchema: listAppsShape,
145
146
  handler: async ({ waitForApps, timeout }) => {
146
147
  if (waitForApps && !appRouter.hasConnectedApps()) {
@@ -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,qBAAqB,EACrB,eAAe,EACf,mBAAmB,EACnB,WAAW,EACX,gBAAgB,EAChB,UAAU,EACV,UAAU,EACV,cAAc,EACd,iBAAiB,GACpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACH,mBAAmB,EACnB,uBAAuB,EAEvB,0BAA0B,GAC7B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,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} 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_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 \"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 =\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: \"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(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 \"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, 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, 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, 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 GTK4 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 {\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,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,M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AAM,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_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 \"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 =\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: \"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:\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 \"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, 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, 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, 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 GTK4 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 {\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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gtkx/mcp",
3
- "version": "2.0.0-beta.2",
3
+ "version": "2.0.0-beta.4",
4
4
  "description": "MCP server exposing the GTK API reference and a running GTK4 app.",
5
5
  "keywords": [
6
6
  "gtkx",
@@ -63,14 +63,14 @@
63
63
  "node": ">=26.7.0"
64
64
  },
65
65
  "dependencies": {
66
- "@gtkx/codegen": "2.0.0-beta.2",
67
- "@gtkx/config": "2.0.0-beta.2",
68
- "@gtkx/utils": "2.0.0-beta.2",
66
+ "@gtkx/codegen": "2.0.0-beta.4",
67
+ "@gtkx/config": "2.0.0-beta.4",
68
+ "@gtkx/utils": "2.0.0-beta.4",
69
69
  "@modelcontextprotocol/sdk": "^1.30.0",
70
70
  "zod": "^4.5.4"
71
71
  },
72
72
  "devDependencies": {
73
- "@gtkx/vitest": "2.0.0-beta.2",
73
+ "@gtkx/vitest": "2.0.0-beta.4",
74
74
  "vitest": "^4.1.11"
75
75
  },
76
76
  "scripts": {
package/src/server.ts CHANGED
@@ -230,7 +230,9 @@ const listAppsTool = (appRouter: AppRouter): Tool =>
230
230
  name: "gtkx_list_apps",
231
231
  title: "List apps",
232
232
  kind: "readOnly",
233
- description: "List all connected GTKX applications and their open windows.",
233
+ description:
234
+ "List connected GTKX applications and their open windows. " +
235
+ "Returns the current snapshot immediately unless waitForApps is true.",
234
236
  inputSchema: listAppsShape,
235
237
  handler: async ({ waitForApps, timeout }) => {
236
238
  if (waitForApps && !appRouter.hasConnectedApps()) {