@gtkx/mcp 0.21.0 → 1.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +137 -34
- package/bin/gtkx-mcp.js +9 -1
- package/dist/app-router.d.ts +35 -0
- package/dist/app-router.d.ts.map +1 -0
- package/dist/app-router.js +143 -0
- package/dist/app-router.js.map +1 -0
- package/dist/connection-registry.d.ts +12 -0
- package/dist/connection-registry.d.ts.map +1 -0
- package/dist/connection-registry.js +39 -0
- package/dist/connection-registry.js.map +1 -0
- package/dist/internal.d.ts +4 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +4 -0
- package/dist/internal.js.map +1 -0
- package/dist/protocol/errors.d.ts +25 -87
- package/dist/protocol/errors.d.ts.map +1 -1
- package/dist/protocol/errors.js +38 -101
- package/dist/protocol/errors.js.map +1 -1
- package/dist/protocol/schemas.d.ts +93 -0
- package/dist/protocol/schemas.d.ts.map +1 -0
- package/dist/protocol/schemas.js +63 -0
- package/dist/protocol/schemas.js.map +1 -0
- package/dist/reference.d.ts +13 -0
- package/dist/reference.d.ts.map +1 -0
- package/dist/reference.js +293 -0
- package/dist/reference.js.map +1 -0
- package/dist/server.d.ts +14 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +244 -0
- package/dist/server.js.map +1 -0
- package/dist/socket-server.d.ts +5 -38
- package/dist/socket-server.d.ts.map +1 -1
- package/dist/socket-server.js +36 -108
- package/dist/socket-server.js.map +1 -1
- package/dist/tool.d.ts +22 -0
- package/dist/tool.d.ts.map +1 -0
- package/dist/tool.js +40 -0
- package/dist/tool.js.map +1 -0
- package/dist/transport.d.ts +49 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +152 -0
- package/dist/transport.js.map +1 -0
- package/package.json +15 -11
- package/src/app-router.ts +209 -0
- package/src/connection-registry.ts +57 -0
- package/src/internal.ts +17 -0
- package/src/protocol/errors.ts +67 -110
- package/src/protocol/schemas.ts +173 -0
- package/src/reference.ts +449 -0
- package/src/server.ts +334 -0
- package/src/socket-server.ts +46 -147
- package/src/tool.ts +73 -0
- package/src/transport.ts +242 -0
- package/dist/cli.d.ts +0 -3
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js +0 -399
- package/dist/cli.js.map +0 -1
- package/dist/connection-manager.d.ts +0 -48
- package/dist/connection-manager.d.ts.map +0 -1
- package/dist/connection-manager.js +0 -185
- package/dist/connection-manager.js.map +0 -1
- package/dist/index.d.ts +0 -5
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -5
- package/dist/index.js.map +0 -1
- package/dist/protocol/types.d.ts +0 -132
- package/dist/protocol/types.d.ts.map +0 -1
- package/dist/protocol/types.js +0 -46
- package/dist/protocol/types.js.map +0 -1
- package/src/cli.ts +0 -449
- package/src/connection-manager.ts +0 -247
- package/src/index.ts +0 -27
- package/src/protocol/types.ts +0 -153
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { loadApiReference, resolveGirPath, resolveLibraries } from "@gtkx/codegen";
|
|
2
|
+
import { loadConfig } from "@gtkx/config";
|
|
3
|
+
import { ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
4
|
+
import { ErrorCode, McpError } from "@modelcontextprotocol/sdk/types.js";
|
|
5
|
+
import { statSync } from "node:fs";
|
|
6
|
+
import { resolve } from "node:path";
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
import { defineTool, textContent, textError } from "./tool.js";
|
|
9
|
+
const FRESHNESS_INTERVAL_MS = 2000;
|
|
10
|
+
const FAILURE_RETRY_MS = 5000;
|
|
11
|
+
const SYMBOL_KIND = z.enum([
|
|
12
|
+
"element",
|
|
13
|
+
"class",
|
|
14
|
+
"interface",
|
|
15
|
+
"record",
|
|
16
|
+
"enum",
|
|
17
|
+
"callback",
|
|
18
|
+
"alias",
|
|
19
|
+
"function",
|
|
20
|
+
"constant",
|
|
21
|
+
]);
|
|
22
|
+
const SYMBOL_DESCRIPTION = "Qualified symbol name (`Gtk.Button`, `Gtk.Orientation`, `GLib.idleAdd`), JSX element name (`GtkButton`), " +
|
|
23
|
+
"or bare symbol name when unambiguous (`Button`).";
|
|
24
|
+
const listApiShape = {
|
|
25
|
+
namespace: z
|
|
26
|
+
.string()
|
|
27
|
+
.optional()
|
|
28
|
+
.describe("Namespace to list (e.g. `Gtk`, `Adw`, `Gio`). Omit for an overview of all namespaces."),
|
|
29
|
+
};
|
|
30
|
+
const searchApiShape = {
|
|
31
|
+
query: z.string().describe("Case-insensitive substring of a symbol name, e.g. `headerbar` or `orientation`."),
|
|
32
|
+
namespace: z.string().optional().describe("Restrict matches to one namespace (e.g. `Gtk`)."),
|
|
33
|
+
kind: SYMBOL_KIND.optional().describe("Restrict matches to one symbol kind."),
|
|
34
|
+
limit: z.number().int().min(1).optional().describe("Maximum number of results (default: 20)."),
|
|
35
|
+
};
|
|
36
|
+
const apiDocsShape = {
|
|
37
|
+
symbol: z.string().describe(SYMBOL_DESCRIPTION),
|
|
38
|
+
kind: SYMBOL_KIND.optional().describe("Disambiguate when several kinds share the symbol name."),
|
|
39
|
+
};
|
|
40
|
+
const watchFile = (path) => {
|
|
41
|
+
try {
|
|
42
|
+
const stats = statSync(path);
|
|
43
|
+
return { path, mtimeMs: stats.mtimeMs, size: stats.size };
|
|
44
|
+
}
|
|
45
|
+
catch {
|
|
46
|
+
return { path, mtimeMs: -1, size: -1 };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const isFresh = (loaded) => loaded.watched.every((file) => {
|
|
50
|
+
const current = watchFile(file.path);
|
|
51
|
+
return current.mtimeMs === file.mtimeMs && current.size === file.size;
|
|
52
|
+
});
|
|
53
|
+
const loadReference = async (root) => {
|
|
54
|
+
const { config, configFile } = await loadConfig(root);
|
|
55
|
+
if (config.codegen === false) {
|
|
56
|
+
throw new Error(`codegen is disabled for the project at ${root}, so there are no generated bindings to document. ` +
|
|
57
|
+
"Remove `codegen: false` from gtkx.config.ts to use the API reference.");
|
|
58
|
+
}
|
|
59
|
+
const girPath = resolveGirPath(config.girPath);
|
|
60
|
+
if (girPath.length === 0) {
|
|
61
|
+
throw new Error("No GIR search paths available. Install gobject-introspection " +
|
|
62
|
+
"(Linux: `sudo dnf install gobject-introspection-devel` or `sudo apt install libgirepository1.0-dev`), " +
|
|
63
|
+
"or set `girPath` in gtkx.config.ts.");
|
|
64
|
+
}
|
|
65
|
+
const libraries = resolveLibraries(config.libraries, girPath);
|
|
66
|
+
const reference = loadApiReference({ libraries, girPath });
|
|
67
|
+
const watched = [
|
|
68
|
+
...(configFile === undefined ? [] : [watchFile(resolve(root, configFile))]),
|
|
69
|
+
...reference.girFiles.map((file) => watchFile(file)),
|
|
70
|
+
];
|
|
71
|
+
return { reference, watched };
|
|
72
|
+
};
|
|
73
|
+
const markFailed = async (entry) => {
|
|
74
|
+
try {
|
|
75
|
+
await entry.pending;
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
entry.failedAt = Date.now();
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
const startLoad = (cache, root) => {
|
|
82
|
+
const entry = { pending: loadReference(root), verifiedAt: Date.now(), failedAt: undefined };
|
|
83
|
+
void markFailed(entry);
|
|
84
|
+
cache.set(root, entry);
|
|
85
|
+
return entry;
|
|
86
|
+
};
|
|
87
|
+
const isRetryDue = (entry) => entry.failedAt !== undefined && Date.now() - entry.failedAt >= FAILURE_RETRY_MS;
|
|
88
|
+
const resolveEntry = (cache, root) => {
|
|
89
|
+
const entry = cache.get(root) ?? startLoad(cache, root);
|
|
90
|
+
return isRetryDue(entry) ? startLoad(cache, root) : entry;
|
|
91
|
+
};
|
|
92
|
+
const revalidate = (cache, root, entry) => {
|
|
93
|
+
const current = cache.get(root);
|
|
94
|
+
return current === undefined || current === entry ? startLoad(cache, root) : current;
|
|
95
|
+
};
|
|
96
|
+
const currentReference = async (cache, root) => {
|
|
97
|
+
const entry = resolveEntry(cache, root);
|
|
98
|
+
const loaded = await entry.pending;
|
|
99
|
+
if (Date.now() - entry.verifiedAt < FRESHNESS_INTERVAL_MS) {
|
|
100
|
+
return loaded.reference;
|
|
101
|
+
}
|
|
102
|
+
if (isFresh(loaded)) {
|
|
103
|
+
entry.verifiedAt = Date.now();
|
|
104
|
+
return loaded.reference;
|
|
105
|
+
}
|
|
106
|
+
const revalidated = await revalidate(cache, root, entry).pending;
|
|
107
|
+
return revalidated.reference;
|
|
108
|
+
};
|
|
109
|
+
const createReferenceProvider = (resolveRoot) => {
|
|
110
|
+
const cache = new Map();
|
|
111
|
+
return {
|
|
112
|
+
get: () => currentReference(cache, resolve(resolveRoot())),
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
const formatCandidates = (candidates) => candidates.map((candidate) => `- ${candidate.namespace}.${candidate.name} (${candidate.kind})`).join("\n");
|
|
116
|
+
const buildSearchOptions = (args) => {
|
|
117
|
+
const options = { query: args.query };
|
|
118
|
+
if (args.namespace !== undefined) {
|
|
119
|
+
options.namespace = args.namespace;
|
|
120
|
+
}
|
|
121
|
+
if (args.kind !== undefined) {
|
|
122
|
+
options.kinds = [args.kind];
|
|
123
|
+
}
|
|
124
|
+
if (args.limit !== undefined) {
|
|
125
|
+
options.limit = args.limit;
|
|
126
|
+
}
|
|
127
|
+
return options;
|
|
128
|
+
};
|
|
129
|
+
const listApiTool = (provider) => defineTool({
|
|
130
|
+
name: "gtkx_list_api",
|
|
131
|
+
title: "List API reference",
|
|
132
|
+
kind: "readOnly",
|
|
133
|
+
description: "List the project's generated GTK4 bindings API (`@gtkx/gi` and `@gtkx/jsx`). Without a namespace, " +
|
|
134
|
+
"returns every namespace with symbol counts; with a namespace, lists all of its symbols grouped by kind.",
|
|
135
|
+
inputSchema: listApiShape,
|
|
136
|
+
handler: async ({ namespace }) => {
|
|
137
|
+
const reference = await provider.get();
|
|
138
|
+
if (namespace === undefined) {
|
|
139
|
+
return textContent(reference.overview());
|
|
140
|
+
}
|
|
141
|
+
const overview = reference.namespaceOverview(namespace);
|
|
142
|
+
if (overview === undefined) {
|
|
143
|
+
const names = reference
|
|
144
|
+
.namespaces()
|
|
145
|
+
.map((summary) => summary.name)
|
|
146
|
+
.join(", ");
|
|
147
|
+
return textError(`Unknown namespace "${namespace}". Available namespaces: ${names}`);
|
|
148
|
+
}
|
|
149
|
+
return textContent(overview);
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
const searchApiTool = (provider) => defineTool({
|
|
153
|
+
name: "gtkx_search_api",
|
|
154
|
+
title: "Search API reference",
|
|
155
|
+
kind: "readOnly",
|
|
156
|
+
description: "Search the project's generated GTK4 bindings API by symbol name. Returns matching symbols with " +
|
|
157
|
+
"their namespace, kind, and a one-line summary; fetch full pages with `gtkx_get_api_docs`.",
|
|
158
|
+
inputSchema: searchApiShape,
|
|
159
|
+
handler: async (args) => {
|
|
160
|
+
const reference = await provider.get();
|
|
161
|
+
const results = reference.search(buildSearchOptions(args));
|
|
162
|
+
if (results.length === 0) {
|
|
163
|
+
return textContent(`No symbols matched "${args.query}". Try a shorter substring or \`gtkx_list_api\`.`);
|
|
164
|
+
}
|
|
165
|
+
return textContent(JSON.stringify(results, null, 2));
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
const getApiDocsTool = (provider) => defineTool({
|
|
169
|
+
name: "gtkx_get_api_docs",
|
|
170
|
+
title: "Get API docs",
|
|
171
|
+
kind: "readOnly",
|
|
172
|
+
description: "Get the full reference page for one symbol of the project's generated GTK4 bindings: JSX elements " +
|
|
173
|
+
"(props, signals, methods) or `@gtkx/gi` classes, interfaces, records, enums, callbacks, aliases, " +
|
|
174
|
+
"functions, and constants.",
|
|
175
|
+
inputSchema: apiDocsShape,
|
|
176
|
+
handler: async ({ symbol, kind }) => {
|
|
177
|
+
const reference = await provider.get();
|
|
178
|
+
const result = reference.lookup(symbol, kind);
|
|
179
|
+
if (result.outcome === "notFound") {
|
|
180
|
+
return textError(`No symbol named "${symbol}". Use \`gtkx_search_api\` to find the right name.`);
|
|
181
|
+
}
|
|
182
|
+
if (result.outcome === "ambiguous") {
|
|
183
|
+
return textError(`"${symbol}" matches several symbols. Pass a qualified name or a kind:\n` +
|
|
184
|
+
formatCandidates(result.candidates));
|
|
185
|
+
}
|
|
186
|
+
return textContent(result.markdown);
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
const buildReferenceTools = (provider) => [
|
|
190
|
+
listApiTool(provider),
|
|
191
|
+
searchApiTool(provider),
|
|
192
|
+
getApiDocsTool(provider),
|
|
193
|
+
];
|
|
194
|
+
const markdownResource = (uri, text) => ({
|
|
195
|
+
contents: [{ uri: uri.href, mimeType: "text/markdown", text }],
|
|
196
|
+
});
|
|
197
|
+
const variableValue = (value) => Array.isArray(value) ? (value[0] ?? "") : (value ?? "");
|
|
198
|
+
const withLoadFallback = async (load, fallback) => {
|
|
199
|
+
try {
|
|
200
|
+
return await load();
|
|
201
|
+
}
|
|
202
|
+
catch {
|
|
203
|
+
return fallback;
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
const namespaceCompleter = (provider) => (value) => withLoadFallback(async () => {
|
|
207
|
+
const reference = await provider.get();
|
|
208
|
+
return reference
|
|
209
|
+
.namespaces()
|
|
210
|
+
.map((summary) => summary.name)
|
|
211
|
+
.filter((name) => name.toLowerCase().startsWith(value.toLowerCase()));
|
|
212
|
+
}, []);
|
|
213
|
+
const completeSymbol = async (provider, namespace, value) => {
|
|
214
|
+
if (namespace.length === 0) {
|
|
215
|
+
return [];
|
|
216
|
+
}
|
|
217
|
+
return withLoadFallback(async () => {
|
|
218
|
+
const reference = await provider.get();
|
|
219
|
+
return reference.symbolNames(namespace).filter((name) => name.toLowerCase().startsWith(value.toLowerCase()));
|
|
220
|
+
}, []);
|
|
221
|
+
};
|
|
222
|
+
const resourceNotFound = (message) => new McpError(ErrorCode.InvalidParams, message);
|
|
223
|
+
const symbolPage = async (uri, provider, namespace, symbol) => {
|
|
224
|
+
const reference = await provider.get();
|
|
225
|
+
const result = reference.lookup(`${namespace}.${symbol}`);
|
|
226
|
+
if (result.outcome === "page") {
|
|
227
|
+
return markdownResource(uri, result.markdown);
|
|
228
|
+
}
|
|
229
|
+
if (result.outcome === "ambiguous") {
|
|
230
|
+
throw resourceNotFound(`"${namespace}.${symbol}" matches several symbols:\n${formatCandidates(result.candidates)}`);
|
|
231
|
+
}
|
|
232
|
+
throw resourceNotFound(`No symbol named "${namespace}.${symbol}"`);
|
|
233
|
+
};
|
|
234
|
+
const registerIndexResource = (server, provider) => {
|
|
235
|
+
server.registerResource("gtkx-api-reference", "gtkx://reference/index", {
|
|
236
|
+
title: "GTKX API reference index",
|
|
237
|
+
description: "Namespaces of the project's generated GTK4 bindings, with symbol and JSX element counts.",
|
|
238
|
+
mimeType: "text/markdown",
|
|
239
|
+
}, async (uri) => {
|
|
240
|
+
const reference = await provider.get();
|
|
241
|
+
return markdownResource(uri, reference.overview());
|
|
242
|
+
});
|
|
243
|
+
};
|
|
244
|
+
const registerNamespaceResource = (server, provider) => {
|
|
245
|
+
server.registerResource("gtkx-api-namespace", new ResourceTemplate("gtkx://reference/{namespace}", {
|
|
246
|
+
list: () => withLoadFallback(async () => {
|
|
247
|
+
const reference = await provider.get();
|
|
248
|
+
return {
|
|
249
|
+
resources: reference.namespaces().map((summary) => ({
|
|
250
|
+
uri: `gtkx://reference/${summary.name}`,
|
|
251
|
+
name: `${summary.name} namespace reference`,
|
|
252
|
+
mimeType: "text/markdown",
|
|
253
|
+
})),
|
|
254
|
+
};
|
|
255
|
+
}, { resources: [] }),
|
|
256
|
+
complete: {
|
|
257
|
+
namespace: namespaceCompleter(provider),
|
|
258
|
+
},
|
|
259
|
+
}), {
|
|
260
|
+
title: "GTKX namespace reference",
|
|
261
|
+
description: "All symbols of one namespace of the project's generated GTK4 bindings, grouped by kind.",
|
|
262
|
+
mimeType: "text/markdown",
|
|
263
|
+
}, async (uri, variables) => {
|
|
264
|
+
const namespace = variableValue(variables.namespace);
|
|
265
|
+
const reference = await provider.get();
|
|
266
|
+
const overview = reference.namespaceOverview(namespace);
|
|
267
|
+
if (overview === undefined) {
|
|
268
|
+
throw resourceNotFound(`Unknown namespace "${namespace}"`);
|
|
269
|
+
}
|
|
270
|
+
return markdownResource(uri, overview);
|
|
271
|
+
});
|
|
272
|
+
};
|
|
273
|
+
const registerSymbolResource = (server, provider) => {
|
|
274
|
+
server.registerResource("gtkx-api-symbol", new ResourceTemplate("gtkx://reference/{namespace}/{symbol}", {
|
|
275
|
+
list: undefined,
|
|
276
|
+
complete: {
|
|
277
|
+
namespace: namespaceCompleter(provider),
|
|
278
|
+
symbol: (value, context) => completeSymbol(provider, variableValue(context?.arguments?.namespace), value),
|
|
279
|
+
},
|
|
280
|
+
}), {
|
|
281
|
+
title: "GTKX symbol reference",
|
|
282
|
+
description: "Reference page for one symbol of the project's generated GTK4 bindings: a JSX element or a " +
|
|
283
|
+
"class, interface, record, enum, callback, alias, function, or constant.",
|
|
284
|
+
mimeType: "text/markdown",
|
|
285
|
+
}, (uri, variables) => symbolPage(uri, provider, variableValue(variables.namespace), variableValue(variables.symbol)));
|
|
286
|
+
};
|
|
287
|
+
const registerReferenceResources = (server, provider) => {
|
|
288
|
+
registerIndexResource(server, provider);
|
|
289
|
+
registerNamespaceResource(server, provider);
|
|
290
|
+
registerSymbolResource(server, provider);
|
|
291
|
+
};
|
|
292
|
+
export { createReferenceProvider, buildReferenceTools, registerReferenceResources, };
|
|
293
|
+
//# sourceMappingURL=reference.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reference.js","sourceRoot":"","sources":["../src/reference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqC,gBAAgB,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtH,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAkB,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAC3F,OAAO,EAAE,SAAS,EAAE,QAAQ,EAA2B,MAA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B,EACvB,mBAAmB,EACnB,0BAA0B,GAG7B,CAAC","sourcesContent":["import { type ApiReference, type ApiSymbol, loadApiReference, resolveGirPath, resolveLibraries } from \"@gtkx/codegen\";\nimport { loadConfig } from \"@gtkx/config\";\nimport { type McpServer, ResourceTemplate } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { ErrorCode, McpError, type ReadResourceResult } from \"@modelcontextprotocol/sdk/types.js\";\nimport { statSync } from \"node:fs\";\nimport { resolve } from \"node:path\";\nimport { z } from \"zod\";\nimport { defineTool, textContent, textError, type Tool, type ToolArgs } from \"./tool.js\";\n\ntype ReferenceApi = Pick<\n ApiReference,\n \"lookup\" | \"namespaceOverview\" | \"namespaces\" | \"overview\" | \"search\" | \"symbolNames\"\n>;\n\ntype ReferenceProvider = {\n get(): Promise<ReferenceApi>;\n};\n\ntype WatchedFile = {\n path: string;\n mtimeMs: number;\n size: number;\n};\n\ntype LoadedReference = {\n reference: ApiReference;\n watched: WatchedFile[];\n};\n\ntype CacheEntry = {\n pending: Promise<LoadedReference>;\n verifiedAt: number;\n failedAt: number | undefined;\n};\n\ntype ReferenceCache = Map<string, CacheEntry>;\ntype SearchOptions = Parameters<ReferenceApi[\"search\"]>[0];\ntype ResourceServer = Pick<McpServer, \"registerResource\">;\n\nconst FRESHNESS_INTERVAL_MS = 2000;\nconst FAILURE_RETRY_MS = 5000;\n\nconst SYMBOL_KIND = z.enum([\n \"element\",\n \"class\",\n \"interface\",\n \"record\",\n \"enum\",\n \"callback\",\n \"alias\",\n \"function\",\n \"constant\",\n]);\n\nconst SYMBOL_DESCRIPTION =\n \"Qualified symbol name (`Gtk.Button`, `Gtk.Orientation`, `GLib.idleAdd`), JSX element name (`GtkButton`), \" +\n \"or bare symbol name when unambiguous (`Button`).\";\n\nconst listApiShape = {\n namespace: z\n .string()\n .optional()\n .describe(\"Namespace to list (e.g. `Gtk`, `Adw`, `Gio`). Omit for an overview of all namespaces.\"),\n};\n\nconst searchApiShape = {\n query: z.string().describe(\"Case-insensitive substring of a symbol name, e.g. `headerbar` or `orientation`.\"),\n namespace: z.string().optional().describe(\"Restrict matches to one namespace (e.g. `Gtk`).\"),\n kind: SYMBOL_KIND.optional().describe(\"Restrict matches to one symbol kind.\"),\n limit: z.number().int().min(1).optional().describe(\"Maximum number of results (default: 20).\"),\n};\n\nconst apiDocsShape = {\n symbol: z.string().describe(SYMBOL_DESCRIPTION),\n kind: SYMBOL_KIND.optional().describe(\"Disambiguate when several kinds share the symbol name.\"),\n};\n\nconst watchFile = (path: string): WatchedFile => {\n try {\n const stats = statSync(path);\n\n return { path, mtimeMs: stats.mtimeMs, size: stats.size };\n } catch {\n return { path, mtimeMs: -1, size: -1 };\n }\n};\n\nconst isFresh = (loaded: LoadedReference): boolean =>\n loaded.watched.every((file) => {\n const current = watchFile(file.path);\n\n return current.mtimeMs === file.mtimeMs && current.size === file.size;\n });\n\nconst loadReference = async (root: string): Promise<LoadedReference> => {\n const { config, configFile } = await loadConfig(root);\n\n if (config.codegen === false) {\n throw new Error(\n `codegen is disabled for the project at ${root}, so there are no generated bindings to document. ` +\n \"Remove `codegen: false` from gtkx.config.ts to use the API reference.\",\n );\n }\n\n const girPath = resolveGirPath(config.girPath);\n\n if (girPath.length === 0) {\n throw new Error(\n \"No GIR search paths available. Install gobject-introspection \" +\n \"(Linux: `sudo dnf install gobject-introspection-devel` or `sudo apt install libgirepository1.0-dev`), \" +\n \"or set `girPath` in gtkx.config.ts.\",\n );\n }\n\n const libraries = resolveLibraries(config.libraries, girPath);\n const reference = loadApiReference({ libraries, girPath });\n\n const watched = [\n ...(configFile === undefined ? [] : [watchFile(resolve(root, configFile))]),\n ...reference.girFiles.map((file) => watchFile(file)),\n ];\n\n return { reference, watched };\n};\n\nconst markFailed = async (entry: CacheEntry): Promise<void> => {\n try {\n await entry.pending;\n } catch {\n entry.failedAt = Date.now();\n }\n};\n\nconst startLoad = (cache: ReferenceCache, root: string): CacheEntry => {\n const entry: CacheEntry = { pending: loadReference(root), verifiedAt: Date.now(), failedAt: undefined };\n void markFailed(entry);\n cache.set(root, entry);\n\n return entry;\n};\n\nconst isRetryDue = (entry: CacheEntry): boolean =>\n entry.failedAt !== undefined && Date.now() - entry.failedAt >= FAILURE_RETRY_MS;\n\nconst resolveEntry = (cache: ReferenceCache, root: string): CacheEntry => {\n const entry = cache.get(root) ?? startLoad(cache, root);\n\n return isRetryDue(entry) ? startLoad(cache, root) : entry;\n};\n\nconst revalidate = (cache: ReferenceCache, root: string, entry: CacheEntry): CacheEntry => {\n const current = cache.get(root);\n\n return current === undefined || current === entry ? startLoad(cache, root) : current;\n};\n\nconst currentReference = async (cache: ReferenceCache, root: string): Promise<ReferenceApi> => {\n const entry = resolveEntry(cache, root);\n const loaded = await entry.pending;\n\n if (Date.now() - entry.verifiedAt < FRESHNESS_INTERVAL_MS) {\n return loaded.reference;\n }\n\n if (isFresh(loaded)) {\n entry.verifiedAt = Date.now();\n\n return loaded.reference;\n }\n\n const revalidated = await revalidate(cache, root, entry).pending;\n\n return revalidated.reference;\n};\n\nconst createReferenceProvider = (resolveRoot: () => string): ReferenceProvider => {\n const cache: ReferenceCache = new Map();\n\n return {\n get: () => currentReference(cache, resolve(resolveRoot())),\n };\n};\n\nconst formatCandidates = (candidates: ApiSymbol[]): string =>\n candidates.map((candidate) => `- ${candidate.namespace}.${candidate.name} (${candidate.kind})`).join(\"\\n\");\n\nconst buildSearchOptions = (args: ToolArgs<typeof searchApiShape>): SearchOptions => {\n const options: SearchOptions = { query: args.query };\n\n if (args.namespace !== undefined) {\n options.namespace = args.namespace;\n }\n\n if (args.kind !== undefined) {\n options.kinds = [args.kind];\n }\n\n if (args.limit !== undefined) {\n options.limit = args.limit;\n }\n\n return options;\n};\n\nconst listApiTool = (provider: ReferenceProvider): Tool =>\n defineTool({\n name: \"gtkx_list_api\",\n title: \"List API reference\",\n kind: \"readOnly\",\n description:\n \"List the project's generated GTK4 bindings API (`@gtkx/gi` and `@gtkx/jsx`). Without a namespace, \" +\n \"returns every namespace with symbol counts; with a namespace, lists all of its symbols grouped by kind.\",\n inputSchema: listApiShape,\n handler: async ({ namespace }) => {\n const reference = await provider.get();\n\n if (namespace === undefined) {\n return textContent(reference.overview());\n }\n\n const overview = reference.namespaceOverview(namespace);\n\n if (overview === undefined) {\n const names = reference\n .namespaces()\n .map((summary) => summary.name)\n .join(\", \");\n\n return textError(`Unknown namespace \"${namespace}\". Available namespaces: ${names}`);\n }\n\n return textContent(overview);\n },\n });\n\nconst searchApiTool = (provider: ReferenceProvider): Tool =>\n defineTool({\n name: \"gtkx_search_api\",\n title: \"Search API reference\",\n kind: \"readOnly\",\n description:\n \"Search the project's generated GTK4 bindings API by symbol name. Returns matching symbols with \" +\n \"their namespace, kind, and a one-line summary; fetch full pages with `gtkx_get_api_docs`.\",\n inputSchema: searchApiShape,\n handler: async (args) => {\n const reference = await provider.get();\n const results = reference.search(buildSearchOptions(args));\n\n if (results.length === 0) {\n return textContent(`No symbols matched \"${args.query}\". Try a shorter substring or \\`gtkx_list_api\\`.`);\n }\n\n return textContent(JSON.stringify(results, null, 2));\n },\n });\n\nconst getApiDocsTool = (provider: ReferenceProvider): Tool =>\n defineTool({\n name: \"gtkx_get_api_docs\",\n title: \"Get API docs\",\n kind: \"readOnly\",\n description:\n \"Get the full reference page for one symbol of the project's generated GTK4 bindings: JSX elements \" +\n \"(props, signals, methods) or `@gtkx/gi` classes, interfaces, records, enums, callbacks, aliases, \" +\n \"functions, and constants.\",\n inputSchema: apiDocsShape,\n handler: async ({ symbol, kind }) => {\n const reference = await provider.get();\n const result = reference.lookup(symbol, kind);\n\n if (result.outcome === \"notFound\") {\n return textError(`No symbol named \"${symbol}\". Use \\`gtkx_search_api\\` to find the right name.`);\n }\n\n if (result.outcome === \"ambiguous\") {\n return textError(\n `\"${symbol}\" matches several symbols. Pass a qualified name or a kind:\\n` +\n formatCandidates(result.candidates),\n );\n }\n\n return textContent(result.markdown);\n },\n });\n\nconst buildReferenceTools = (provider: ReferenceProvider): Tool[] => [\n listApiTool(provider),\n searchApiTool(provider),\n getApiDocsTool(provider),\n];\n\nconst markdownResource = (uri: URL, text: string): ReadResourceResult => ({\n contents: [{ uri: uri.href, mimeType: \"text/markdown\", text }],\n});\n\nconst variableValue = (value: string | string[] | undefined): string =>\n Array.isArray(value) ? (value[0] ?? \"\") : (value ?? \"\");\n\nconst withLoadFallback = async <T>(load: () => Promise<T>, fallback: T): Promise<T> => {\n try {\n return await load();\n } catch {\n return fallback;\n }\n};\n\nconst namespaceCompleter =\n (provider: ReferenceProvider) =>\n (value: string): Promise<string[]> =>\n withLoadFallback(async () => {\n const reference = await provider.get();\n\n return reference\n .namespaces()\n .map((summary) => summary.name)\n .filter((name) => name.toLowerCase().startsWith(value.toLowerCase()));\n }, []);\n\nconst completeSymbol = async (provider: ReferenceProvider, namespace: string, value: string): Promise<string[]> => {\n if (namespace.length === 0) {\n return [];\n }\n\n return withLoadFallback(async () => {\n const reference = await provider.get();\n\n return reference.symbolNames(namespace).filter((name) => name.toLowerCase().startsWith(value.toLowerCase()));\n }, []);\n};\n\nconst resourceNotFound = (message: string): McpError => new McpError(ErrorCode.InvalidParams, message);\n\nconst symbolPage = async (\n uri: URL,\n provider: ReferenceProvider,\n namespace: string,\n symbol: string,\n): Promise<ReadResourceResult> => {\n const reference = await provider.get();\n const result = reference.lookup(`${namespace}.${symbol}`);\n\n if (result.outcome === \"page\") {\n return markdownResource(uri, result.markdown);\n }\n\n if (result.outcome === \"ambiguous\") {\n throw resourceNotFound(\n `\"${namespace}.${symbol}\" matches several symbols:\\n${formatCandidates(result.candidates)}`,\n );\n }\n\n throw resourceNotFound(`No symbol named \"${namespace}.${symbol}\"`);\n};\n\nconst registerIndexResource = (server: ResourceServer, provider: ReferenceProvider): void => {\n server.registerResource(\n \"gtkx-api-reference\",\n \"gtkx://reference/index\",\n {\n title: \"GTKX API reference index\",\n description: \"Namespaces of the project's generated GTK4 bindings, with symbol and JSX element counts.\",\n mimeType: \"text/markdown\",\n },\n async (uri) => {\n const reference = await provider.get();\n\n return markdownResource(uri, reference.overview());\n },\n );\n};\n\nconst registerNamespaceResource = (server: ResourceServer, provider: ReferenceProvider): void => {\n server.registerResource(\n \"gtkx-api-namespace\",\n new ResourceTemplate(\"gtkx://reference/{namespace}\", {\n list: () =>\n withLoadFallback(\n async () => {\n const reference = await provider.get();\n\n return {\n resources: reference.namespaces().map((summary) => ({\n uri: `gtkx://reference/${summary.name}`,\n name: `${summary.name} namespace reference`,\n mimeType: \"text/markdown\",\n })),\n };\n },\n { resources: [] },\n ),\n complete: {\n namespace: namespaceCompleter(provider),\n },\n }),\n {\n title: \"GTKX namespace reference\",\n description: \"All symbols of one namespace of the project's generated GTK4 bindings, grouped by kind.\",\n mimeType: \"text/markdown\",\n },\n async (uri, variables) => {\n const namespace = variableValue(variables.namespace);\n const reference = await provider.get();\n const overview = reference.namespaceOverview(namespace);\n\n if (overview === undefined) {\n throw resourceNotFound(`Unknown namespace \"${namespace}\"`);\n }\n\n return markdownResource(uri, overview);\n },\n );\n};\n\nconst registerSymbolResource = (server: ResourceServer, provider: ReferenceProvider): void => {\n server.registerResource(\n \"gtkx-api-symbol\",\n new ResourceTemplate(\"gtkx://reference/{namespace}/{symbol}\", {\n list: undefined,\n complete: {\n namespace: namespaceCompleter(provider),\n symbol: (value, context) =>\n completeSymbol(provider, variableValue(context?.arguments?.namespace), value),\n },\n }),\n {\n title: \"GTKX symbol reference\",\n description:\n \"Reference page for one symbol of the project's generated GTK4 bindings: a JSX element or a \" +\n \"class, interface, record, enum, callback, alias, function, or constant.\",\n mimeType: \"text/markdown\",\n },\n (uri, variables) =>\n symbolPage(uri, provider, variableValue(variables.namespace), variableValue(variables.symbol)),\n );\n};\n\nconst registerReferenceResources = (server: ResourceServer, provider: ReferenceProvider): void => {\n registerIndexResource(server, provider);\n registerNamespaceResource(server, provider);\n registerSymbolResource(server, provider);\n};\n\nexport {\n createReferenceProvider,\n buildReferenceTools,\n registerReferenceResources,\n type ReferenceApi,\n type ReferenceProvider,\n};\n"]}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type Logger } from "@gtkx/utils";
|
|
2
|
+
type CreateMcpServerOptions = {
|
|
3
|
+
socketPath?: string;
|
|
4
|
+
version: string;
|
|
5
|
+
};
|
|
6
|
+
type McpServerHandle = {
|
|
7
|
+
start(): Promise<void>;
|
|
8
|
+
stop(): Promise<void>;
|
|
9
|
+
};
|
|
10
|
+
declare const log: Logger;
|
|
11
|
+
declare const createMcpServer: (options: CreateMcpServerOptions) => McpServerHandle;
|
|
12
|
+
declare function main(): Promise<void>;
|
|
13
|
+
export { log, createMcpServer, main };
|
|
14
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyC,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AAsBjF,KAAK,sBAAsB,GAAG;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,KAAK,eAAe,GAAG;IACnB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACzB,CAAC;AAOF,QAAA,MAAM,GAAG,EAAE,MAA4B,CAAC;AA8OxC,QAAA,MAAM,eAAe,GAAI,SAAS,sBAAsB,KAAG,eA8C1D,CAAC;AAEF,iBAAe,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAQnC;AAED,OAAO,EAAE,GAAG,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC"}
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { createLogger, installGracefulShutdown } from "@gtkx/utils";
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
import { AppRouter } from "./app-router.js";
|
|
7
|
+
import { ConnectionRegistry } from "./connection-registry.js";
|
|
8
|
+
import { DEFAULT_SOCKET_PATH, fireEventParams, queryParams, screenshotParams, treeParams, typeParams, widgetIdParams, } from "./protocol/schemas.js";
|
|
9
|
+
import { buildReferenceTools, createReferenceProvider, registerReferenceResources } from "./reference.js";
|
|
10
|
+
import { SocketServer } from "./socket-server.js";
|
|
11
|
+
import { defineTool, imageContent, registerTool, textContent } from "./tool.js";
|
|
12
|
+
const require = createRequire(import.meta.url);
|
|
13
|
+
const { version } = require("../package.json");
|
|
14
|
+
const log = createLogger("mcp");
|
|
15
|
+
const APPLICATION_ID_DESCRIPTION = "Application ID to query. If not specified, uses the first connected app.";
|
|
16
|
+
const WIDGET_ID_DESCRIPTION = "Widget ID obtained from `gtkx_get_widget_tree`, `gtkx_query_widgets`, or `gtkx_get_widget_props`. " +
|
|
17
|
+
"IDs are scoped to a single app. An ID stays valid for as long as its widget is mounted and stops " +
|
|
18
|
+
"resolving once the widget is unmounted.";
|
|
19
|
+
const applicationIdShape = { applicationId: z.string().optional().describe(APPLICATION_ID_DESCRIPTION) };
|
|
20
|
+
const widgetIdShape = {
|
|
21
|
+
...applicationIdShape,
|
|
22
|
+
widgetId: widgetIdParams.shape.widgetId.describe(WIDGET_ID_DESCRIPTION),
|
|
23
|
+
};
|
|
24
|
+
const treeShape = {
|
|
25
|
+
...applicationIdShape,
|
|
26
|
+
rootId: treeParams.shape.rootId.describe("Render only the subtree rooted at this widget ID (from a prior tree or query). Omit for the whole app."),
|
|
27
|
+
maxDepth: treeParams.shape.maxDepth.describe("Limit how many levels deep to render; deeper descendants are summarized with a count. " +
|
|
28
|
+
"Combine with rootId to drill in without dumping the whole tree."),
|
|
29
|
+
};
|
|
30
|
+
const listAppsShape = {
|
|
31
|
+
waitForApps: z
|
|
32
|
+
.boolean()
|
|
33
|
+
.optional()
|
|
34
|
+
.describe("If true, wait for at least one app to register before returning. Useful when app is still starting."),
|
|
35
|
+
timeout: z.number().optional().describe("Timeout in milliseconds when waitForApps is true (default: 10000)"),
|
|
36
|
+
};
|
|
37
|
+
const queryWidgetsShape = {
|
|
38
|
+
...applicationIdShape,
|
|
39
|
+
by: queryParams.shape.by.describe("Query type"),
|
|
40
|
+
value: queryParams.shape.value.describe("Value to search for"),
|
|
41
|
+
options: queryParams.shape.options.describe("Additional query options"),
|
|
42
|
+
};
|
|
43
|
+
const typeShape = {
|
|
44
|
+
...widgetIdShape,
|
|
45
|
+
text: typeParams.shape.text.describe("Text to type"),
|
|
46
|
+
clear: typeParams.shape.clear.describe("Clear existing text before typing"),
|
|
47
|
+
};
|
|
48
|
+
const fireEventShape = {
|
|
49
|
+
...widgetIdShape,
|
|
50
|
+
signal: fireEventParams.shape.signal.describe("GTK4 signal name to emit"),
|
|
51
|
+
args: fireEventParams.shape.args.describe("Arguments to pass to the signal"),
|
|
52
|
+
};
|
|
53
|
+
const screenshotShape = {
|
|
54
|
+
...applicationIdShape,
|
|
55
|
+
windowId: screenshotParams.shape.windowId.describe("Window ID to capture. If not specified, captures the first window."),
|
|
56
|
+
path: screenshotParams.shape.path.describe("Absolute path to write the PNG to on the app's machine. If set, the screenshot is saved there " +
|
|
57
|
+
"in addition to being returned."),
|
|
58
|
+
};
|
|
59
|
+
const logSocketError = (event) => {
|
|
60
|
+
const error = event.detail;
|
|
61
|
+
const code = error.code;
|
|
62
|
+
if (code === "EPIPE" || code === "ECONNRESET") {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
log.error(`socket error: ${error.message}`);
|
|
66
|
+
};
|
|
67
|
+
const appWithWindows = async (appRouter, app) => {
|
|
68
|
+
try {
|
|
69
|
+
const result = await appRouter.sendToApp(app.applicationId, "app.getWindows", {});
|
|
70
|
+
return { ...app, windows: result.windows };
|
|
71
|
+
}
|
|
72
|
+
catch {
|
|
73
|
+
return app;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const listAppsTool = (appRouter) => defineTool({
|
|
77
|
+
name: "gtkx_list_apps",
|
|
78
|
+
title: "List apps",
|
|
79
|
+
kind: "readOnly",
|
|
80
|
+
description: "List all connected GTKX applications and their open windows.",
|
|
81
|
+
inputSchema: listAppsShape,
|
|
82
|
+
handler: async ({ waitForApps, timeout }) => {
|
|
83
|
+
if (waitForApps && !appRouter.hasConnectedApps()) {
|
|
84
|
+
await appRouter.waitForApp(timeout);
|
|
85
|
+
}
|
|
86
|
+
const apps = appRouter.getApps();
|
|
87
|
+
const appsWithWindows = await Promise.all(apps.map((app) => appWithWindows(appRouter, app)));
|
|
88
|
+
return textContent(JSON.stringify(appsWithWindows, null, 2));
|
|
89
|
+
},
|
|
90
|
+
});
|
|
91
|
+
const screenshotTool = (appRouter) => defineTool({
|
|
92
|
+
name: "gtkx_take_screenshot",
|
|
93
|
+
title: "Take screenshot",
|
|
94
|
+
kind: "readOnly",
|
|
95
|
+
description: "Capture a screenshot of a window. Returns base64-encoded PNG image data, and optionally writes " +
|
|
96
|
+
"the PNG to `path` on the app's machine. You can't target widgets from a screenshot; use " +
|
|
97
|
+
"`gtkx_get_widget_tree` to find widget IDs for interaction.",
|
|
98
|
+
inputSchema: screenshotShape,
|
|
99
|
+
handler: async ({ applicationId, ...params }) => {
|
|
100
|
+
const result = await appRouter.sendToApp(applicationId, "widget.screenshot", params);
|
|
101
|
+
if (result.savedPath) {
|
|
102
|
+
return {
|
|
103
|
+
content: [
|
|
104
|
+
{ type: "text", text: `Screenshot saved to ${result.savedPath}` },
|
|
105
|
+
{ type: "image", data: result.data, mimeType: result.mimeType },
|
|
106
|
+
],
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
return imageContent(result.data, result.mimeType);
|
|
110
|
+
},
|
|
111
|
+
});
|
|
112
|
+
function buildInspectionTools(appRouter) {
|
|
113
|
+
return [
|
|
114
|
+
listAppsTool(appRouter),
|
|
115
|
+
defineTool({
|
|
116
|
+
name: "gtkx_get_widget_tree",
|
|
117
|
+
title: "Widget tree",
|
|
118
|
+
kind: "readOnly",
|
|
119
|
+
description: "Get the widget hierarchy for a connected GTKX app. Returns a tree of widgets with their IDs, " +
|
|
120
|
+
"types, roles, and properties. For large apps, pass `maxDepth` for a shallow overview and/or " +
|
|
121
|
+
"`rootId` to render just one subtree instead of the whole (possibly truncated) tree.",
|
|
122
|
+
inputSchema: treeShape,
|
|
123
|
+
handler: async ({ applicationId, rootId, maxDepth }) => {
|
|
124
|
+
const result = await appRouter.sendToApp(applicationId, "widget.getTree", {
|
|
125
|
+
rootId,
|
|
126
|
+
maxDepth,
|
|
127
|
+
});
|
|
128
|
+
return textContent(result.tree);
|
|
129
|
+
},
|
|
130
|
+
}),
|
|
131
|
+
defineTool({
|
|
132
|
+
name: "gtkx_query_widgets",
|
|
133
|
+
title: "Query widgets",
|
|
134
|
+
kind: "readOnly",
|
|
135
|
+
description: "Find widgets by role, text, name, or label. Returns matching widgets with their IDs and properties.",
|
|
136
|
+
inputSchema: queryWidgetsShape,
|
|
137
|
+
handler: async ({ applicationId, ...params }) => {
|
|
138
|
+
const result = await appRouter.sendToApp(applicationId, "widget.query", params);
|
|
139
|
+
return textContent(JSON.stringify(result, null, 2));
|
|
140
|
+
},
|
|
141
|
+
}),
|
|
142
|
+
defineTool({
|
|
143
|
+
name: "gtkx_get_widget_props",
|
|
144
|
+
title: "Get widget properties",
|
|
145
|
+
kind: "readOnly",
|
|
146
|
+
description: "Get a fixed summary of one widget by ID: type, accessible role, name, text, sensitivity, " +
|
|
147
|
+
"visibility, CSS classes, and the full subtree of descendant widgets. It does not return " +
|
|
148
|
+
"arbitrary GObject properties.",
|
|
149
|
+
inputSchema: widgetIdShape,
|
|
150
|
+
handler: async ({ applicationId, ...params }) => {
|
|
151
|
+
const result = await appRouter.sendToApp(applicationId, "widget.getProps", params);
|
|
152
|
+
return textContent(JSON.stringify(result, null, 2));
|
|
153
|
+
},
|
|
154
|
+
}),
|
|
155
|
+
screenshotTool(appRouter),
|
|
156
|
+
];
|
|
157
|
+
}
|
|
158
|
+
function buildInteractionTools(appRouter) {
|
|
159
|
+
return [
|
|
160
|
+
defineTool({
|
|
161
|
+
name: "gtkx_click",
|
|
162
|
+
title: "Click widget",
|
|
163
|
+
kind: "action",
|
|
164
|
+
description: "Click a widget. Works with buttons, checkboxes, and other interactive widgets.",
|
|
165
|
+
inputSchema: widgetIdShape,
|
|
166
|
+
handler: async ({ applicationId, ...params }) => {
|
|
167
|
+
await appRouter.sendToApp(applicationId, "widget.click", params);
|
|
168
|
+
return textContent("Clicked");
|
|
169
|
+
},
|
|
170
|
+
}),
|
|
171
|
+
defineTool({
|
|
172
|
+
name: "gtkx_type",
|
|
173
|
+
title: "Type text",
|
|
174
|
+
kind: "action",
|
|
175
|
+
description: "Type text into an editable widget like Entry or TextView",
|
|
176
|
+
inputSchema: typeShape,
|
|
177
|
+
handler: async ({ applicationId, ...params }) => {
|
|
178
|
+
await appRouter.sendToApp(applicationId, "widget.type", params);
|
|
179
|
+
return textContent("Typed text");
|
|
180
|
+
},
|
|
181
|
+
}),
|
|
182
|
+
defineTool({
|
|
183
|
+
name: "gtkx_fire_event",
|
|
184
|
+
title: "Fire event",
|
|
185
|
+
kind: "action",
|
|
186
|
+
description: "Emit a GTK4 signal on a widget. Use this for custom interactions.",
|
|
187
|
+
inputSchema: fireEventShape,
|
|
188
|
+
handler: async ({ applicationId, ...params }) => {
|
|
189
|
+
await appRouter.sendToApp(applicationId, "widget.fireEvent", params);
|
|
190
|
+
return textContent("Fired event");
|
|
191
|
+
},
|
|
192
|
+
}),
|
|
193
|
+
];
|
|
194
|
+
}
|
|
195
|
+
function buildTools(appRouter) {
|
|
196
|
+
return [...buildInspectionTools(appRouter), ...buildInteractionTools(appRouter)];
|
|
197
|
+
}
|
|
198
|
+
const createMcpServer = (options) => {
|
|
199
|
+
const socketPath = options.socketPath ?? DEFAULT_SOCKET_PATH;
|
|
200
|
+
const registry = new ConnectionRegistry();
|
|
201
|
+
const socketServer = new SocketServer(registry, socketPath);
|
|
202
|
+
const appRouter = new AppRouter(registry);
|
|
203
|
+
registry.addEventListener("error", logSocketError);
|
|
204
|
+
appRouter.addEventListener("appRegistered", (event) => {
|
|
205
|
+
const appInfo = event.detail;
|
|
206
|
+
log.info(`app registered: ${appInfo.applicationId} (PID: ${String(appInfo.pid)})`);
|
|
207
|
+
});
|
|
208
|
+
appRouter.addEventListener("appUnregistered", (event) => {
|
|
209
|
+
log.info(`app unregistered: ${event.detail}`);
|
|
210
|
+
});
|
|
211
|
+
const mcpServer = new McpServer({ name: "gtkx-mcp", version: options.version });
|
|
212
|
+
const referenceProvider = createReferenceProvider(() => appRouter.getProjectRoot() ?? process.cwd());
|
|
213
|
+
for (const tool of [...buildTools(appRouter), ...buildReferenceTools(referenceProvider)]) {
|
|
214
|
+
registerTool(mcpServer, tool);
|
|
215
|
+
}
|
|
216
|
+
registerReferenceResources(mcpServer, referenceProvider);
|
|
217
|
+
let isStopped = false;
|
|
218
|
+
const stop = async () => {
|
|
219
|
+
if (isStopped) {
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
isStopped = true;
|
|
223
|
+
await socketServer.stop();
|
|
224
|
+
await mcpServer.close();
|
|
225
|
+
};
|
|
226
|
+
const start = async () => {
|
|
227
|
+
await socketServer.start();
|
|
228
|
+
log.info(`socket server listening on ${socketPath}`);
|
|
229
|
+
const transport = new StdioServerTransport();
|
|
230
|
+
process.stdin.on("end", () => void stop());
|
|
231
|
+
process.stdin.on("close", () => void stop());
|
|
232
|
+
await mcpServer.connect(transport);
|
|
233
|
+
};
|
|
234
|
+
return { start, stop };
|
|
235
|
+
};
|
|
236
|
+
async function main() {
|
|
237
|
+
const server = createMcpServer({ version });
|
|
238
|
+
installGracefulShutdown({
|
|
239
|
+
onSignal: () => server.stop(),
|
|
240
|
+
});
|
|
241
|
+
await server.start();
|
|
242
|
+
}
|
|
243
|
+
export { log, createMcpServer, main };
|
|
244
|
+
//# sourceMappingURL=server.js.map
|