@gtkx/mcp 0.21.0 → 1.0.0-rc.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/README.md +137 -34
- package/bin/gtkx-mcp.js +8 -1
- package/dist/app-router.d.ts +35 -0
- package/dist/app-router.d.ts.map +1 -0
- package/dist/app-router.js +130 -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 +38 -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 +24 -87
- package/dist/protocol/errors.d.ts.map +1 -1
- package/dist/protocol/errors.js +27 -91
- package/dist/protocol/errors.js.map +1 -1
- package/dist/protocol/schemas.d.ts +89 -0
- package/dist/protocol/schemas.d.ts.map +1 -0
- package/dist/protocol/schemas.js +56 -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 +250 -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 +220 -0
- package/dist/server.js.map +1 -0
- package/dist/socket-server.d.ts +4 -38
- package/dist/socket-server.d.ts.map +1 -1
- package/dist/socket-server.js +26 -109
- 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 +36 -0
- package/dist/tool.js.map +1 -0
- package/dist/transport.d.ts +41 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +121 -0
- package/dist/transport.js.map +1 -0
- package/package.json +17 -11
- package/src/app-router.ts +172 -0
- package/src/connection-registry.ts +42 -0
- package/src/internal.ts +17 -0
- package/src/protocol/errors.ts +43 -99
- package/src/protocol/schemas.ts +148 -0
- package/src/reference.ts +340 -0
- package/src/server.ts +281 -0
- package/src/socket-server.ts +30 -154
- package/src/tool.ts +66 -0
- package/src/transport.ts +165 -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
package/src/transport.ts
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import EventEmitter from "node:events";
|
|
2
|
+
import type { Socket } from "node:net";
|
|
3
|
+
import type { Duplex } from "node:stream";
|
|
4
|
+
import { ErrorCode, invalidRequestError, isErrorCode, ProtocolError, requestTimeoutError } from "./protocol/errors.js";
|
|
5
|
+
import { type Message, type Request, RequestSchema, type Response, ResponseSchema } from "./protocol/schemas.js";
|
|
6
|
+
|
|
7
|
+
export type ProtocolConnectionEvents = {
|
|
8
|
+
request: [Request];
|
|
9
|
+
invalid: [{ id: string; error: ProtocolError }];
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
type PendingRequest = {
|
|
13
|
+
resolve: (result: unknown) => void;
|
|
14
|
+
reject: (error: Error) => void;
|
|
15
|
+
timeout: NodeJS.Timeout;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export class ConnectionClosedError extends Error {
|
|
19
|
+
constructor() {
|
|
20
|
+
super("Connection stream is not writable");
|
|
21
|
+
this.name = "ConnectionClosedError";
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export class ProtocolConnection extends EventEmitter<ProtocolConnectionEvents> {
|
|
26
|
+
id: string = crypto.randomUUID();
|
|
27
|
+
private buffer = "";
|
|
28
|
+
private pending: Map<string, PendingRequest> = new Map();
|
|
29
|
+
private writer: Duplex;
|
|
30
|
+
|
|
31
|
+
constructor(writer: Duplex) {
|
|
32
|
+
super();
|
|
33
|
+
this.writer = writer;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
feed(data: Buffer | string): void {
|
|
37
|
+
this.buffer += typeof data === "string" ? data : data.toString();
|
|
38
|
+
|
|
39
|
+
let newlineIndex = this.buffer.indexOf("\n");
|
|
40
|
+
while (newlineIndex !== -1) {
|
|
41
|
+
const line = this.buffer.slice(0, newlineIndex);
|
|
42
|
+
this.buffer = this.buffer.slice(newlineIndex + 1);
|
|
43
|
+
|
|
44
|
+
if (line.trim()) {
|
|
45
|
+
this.processLine(line);
|
|
46
|
+
}
|
|
47
|
+
newlineIndex = this.buffer.indexOf("\n");
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
write(message: Message): void {
|
|
52
|
+
if (!this.writer.writable) return;
|
|
53
|
+
this.writer.write(`${JSON.stringify(message)}\n`);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
static fromSocket(
|
|
57
|
+
socket: Socket,
|
|
58
|
+
options: {
|
|
59
|
+
onClose?: () => void;
|
|
60
|
+
onError?: (error: Error) => void;
|
|
61
|
+
} = {},
|
|
62
|
+
): ProtocolConnection {
|
|
63
|
+
const connection = new ProtocolConnection(socket);
|
|
64
|
+
socket.on("data", (data: Buffer) => connection.feed(data));
|
|
65
|
+
socket.on("close", () => {
|
|
66
|
+
connection.rejectPending(new Error("Connection closed"));
|
|
67
|
+
options.onClose?.();
|
|
68
|
+
});
|
|
69
|
+
if (options.onError) {
|
|
70
|
+
socket.on("error", options.onError);
|
|
71
|
+
}
|
|
72
|
+
return connection;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
send<T = unknown>(method: string, params: unknown, timeout: number): Promise<T> {
|
|
76
|
+
return new Promise<T>((resolve, reject) => {
|
|
77
|
+
if (!this.writer.writable) {
|
|
78
|
+
reject(new ConnectionClosedError());
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const id = crypto.randomUUID();
|
|
83
|
+
const timeoutHandle = setTimeout(() => {
|
|
84
|
+
this.pending.delete(id);
|
|
85
|
+
reject(requestTimeoutError(timeout));
|
|
86
|
+
}, timeout);
|
|
87
|
+
|
|
88
|
+
this.pending.set(id, {
|
|
89
|
+
resolve: resolve as (result: unknown) => void,
|
|
90
|
+
reject,
|
|
91
|
+
timeout: timeoutHandle,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
this.write({ id, method, params });
|
|
95
|
+
if (!this.writer.writable) {
|
|
96
|
+
clearTimeout(timeoutHandle);
|
|
97
|
+
this.pending.delete(id);
|
|
98
|
+
reject(new ConnectionClosedError());
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
rejectPending(error: Error): void {
|
|
104
|
+
for (const entry of this.pending.values()) {
|
|
105
|
+
clearTimeout(entry.timeout);
|
|
106
|
+
entry.reject(error);
|
|
107
|
+
}
|
|
108
|
+
this.pending.clear();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private processLine(line: string): void {
|
|
112
|
+
let parsed: unknown;
|
|
113
|
+
try {
|
|
114
|
+
parsed = JSON.parse(line);
|
|
115
|
+
} catch {
|
|
116
|
+
this.emit("invalid", { id: "unknown", error: invalidRequestError("Invalid JSON") });
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const message = parsed as Record<string, unknown>;
|
|
121
|
+
if (typeof message.method === "string") {
|
|
122
|
+
const requestResult = RequestSchema.safeParse(parsed);
|
|
123
|
+
if (requestResult.success) {
|
|
124
|
+
this.emit("request", requestResult.data);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
} else {
|
|
128
|
+
const responseResult = ResponseSchema.safeParse(parsed);
|
|
129
|
+
if (responseResult.success) {
|
|
130
|
+
this.handleResponse(responseResult.data);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const id = typeof message.id === "string" ? message.id : "unknown";
|
|
136
|
+
this.emit("invalid", { id, error: invalidRequestError("Invalid message format") });
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
private handleResponse(response: Response): void {
|
|
140
|
+
const entry = this.pending.get(response.id);
|
|
141
|
+
if (!entry) return;
|
|
142
|
+
|
|
143
|
+
clearTimeout(entry.timeout);
|
|
144
|
+
this.pending.delete(response.id);
|
|
145
|
+
|
|
146
|
+
if (response.error) {
|
|
147
|
+
const err = response.error;
|
|
148
|
+
entry.reject(
|
|
149
|
+
new ProtocolError(isErrorCode(err.code) ? err.code : ErrorCode.INTERNAL_ERROR, err.message, err.data),
|
|
150
|
+
);
|
|
151
|
+
} else {
|
|
152
|
+
entry.resolve(response.result);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export type AppConnectionEvents = {
|
|
158
|
+
disconnection: [ProtocolConnection];
|
|
159
|
+
request: [ProtocolConnection, Request];
|
|
160
|
+
error: [Error];
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
export interface AppConnections extends EventEmitter<AppConnectionEvents> {
|
|
164
|
+
send(connectionId: string, message: Message): void;
|
|
165
|
+
}
|
package/dist/cli.d.ts
DELETED
package/dist/cli.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.js
DELETED
|
@@ -1,399 +0,0 @@
|
|
|
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 { DEFAULT_SOCKET_PATH } from "./protocol/types.js";
|
|
9
|
-
import { SocketServer } from "./socket-server.js";
|
|
10
|
-
const require = createRequire(import.meta.url);
|
|
11
|
-
const { version } = require("../package.json");
|
|
12
|
-
const AppIdSchema = z.object({
|
|
13
|
-
appId: z.string().optional().describe("App ID to query. If not specified, uses the first connected app."),
|
|
14
|
-
});
|
|
15
|
-
const ListAppsInputSchema = z.object({
|
|
16
|
-
waitForApps: z
|
|
17
|
-
.boolean()
|
|
18
|
-
.optional()
|
|
19
|
-
.describe("If true, wait for at least one app to register before returning. Useful when app is still starting."),
|
|
20
|
-
timeout: z.number().optional().describe("Timeout in milliseconds when waitForApps is true (default: 10000)"),
|
|
21
|
-
});
|
|
22
|
-
const GetWidgetTreeInputSchema = AppIdSchema;
|
|
23
|
-
const QueryWidgetsInputSchema = AppIdSchema.extend({
|
|
24
|
-
by: z.enum(["role", "text", "name", "labelText"]).describe("Query type"),
|
|
25
|
-
value: z.union([z.string(), z.number()]).describe("Value to search for"),
|
|
26
|
-
options: z
|
|
27
|
-
.object({
|
|
28
|
-
name: z.string().optional(),
|
|
29
|
-
exact: z.boolean().optional(),
|
|
30
|
-
timeout: z.number().optional(),
|
|
31
|
-
})
|
|
32
|
-
.optional()
|
|
33
|
-
.describe("Additional query options"),
|
|
34
|
-
});
|
|
35
|
-
const WidgetIdSchema = AppIdSchema.extend({
|
|
36
|
-
widgetId: z.string().describe("Widget ID"),
|
|
37
|
-
});
|
|
38
|
-
const GetWidgetPropsInputSchema = WidgetIdSchema;
|
|
39
|
-
const ClickInputSchema = WidgetIdSchema;
|
|
40
|
-
const TypeInputSchema = WidgetIdSchema.extend({
|
|
41
|
-
text: z.string().describe("Text to type"),
|
|
42
|
-
clear: z.boolean().optional().describe("Clear existing text before typing"),
|
|
43
|
-
});
|
|
44
|
-
const FireEventInputSchema = WidgetIdSchema.extend({
|
|
45
|
-
signal: z.string().describe("GTK signal name to emit"),
|
|
46
|
-
args: z.array(z.unknown()).optional().describe("Arguments to pass to the signal"),
|
|
47
|
-
});
|
|
48
|
-
const TakeScreenshotInputSchema = AppIdSchema.extend({
|
|
49
|
-
windowId: z.string().optional().describe("Window ID to capture. If not specified, captures the first window."),
|
|
50
|
-
});
|
|
51
|
-
const tools = [
|
|
52
|
-
{
|
|
53
|
-
name: "gtkx_list_apps",
|
|
54
|
-
description: "List all connected GTKX applications",
|
|
55
|
-
inputSchema: {
|
|
56
|
-
type: "object",
|
|
57
|
-
properties: {
|
|
58
|
-
waitForApps: {
|
|
59
|
-
type: "boolean",
|
|
60
|
-
description: "If true, wait for at least one app to register before returning. Useful when app is still starting.",
|
|
61
|
-
},
|
|
62
|
-
timeout: {
|
|
63
|
-
type: "number",
|
|
64
|
-
description: "Timeout in milliseconds when waitForApps is true (default: 10000)",
|
|
65
|
-
},
|
|
66
|
-
},
|
|
67
|
-
required: [],
|
|
68
|
-
},
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
name: "gtkx_get_widget_tree",
|
|
72
|
-
description: "Get the widget hierarchy for a connected GTKX app. Returns a tree of all widgets with their IDs, types, roles, 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
|
-
},
|
|
81
|
-
required: [],
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
name: "gtkx_query_widgets",
|
|
86
|
-
description: "Find widgets by role, text, name, or label. Returns matching widgets with their IDs and properties.",
|
|
87
|
-
inputSchema: {
|
|
88
|
-
type: "object",
|
|
89
|
-
properties: {
|
|
90
|
-
appId: {
|
|
91
|
-
type: "string",
|
|
92
|
-
description: "App ID to query. If not specified, uses the first connected app.",
|
|
93
|
-
},
|
|
94
|
-
by: {
|
|
95
|
-
type: "string",
|
|
96
|
-
enum: ["role", "text", "name", "labelText"],
|
|
97
|
-
description: "Query type",
|
|
98
|
-
},
|
|
99
|
-
value: {
|
|
100
|
-
oneOf: [{ type: "string" }, { type: "number" }],
|
|
101
|
-
description: "Value to search for",
|
|
102
|
-
},
|
|
103
|
-
options: {
|
|
104
|
-
type: "object",
|
|
105
|
-
properties: {
|
|
106
|
-
name: { type: "string" },
|
|
107
|
-
exact: { type: "boolean" },
|
|
108
|
-
timeout: { type: "number" },
|
|
109
|
-
},
|
|
110
|
-
description: "Additional query options",
|
|
111
|
-
},
|
|
112
|
-
},
|
|
113
|
-
required: ["by", "value"],
|
|
114
|
-
},
|
|
115
|
-
},
|
|
116
|
-
{
|
|
117
|
-
name: "gtkx_get_widget_props",
|
|
118
|
-
description: "Get all properties of a specific widget by its ID",
|
|
119
|
-
inputSchema: {
|
|
120
|
-
type: "object",
|
|
121
|
-
properties: {
|
|
122
|
-
appId: {
|
|
123
|
-
type: "string",
|
|
124
|
-
description: "App ID to query. If not specified, uses the first connected app.",
|
|
125
|
-
},
|
|
126
|
-
widgetId: {
|
|
127
|
-
type: "string",
|
|
128
|
-
description: "Widget ID to get properties for",
|
|
129
|
-
},
|
|
130
|
-
},
|
|
131
|
-
required: ["widgetId"],
|
|
132
|
-
},
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
name: "gtkx_click",
|
|
136
|
-
description: "Click a widget. Works with buttons, checkboxes, and other interactive widgets.",
|
|
137
|
-
inputSchema: {
|
|
138
|
-
type: "object",
|
|
139
|
-
properties: {
|
|
140
|
-
appId: {
|
|
141
|
-
type: "string",
|
|
142
|
-
description: "App ID to query. If not specified, uses the first connected app.",
|
|
143
|
-
},
|
|
144
|
-
widgetId: {
|
|
145
|
-
type: "string",
|
|
146
|
-
description: "Widget ID to click",
|
|
147
|
-
},
|
|
148
|
-
},
|
|
149
|
-
required: ["widgetId"],
|
|
150
|
-
},
|
|
151
|
-
},
|
|
152
|
-
{
|
|
153
|
-
name: "gtkx_type",
|
|
154
|
-
description: "Type text into an editable widget like Entry or TextView",
|
|
155
|
-
inputSchema: {
|
|
156
|
-
type: "object",
|
|
157
|
-
properties: {
|
|
158
|
-
appId: {
|
|
159
|
-
type: "string",
|
|
160
|
-
description: "App ID to query. If not specified, uses the first connected app.",
|
|
161
|
-
},
|
|
162
|
-
widgetId: {
|
|
163
|
-
type: "string",
|
|
164
|
-
description: "Widget ID to type into",
|
|
165
|
-
},
|
|
166
|
-
text: {
|
|
167
|
-
type: "string",
|
|
168
|
-
description: "Text to type",
|
|
169
|
-
},
|
|
170
|
-
clear: {
|
|
171
|
-
type: "boolean",
|
|
172
|
-
description: "Clear existing text before typing",
|
|
173
|
-
},
|
|
174
|
-
},
|
|
175
|
-
required: ["widgetId", "text"],
|
|
176
|
-
},
|
|
177
|
-
},
|
|
178
|
-
{
|
|
179
|
-
name: "gtkx_fire_event",
|
|
180
|
-
description: "Emit a GTK signal on a widget. Use this for custom interactions.",
|
|
181
|
-
inputSchema: {
|
|
182
|
-
type: "object",
|
|
183
|
-
properties: {
|
|
184
|
-
appId: {
|
|
185
|
-
type: "string",
|
|
186
|
-
description: "App ID to query. If not specified, uses the first connected app.",
|
|
187
|
-
},
|
|
188
|
-
widgetId: {
|
|
189
|
-
type: "string",
|
|
190
|
-
description: "Widget ID to emit event on",
|
|
191
|
-
},
|
|
192
|
-
signal: {
|
|
193
|
-
type: "string",
|
|
194
|
-
description: "GTK signal name to emit",
|
|
195
|
-
},
|
|
196
|
-
args: {
|
|
197
|
-
type: "array",
|
|
198
|
-
items: {},
|
|
199
|
-
description: "Arguments to pass to the signal",
|
|
200
|
-
},
|
|
201
|
-
},
|
|
202
|
-
required: ["widgetId", "signal"],
|
|
203
|
-
},
|
|
204
|
-
},
|
|
205
|
-
{
|
|
206
|
-
name: "gtkx_take_screenshot",
|
|
207
|
-
description: "Capture a screenshot of a window. Returns base64-encoded PNG image data.",
|
|
208
|
-
inputSchema: {
|
|
209
|
-
type: "object",
|
|
210
|
-
properties: {
|
|
211
|
-
appId: {
|
|
212
|
-
type: "string",
|
|
213
|
-
description: "App ID to query. If not specified, uses the first connected app.",
|
|
214
|
-
},
|
|
215
|
-
windowId: {
|
|
216
|
-
type: "string",
|
|
217
|
-
description: "Window ID to capture. If not specified, captures the first window.",
|
|
218
|
-
},
|
|
219
|
-
},
|
|
220
|
-
required: [],
|
|
221
|
-
},
|
|
222
|
-
},
|
|
223
|
-
];
|
|
224
|
-
async function main() {
|
|
225
|
-
const socketServer = new SocketServer(DEFAULT_SOCKET_PATH);
|
|
226
|
-
const connectionManager = new ConnectionManager(socketServer);
|
|
227
|
-
socketServer.on("error", (error) => {
|
|
228
|
-
const code = error.code;
|
|
229
|
-
if (code !== "EPIPE" && code !== "ECONNRESET") {
|
|
230
|
-
console.error("[gtkx] Socket error:", error.message);
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
await socketServer.start();
|
|
234
|
-
console.error(`[gtkx] Socket server listening on ${DEFAULT_SOCKET_PATH}`);
|
|
235
|
-
connectionManager.on("appRegistered", (appInfo) => {
|
|
236
|
-
console.error(`[gtkx] App registered: ${appInfo.appId} (PID: ${appInfo.pid})`);
|
|
237
|
-
});
|
|
238
|
-
connectionManager.on("appUnregistered", (appId) => {
|
|
239
|
-
console.error(`[gtkx] App unregistered: ${appId}`);
|
|
240
|
-
});
|
|
241
|
-
const server = new Server({
|
|
242
|
-
name: "gtkx-mcp",
|
|
243
|
-
version,
|
|
244
|
-
}, {
|
|
245
|
-
capabilities: {
|
|
246
|
-
tools: {},
|
|
247
|
-
},
|
|
248
|
-
});
|
|
249
|
-
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
250
|
-
return { tools };
|
|
251
|
-
});
|
|
252
|
-
server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
253
|
-
const { name, arguments: args } = request.params;
|
|
254
|
-
try {
|
|
255
|
-
switch (name) {
|
|
256
|
-
case "gtkx_list_apps": {
|
|
257
|
-
const input = ListAppsInputSchema.parse(args);
|
|
258
|
-
if (input.waitForApps && !connectionManager.hasConnectedApps()) {
|
|
259
|
-
try {
|
|
260
|
-
await connectionManager.waitForApp(input.timeout);
|
|
261
|
-
}
|
|
262
|
-
catch (error) {
|
|
263
|
-
return {
|
|
264
|
-
content: [
|
|
265
|
-
{
|
|
266
|
-
type: "text",
|
|
267
|
-
text: error instanceof Error ? error.message : "Timeout waiting for app",
|
|
268
|
-
},
|
|
269
|
-
],
|
|
270
|
-
isError: true,
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
const apps = connectionManager.getApps();
|
|
275
|
-
const appsWithWindows = await Promise.all(apps.map(async (app) => {
|
|
276
|
-
try {
|
|
277
|
-
const result = await connectionManager.sendToApp(app.appId, "app.getWindows", {});
|
|
278
|
-
return { ...app, windows: result.windows };
|
|
279
|
-
}
|
|
280
|
-
catch {
|
|
281
|
-
return app;
|
|
282
|
-
}
|
|
283
|
-
}));
|
|
284
|
-
return {
|
|
285
|
-
content: [{ type: "text", text: JSON.stringify(appsWithWindows, null, 2) }],
|
|
286
|
-
};
|
|
287
|
-
}
|
|
288
|
-
case "gtkx_get_widget_tree": {
|
|
289
|
-
const input = GetWidgetTreeInputSchema.parse(args);
|
|
290
|
-
const result = await connectionManager.sendToApp(input.appId, "widget.getTree", {});
|
|
291
|
-
return {
|
|
292
|
-
content: [{ type: "text", text: result.tree }],
|
|
293
|
-
};
|
|
294
|
-
}
|
|
295
|
-
case "gtkx_query_widgets": {
|
|
296
|
-
const input = QueryWidgetsInputSchema.parse(args);
|
|
297
|
-
const result = await connectionManager.sendToApp(input.appId, "widget.query", {
|
|
298
|
-
queryType: input.by,
|
|
299
|
-
value: input.value,
|
|
300
|
-
options: input.options,
|
|
301
|
-
});
|
|
302
|
-
return {
|
|
303
|
-
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
case "gtkx_get_widget_props": {
|
|
307
|
-
const input = GetWidgetPropsInputSchema.parse(args);
|
|
308
|
-
const result = await connectionManager.sendToApp(input.appId, "widget.getProps", {
|
|
309
|
-
widgetId: input.widgetId,
|
|
310
|
-
});
|
|
311
|
-
return {
|
|
312
|
-
content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
|
|
313
|
-
};
|
|
314
|
-
}
|
|
315
|
-
case "gtkx_click": {
|
|
316
|
-
const input = ClickInputSchema.parse(args);
|
|
317
|
-
await connectionManager.sendToApp(input.appId, "widget.click", {
|
|
318
|
-
widgetId: input.widgetId,
|
|
319
|
-
});
|
|
320
|
-
return {
|
|
321
|
-
content: [{ type: "text", text: "Click successful" }],
|
|
322
|
-
};
|
|
323
|
-
}
|
|
324
|
-
case "gtkx_type": {
|
|
325
|
-
const input = TypeInputSchema.parse(args);
|
|
326
|
-
await connectionManager.sendToApp(input.appId, "widget.type", {
|
|
327
|
-
widgetId: input.widgetId,
|
|
328
|
-
text: input.text,
|
|
329
|
-
clear: input.clear,
|
|
330
|
-
});
|
|
331
|
-
return {
|
|
332
|
-
content: [{ type: "text", text: "Type successful" }],
|
|
333
|
-
};
|
|
334
|
-
}
|
|
335
|
-
case "gtkx_fire_event": {
|
|
336
|
-
const input = FireEventInputSchema.parse(args);
|
|
337
|
-
await connectionManager.sendToApp(input.appId, "widget.fireEvent", {
|
|
338
|
-
widgetId: input.widgetId,
|
|
339
|
-
signal: input.signal,
|
|
340
|
-
args: input.args,
|
|
341
|
-
});
|
|
342
|
-
return {
|
|
343
|
-
content: [{ type: "text", text: "Event fired successfully" }],
|
|
344
|
-
};
|
|
345
|
-
}
|
|
346
|
-
case "gtkx_take_screenshot": {
|
|
347
|
-
const input = TakeScreenshotInputSchema.parse(args);
|
|
348
|
-
const result = await connectionManager.sendToApp(input.appId, "widget.screenshot", {
|
|
349
|
-
windowId: input.windowId,
|
|
350
|
-
});
|
|
351
|
-
return {
|
|
352
|
-
content: [
|
|
353
|
-
{
|
|
354
|
-
type: "image",
|
|
355
|
-
data: result.data,
|
|
356
|
-
mimeType: result.mimeType,
|
|
357
|
-
},
|
|
358
|
-
],
|
|
359
|
-
};
|
|
360
|
-
}
|
|
361
|
-
default:
|
|
362
|
-
return {
|
|
363
|
-
content: [{ type: "text", text: `Unknown tool: ${name}` }],
|
|
364
|
-
isError: true,
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
catch (error) {
|
|
369
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
370
|
-
return {
|
|
371
|
-
content: [{ type: "text", text: message }],
|
|
372
|
-
isError: true,
|
|
373
|
-
};
|
|
374
|
-
}
|
|
375
|
-
});
|
|
376
|
-
const transport = new StdioServerTransport();
|
|
377
|
-
await server.connect(transport);
|
|
378
|
-
let isShuttingDown = false;
|
|
379
|
-
const shutdown = async () => {
|
|
380
|
-
if (isShuttingDown)
|
|
381
|
-
return;
|
|
382
|
-
isShuttingDown = true;
|
|
383
|
-
try {
|
|
384
|
-
connectionManager.cleanup();
|
|
385
|
-
await socketServer.stop();
|
|
386
|
-
await server.close();
|
|
387
|
-
}
|
|
388
|
-
finally {
|
|
389
|
-
process.exit(0);
|
|
390
|
-
}
|
|
391
|
-
};
|
|
392
|
-
process.on("SIGINT", shutdown);
|
|
393
|
-
process.on("SIGTERM", shutdown);
|
|
394
|
-
}
|
|
395
|
-
main().catch((error) => {
|
|
396
|
-
console.error("[gtkx] Fatal error:", error);
|
|
397
|
-
process.exit(1);
|
|
398
|
-
});
|
|
399
|
-
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","sourceRoot":"","sources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AAG,IAAI,CAAC;QACtB,IAAI,CAAC;YACD,iBAAiB,CAAC,OAAO,EAAE,CAAC;YAC5B,MAAM,YAAY,CAAC,IAAI,EAAE,CAAC;YAC1B,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;QACzB,CAAC;gBAAS,CAAC;YACP,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,CAAC;IACL,CAAC,CAAC;IAEF,OAAO,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAC/B,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;AACpC,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACnB,OAAO,CAAC,KAAK,CAAC,qBAAqB,EAAE,KAAK,CAAC,CAAC;IAC5C,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACpB,CAAC,CAAC,CAAC"}
|
|
@@ -1,48 +0,0 @@
|
|
|
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
|
-
type RegisteredApp = {
|
|
9
|
-
info: AppInfo;
|
|
10
|
-
connection: AppConnection;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Manages connections between the MCP server and GTKX applications.
|
|
14
|
-
*
|
|
15
|
-
* Handles app registration, request routing, and connection lifecycle.
|
|
16
|
-
*/
|
|
17
|
-
export declare class ConnectionManager extends EventEmitter<ConnectionManagerEventMap> {
|
|
18
|
-
private socketServer;
|
|
19
|
-
private static readonly DEFAULT_WAIT_TIMEOUT;
|
|
20
|
-
private apps;
|
|
21
|
-
private connectionToApp;
|
|
22
|
-
private pendingRequests;
|
|
23
|
-
private requestTimeout;
|
|
24
|
-
constructor(socketServer: SocketServer, options?: {
|
|
25
|
-
requestTimeout?: number;
|
|
26
|
-
});
|
|
27
|
-
getApps(): AppInfo[];
|
|
28
|
-
getApp(appId: string): AppInfo | undefined;
|
|
29
|
-
hasConnectedApps(): boolean;
|
|
30
|
-
getDefaultApp(): RegisteredApp | undefined;
|
|
31
|
-
/**
|
|
32
|
-
* Waits for at least one app to connect and register.
|
|
33
|
-
*
|
|
34
|
-
* @param timeout - Maximum time to wait in milliseconds (default: 10000)
|
|
35
|
-
* @returns Promise that resolves with the first registered app info
|
|
36
|
-
* @throws Error if timeout is reached before any app registers
|
|
37
|
-
*/
|
|
38
|
-
waitForApp(timeout?: number): Promise<AppInfo>;
|
|
39
|
-
sendToApp<T>(appId: string | undefined, method: string, params?: unknown): Promise<T>;
|
|
40
|
-
cleanup(): void;
|
|
41
|
-
private handleRequest;
|
|
42
|
-
private handleResponse;
|
|
43
|
-
private handleRegister;
|
|
44
|
-
private handleUnregister;
|
|
45
|
-
private handleDisconnection;
|
|
46
|
-
}
|
|
47
|
-
export {};
|
|
48
|
-
//# sourceMappingURL=connection-manager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connection-manager.d.ts","sourceRoot":"","sources":["../src/connection-manager.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,aAAa,CAAC;AASvC,OAAO,EAAE,KAAK,OAAO,EAA2D,MAAM,qBAAqB,CAAC;AAC5G,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEtE,KAAK,yBAAyB,GAAG;IAC7B,aAAa,EAAE,CAAC,OAAO,CAAC,CAAC;IACzB,eAAe,EAAE,CAAC,MAAM,CAAC,CAAC;CAC7B,CAAC;AAQF,KAAK,aAAa,GAAG;IACjB,IAAI,EAAE,OAAO,CAAC;IACd,UAAU,EAAE,aAAa,CAAC;CAC7B,CAAC;AAEF;;;;GAIG;AACH,q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