@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.
Files changed (73) hide show
  1. package/README.md +137 -34
  2. package/bin/gtkx-mcp.js +9 -1
  3. package/dist/app-router.d.ts +35 -0
  4. package/dist/app-router.d.ts.map +1 -0
  5. package/dist/app-router.js +143 -0
  6. package/dist/app-router.js.map +1 -0
  7. package/dist/connection-registry.d.ts +12 -0
  8. package/dist/connection-registry.d.ts.map +1 -0
  9. package/dist/connection-registry.js +39 -0
  10. package/dist/connection-registry.js.map +1 -0
  11. package/dist/internal.d.ts +4 -0
  12. package/dist/internal.d.ts.map +1 -0
  13. package/dist/internal.js +4 -0
  14. package/dist/internal.js.map +1 -0
  15. package/dist/protocol/errors.d.ts +25 -87
  16. package/dist/protocol/errors.d.ts.map +1 -1
  17. package/dist/protocol/errors.js +38 -101
  18. package/dist/protocol/errors.js.map +1 -1
  19. package/dist/protocol/schemas.d.ts +93 -0
  20. package/dist/protocol/schemas.d.ts.map +1 -0
  21. package/dist/protocol/schemas.js +63 -0
  22. package/dist/protocol/schemas.js.map +1 -0
  23. package/dist/reference.d.ts +13 -0
  24. package/dist/reference.d.ts.map +1 -0
  25. package/dist/reference.js +293 -0
  26. package/dist/reference.js.map +1 -0
  27. package/dist/server.d.ts +14 -0
  28. package/dist/server.d.ts.map +1 -0
  29. package/dist/server.js +244 -0
  30. package/dist/server.js.map +1 -0
  31. package/dist/socket-server.d.ts +5 -38
  32. package/dist/socket-server.d.ts.map +1 -1
  33. package/dist/socket-server.js +36 -108
  34. package/dist/socket-server.js.map +1 -1
  35. package/dist/tool.d.ts +22 -0
  36. package/dist/tool.d.ts.map +1 -0
  37. package/dist/tool.js +40 -0
  38. package/dist/tool.js.map +1 -0
  39. package/dist/transport.d.ts +49 -0
  40. package/dist/transport.d.ts.map +1 -0
  41. package/dist/transport.js +152 -0
  42. package/dist/transport.js.map +1 -0
  43. package/package.json +15 -11
  44. package/src/app-router.ts +209 -0
  45. package/src/connection-registry.ts +57 -0
  46. package/src/internal.ts +17 -0
  47. package/src/protocol/errors.ts +67 -110
  48. package/src/protocol/schemas.ts +173 -0
  49. package/src/reference.ts +449 -0
  50. package/src/server.ts +334 -0
  51. package/src/socket-server.ts +46 -147
  52. package/src/tool.ts +73 -0
  53. package/src/transport.ts +242 -0
  54. package/dist/cli.d.ts +0 -3
  55. package/dist/cli.d.ts.map +0 -1
  56. package/dist/cli.js +0 -399
  57. package/dist/cli.js.map +0 -1
  58. package/dist/connection-manager.d.ts +0 -48
  59. package/dist/connection-manager.d.ts.map +0 -1
  60. package/dist/connection-manager.js +0 -185
  61. package/dist/connection-manager.js.map +0 -1
  62. package/dist/index.d.ts +0 -5
  63. package/dist/index.d.ts.map +0 -1
  64. package/dist/index.js +0 -5
  65. package/dist/index.js.map +0 -1
  66. package/dist/protocol/types.d.ts +0 -132
  67. package/dist/protocol/types.d.ts.map +0 -1
  68. package/dist/protocol/types.js +0 -46
  69. package/dist/protocol/types.js.map +0 -1
  70. package/src/cli.ts +0 -449
  71. package/src/connection-manager.ts +0 -247
  72. package/src/index.ts +0 -27
  73. package/src/protocol/types.ts +0 -153
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/protocol/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,YAAY;IACpB,4BAA4B;IAC5B,cAAc,OAAO;IACrB,uCAAuC;IACvC,gBAAgB,OAAO;IACvB,6CAA6C;IAC7C,aAAa,OAAO;IACpB,6CAA6C;IAC7C,gBAAgB,OAAO;IACvB,uCAAuC;IACvC,uBAAuB,OAAO;IAC9B,yCAAyC;IACzC,aAAa,OAAO;IACpB,sCAAsC;IACtC,mBAAmB,OAAO;IAC1B,gCAAgC;IAChC,iBAAiB,OAAO;IACxB,4BAA4B;IAC5B,WAAW,OAAO;IAClB,+BAA+B;IAC/B,mBAAmB,OAAO;IAC1B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I,aAAa,CAM5C;AAED,iBAAS,gBAAgB,CAAC,aAAa,EAAE,MAAM,GAAG,aAAa,CAE9D;AAED,iBAAS,0BAA0B,CAAC,aAAa,EAAE,MAAM,GAAG,aAAa,CAMxE;AAED,iBAAS,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,aAAa,CAE5D;AAED,iBAAS,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,aAAa,CAE3D;AAED,iBAAS,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,CAE1D;AAED,iBAAS,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,CAE1D;AAED,cAAM,aAAc,SAAQ,KAAK;IAC7B,IAAI,EAAE,SAAS,CAAC;IAChB,IAAI,CAAC,EAAE,OAAO,CAAC;gBAEH,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO;IAO5D,aAAa,IAAI;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE;CAOrE;AAED,OAAO,EACH,SAAS,EACT,WAAW,EACX,mBAAmB,EACnB,gBAAgB,EAChB,0BAA0B,EAC1B,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,aAAa,GAChB,CAAC"}
@@ -1,58 +1,47 @@
1
- /**
2
- * Error codes for MCP protocol errors.
3
- */
4
- export var McpErrorCode;
5
- (function (McpErrorCode) {
6
- /** Internal server error */
7
- McpErrorCode[McpErrorCode["INTERNAL_ERROR"] = 1000] = "INTERNAL_ERROR";
8
- /** No GTKX application is connected */
9
- McpErrorCode[McpErrorCode["NO_APP_CONNECTED"] = 1001] = "NO_APP_CONNECTED";
10
- /** Requested application ID was not found */
11
- McpErrorCode[McpErrorCode["APP_NOT_FOUND"] = 1002] = "APP_NOT_FOUND";
12
- /** Widget with specified ID was not found */
13
- McpErrorCode[McpErrorCode["WIDGET_NOT_FOUND"] = 1003] = "WIDGET_NOT_FOUND";
14
- /** Widget cannot be interacted with */
15
- McpErrorCode[McpErrorCode["WIDGET_NOT_INTERACTABLE"] = 1004] = "WIDGET_NOT_INTERACTABLE";
16
- /** Query timed out waiting for widget */
17
- McpErrorCode[McpErrorCode["QUERY_TIMEOUT"] = 1005] = "QUERY_TIMEOUT";
18
- /** Widget is not the expected type */
19
- McpErrorCode[McpErrorCode["INVALID_WIDGET_TYPE"] = 1006] = "INVALID_WIDGET_TYPE";
20
- /** Screenshot capture failed */
21
- McpErrorCode[McpErrorCode["SCREENSHOT_FAILED"] = 1007] = "SCREENSHOT_FAILED";
22
- /** IPC request timed out */
23
- McpErrorCode[McpErrorCode["IPC_TIMEOUT"] = 1008] = "IPC_TIMEOUT";
24
- /** Failed to serialize data */
25
- McpErrorCode[McpErrorCode["SERIALIZATION_ERROR"] = 1009] = "SERIALIZATION_ERROR";
26
- /** Request format is invalid */
27
- McpErrorCode[McpErrorCode["INVALID_REQUEST"] = 1010] = "INVALID_REQUEST";
28
- /** Requested method does not exist */
29
- McpErrorCode[McpErrorCode["METHOD_NOT_FOUND"] = 1011] = "METHOD_NOT_FOUND";
30
- })(McpErrorCode || (McpErrorCode = {}));
31
- /**
32
- * Error class for MCP protocol errors.
33
- *
34
- * Contains an error code, message, and optional additional data.
35
- */
36
- export class McpError extends Error {
37
- /** The MCP error code */
1
+ const ErrorCode = {
2
+ INTERNAL_ERROR: 1000,
3
+ NO_APP_CONNECTED: 1001,
4
+ APP_NOT_FOUND: 1002,
5
+ WIDGET_NOT_FOUND: 1003,
6
+ CONNECTION_WRITE_FAILED: 1004,
7
+ REQUEST_TIMEOUT: 1005,
8
+ INVALID_REQUEST: 1006,
9
+ METHOD_NOT_FOUND: 1007,
10
+ };
11
+ function isErrorCode(code) {
12
+ return Object.values(ErrorCode).includes(code);
13
+ }
14
+ function noAppConnectedError() {
15
+ return new ProtocolError(ErrorCode.NO_APP_CONNECTED, "No GTKX application connected: start an app with 'gtkx dev' to connect", { hint: "Run 'gtkx dev' in your project directory" });
16
+ }
17
+ function appNotFoundError(applicationId) {
18
+ return new ProtocolError(ErrorCode.APP_NOT_FOUND, `Application '${applicationId}' not found`, { applicationId });
19
+ }
20
+ function connectionWriteFailedError(applicationId) {
21
+ return new ProtocolError(ErrorCode.CONNECTION_WRITE_FAILED, `Connection to application '${applicationId}' is no longer writable`, { applicationId });
22
+ }
23
+ function widgetNotFoundError(widgetId) {
24
+ return new ProtocolError(ErrorCode.WIDGET_NOT_FOUND, `Widget '${widgetId}' not found`, { widgetId });
25
+ }
26
+ function requestTimeoutError(timeout) {
27
+ return new ProtocolError(ErrorCode.REQUEST_TIMEOUT, `Request timed out after ${String(timeout)}ms`, { timeout });
28
+ }
29
+ function invalidRequestError(reason) {
30
+ return new ProtocolError(ErrorCode.INVALID_REQUEST, `Invalid request: ${reason}`, { reason });
31
+ }
32
+ function methodNotFoundError(method) {
33
+ return new ProtocolError(ErrorCode.METHOD_NOT_FOUND, `Method '${method}' not found`, { method });
34
+ }
35
+ class ProtocolError extends Error {
38
36
  code;
39
- /** Additional error context */
40
37
  data;
41
38
  constructor(code, message, data) {
42
39
  super(message);
43
40
  this.code = code;
44
41
  this.data = data;
45
- this.name = "McpError";
46
- if (Error.captureStackTrace) {
47
- Error.captureStackTrace(this, McpError);
48
- }
42
+ this.name = "ProtocolError";
49
43
  }
50
- /**
51
- * Converts the error to an IPC-compatible format.
52
- *
53
- * @returns Object suitable for IPC response error field
54
- */
55
- toIpcError() {
44
+ toErrorObject() {
56
45
  return {
57
46
  code: this.code,
58
47
  message: this.message,
@@ -60,57 +49,5 @@ export class McpError extends Error {
60
49
  };
61
50
  }
62
51
  }
63
- /**
64
- * Creates an error for when no GTKX application is connected.
65
- *
66
- * @returns McpError with NO_APP_CONNECTED code
67
- */
68
- export function noAppConnectedError() {
69
- 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" });
70
- }
71
- /**
72
- * Creates an error for when a requested app is not found.
73
- *
74
- * @param appId - The application ID that was not found
75
- * @returns McpError with APP_NOT_FOUND code
76
- */
77
- export function appNotFoundError(appId) {
78
- return new McpError(McpErrorCode.APP_NOT_FOUND, `Application '${appId}' not found`, { appId });
79
- }
80
- /**
81
- * Creates an error for when a widget is not found.
82
- *
83
- * @param widgetId - The widget ID that was not found
84
- * @returns McpError with WIDGET_NOT_FOUND code
85
- */
86
- export function widgetNotFoundError(widgetId) {
87
- return new McpError(McpErrorCode.WIDGET_NOT_FOUND, `Widget '${widgetId}' not found`, { widgetId });
88
- }
89
- /**
90
- * Creates an error for when an IPC request times out.
91
- *
92
- * @param timeout - The timeout duration in milliseconds
93
- * @returns McpError with IPC_TIMEOUT code
94
- */
95
- export function ipcTimeoutError(timeout) {
96
- return new McpError(McpErrorCode.IPC_TIMEOUT, `IPC request timed out after ${timeout}ms`, { timeout });
97
- }
98
- /**
99
- * Creates an error for invalid request format.
100
- *
101
- * @param reason - Description of why the request is invalid
102
- * @returns McpError with INVALID_REQUEST code
103
- */
104
- export function invalidRequestError(reason) {
105
- return new McpError(McpErrorCode.INVALID_REQUEST, `Invalid request: ${reason}`, { reason });
106
- }
107
- /**
108
- * Creates an error for when a method is not found.
109
- *
110
- * @param method - The method name that was not found
111
- * @returns McpError with METHOD_NOT_FOUND code
112
- */
113
- export function methodNotFoundError(method) {
114
- return new McpError(McpErrorCode.METHOD_NOT_FOUND, `Method '${method}' not found`, { method });
115
- }
52
+ export { ErrorCode, isErrorCode, noAppConnectedError, appNotFoundError, connectionWriteFailedError, widgetNotFoundError, requestTimeoutError, invalidRequestError, methodNotFoundError, ProtocolError, };
116
53
  //# sourceMappingURL=errors.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/protocol/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAN,IAAY,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Aa,CAAC,SAAS,CAAC,gBAAgB,EAAE,WAAW,MAAM,aAAa,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;AACrG,CAAC;AAED,MAAM,aAAc,SAAQ,KAAK;IAC7B,IAAI,CAAY;IAChB,IAAI,CAAW;IAEf,YAAY,IAAe,EAAE,OAAe,EAAE,IAAc;QACxD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAChC,CAAC;IAED,aAAa;QACT,OAAO;YACH,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,GAAG,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC;SACtD,CAAC;IACN,CAAC;CACJ;AAED,OAAO,EACH,SAAS,EACT,WAAW,EACX,mBAAmB,EACnB,gBAAgB,EAChB,0BAA0B,EAC1B,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,mBAAmB,EACnB,aAAa,GAChB,CAAC","sourcesContent":["type ErrorCode = (typeof ErrorCode)[keyof typeof ErrorCode];\n\nconst ErrorCode = {\n INTERNAL_ERROR: 1000,\n NO_APP_CONNECTED: 1001,\n APP_NOT_FOUND: 1002,\n WIDGET_NOT_FOUND: 1003,\n CONNECTION_WRITE_FAILED: 1004,\n REQUEST_TIMEOUT: 1005,\n INVALID_REQUEST: 1006,\n METHOD_NOT_FOUND: 1007,\n} as const;\n\nfunction isErrorCode(code: number): code is ErrorCode {\n return (Object.values(ErrorCode) as number[]).includes(code);\n}\n\nfunction noAppConnectedError(): ProtocolError {\n return new ProtocolError(\n ErrorCode.NO_APP_CONNECTED,\n \"No GTKX application connected: start an app with 'gtkx dev' to connect\",\n { hint: \"Run 'gtkx dev' in your project directory\" },\n );\n}\n\nfunction appNotFoundError(applicationId: string): ProtocolError {\n return new ProtocolError(ErrorCode.APP_NOT_FOUND, `Application '${applicationId}' not found`, { applicationId });\n}\n\nfunction connectionWriteFailedError(applicationId: string): ProtocolError {\n return new ProtocolError(\n ErrorCode.CONNECTION_WRITE_FAILED,\n `Connection to application '${applicationId}' is no longer writable`,\n { applicationId },\n );\n}\n\nfunction widgetNotFoundError(widgetId: string): ProtocolError {\n return new ProtocolError(ErrorCode.WIDGET_NOT_FOUND, `Widget '${widgetId}' not found`, { widgetId });\n}\n\nfunction requestTimeoutError(timeout: number): ProtocolError {\n return new ProtocolError(ErrorCode.REQUEST_TIMEOUT, `Request timed out after ${String(timeout)}ms`, { timeout });\n}\n\nfunction invalidRequestError(reason: string): ProtocolError {\n return new ProtocolError(ErrorCode.INVALID_REQUEST, `Invalid request: ${reason}`, { reason });\n}\n\nfunction methodNotFoundError(method: string): ProtocolError {\n return new ProtocolError(ErrorCode.METHOD_NOT_FOUND, `Method '${method}' not found`, { method });\n}\n\nclass ProtocolError extends Error {\n code: ErrorCode;\n data?: unknown;\n\n constructor(code: ErrorCode, message: string, data?: unknown) {\n super(message);\n this.code = code;\n this.data = data;\n this.name = \"ProtocolError\";\n }\n\n toErrorObject(): { code: number; message: string; data?: unknown } {\n return {\n code: this.code,\n message: this.message,\n ...(this.data !== undefined && { data: this.data }),\n };\n }\n}\n\nexport {\n ErrorCode,\n isErrorCode,\n noAppConnectedError,\n appNotFoundError,\n connectionWriteFailedError,\n widgetNotFoundError,\n requestTimeoutError,\n invalidRequestError,\n methodNotFoundError,\n ProtocolError,\n};\n"]}
@@ -0,0 +1,93 @@
1
+ import { z } from "zod";
2
+ type Request = z.infer<typeof RequestSchema>;
3
+ type Response = z.infer<typeof ResponseSchema>;
4
+ type SerializedWidget = {
5
+ id: string;
6
+ type: string;
7
+ role: string;
8
+ name: string | null;
9
+ text: string | null;
10
+ sensitive: boolean;
11
+ visible: boolean;
12
+ cssClasses: string[];
13
+ children: SerializedWidget[];
14
+ };
15
+ type AppInfo = {
16
+ applicationId: string;
17
+ pid: number;
18
+ projectRoot?: string;
19
+ };
20
+ type ServerRequestParams<Method extends keyof typeof ServerRequestParamsSchemas> = z.infer<(typeof ServerRequestParamsSchemas)[Method]>;
21
+ type ParamsSchema<Output> = z.ZodType<Output>;
22
+ type ServerInitiatedMethod = keyof typeof ServerRequestParamsSchemas;
23
+ type Message = Request | Response;
24
+ declare const RequestSchema: z.ZodObject<{
25
+ id: z.ZodString;
26
+ method: z.ZodString;
27
+ params: z.ZodOptional<z.ZodUnknown>;
28
+ }>;
29
+ declare const ErrorSchema: z.ZodObject<{
30
+ code: z.ZodNumber;
31
+ message: z.ZodString;
32
+ data: z.ZodOptional<z.ZodUnknown>;
33
+ }>;
34
+ declare const ResponseSchema: z.ZodObject<{
35
+ id: z.ZodString;
36
+ result: z.ZodOptional<z.ZodUnknown>;
37
+ error: z.ZodOptional<typeof ErrorSchema>;
38
+ }>;
39
+ declare const RegisterParamsSchema: z.ZodObject<{
40
+ applicationId: z.ZodString;
41
+ pid: z.ZodNumber;
42
+ projectRoot: z.ZodOptional<z.ZodString>;
43
+ }>;
44
+ declare const emptyParams: z.ZodObject<Record<string, never>>;
45
+ declare const widgetIdParams: z.ZodObject<{
46
+ widgetId: z.ZodString;
47
+ }>;
48
+ declare const treeParams: z.ZodObject<{
49
+ rootId: z.ZodOptional<z.ZodString>;
50
+ maxDepth: z.ZodOptional<z.ZodNumber>;
51
+ }>;
52
+ declare const queryOptionsSchema: z.ZodObject<{
53
+ name: z.ZodOptional<z.ZodString>;
54
+ exact: z.ZodOptional<z.ZodBoolean>;
55
+ timeout: z.ZodOptional<z.ZodNumber>;
56
+ }>;
57
+ declare const queryParams: z.ZodObject<{
58
+ by: z.ZodEnum<{
59
+ role: "role";
60
+ text: "text";
61
+ name: "name";
62
+ labelText: "labelText";
63
+ }>;
64
+ value: z.ZodUnion<[z.ZodString, z.ZodNumber]>;
65
+ options: z.ZodOptional<typeof queryOptionsSchema>;
66
+ }>;
67
+ declare const typeParams: z.ZodObject<{
68
+ widgetId: z.ZodString;
69
+ text: z.ZodString;
70
+ clear: z.ZodOptional<z.ZodBoolean>;
71
+ }>;
72
+ declare const fireEventParams: z.ZodObject<{
73
+ widgetId: z.ZodString;
74
+ signal: z.ZodString;
75
+ args: z.ZodOptional<z.ZodArray<z.ZodUnknown>>;
76
+ }>;
77
+ declare const screenshotParams: z.ZodObject<{
78
+ windowId: z.ZodOptional<z.ZodString>;
79
+ path: z.ZodOptional<z.ZodString>;
80
+ }>;
81
+ declare const ServerRequestParamsSchemas: {
82
+ "app.getWindows": typeof emptyParams;
83
+ "widget.getTree": typeof treeParams;
84
+ "widget.query": typeof queryParams;
85
+ "widget.getProps": typeof widgetIdParams;
86
+ "widget.click": typeof widgetIdParams;
87
+ "widget.type": typeof typeParams;
88
+ "widget.fireEvent": typeof fireEventParams;
89
+ "widget.screenshot": typeof screenshotParams;
90
+ };
91
+ declare const DEFAULT_SOCKET_PATH: string;
92
+ export { RequestSchema, ResponseSchema, RegisterParamsSchema, widgetIdParams, treeParams, queryOptionsSchema, queryParams, typeParams, fireEventParams, screenshotParams, ServerRequestParamsSchemas, DEFAULT_SOCKET_PATH, type Request, type Response, type SerializedWidget, type AppInfo, type ServerRequestParams, type ParamsSchema, type ServerInitiatedMethod, type Message, };
93
+ //# sourceMappingURL=schemas.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../src/protocol/schemas.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,KAAK,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAC7C,KAAK,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAE/C,KAAK,gBAAgB,GAAG;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAA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CAAC;IACnC,iBAAiB,EAAE,OAAO,cAAc,CAAC;IACzC,cAAc,EAAE,OAAO,cAAc,CAAC;IACtC,aAAa,EAAE,OAAO,UAAU,CAAC;IACjC,kBAAkB,EAAE,OAAO,eAAe,CAAC;IAC3C,mBAAmB,EAAE,OAAO,gBAAgB,CAAC;CAUhD,CAAC;AAEF,QAAA,MAAM,mBAAmB,EAAE,MAA+C,CAAC;AAM3E,OAAO,EACH,aAAa,EACb,cAAc,EACd,oBAAoB,EACpB,cAAc,EACd,UAAU,EACV,kBAAkB,EAClB,WAAW,EACX,UAAU,EACV,eAAe,EACf,gBAAgB,EAChB,0BAA0B,EAC1B,mBAAmB,EACnB,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB,KAAK,OAAO,EACZ,KAAK,mBAAmB,EACxB,KAAK,YAAY,EACjB,KAAK,qBAAqB,EAC1B,KAAK,OAAO,GACf,CAAC"}
@@ -0,0 +1,63 @@
1
+ import { tmpdir } from "node:os";
2
+ import { join } from "node:path";
3
+ import { z } from "zod";
4
+ const RequestSchema = z.object({
5
+ id: z.string(),
6
+ method: z.string(),
7
+ params: z.unknown().optional(),
8
+ });
9
+ const ErrorSchema = z.object({
10
+ code: z.number(),
11
+ message: z.string(),
12
+ data: z.unknown().optional(),
13
+ });
14
+ const ResponseSchema = z.object({
15
+ id: z.string(),
16
+ result: z.unknown().optional(),
17
+ error: ErrorSchema.optional(),
18
+ });
19
+ const RegisterParamsSchema = z.object({
20
+ applicationId: z.string(),
21
+ pid: z.number(),
22
+ projectRoot: z.string().optional(),
23
+ });
24
+ const emptyParams = z.object({});
25
+ const widgetIdParams = z.object({
26
+ widgetId: z.string(),
27
+ });
28
+ const treeParams = z.object({
29
+ rootId: z.string().optional(),
30
+ maxDepth: z.number().int().positive().optional(),
31
+ });
32
+ const queryOptionsSchema = z.object({
33
+ name: z.string().optional(),
34
+ exact: z.boolean().optional(),
35
+ timeout: z.number().optional(),
36
+ });
37
+ const queryParams = z.object({
38
+ by: z.enum(["role", "text", "name", "labelText"]),
39
+ value: z.union([z.string(), z.number()]),
40
+ options: queryOptionsSchema.optional(),
41
+ });
42
+ const typeParams = z.object({ widgetId: z.string(), text: z.string(), clear: z.boolean().optional() });
43
+ const fireEventParams = z.object({ widgetId: z.string(), signal: z.string(), args: z.array(z.unknown()).optional() });
44
+ const screenshotParams = z.object({
45
+ windowId: z.string().optional(),
46
+ path: z.string().optional(),
47
+ });
48
+ const ServerRequestParamsSchemas = {
49
+ "app.getWindows": emptyParams,
50
+ "widget.getTree": treeParams,
51
+ "widget.query": queryParams,
52
+ "widget.getProps": widgetIdParams,
53
+ "widget.click": widgetIdParams,
54
+ "widget.type": typeParams,
55
+ "widget.fireEvent": fireEventParams,
56
+ "widget.screenshot": screenshotParams,
57
+ };
58
+ const DEFAULT_SOCKET_PATH = join(getRuntimeDir(), "gtkx-mcp.sock");
59
+ function getRuntimeDir() {
60
+ return process.env.XDG_RUNTIME_DIR ?? tmpdir();
61
+ }
62
+ export { RequestSchema, ResponseSchema, RegisterParamsSchema, widgetIdParams, treeParams, queryOptionsSchema, queryParams, typeParams, fireEventParams, screenshotParams, ServerRequestParamsSchemas, DEFAULT_SOCKET_PATH, };
63
+ //# sourceMappingURL=schemas.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../src/protocol/schemas.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AA+BxB,MAAM,aAAa,GAMf,CAAC,CAAC,MAAM,CAAC;IACT,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;IAClB,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,QAAQ,EAAE;CACjC,CAAC,CA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;IACzB,kBAAkB,EAAE,eAAe;IACnC,mBAAmB,EAAE,gBAAgB;CACxC,CAAC;AAEF,MAAM,mBAAmB,GAAW,IAAI,CAAC,aAAa,EAAE,EAAE,eAAe,CAAC,CAAC;AAE3E,SAAS,aAAa;IAClB,OAAO,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,MAAM,EAAE,CAAC;AACnD,CAAC;AAED,OAAO,EACH,aAAa,EACb,cAAc,EACd,oBAAoB,EACpB,cAAc,EACd,UAAU,EACV,kBAAkB,EAClB,WAAW,EACX,UAAU,EACV,eAAe,EACf,gBAAgB,EAChB,0BAA0B,EAC1B,mBAAmB,GAStB,CAAC","sourcesContent":["import { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport { z } from \"zod\";\n\ntype Request = z.infer<typeof RequestSchema>;\ntype Response = z.infer<typeof ResponseSchema>;\n\ntype SerializedWidget = {\n id: string;\n type: string;\n role: string;\n name: string | null;\n text: string | null;\n sensitive: boolean;\n visible: boolean;\n cssClasses: string[];\n children: SerializedWidget[];\n};\n\ntype AppInfo = {\n applicationId: string;\n pid: number;\n projectRoot?: string;\n};\n\ntype ServerRequestParams<Method extends keyof typeof ServerRequestParamsSchemas> = z.infer<\n (typeof ServerRequestParamsSchemas)[Method]\n>;\n\ntype ParamsSchema<Output> = z.ZodType<Output>;\ntype ServerInitiatedMethod = keyof typeof ServerRequestParamsSchemas;\ntype Message = Request | Response;\n\nconst RequestSchema: z.ZodObject<\n {\n id: z.ZodString;\n method: z.ZodString;\n params: z.ZodOptional<z.ZodUnknown>;\n }\n> = z.object({\n id: z.string(),\n method: z.string(),\n params: z.unknown().optional(),\n});\n\nconst ErrorSchema: z.ZodObject<\n { code: z.ZodNumber; message: z.ZodString; data: z.ZodOptional<z.ZodUnknown> }\n> = z.object({\n code: z.number(),\n message: z.string(),\n data: z.unknown().optional(),\n});\n\nconst ResponseSchema: z.ZodObject<\n {\n id: z.ZodString;\n result: z.ZodOptional<z.ZodUnknown>;\n error: z.ZodOptional<typeof ErrorSchema>;\n }\n> = z.object({\n id: z.string(),\n result: z.unknown().optional(),\n error: ErrorSchema.optional(),\n});\n\nconst RegisterParamsSchema: z.ZodObject<\n {\n applicationId: z.ZodString;\n pid: z.ZodNumber;\n projectRoot: z.ZodOptional<z.ZodString>;\n }\n> = z.object({\n applicationId: z.string(),\n pid: z.number(),\n projectRoot: z.string().optional(),\n});\n\nconst emptyParams: z.ZodObject<Record<string, never>> = z.object({});\n\nconst widgetIdParams: z.ZodObject<{ widgetId: z.ZodString }> = z.object({\n widgetId: z.string(),\n});\n\nconst treeParams: z.ZodObject<\n { rootId: z.ZodOptional<z.ZodString>; maxDepth: z.ZodOptional<z.ZodNumber> }\n> = z.object({\n rootId: z.string().optional(),\n maxDepth: z.number().int().positive().optional(),\n});\n\nconst queryOptionsSchema: z.ZodObject<\n { name: z.ZodOptional<z.ZodString>; exact: z.ZodOptional<z.ZodBoolean>; timeout: z.ZodOptional<z.ZodNumber> }\n> = z.object({\n name: z.string().optional(),\n exact: z.boolean().optional(),\n timeout: z.number().optional(),\n});\n\nconst queryParams: z.ZodObject<\n {\n by: z.ZodEnum<{ role: \"role\"; text: \"text\"; name: \"name\"; labelText: \"labelText\" }>;\n value: z.ZodUnion<[z.ZodString, z.ZodNumber]>;\n options: z.ZodOptional<typeof queryOptionsSchema>;\n }\n> = z.object({\n by: z.enum([\"role\", \"text\", \"name\", \"labelText\"]),\n value: z.union([z.string(), z.number()]),\n options: queryOptionsSchema.optional(),\n});\n\nconst typeParams: z.ZodObject<\n { widgetId: z.ZodString; text: z.ZodString; clear: z.ZodOptional<z.ZodBoolean> }\n> = z.object({ widgetId: z.string(), text: z.string(), clear: z.boolean().optional() });\n\nconst fireEventParams: z.ZodObject<\n { widgetId: z.ZodString; signal: z.ZodString; args: z.ZodOptional<z.ZodArray<z.ZodUnknown>> }\n> = z.object({ widgetId: z.string(), signal: z.string(), args: z.array(z.unknown()).optional() });\n\nconst screenshotParams: z.ZodObject<\n { windowId: z.ZodOptional<z.ZodString>; path: z.ZodOptional<z.ZodString> }\n> = z.object({\n windowId: z.string().optional(),\n path: z.string().optional(),\n});\n\nconst ServerRequestParamsSchemas: {\n \"app.getWindows\": typeof emptyParams;\n \"widget.getTree\": typeof treeParams;\n \"widget.query\": typeof queryParams;\n \"widget.getProps\": typeof widgetIdParams;\n \"widget.click\": typeof widgetIdParams;\n \"widget.type\": typeof typeParams;\n \"widget.fireEvent\": typeof fireEventParams;\n \"widget.screenshot\": typeof screenshotParams;\n} = {\n \"app.getWindows\": emptyParams,\n \"widget.getTree\": treeParams,\n \"widget.query\": queryParams,\n \"widget.getProps\": widgetIdParams,\n \"widget.click\": widgetIdParams,\n \"widget.type\": typeParams,\n \"widget.fireEvent\": fireEventParams,\n \"widget.screenshot\": screenshotParams,\n};\n\nconst DEFAULT_SOCKET_PATH: string = join(getRuntimeDir(), \"gtkx-mcp.sock\");\n\nfunction getRuntimeDir(): string {\n return process.env.XDG_RUNTIME_DIR ?? tmpdir();\n}\n\nexport {\n RequestSchema,\n ResponseSchema,\n RegisterParamsSchema,\n widgetIdParams,\n treeParams,\n queryOptionsSchema,\n queryParams,\n typeParams,\n fireEventParams,\n screenshotParams,\n ServerRequestParamsSchemas,\n DEFAULT_SOCKET_PATH,\n type Request,\n type Response,\n type SerializedWidget,\n type AppInfo,\n type ServerRequestParams,\n type ParamsSchema,\n type ServerInitiatedMethod,\n type Message,\n};\n"]}
@@ -0,0 +1,13 @@
1
+ import { type ApiReference } from "@gtkx/codegen";
2
+ import { type McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
+ import { type Tool } from "./tool.js";
4
+ type ReferenceApi = Pick<ApiReference, "lookup" | "namespaceOverview" | "namespaces" | "overview" | "search" | "symbolNames">;
5
+ type ReferenceProvider = {
6
+ get(): Promise<ReferenceApi>;
7
+ };
8
+ type ResourceServer = Pick<McpServer, "registerResource">;
9
+ declare const createReferenceProvider: (resolveRoot: () => string) => ReferenceProvider;
10
+ declare const buildReferenceTools: (provider: ReferenceProvider) => Tool[];
11
+ declare const registerReferenceResources: (server: ResourceServer, provider: ReferenceProvider) => void;
12
+ export { createReferenceProvider, buildReferenceTools, registerReferenceResources, type ReferenceApi, type ReferenceProvider, };
13
+ //# sourceMappingURL=reference.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reference.d.ts","sourceRoot":"","sources":["../src/reference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAsE,MAAM,eAAe,CAAC;AAEtH,OAAO,EAAE,KAAK,SAAS,EAAoB,MAAM,yCAAyC,CAAC;AAK3F,OAAO,EAAsC,KAAK,IAAI,EAAiB,MAAM,WAAW,CAAC;AAEzF,KAAK,YAAY,GAAG,IAAI,CACpB,YAAY,EACZ,QAAQ,GAAG,mBAAmB,GAAG,YAAY,GAAG,UAAU,GAAG,QAAQ,GAAG,aAAa,CACxF,CAAC;AAEF,KAAK,iBAAiB,GAAG;IACrB,GAAG,IAAI,OAAO,CAAC,YAAY,CAAC,CAAC;CAChC,CAAC;AAqBF,KAAK,cAAc,GAAG,IAAI,CAAC,SAAS,EAAE,kBAAkB,CAAC,CAAC;AA0I1D,QAAA,MAAM,uBAAuB,GAAI,aAAa,MAAM,MAAM,KAAG,iBAM5D,CAAC;AAwGF,QAAA,MAAM,mBAAmB,GAAI,UAAU,iBAAiB,KAAG,IAAI,EAI9D,CAAC;AAmJF,QAAA,MAAM,0BAA0B,GAAI,QAAQ,cAAc,EAAE,UAAU,iBAAiB,KAAG,IAIzF,CAAC;AAEF,OAAO,EACH,uBAAuB,EACvB,mBAAmB,EACnB,0BAA0B,EAC1B,KAAK,YAAY,EACjB,KAAK,iBAAiB,GACzB,CAAC"}