@gtkx/mcp 0.11.1
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/LICENSE +373 -0
- package/bin/gtkx-mcp.js +2 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +370 -0
- package/dist/connection-manager.d.ts +33 -0
- package/dist/connection-manager.js +145 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/protocol/errors.d.ts +30 -0
- package/dist/protocol/errors.js +53 -0
- package/dist/protocol/types.d.ts +71 -0
- package/dist/protocol/types.js +11 -0
- package/dist/socket-server.d.ts +31 -0
- package/dist/socket-server.js +125 -0
- package/package.json +51 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
Mozilla Public License Version 2.0
|
|
2
|
+
==================================
|
|
3
|
+
|
|
4
|
+
1. Definitions
|
|
5
|
+
--------------
|
|
6
|
+
|
|
7
|
+
1.1. "Contributor"
|
|
8
|
+
means each individual or legal entity that creates, contributes to
|
|
9
|
+
the creation of, or owns Covered Software.
|
|
10
|
+
|
|
11
|
+
1.2. "Contributor Version"
|
|
12
|
+
means the combination of the Contributions of others (if any) used
|
|
13
|
+
by a Contributor and that particular Contributor's Contribution.
|
|
14
|
+
|
|
15
|
+
1.3. "Contribution"
|
|
16
|
+
means Covered Software of a particular Contributor.
|
|
17
|
+
|
|
18
|
+
1.4. "Covered Software"
|
|
19
|
+
means Source Code Form to which the initial Contributor has attached
|
|
20
|
+
the notice in Exhibit A, the Executable Form of such Source Code
|
|
21
|
+
Form, and Modifications of such Source Code Form, in each case
|
|
22
|
+
including portions thereof.
|
|
23
|
+
|
|
24
|
+
1.5. "Incompatible With Secondary Licenses"
|
|
25
|
+
means
|
|
26
|
+
|
|
27
|
+
(a) that the initial Contributor has attached the notice described
|
|
28
|
+
in Exhibit B to the Covered Software; or
|
|
29
|
+
|
|
30
|
+
(b) that the Covered Software was made available under the terms of
|
|
31
|
+
version 1.1 or earlier of the License, but not also under the
|
|
32
|
+
terms of a Secondary License.
|
|
33
|
+
|
|
34
|
+
1.6. "Executable Form"
|
|
35
|
+
means any form of the work other than Source Code Form.
|
|
36
|
+
|
|
37
|
+
1.7. "Larger Work"
|
|
38
|
+
means a work that combines Covered Software with other material, in
|
|
39
|
+
a separate file or files, that is not Covered Software.
|
|
40
|
+
|
|
41
|
+
1.8. "License"
|
|
42
|
+
means this document.
|
|
43
|
+
|
|
44
|
+
1.9. "Licensable"
|
|
45
|
+
means having the right to grant, to the maximum extent possible,
|
|
46
|
+
whether at the time of the initial grant or subsequently, any and
|
|
47
|
+
all of the rights conveyed by this License.
|
|
48
|
+
|
|
49
|
+
1.10. "Modifications"
|
|
50
|
+
means any of the following:
|
|
51
|
+
|
|
52
|
+
(a) any file in Source Code Form that results from an addition to,
|
|
53
|
+
deletion from, or modification of the contents of Covered
|
|
54
|
+
Software; or
|
|
55
|
+
|
|
56
|
+
(b) any new file in Source Code Form that contains any Covered
|
|
57
|
+
Software.
|
|
58
|
+
|
|
59
|
+
1.11. "Patent Claims" of a Contributor
|
|
60
|
+
means any patent claim(s), including without limitation, method,
|
|
61
|
+
process, and apparatus claims, in any patent Licensable by such
|
|
62
|
+
Contributor that would be infringed, but for the grant of the
|
|
63
|
+
License, by the making, using, selling, offering for sale, having
|
|
64
|
+
made, import, or transfer of either its Contributions or its
|
|
65
|
+
Contributor Version.
|
|
66
|
+
|
|
67
|
+
1.12. "Secondary License"
|
|
68
|
+
means either the GNU General Public License, Version 2.0, the GNU
|
|
69
|
+
Lesser General Public License, Version 2.1, the GNU Affero General
|
|
70
|
+
Public License, Version 3.0, or any later versions of those
|
|
71
|
+
licenses.
|
|
72
|
+
|
|
73
|
+
1.13. "Source Code Form"
|
|
74
|
+
means the form of the work preferred for making modifications.
|
|
75
|
+
|
|
76
|
+
1.14. "You" (or "Your")
|
|
77
|
+
means an individual or a legal entity exercising rights under this
|
|
78
|
+
License. For legal entities, "You" includes any entity that
|
|
79
|
+
controls, is controlled by, or is under common control with You. For
|
|
80
|
+
purposes of this definition, "control" means (a) the power, direct
|
|
81
|
+
or indirect, to cause the direction or management of such entity,
|
|
82
|
+
whether by contract or otherwise, or (b) ownership of more than
|
|
83
|
+
fifty percent (50%) of the outstanding shares or beneficial
|
|
84
|
+
ownership of such entity.
|
|
85
|
+
|
|
86
|
+
2. License Grants and Conditions
|
|
87
|
+
--------------------------------
|
|
88
|
+
|
|
89
|
+
2.1. Grants
|
|
90
|
+
|
|
91
|
+
Each Contributor hereby grants You a world-wide, royalty-free,
|
|
92
|
+
non-exclusive license:
|
|
93
|
+
|
|
94
|
+
(a) under intellectual property rights (other than patent or trademark)
|
|
95
|
+
Licensable by such Contributor to use, reproduce, make available,
|
|
96
|
+
modify, display, perform, distribute, and otherwise exploit its
|
|
97
|
+
Contributions, either on an unmodified basis, with Modifications, or
|
|
98
|
+
as part of a Larger Work; and
|
|
99
|
+
|
|
100
|
+
(b) under Patent Claims of such Contributor to make, use, sell, offer
|
|
101
|
+
for sale, have made, import, and otherwise transfer either its
|
|
102
|
+
Contributions or its Contributor Version.
|
|
103
|
+
|
|
104
|
+
2.2. Effective Date
|
|
105
|
+
|
|
106
|
+
The licenses granted in Section 2.1 with respect to any Contribution
|
|
107
|
+
become effective for each Contribution on the date the Contributor first
|
|
108
|
+
distributes such Contribution.
|
|
109
|
+
|
|
110
|
+
2.3. Limitations on Grant Scope
|
|
111
|
+
|
|
112
|
+
The licenses granted in this Section 2 are the only rights granted under
|
|
113
|
+
this License. No additional rights or licenses will be implied from the
|
|
114
|
+
distribution or licensing of Covered Software under this License.
|
|
115
|
+
Notwithstanding Section 2.1(b) above, no patent license is granted by a
|
|
116
|
+
Contributor:
|
|
117
|
+
|
|
118
|
+
(a) for any code that a Contributor has removed from Covered Software;
|
|
119
|
+
or
|
|
120
|
+
|
|
121
|
+
(b) for infringements caused by: (i) Your and any other third party's
|
|
122
|
+
modifications of Covered Software, or (ii) the combination of its
|
|
123
|
+
Contributions with other software (except as part of its Contributor
|
|
124
|
+
Version); or
|
|
125
|
+
|
|
126
|
+
(c) under Patent Claims infringed by Covered Software in the absence of
|
|
127
|
+
its Contributions.
|
|
128
|
+
|
|
129
|
+
This License does not grant any rights in the trademarks, service marks,
|
|
130
|
+
or logos of any Contributor (except as may be necessary to comply with
|
|
131
|
+
the notice requirements in Section 3.4).
|
|
132
|
+
|
|
133
|
+
2.4. Subsequent Licenses
|
|
134
|
+
|
|
135
|
+
No Contributor makes additional grants as a result of Your choice to
|
|
136
|
+
distribute the Covered Software under a subsequent version of this
|
|
137
|
+
License (see Section 10.2) or under the terms of a Secondary License (if
|
|
138
|
+
permitted under the terms of Section 3.3).
|
|
139
|
+
|
|
140
|
+
2.5. Representation
|
|
141
|
+
|
|
142
|
+
Each Contributor represents that the Contributor believes its
|
|
143
|
+
Contributions are its original creation(s) or it has sufficient rights
|
|
144
|
+
to grant the rights to its Contributions conveyed by this License.
|
|
145
|
+
|
|
146
|
+
2.6. Fair Use
|
|
147
|
+
|
|
148
|
+
This License is not intended to limit any rights You have under
|
|
149
|
+
applicable copyright doctrines of fair use, fair dealing, or other
|
|
150
|
+
equivalents.
|
|
151
|
+
|
|
152
|
+
2.7. Conditions
|
|
153
|
+
|
|
154
|
+
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
|
|
155
|
+
in Section 2.1.
|
|
156
|
+
|
|
157
|
+
3. Responsibilities
|
|
158
|
+
-------------------
|
|
159
|
+
|
|
160
|
+
3.1. Distribution of Source Form
|
|
161
|
+
|
|
162
|
+
All distribution of Covered Software in Source Code Form, including any
|
|
163
|
+
Modifications that You create or to which You contribute, must be under
|
|
164
|
+
the terms of this License. You must inform recipients that the Source
|
|
165
|
+
Code Form of the Covered Software is governed by the terms of this
|
|
166
|
+
License, and how they can obtain a copy of this License. You may not
|
|
167
|
+
attempt to alter or restrict the recipients' rights in the Source Code
|
|
168
|
+
Form.
|
|
169
|
+
|
|
170
|
+
3.2. Distribution of Executable Form
|
|
171
|
+
|
|
172
|
+
If You distribute Covered Software in Executable Form then:
|
|
173
|
+
|
|
174
|
+
(a) such Covered Software must also be made available in Source Code
|
|
175
|
+
Form, as described in Section 3.1, and You must inform recipients of
|
|
176
|
+
the Executable Form how they can obtain a copy of such Source Code
|
|
177
|
+
Form by reasonable means in a timely manner, at a charge no more
|
|
178
|
+
than the cost of distribution to the recipient; and
|
|
179
|
+
|
|
180
|
+
(b) You may distribute such Executable Form under the terms of this
|
|
181
|
+
License, or sublicense it under different terms, provided that the
|
|
182
|
+
license for the Executable Form does not attempt to limit or alter
|
|
183
|
+
the recipients' rights in the Source Code Form under this License.
|
|
184
|
+
|
|
185
|
+
3.3. Distribution of a Larger Work
|
|
186
|
+
|
|
187
|
+
You may create and distribute a Larger Work under terms of Your choice,
|
|
188
|
+
provided that You also comply with the requirements of this License for
|
|
189
|
+
the Covered Software. If the Larger Work is a combination of Covered
|
|
190
|
+
Software with a work governed by one or more Secondary Licenses, and the
|
|
191
|
+
Covered Software is not Incompatible With Secondary Licenses, this
|
|
192
|
+
License permits You to additionally distribute such Covered Software
|
|
193
|
+
under the terms of such Secondary License(s), so that the recipient of
|
|
194
|
+
the Larger Work may, at their option, further distribute the Covered
|
|
195
|
+
Software under the terms of either this License or such Secondary
|
|
196
|
+
License(s).
|
|
197
|
+
|
|
198
|
+
3.4. Notices
|
|
199
|
+
|
|
200
|
+
You may not remove or alter the substance of any license notices
|
|
201
|
+
(including copyright notices, patent notices, disclaimers of warranty,
|
|
202
|
+
or limitations of liability) contained within the Source Code Form of
|
|
203
|
+
the Covered Software, except that You may alter any license notices to
|
|
204
|
+
the extent required to remedy known factual inaccuracies.
|
|
205
|
+
|
|
206
|
+
3.5. Application of Additional Terms
|
|
207
|
+
|
|
208
|
+
You may choose to offer, and to charge a fee for, warranty, support,
|
|
209
|
+
indemnity or liability obligations to one or more recipients of Covered
|
|
210
|
+
Software. However, You may do so only on Your own behalf, and not on
|
|
211
|
+
behalf of any Contributor. You must make it absolutely clear that any
|
|
212
|
+
such warranty, support, indemnity, or liability obligation is offered by
|
|
213
|
+
You alone, and You hereby agree to indemnify every Contributor for any
|
|
214
|
+
liability incurred by such Contributor as a result of warranty, support,
|
|
215
|
+
indemnity or liability terms You offer. You may include additional
|
|
216
|
+
disclaimers of warranty and limitations of liability specific to any
|
|
217
|
+
jurisdiction.
|
|
218
|
+
|
|
219
|
+
4. Inability to Comply Due to Statute or Regulation
|
|
220
|
+
---------------------------------------------------
|
|
221
|
+
|
|
222
|
+
If it is impossible for You to comply with any of the terms of this
|
|
223
|
+
License with respect to some or all of the Covered Software due to
|
|
224
|
+
statute, judicial order, or regulation then You must: (a) comply with
|
|
225
|
+
the terms of this License to the maximum extent possible; and (b)
|
|
226
|
+
describe the limitations and the code they affect. Such description must
|
|
227
|
+
be placed in a text file included with all distributions of the Covered
|
|
228
|
+
Software under this License. Except to the extent prohibited by statute
|
|
229
|
+
or regulation, such description must be sufficiently detailed for a
|
|
230
|
+
recipient of ordinary skill to be able to understand it.
|
|
231
|
+
|
|
232
|
+
5. Termination
|
|
233
|
+
--------------
|
|
234
|
+
|
|
235
|
+
5.1. The rights granted under this License will terminate automatically
|
|
236
|
+
if You fail to comply with any of its terms. However, if You become
|
|
237
|
+
compliant, then the rights granted under this License from a particular
|
|
238
|
+
Contributor are reinstated (a) provisionally, unless and until such
|
|
239
|
+
Contributor explicitly and finally terminates Your grants, and (b) on an
|
|
240
|
+
ongoing basis, if such Contributor fails to notify You of the
|
|
241
|
+
non-compliance by some reasonable means prior to 60 days after You have
|
|
242
|
+
come back into compliance. Moreover, Your grants from a particular
|
|
243
|
+
Contributor are reinstated on an ongoing basis if such Contributor
|
|
244
|
+
notifies You of the non-compliance by some reasonable means, this is the
|
|
245
|
+
first time You have received notice of non-compliance with this License
|
|
246
|
+
from such Contributor, and You become compliant prior to 30 days after
|
|
247
|
+
Your receipt of the notice.
|
|
248
|
+
|
|
249
|
+
5.2. If You initiate litigation against any entity by asserting a patent
|
|
250
|
+
infringement claim (excluding declaratory judgment actions,
|
|
251
|
+
counter-claims, and cross-claims) alleging that a Contributor Version
|
|
252
|
+
directly or indirectly infringes any patent, then the rights granted to
|
|
253
|
+
You by any and all Contributors for the Covered Software under Section
|
|
254
|
+
2.1 of this License shall terminate.
|
|
255
|
+
|
|
256
|
+
5.3. In the event of termination under Sections 5.1 or 5.2 above, all
|
|
257
|
+
end user license agreements (excluding distributors and resellers) which
|
|
258
|
+
have been validly granted by You or Your distributors under this License
|
|
259
|
+
prior to termination shall survive termination.
|
|
260
|
+
|
|
261
|
+
************************************************************************
|
|
262
|
+
* *
|
|
263
|
+
* 6. Disclaimer of Warranty *
|
|
264
|
+
* ------------------------- *
|
|
265
|
+
* *
|
|
266
|
+
* Covered Software is provided under this License on an "as is" *
|
|
267
|
+
* basis, without warranty of any kind, either expressed, implied, or *
|
|
268
|
+
* statutory, including, without limitation, warranties that the *
|
|
269
|
+
* Covered Software is free of defects, merchantable, fit for a *
|
|
270
|
+
* particular purpose or non-infringing. The entire risk as to the *
|
|
271
|
+
* quality and performance of the Covered Software is with You. *
|
|
272
|
+
* Should any Covered Software prove defective in any respect, You *
|
|
273
|
+
* (not any Contributor) assume the cost of any necessary servicing, *
|
|
274
|
+
* repair, or correction. This disclaimer of warranty constitutes an *
|
|
275
|
+
* essential part of this License. No use of any Covered Software is *
|
|
276
|
+
* authorized under this License except under this disclaimer. *
|
|
277
|
+
* *
|
|
278
|
+
************************************************************************
|
|
279
|
+
|
|
280
|
+
************************************************************************
|
|
281
|
+
* *
|
|
282
|
+
* 7. Limitation of Liability *
|
|
283
|
+
* -------------------------- *
|
|
284
|
+
* *
|
|
285
|
+
* Under no circumstances and under no legal theory, whether tort *
|
|
286
|
+
* (including negligence), contract, or otherwise, shall any *
|
|
287
|
+
* Contributor, or anyone who distributes Covered Software as *
|
|
288
|
+
* permitted above, be liable to You for any direct, indirect, *
|
|
289
|
+
* special, incidental, or consequential damages of any character *
|
|
290
|
+
* including, without limitation, damages for lost profits, loss of *
|
|
291
|
+
* goodwill, work stoppage, computer failure or malfunction, or any *
|
|
292
|
+
* and all other commercial damages or losses, even if such party *
|
|
293
|
+
* shall have been informed of the possibility of such damages. This *
|
|
294
|
+
* limitation of liability shall not apply to liability for death or *
|
|
295
|
+
* personal injury resulting from such party's negligence to the *
|
|
296
|
+
* extent applicable law prohibits such limitation. Some *
|
|
297
|
+
* jurisdictions do not allow the exclusion or limitation of *
|
|
298
|
+
* incidental or consequential damages, so this exclusion and *
|
|
299
|
+
* limitation may not apply to You. *
|
|
300
|
+
* *
|
|
301
|
+
************************************************************************
|
|
302
|
+
|
|
303
|
+
8. Litigation
|
|
304
|
+
-------------
|
|
305
|
+
|
|
306
|
+
Any litigation relating to this License may be brought only in the
|
|
307
|
+
courts of a jurisdiction where the defendant maintains its principal
|
|
308
|
+
place of business and such litigation shall be governed by laws of that
|
|
309
|
+
jurisdiction, without reference to its conflict-of-law provisions.
|
|
310
|
+
Nothing in this Section shall prevent a party's ability to bring
|
|
311
|
+
cross-claims or counter-claims.
|
|
312
|
+
|
|
313
|
+
9. Miscellaneous
|
|
314
|
+
----------------
|
|
315
|
+
|
|
316
|
+
This License represents the complete agreement concerning the subject
|
|
317
|
+
matter hereof. If any provision of this License is held to be
|
|
318
|
+
unenforceable, such provision shall be reformed only to the extent
|
|
319
|
+
necessary to make it enforceable. Any law or regulation which provides
|
|
320
|
+
that the language of a contract shall be construed against the drafter
|
|
321
|
+
shall not be used to construe this License against a Contributor.
|
|
322
|
+
|
|
323
|
+
10. Versions of the License
|
|
324
|
+
---------------------------
|
|
325
|
+
|
|
326
|
+
10.1. New Versions
|
|
327
|
+
|
|
328
|
+
Mozilla Foundation is the license steward. Except as provided in Section
|
|
329
|
+
10.3, no one other than the license steward has the right to modify or
|
|
330
|
+
publish new versions of this License. Each version will be given a
|
|
331
|
+
distinguishing version number.
|
|
332
|
+
|
|
333
|
+
10.2. Effect of New Versions
|
|
334
|
+
|
|
335
|
+
You may distribute the Covered Software under the terms of the version
|
|
336
|
+
of the License under which You originally received the Covered Software,
|
|
337
|
+
or under the terms of any subsequent version published by the license
|
|
338
|
+
steward.
|
|
339
|
+
|
|
340
|
+
10.3. Modified Versions
|
|
341
|
+
|
|
342
|
+
If you create software not governed by this License, and you want to
|
|
343
|
+
create a new license for such software, you may create and use a
|
|
344
|
+
modified version of this License if you rename the license and remove
|
|
345
|
+
any references to the name of the license steward (except to note that
|
|
346
|
+
such modified license differs from this License).
|
|
347
|
+
|
|
348
|
+
10.4. Distributing Source Code Form that is Incompatible With Secondary
|
|
349
|
+
Licenses
|
|
350
|
+
|
|
351
|
+
If You choose to distribute Source Code Form that is Incompatible With
|
|
352
|
+
Secondary Licenses under the terms of this version of the License, the
|
|
353
|
+
notice described in Exhibit B of this License must be attached.
|
|
354
|
+
|
|
355
|
+
Exhibit A - Source Code Form License Notice
|
|
356
|
+
-------------------------------------------
|
|
357
|
+
|
|
358
|
+
This Source Code Form is subject to the terms of the Mozilla Public
|
|
359
|
+
License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
360
|
+
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
361
|
+
|
|
362
|
+
If it is not possible or desirable to put the notice in a particular
|
|
363
|
+
file, then You may include the notice in a location (such as a LICENSE
|
|
364
|
+
file in a relevant directory) where a recipient would be likely to look
|
|
365
|
+
for such a notice.
|
|
366
|
+
|
|
367
|
+
You may add additional accurate notices of copyright ownership.
|
|
368
|
+
|
|
369
|
+
Exhibit B - "Incompatible With Secondary Licenses" Notice
|
|
370
|
+
---------------------------------------------------------
|
|
371
|
+
|
|
372
|
+
This Source Code Form is "Incompatible With Secondary Licenses", as
|
|
373
|
+
defined by the Mozilla Public License, v. 2.0.
|
package/bin/gtkx-mcp.js
ADDED
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { Server } from "@modelcontextprotocol/sdk/server/index.js";
|
|
4
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
5
|
+
import { CallToolRequestSchema, ListToolsRequestSchema } from "@modelcontextprotocol/sdk/types.js";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
import { ConnectionManager } from "./connection-manager.js";
|
|
8
|
+
import { noAppConnectedError } from "./protocol/errors.js";
|
|
9
|
+
import { DEFAULT_SOCKET_PATH } from "./protocol/types.js";
|
|
10
|
+
import { SocketServer } from "./socket-server.js";
|
|
11
|
+
const require = createRequire(import.meta.url);
|
|
12
|
+
const { version } = require("../package.json");
|
|
13
|
+
const AppIdSchema = z.object({
|
|
14
|
+
appId: z.string().optional().describe("App ID to query. If not specified, uses the first connected app."),
|
|
15
|
+
});
|
|
16
|
+
const GetWidgetTreeInputSchema = AppIdSchema;
|
|
17
|
+
const QueryWidgetsInputSchema = AppIdSchema.extend({
|
|
18
|
+
by: z.enum(["role", "text", "testId", "labelText"]).describe("Query type"),
|
|
19
|
+
value: z.union([z.string(), z.number()]).describe("Value to search for"),
|
|
20
|
+
options: z
|
|
21
|
+
.object({
|
|
22
|
+
name: z.string().optional(),
|
|
23
|
+
exact: z.boolean().optional(),
|
|
24
|
+
timeout: z.number().optional(),
|
|
25
|
+
})
|
|
26
|
+
.optional()
|
|
27
|
+
.describe("Additional query options"),
|
|
28
|
+
});
|
|
29
|
+
const WidgetIdSchema = AppIdSchema.extend({
|
|
30
|
+
widgetId: z.string().describe("Widget ID"),
|
|
31
|
+
});
|
|
32
|
+
const GetWidgetPropsInputSchema = WidgetIdSchema;
|
|
33
|
+
const ClickInputSchema = WidgetIdSchema;
|
|
34
|
+
const TypeInputSchema = WidgetIdSchema.extend({
|
|
35
|
+
text: z.string().describe("Text to type"),
|
|
36
|
+
clear: z.boolean().optional().describe("Clear existing text before typing"),
|
|
37
|
+
});
|
|
38
|
+
const FireEventInputSchema = WidgetIdSchema.extend({
|
|
39
|
+
signal: z.string().describe("GTK signal name to emit"),
|
|
40
|
+
args: z.array(z.unknown()).optional().describe("Arguments to pass to the signal"),
|
|
41
|
+
});
|
|
42
|
+
const TakeScreenshotInputSchema = AppIdSchema.extend({
|
|
43
|
+
windowId: z.string().optional().describe("Window ID to capture. If not specified, captures the first window."),
|
|
44
|
+
format: z.enum(["png", "jpeg"]).optional().describe("Image format (default: png)"),
|
|
45
|
+
});
|
|
46
|
+
const tools = [
|
|
47
|
+
{
|
|
48
|
+
name: "gtkx_list_apps",
|
|
49
|
+
description: "List all connected GTKX applications",
|
|
50
|
+
inputSchema: {
|
|
51
|
+
type: "object",
|
|
52
|
+
properties: {},
|
|
53
|
+
required: [],
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: "gtkx_get_widget_tree",
|
|
58
|
+
description: "Get the widget hierarchy for a connected GTKX app. Returns a tree of all widgets with their IDs, types, roles, and properties.",
|
|
59
|
+
inputSchema: {
|
|
60
|
+
type: "object",
|
|
61
|
+
properties: {
|
|
62
|
+
appId: {
|
|
63
|
+
type: "string",
|
|
64
|
+
description: "App ID to query. If not specified, uses the first connected app.",
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
required: [],
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: "gtkx_query_widgets",
|
|
72
|
+
description: "Find widgets by role, text, testId, or label. Returns matching widgets with their IDs and properties.",
|
|
73
|
+
inputSchema: {
|
|
74
|
+
type: "object",
|
|
75
|
+
properties: {
|
|
76
|
+
appId: {
|
|
77
|
+
type: "string",
|
|
78
|
+
description: "App ID to query. If not specified, uses the first connected app.",
|
|
79
|
+
},
|
|
80
|
+
by: {
|
|
81
|
+
type: "string",
|
|
82
|
+
enum: ["role", "text", "testId", "labelText"],
|
|
83
|
+
description: "Query type",
|
|
84
|
+
},
|
|
85
|
+
value: {
|
|
86
|
+
oneOf: [{ type: "string" }, { type: "number" }],
|
|
87
|
+
description: "Value to search for",
|
|
88
|
+
},
|
|
89
|
+
options: {
|
|
90
|
+
type: "object",
|
|
91
|
+
properties: {
|
|
92
|
+
name: { type: "string" },
|
|
93
|
+
exact: { type: "boolean" },
|
|
94
|
+
timeout: { type: "number" },
|
|
95
|
+
},
|
|
96
|
+
description: "Additional query options",
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
required: ["by", "value"],
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
name: "gtkx_get_widget_props",
|
|
104
|
+
description: "Get all properties of a specific widget by its ID",
|
|
105
|
+
inputSchema: {
|
|
106
|
+
type: "object",
|
|
107
|
+
properties: {
|
|
108
|
+
appId: {
|
|
109
|
+
type: "string",
|
|
110
|
+
description: "App ID to query. If not specified, uses the first connected app.",
|
|
111
|
+
},
|
|
112
|
+
widgetId: {
|
|
113
|
+
type: "string",
|
|
114
|
+
description: "Widget ID to get properties for",
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
required: ["widgetId"],
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
name: "gtkx_click",
|
|
122
|
+
description: "Click a widget. Works with buttons, checkboxes, and other interactive widgets.",
|
|
123
|
+
inputSchema: {
|
|
124
|
+
type: "object",
|
|
125
|
+
properties: {
|
|
126
|
+
appId: {
|
|
127
|
+
type: "string",
|
|
128
|
+
description: "App ID to query. If not specified, uses the first connected app.",
|
|
129
|
+
},
|
|
130
|
+
widgetId: {
|
|
131
|
+
type: "string",
|
|
132
|
+
description: "Widget ID to click",
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
required: ["widgetId"],
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
name: "gtkx_type",
|
|
140
|
+
description: "Type text into an editable widget like Entry or TextView",
|
|
141
|
+
inputSchema: {
|
|
142
|
+
type: "object",
|
|
143
|
+
properties: {
|
|
144
|
+
appId: {
|
|
145
|
+
type: "string",
|
|
146
|
+
description: "App ID to query. If not specified, uses the first connected app.",
|
|
147
|
+
},
|
|
148
|
+
widgetId: {
|
|
149
|
+
type: "string",
|
|
150
|
+
description: "Widget ID to type into",
|
|
151
|
+
},
|
|
152
|
+
text: {
|
|
153
|
+
type: "string",
|
|
154
|
+
description: "Text to type",
|
|
155
|
+
},
|
|
156
|
+
clear: {
|
|
157
|
+
type: "boolean",
|
|
158
|
+
description: "Clear existing text before typing",
|
|
159
|
+
},
|
|
160
|
+
},
|
|
161
|
+
required: ["widgetId", "text"],
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
name: "gtkx_fire_event",
|
|
166
|
+
description: "Emit a GTK signal on a widget. Use this for custom interactions.",
|
|
167
|
+
inputSchema: {
|
|
168
|
+
type: "object",
|
|
169
|
+
properties: {
|
|
170
|
+
appId: {
|
|
171
|
+
type: "string",
|
|
172
|
+
description: "App ID to query. If not specified, uses the first connected app.",
|
|
173
|
+
},
|
|
174
|
+
widgetId: {
|
|
175
|
+
type: "string",
|
|
176
|
+
description: "Widget ID to emit event on",
|
|
177
|
+
},
|
|
178
|
+
signal: {
|
|
179
|
+
type: "string",
|
|
180
|
+
description: "GTK signal name to emit",
|
|
181
|
+
},
|
|
182
|
+
args: {
|
|
183
|
+
type: "array",
|
|
184
|
+
items: {},
|
|
185
|
+
description: "Arguments to pass to the signal",
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
required: ["widgetId", "signal"],
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
name: "gtkx_take_screenshot",
|
|
193
|
+
description: "Capture a screenshot of a window. Returns base64-encoded image data.",
|
|
194
|
+
inputSchema: {
|
|
195
|
+
type: "object",
|
|
196
|
+
properties: {
|
|
197
|
+
appId: {
|
|
198
|
+
type: "string",
|
|
199
|
+
description: "App ID to query. If not specified, uses the first connected app.",
|
|
200
|
+
},
|
|
201
|
+
windowId: {
|
|
202
|
+
type: "string",
|
|
203
|
+
description: "Window ID to capture. If not specified, captures the first window.",
|
|
204
|
+
},
|
|
205
|
+
format: {
|
|
206
|
+
type: "string",
|
|
207
|
+
enum: ["png", "jpeg"],
|
|
208
|
+
description: "Image format (default: png)",
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
required: [],
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
];
|
|
215
|
+
async function main() {
|
|
216
|
+
const socketServer = new SocketServer(DEFAULT_SOCKET_PATH);
|
|
217
|
+
const connectionManager = new ConnectionManager(socketServer);
|
|
218
|
+
await socketServer.start();
|
|
219
|
+
console.error(`[gtkx-mcp] Socket server listening on ${DEFAULT_SOCKET_PATH}`);
|
|
220
|
+
connectionManager.on("appRegistered", (appInfo) => {
|
|
221
|
+
console.error(`[gtkx-mcp] App registered: ${appInfo.appId} (PID: ${appInfo.pid})`);
|
|
222
|
+
});
|
|
223
|
+
connectionManager.on("appUnregistered", (appId) => {
|
|
224
|
+
console.error(`[gtkx-mcp] App unregistered: ${appId}`);
|
|
225
|
+
});
|
|
226
|
+
const requireConnectedApp = () => {
|
|
227
|
+
if (!connectionManager.hasConnectedApps()) {
|
|
228
|
+
throw noAppConnectedError();
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
const server = new Server({
|
|
232
|
+
name: "gtkx-mcp",
|
|
233
|
+
version,
|
|
234
|
+
}, {
|
|
235
|
+
capabilities: {
|
|
236
|
+
tools: {},
|
|
237
|
+
},
|
|
238
|
+
});
|
|
239
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
240
|
+
return { tools };
|
|
241
|
+
});
|
|
242
|
+
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
243
|
+
const { name, arguments: args } = request.params;
|
|
244
|
+
try {
|
|
245
|
+
switch (name) {
|
|
246
|
+
case "gtkx_list_apps": {
|
|
247
|
+
const apps = connectionManager.getApps();
|
|
248
|
+
return {
|
|
249
|
+
content: [{ type: "text", text: JSON.stringify(apps, null, 2) }],
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
case "gtkx_get_widget_tree": {
|
|
253
|
+
const input = GetWidgetTreeInputSchema.parse(args);
|
|
254
|
+
requireConnectedApp();
|
|
255
|
+
const result = await connectionManager.sendToApp(input.appId, "widget.getTree", {});
|
|
256
|
+
return {
|
|
257
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
case "gtkx_query_widgets": {
|
|
261
|
+
const input = QueryWidgetsInputSchema.parse(args);
|
|
262
|
+
requireConnectedApp();
|
|
263
|
+
const result = await connectionManager.sendToApp(input.appId, "widget.query", {
|
|
264
|
+
queryType: input.by,
|
|
265
|
+
value: input.value,
|
|
266
|
+
options: input.options,
|
|
267
|
+
});
|
|
268
|
+
return {
|
|
269
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
case "gtkx_get_widget_props": {
|
|
273
|
+
const input = GetWidgetPropsInputSchema.parse(args);
|
|
274
|
+
requireConnectedApp();
|
|
275
|
+
const result = await connectionManager.sendToApp(input.appId, "widget.getProps", {
|
|
276
|
+
widgetId: input.widgetId,
|
|
277
|
+
});
|
|
278
|
+
return {
|
|
279
|
+
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
case "gtkx_click": {
|
|
283
|
+
const input = ClickInputSchema.parse(args);
|
|
284
|
+
requireConnectedApp();
|
|
285
|
+
await connectionManager.sendToApp(input.appId, "widget.click", {
|
|
286
|
+
widgetId: input.widgetId,
|
|
287
|
+
});
|
|
288
|
+
return {
|
|
289
|
+
content: [{ type: "text", text: "Click successful" }],
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
case "gtkx_type": {
|
|
293
|
+
const input = TypeInputSchema.parse(args);
|
|
294
|
+
requireConnectedApp();
|
|
295
|
+
await connectionManager.sendToApp(input.appId, "widget.type", {
|
|
296
|
+
widgetId: input.widgetId,
|
|
297
|
+
text: input.text,
|
|
298
|
+
clear: input.clear,
|
|
299
|
+
});
|
|
300
|
+
return {
|
|
301
|
+
content: [{ type: "text", text: "Type successful" }],
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
case "gtkx_fire_event": {
|
|
305
|
+
const input = FireEventInputSchema.parse(args);
|
|
306
|
+
requireConnectedApp();
|
|
307
|
+
await connectionManager.sendToApp(input.appId, "widget.fireEvent", {
|
|
308
|
+
widgetId: input.widgetId,
|
|
309
|
+
signal: input.signal,
|
|
310
|
+
args: input.args,
|
|
311
|
+
});
|
|
312
|
+
return {
|
|
313
|
+
content: [{ type: "text", text: "Event fired successfully" }],
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
case "gtkx_take_screenshot": {
|
|
317
|
+
const input = TakeScreenshotInputSchema.parse(args);
|
|
318
|
+
requireConnectedApp();
|
|
319
|
+
const result = await connectionManager.sendToApp(input.appId, "widget.screenshot", {
|
|
320
|
+
windowId: input.windowId,
|
|
321
|
+
format: input.format,
|
|
322
|
+
});
|
|
323
|
+
return {
|
|
324
|
+
content: [
|
|
325
|
+
{
|
|
326
|
+
type: "image",
|
|
327
|
+
data: result.data,
|
|
328
|
+
mimeType: result.mimeType,
|
|
329
|
+
},
|
|
330
|
+
],
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
default:
|
|
334
|
+
return {
|
|
335
|
+
content: [{ type: "text", text: `Unknown tool: ${name}` }],
|
|
336
|
+
isError: true,
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
catch (error) {
|
|
341
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
342
|
+
return {
|
|
343
|
+
content: [{ type: "text", text: message }],
|
|
344
|
+
isError: true,
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
const transport = new StdioServerTransport();
|
|
349
|
+
await server.connect(transport);
|
|
350
|
+
let isShuttingDown = false;
|
|
351
|
+
const shutdown = async () => {
|
|
352
|
+
if (isShuttingDown)
|
|
353
|
+
return;
|
|
354
|
+
isShuttingDown = true;
|
|
355
|
+
try {
|
|
356
|
+
connectionManager.cleanup();
|
|
357
|
+
await socketServer.stop();
|
|
358
|
+
await server.close();
|
|
359
|
+
}
|
|
360
|
+
finally {
|
|
361
|
+
process.exit(0);
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
process.on("SIGINT", shutdown);
|
|
365
|
+
process.on("SIGTERM", shutdown);
|
|
366
|
+
}
|
|
367
|
+
main().catch((error) => {
|
|
368
|
+
console.error("[gtkx-mcp] Fatal error:", error);
|
|
369
|
+
process.exit(1);
|
|
370
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import EventEmitter from "node:events";
|
|
2
|
+
import { type AppInfo } from "./protocol/types.js";
|
|
3
|
+
import type { AppConnection, SocketServer } from "./socket-server.js";
|
|
4
|
+
type ConnectionManagerEventMap = {
|
|
5
|
+
appRegistered: [AppInfo];
|
|
6
|
+
appUnregistered: [string];
|
|
7
|
+
};
|
|
8
|
+
interface RegisteredApp {
|
|
9
|
+
info: AppInfo;
|
|
10
|
+
connection: AppConnection;
|
|
11
|
+
}
|
|
12
|
+
export declare class ConnectionManager extends EventEmitter<ConnectionManagerEventMap> {
|
|
13
|
+
private socketServer;
|
|
14
|
+
private apps;
|
|
15
|
+
private connectionToApp;
|
|
16
|
+
private pendingRequests;
|
|
17
|
+
private requestTimeout;
|
|
18
|
+
constructor(socketServer: SocketServer, options?: {
|
|
19
|
+
requestTimeout?: number;
|
|
20
|
+
});
|
|
21
|
+
getApps(): AppInfo[];
|
|
22
|
+
getApp(appId: string): AppInfo | undefined;
|
|
23
|
+
hasConnectedApps(): boolean;
|
|
24
|
+
getDefaultApp(): RegisteredApp | undefined;
|
|
25
|
+
sendToApp<T>(appId: string | undefined, method: string, params?: unknown): Promise<T>;
|
|
26
|
+
cleanup(): void;
|
|
27
|
+
private handleRequest;
|
|
28
|
+
private handleResponse;
|
|
29
|
+
private handleRegister;
|
|
30
|
+
private handleUnregister;
|
|
31
|
+
private handleDisconnection;
|
|
32
|
+
}
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import EventEmitter from "node:events";
|
|
2
|
+
import { appNotFoundError, invalidRequestError, ipcTimeoutError, McpError, noAppConnectedError, } from "./protocol/errors.js";
|
|
3
|
+
import { RegisterParamsSchema } from "./protocol/types.js";
|
|
4
|
+
export class ConnectionManager extends EventEmitter {
|
|
5
|
+
socketServer;
|
|
6
|
+
apps = new Map();
|
|
7
|
+
connectionToApp = new Map();
|
|
8
|
+
pendingRequests = new Map();
|
|
9
|
+
requestTimeout;
|
|
10
|
+
constructor(socketServer, options = {}) {
|
|
11
|
+
super();
|
|
12
|
+
this.socketServer = socketServer;
|
|
13
|
+
this.requestTimeout = options.requestTimeout ?? 30000;
|
|
14
|
+
this.socketServer.on("request", (connection, request) => {
|
|
15
|
+
this.handleRequest(connection, request);
|
|
16
|
+
});
|
|
17
|
+
this.socketServer.on("disconnection", (connection) => {
|
|
18
|
+
this.handleDisconnection(connection);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
getApps() {
|
|
22
|
+
return Array.from(this.apps.values()).map((app) => app.info);
|
|
23
|
+
}
|
|
24
|
+
getApp(appId) {
|
|
25
|
+
return this.apps.get(appId)?.info;
|
|
26
|
+
}
|
|
27
|
+
hasConnectedApps() {
|
|
28
|
+
return this.apps.size > 0;
|
|
29
|
+
}
|
|
30
|
+
getDefaultApp() {
|
|
31
|
+
const first = this.apps.values().next();
|
|
32
|
+
return first.done ? undefined : first.value;
|
|
33
|
+
}
|
|
34
|
+
async sendToApp(appId, method, params) {
|
|
35
|
+
const app = appId ? this.apps.get(appId) : this.getDefaultApp();
|
|
36
|
+
if (!app) {
|
|
37
|
+
if (appId) {
|
|
38
|
+
throw appNotFoundError(appId);
|
|
39
|
+
}
|
|
40
|
+
throw noAppConnectedError();
|
|
41
|
+
}
|
|
42
|
+
const requestId = crypto.randomUUID();
|
|
43
|
+
const request = {
|
|
44
|
+
id: requestId,
|
|
45
|
+
method,
|
|
46
|
+
params,
|
|
47
|
+
};
|
|
48
|
+
return new Promise((resolve, reject) => {
|
|
49
|
+
const timeout = setTimeout(() => {
|
|
50
|
+
this.pendingRequests.delete(requestId);
|
|
51
|
+
reject(ipcTimeoutError(this.requestTimeout));
|
|
52
|
+
}, this.requestTimeout);
|
|
53
|
+
this.pendingRequests.set(requestId, {
|
|
54
|
+
resolve: resolve,
|
|
55
|
+
reject,
|
|
56
|
+
timeout,
|
|
57
|
+
});
|
|
58
|
+
this.socketServer.send(app.connection.id, request);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
cleanup() {
|
|
62
|
+
for (const pending of this.pendingRequests.values()) {
|
|
63
|
+
clearTimeout(pending.timeout);
|
|
64
|
+
pending.reject(new Error("Connection manager shutting down"));
|
|
65
|
+
}
|
|
66
|
+
this.pendingRequests.clear();
|
|
67
|
+
}
|
|
68
|
+
handleRequest(connection, request) {
|
|
69
|
+
if (request.method === "app.register") {
|
|
70
|
+
this.handleRegister(connection, request);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
if (request.method === "app.unregister") {
|
|
74
|
+
this.handleUnregister(connection, request);
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
this.handleResponse(request);
|
|
78
|
+
}
|
|
79
|
+
handleResponse(message) {
|
|
80
|
+
const pending = this.pendingRequests.get(message.id);
|
|
81
|
+
if (!pending) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
clearTimeout(pending.timeout);
|
|
85
|
+
this.pendingRequests.delete(message.id);
|
|
86
|
+
const response = message;
|
|
87
|
+
if (response.error) {
|
|
88
|
+
const err = response.error;
|
|
89
|
+
pending.reject(new McpError(err.code, err.message, err.data));
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
pending.resolve(response.result);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
handleRegister(connection, request) {
|
|
96
|
+
const parseResult = RegisterParamsSchema.safeParse(request.params);
|
|
97
|
+
if (!parseResult.success) {
|
|
98
|
+
const response = {
|
|
99
|
+
id: request.id,
|
|
100
|
+
error: invalidRequestError(parseResult.error.message).toIpcError(),
|
|
101
|
+
};
|
|
102
|
+
this.socketServer.send(connection.id, response);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const params = parseResult.data;
|
|
106
|
+
const appInfo = {
|
|
107
|
+
appId: params.appId,
|
|
108
|
+
pid: params.pid,
|
|
109
|
+
windows: [],
|
|
110
|
+
};
|
|
111
|
+
const registeredApp = {
|
|
112
|
+
info: appInfo,
|
|
113
|
+
connection,
|
|
114
|
+
};
|
|
115
|
+
this.apps.set(params.appId, registeredApp);
|
|
116
|
+
this.connectionToApp.set(connection.id, params.appId);
|
|
117
|
+
const response = {
|
|
118
|
+
id: request.id,
|
|
119
|
+
result: { success: true },
|
|
120
|
+
};
|
|
121
|
+
this.socketServer.send(connection.id, response);
|
|
122
|
+
this.emit("appRegistered", appInfo);
|
|
123
|
+
}
|
|
124
|
+
handleUnregister(connection, request) {
|
|
125
|
+
const appId = this.connectionToApp.get(connection.id);
|
|
126
|
+
if (appId) {
|
|
127
|
+
this.apps.delete(appId);
|
|
128
|
+
this.connectionToApp.delete(connection.id);
|
|
129
|
+
this.emit("appUnregistered", appId);
|
|
130
|
+
}
|
|
131
|
+
const response = {
|
|
132
|
+
id: request.id,
|
|
133
|
+
result: { success: true },
|
|
134
|
+
};
|
|
135
|
+
this.socketServer.send(connection.id, response);
|
|
136
|
+
}
|
|
137
|
+
handleDisconnection(connection) {
|
|
138
|
+
const appId = this.connectionToApp.get(connection.id);
|
|
139
|
+
if (appId) {
|
|
140
|
+
this.apps.delete(appId);
|
|
141
|
+
this.connectionToApp.delete(connection.id);
|
|
142
|
+
this.emit("appUnregistered", appId);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { ConnectionManager } from "./connection-manager.js";
|
|
2
|
+
export { McpError, McpErrorCode, methodNotFoundError, widgetNotFoundError, } from "./protocol/errors.js";
|
|
3
|
+
export { type AppInfo, DEFAULT_SOCKET_PATH, type IpcError, type IpcMethod, type IpcRequest, type IpcResponse, type QueryOptions, type SerializedWidget, } from "./protocol/types.js";
|
|
4
|
+
export { type AppConnection, SocketServer } from "./socket-server.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { ConnectionManager } from "./connection-manager.js";
|
|
2
|
+
export { McpError, McpErrorCode, methodNotFoundError, widgetNotFoundError, } from "./protocol/errors.js";
|
|
3
|
+
export { DEFAULT_SOCKET_PATH, } from "./protocol/types.js";
|
|
4
|
+
export { SocketServer } from "./socket-server.js";
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export declare enum McpErrorCode {
|
|
2
|
+
INTERNAL_ERROR = 1000,
|
|
3
|
+
NO_APP_CONNECTED = 1001,
|
|
4
|
+
APP_NOT_FOUND = 1002,
|
|
5
|
+
WIDGET_NOT_FOUND = 1003,
|
|
6
|
+
WIDGET_NOT_INTERACTABLE = 1004,
|
|
7
|
+
QUERY_TIMEOUT = 1005,
|
|
8
|
+
INVALID_WIDGET_TYPE = 1006,
|
|
9
|
+
SCREENSHOT_FAILED = 1007,
|
|
10
|
+
IPC_TIMEOUT = 1008,
|
|
11
|
+
SERIALIZATION_ERROR = 1009,
|
|
12
|
+
INVALID_REQUEST = 1010,
|
|
13
|
+
METHOD_NOT_FOUND = 1011
|
|
14
|
+
}
|
|
15
|
+
export declare class McpError extends Error {
|
|
16
|
+
readonly code: McpErrorCode;
|
|
17
|
+
readonly data?: unknown;
|
|
18
|
+
constructor(code: McpErrorCode, message: string, data?: unknown);
|
|
19
|
+
toIpcError(): {
|
|
20
|
+
code: number;
|
|
21
|
+
message: string;
|
|
22
|
+
data?: unknown;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export declare function noAppConnectedError(): McpError;
|
|
26
|
+
export declare function appNotFoundError(appId: string): McpError;
|
|
27
|
+
export declare function widgetNotFoundError(widgetId: string): McpError;
|
|
28
|
+
export declare function ipcTimeoutError(timeout: number): McpError;
|
|
29
|
+
export declare function invalidRequestError(reason: string): McpError;
|
|
30
|
+
export declare function methodNotFoundError(method: string): McpError;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
export var McpErrorCode;
|
|
2
|
+
(function (McpErrorCode) {
|
|
3
|
+
McpErrorCode[McpErrorCode["INTERNAL_ERROR"] = 1000] = "INTERNAL_ERROR";
|
|
4
|
+
McpErrorCode[McpErrorCode["NO_APP_CONNECTED"] = 1001] = "NO_APP_CONNECTED";
|
|
5
|
+
McpErrorCode[McpErrorCode["APP_NOT_FOUND"] = 1002] = "APP_NOT_FOUND";
|
|
6
|
+
McpErrorCode[McpErrorCode["WIDGET_NOT_FOUND"] = 1003] = "WIDGET_NOT_FOUND";
|
|
7
|
+
McpErrorCode[McpErrorCode["WIDGET_NOT_INTERACTABLE"] = 1004] = "WIDGET_NOT_INTERACTABLE";
|
|
8
|
+
McpErrorCode[McpErrorCode["QUERY_TIMEOUT"] = 1005] = "QUERY_TIMEOUT";
|
|
9
|
+
McpErrorCode[McpErrorCode["INVALID_WIDGET_TYPE"] = 1006] = "INVALID_WIDGET_TYPE";
|
|
10
|
+
McpErrorCode[McpErrorCode["SCREENSHOT_FAILED"] = 1007] = "SCREENSHOT_FAILED";
|
|
11
|
+
McpErrorCode[McpErrorCode["IPC_TIMEOUT"] = 1008] = "IPC_TIMEOUT";
|
|
12
|
+
McpErrorCode[McpErrorCode["SERIALIZATION_ERROR"] = 1009] = "SERIALIZATION_ERROR";
|
|
13
|
+
McpErrorCode[McpErrorCode["INVALID_REQUEST"] = 1010] = "INVALID_REQUEST";
|
|
14
|
+
McpErrorCode[McpErrorCode["METHOD_NOT_FOUND"] = 1011] = "METHOD_NOT_FOUND";
|
|
15
|
+
})(McpErrorCode || (McpErrorCode = {}));
|
|
16
|
+
export class McpError extends Error {
|
|
17
|
+
code;
|
|
18
|
+
data;
|
|
19
|
+
constructor(code, message, data) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.code = code;
|
|
22
|
+
this.data = data;
|
|
23
|
+
this.name = "McpError";
|
|
24
|
+
if (Error.captureStackTrace) {
|
|
25
|
+
Error.captureStackTrace(this, McpError);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
toIpcError() {
|
|
29
|
+
return {
|
|
30
|
+
code: this.code,
|
|
31
|
+
message: this.message,
|
|
32
|
+
...(this.data !== undefined && { data: this.data }),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export function noAppConnectedError() {
|
|
37
|
+
return new McpError(McpErrorCode.NO_APP_CONNECTED, "No GTKX application connected. Start an app with 'gtkx dev' to connect.", { hint: "Run 'gtkx dev src/app.tsx' in your project directory" });
|
|
38
|
+
}
|
|
39
|
+
export function appNotFoundError(appId) {
|
|
40
|
+
return new McpError(McpErrorCode.APP_NOT_FOUND, `Application '${appId}' not found`, { appId });
|
|
41
|
+
}
|
|
42
|
+
export function widgetNotFoundError(widgetId) {
|
|
43
|
+
return new McpError(McpErrorCode.WIDGET_NOT_FOUND, `Widget '${widgetId}' not found`, { widgetId });
|
|
44
|
+
}
|
|
45
|
+
export function ipcTimeoutError(timeout) {
|
|
46
|
+
return new McpError(McpErrorCode.IPC_TIMEOUT, `IPC request timed out after ${timeout}ms`, { timeout });
|
|
47
|
+
}
|
|
48
|
+
export function invalidRequestError(reason) {
|
|
49
|
+
return new McpError(McpErrorCode.INVALID_REQUEST, `Invalid request: ${reason}`, { reason });
|
|
50
|
+
}
|
|
51
|
+
export function methodNotFoundError(method) {
|
|
52
|
+
return new McpError(McpErrorCode.METHOD_NOT_FOUND, `Method '${method}' not found`, { method });
|
|
53
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const IpcRequestSchema: z.ZodObject<{
|
|
3
|
+
id: z.ZodString;
|
|
4
|
+
method: z.ZodString;
|
|
5
|
+
params: z.ZodOptional<z.ZodUnknown>;
|
|
6
|
+
}, "strip", z.ZodTypeAny, {
|
|
7
|
+
method: string;
|
|
8
|
+
id: string;
|
|
9
|
+
params?: unknown;
|
|
10
|
+
}, {
|
|
11
|
+
method: string;
|
|
12
|
+
id: string;
|
|
13
|
+
params?: unknown;
|
|
14
|
+
}>;
|
|
15
|
+
export type IpcRequest = z.infer<typeof IpcRequestSchema>;
|
|
16
|
+
export type IpcError = {
|
|
17
|
+
code: number;
|
|
18
|
+
message: string;
|
|
19
|
+
data?: unknown;
|
|
20
|
+
};
|
|
21
|
+
export type IpcResponse = {
|
|
22
|
+
id: string;
|
|
23
|
+
result?: unknown;
|
|
24
|
+
error?: IpcError;
|
|
25
|
+
};
|
|
26
|
+
export interface SerializedWidget {
|
|
27
|
+
id: string;
|
|
28
|
+
type: string;
|
|
29
|
+
role: string;
|
|
30
|
+
name: string | null;
|
|
31
|
+
label: string | null;
|
|
32
|
+
text: string | null;
|
|
33
|
+
sensitive: boolean;
|
|
34
|
+
visible: boolean;
|
|
35
|
+
cssClasses: string[];
|
|
36
|
+
children: SerializedWidget[];
|
|
37
|
+
bounds?: {
|
|
38
|
+
x: number;
|
|
39
|
+
y: number;
|
|
40
|
+
width: number;
|
|
41
|
+
height: number;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export type AppInfo = {
|
|
45
|
+
appId: string;
|
|
46
|
+
pid: number;
|
|
47
|
+
windows: Array<{
|
|
48
|
+
id: string;
|
|
49
|
+
title: string | null;
|
|
50
|
+
}>;
|
|
51
|
+
};
|
|
52
|
+
export type QueryOptions = {
|
|
53
|
+
name?: string;
|
|
54
|
+
checked?: boolean;
|
|
55
|
+
expanded?: boolean;
|
|
56
|
+
exact?: boolean;
|
|
57
|
+
timeout?: number;
|
|
58
|
+
};
|
|
59
|
+
export declare const RegisterParamsSchema: z.ZodObject<{
|
|
60
|
+
appId: z.ZodString;
|
|
61
|
+
pid: z.ZodNumber;
|
|
62
|
+
}, "strip", z.ZodTypeAny, {
|
|
63
|
+
appId: string;
|
|
64
|
+
pid: number;
|
|
65
|
+
}, {
|
|
66
|
+
appId: string;
|
|
67
|
+
pid: number;
|
|
68
|
+
}>;
|
|
69
|
+
export type IpcMethod = "app.register" | "app.unregister" | "widget.getTree" | "widget.query" | "widget.getProps" | "widget.click" | "widget.type" | "widget.fireEvent" | "widget.screenshot";
|
|
70
|
+
export type IpcMessage = IpcRequest | IpcResponse;
|
|
71
|
+
export declare const DEFAULT_SOCKET_PATH = "/tmp/gtkx-mcp.sock";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const IpcRequestSchema = z.object({
|
|
3
|
+
id: z.string(),
|
|
4
|
+
method: z.string(),
|
|
5
|
+
params: z.unknown().optional(),
|
|
6
|
+
});
|
|
7
|
+
export const RegisterParamsSchema = z.object({
|
|
8
|
+
appId: z.string(),
|
|
9
|
+
pid: z.number(),
|
|
10
|
+
});
|
|
11
|
+
export const DEFAULT_SOCKET_PATH = "/tmp/gtkx-mcp.sock";
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import EventEmitter from "node:events";
|
|
2
|
+
import * as net from "node:net";
|
|
3
|
+
import { type IpcMessage, type IpcRequest } from "./protocol/types.js";
|
|
4
|
+
type SocketServerEventMap = {
|
|
5
|
+
connection: [AppConnection];
|
|
6
|
+
disconnection: [AppConnection];
|
|
7
|
+
request: [AppConnection, IpcRequest];
|
|
8
|
+
error: [Error];
|
|
9
|
+
};
|
|
10
|
+
export interface AppConnection {
|
|
11
|
+
id: string;
|
|
12
|
+
socket: net.Socket;
|
|
13
|
+
buffer: string;
|
|
14
|
+
}
|
|
15
|
+
export declare class SocketServer extends EventEmitter<SocketServerEventMap> {
|
|
16
|
+
private server;
|
|
17
|
+
private connections;
|
|
18
|
+
private socketPath;
|
|
19
|
+
constructor(socketPath?: string);
|
|
20
|
+
get path(): string;
|
|
21
|
+
get isListening(): boolean;
|
|
22
|
+
getConnections(): AppConnection[];
|
|
23
|
+
getConnection(id: string): AppConnection | undefined;
|
|
24
|
+
start(): Promise<void>;
|
|
25
|
+
stop(): Promise<void>;
|
|
26
|
+
send(connectionId: string, message: IpcMessage): boolean;
|
|
27
|
+
private handleConnection;
|
|
28
|
+
private handleData;
|
|
29
|
+
private processMessage;
|
|
30
|
+
}
|
|
31
|
+
export {};
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import EventEmitter from "node:events";
|
|
2
|
+
import * as fs from "node:fs";
|
|
3
|
+
import * as net from "node:net";
|
|
4
|
+
import { invalidRequestError } from "./protocol/errors.js";
|
|
5
|
+
import { DEFAULT_SOCKET_PATH, IpcRequestSchema, } from "./protocol/types.js";
|
|
6
|
+
export class SocketServer extends EventEmitter {
|
|
7
|
+
server = null;
|
|
8
|
+
connections = new Map();
|
|
9
|
+
socketPath;
|
|
10
|
+
constructor(socketPath = DEFAULT_SOCKET_PATH) {
|
|
11
|
+
super();
|
|
12
|
+
this.socketPath = socketPath;
|
|
13
|
+
}
|
|
14
|
+
get path() {
|
|
15
|
+
return this.socketPath;
|
|
16
|
+
}
|
|
17
|
+
get isListening() {
|
|
18
|
+
return this.server?.listening ?? false;
|
|
19
|
+
}
|
|
20
|
+
getConnections() {
|
|
21
|
+
return Array.from(this.connections.values());
|
|
22
|
+
}
|
|
23
|
+
getConnection(id) {
|
|
24
|
+
return this.connections.get(id);
|
|
25
|
+
}
|
|
26
|
+
async start() {
|
|
27
|
+
if (this.server) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (fs.existsSync(this.socketPath)) {
|
|
31
|
+
fs.unlinkSync(this.socketPath);
|
|
32
|
+
}
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
this.server = net.createServer((socket) => this.handleConnection(socket));
|
|
35
|
+
this.server.on("error", (error) => {
|
|
36
|
+
this.emit("error", error);
|
|
37
|
+
reject(error);
|
|
38
|
+
});
|
|
39
|
+
this.server.listen(this.socketPath, () => {
|
|
40
|
+
resolve();
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
async stop() {
|
|
45
|
+
if (!this.server) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
for (const connection of this.connections.values()) {
|
|
49
|
+
connection.socket.destroy();
|
|
50
|
+
}
|
|
51
|
+
this.connections.clear();
|
|
52
|
+
return new Promise((resolve) => {
|
|
53
|
+
this.server?.close(() => {
|
|
54
|
+
this.server = null;
|
|
55
|
+
if (fs.existsSync(this.socketPath)) {
|
|
56
|
+
fs.unlinkSync(this.socketPath);
|
|
57
|
+
}
|
|
58
|
+
resolve();
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
send(connectionId, message) {
|
|
63
|
+
const connection = this.connections.get(connectionId);
|
|
64
|
+
if (!connection) {
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
const data = `${JSON.stringify(message)}\n`;
|
|
68
|
+
connection.socket.write(data);
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
handleConnection(socket) {
|
|
72
|
+
const connectionId = crypto.randomUUID();
|
|
73
|
+
const connection = {
|
|
74
|
+
id: connectionId,
|
|
75
|
+
socket,
|
|
76
|
+
buffer: "",
|
|
77
|
+
};
|
|
78
|
+
this.connections.set(connectionId, connection);
|
|
79
|
+
this.emit("connection", connection);
|
|
80
|
+
socket.on("data", (data) => this.handleData(connection, data));
|
|
81
|
+
socket.on("close", () => {
|
|
82
|
+
this.connections.delete(connectionId);
|
|
83
|
+
this.emit("disconnection", connection);
|
|
84
|
+
});
|
|
85
|
+
socket.on("error", (error) => {
|
|
86
|
+
this.emit("error", error);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
handleData(connection, data) {
|
|
90
|
+
connection.buffer += data.toString();
|
|
91
|
+
let newlineIndex = connection.buffer.indexOf("\n");
|
|
92
|
+
while (newlineIndex !== -1) {
|
|
93
|
+
const line = connection.buffer.slice(0, newlineIndex);
|
|
94
|
+
connection.buffer = connection.buffer.slice(newlineIndex + 1);
|
|
95
|
+
if (line.trim()) {
|
|
96
|
+
this.processMessage(connection, line);
|
|
97
|
+
}
|
|
98
|
+
newlineIndex = connection.buffer.indexOf("\n");
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
processMessage(connection, line) {
|
|
102
|
+
let parsed;
|
|
103
|
+
try {
|
|
104
|
+
parsed = JSON.parse(line);
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
const response = {
|
|
108
|
+
id: "unknown",
|
|
109
|
+
error: invalidRequestError("Invalid JSON").toIpcError(),
|
|
110
|
+
};
|
|
111
|
+
this.send(connection.id, response);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
const result = IpcRequestSchema.safeParse(parsed);
|
|
115
|
+
if (!result.success) {
|
|
116
|
+
const response = {
|
|
117
|
+
id: parsed.id ?? "unknown",
|
|
118
|
+
error: invalidRequestError(result.error.message).toIpcError(),
|
|
119
|
+
};
|
|
120
|
+
this.send(connection.id, response);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
this.emit("request", connection, result.data);
|
|
124
|
+
}
|
|
125
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gtkx/mcp",
|
|
3
|
+
"version": "0.11.1",
|
|
4
|
+
"description": "MCP server for AI-powered interaction with GTKX applications",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"gtkx",
|
|
7
|
+
"gtk",
|
|
8
|
+
"gtk4",
|
|
9
|
+
"mcp",
|
|
10
|
+
"model-context-protocol",
|
|
11
|
+
"ai",
|
|
12
|
+
"typescript",
|
|
13
|
+
"linux",
|
|
14
|
+
"desktop"
|
|
15
|
+
],
|
|
16
|
+
"homepage": "https://eugeniodepalo.github.io/gtkx",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/eugeniodepalo/gtkx/issues"
|
|
19
|
+
},
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/eugeniodepalo/gtkx.git",
|
|
23
|
+
"directory": "packages/mcp"
|
|
24
|
+
},
|
|
25
|
+
"license": "MPL-2.0",
|
|
26
|
+
"author": "Eugenio Depalo <eugeniodepalo@gmail.com>",
|
|
27
|
+
"type": "module",
|
|
28
|
+
"exports": {
|
|
29
|
+
"./package.json": "./package.json",
|
|
30
|
+
".": {
|
|
31
|
+
"types": "./dist/index.d.ts",
|
|
32
|
+
"default": "./dist/index.js"
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
"bin": {
|
|
36
|
+
"gtkx-mcp": "bin/gtkx-mcp.js"
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"bin",
|
|
40
|
+
"dist"
|
|
41
|
+
],
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
44
|
+
"zod": "^3.24.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsc -b",
|
|
49
|
+
"test": "vitest run"
|
|
50
|
+
}
|
|
51
|
+
}
|