@satelliteoflove/godot-mcp 0.1.0
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/dist/__tests__/registry.test.d.ts +2 -0
- package/dist/__tests__/registry.test.d.ts.map +1 -0
- package/dist/__tests__/registry.test.js +116 -0
- package/dist/__tests__/registry.test.js.map +1 -0
- package/dist/__tests__/schema.test.d.ts +2 -0
- package/dist/__tests__/schema.test.d.ts.map +1 -0
- package/dist/__tests__/schema.test.js +67 -0
- package/dist/__tests__/schema.test.js.map +1 -0
- package/dist/connection/protocol.d.ts +103 -0
- package/dist/connection/protocol.d.ts.map +1 -0
- package/dist/connection/protocol.js +34 -0
- package/dist/connection/protocol.js.map +1 -0
- package/dist/connection/websocket.d.ts +33 -0
- package/dist/connection/websocket.d.ts.map +1 -0
- package/dist/connection/websocket.js +203 -0
- package/dist/connection/websocket.js.map +1 -0
- package/dist/core/define-resource.d.ts +9 -0
- package/dist/core/define-resource.d.ts.map +1 -0
- package/dist/core/define-resource.js +4 -0
- package/dist/core/define-resource.js.map +1 -0
- package/dist/core/define-tool.d.ts +9 -0
- package/dist/core/define-tool.d.ts.map +1 -0
- package/dist/core/define-tool.js +4 -0
- package/dist/core/define-tool.js.map +1 -0
- package/dist/core/registry.d.ts +28 -0
- package/dist/core/registry.d.ts.map +1 -0
- package/dist/core/registry.js +70 -0
- package/dist/core/registry.js.map +1 -0
- package/dist/core/schema.d.ts +3 -0
- package/dist/core/schema.d.ts.map +1 -0
- package/dist/core/schema.js +10 -0
- package/dist/core/schema.js.map +1 -0
- package/dist/core/types.d.ts +25 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +2 -0
- package/dist/core/types.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +68 -0
- package/dist/index.js.map +1 -0
- package/dist/resources/index.d.ts +4 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +10 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/resources/scene.d.ts +4 -0
- package/dist/resources/scene.d.ts.map +1 -0
- package/dist/resources/scene.js +32 -0
- package/dist/resources/scene.js.map +1 -0
- package/dist/resources/script.d.ts +3 -0
- package/dist/resources/script.d.ts.map +1 -0
- package/dist/resources/script.js +19 -0
- package/dist/resources/script.js.map +1 -0
- package/dist/tools/editor.d.ts +28 -0
- package/dist/tools/editor.d.ts.map +1 -0
- package/dist/tools/editor.js +83 -0
- package/dist/tools/editor.js.map +1 -0
- package/dist/tools/index.d.ts +7 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +19 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/node.d.ts +54 -0
- package/dist/tools/node.d.ts.map +1 -0
- package/dist/tools/node.js +84 -0
- package/dist/tools/node.js.map +1 -0
- package/dist/tools/project.d.ts +35 -0
- package/dist/tools/project.d.ts.map +1 -0
- package/dist/tools/project.js +78 -0
- package/dist/tools/project.js.map +1 -0
- package/dist/tools/scene.d.ts +32 -0
- package/dist/tools/scene.d.ts.map +1 -0
- package/dist/tools/scene.js +68 -0
- package/dist/tools/scene.js.map +1 -0
- package/dist/tools/script.d.ts +51 -0
- package/dist/tools/script.d.ts.map +1 -0
- package/dist/tools/script.js +86 -0
- package/dist/tools/script.js.map +1 -0
- package/dist/utils/errors.d.ts +16 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +30 -0
- package/dist/utils/errors.js.map +1 -0
- package/package.json +52 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/registry.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from 'vitest';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
class TestRegistry {
|
|
4
|
+
tools = new Map();
|
|
5
|
+
resources = new Map();
|
|
6
|
+
registerTool(tool) {
|
|
7
|
+
if (this.tools.has(tool.name)) {
|
|
8
|
+
throw new Error(`Tool '${tool.name}' already registered`);
|
|
9
|
+
}
|
|
10
|
+
this.tools.set(tool.name, tool);
|
|
11
|
+
}
|
|
12
|
+
registerResource(resource) {
|
|
13
|
+
if (this.resources.has(resource.uri)) {
|
|
14
|
+
throw new Error(`Resource '${resource.uri}' already registered`);
|
|
15
|
+
}
|
|
16
|
+
this.resources.set(resource.uri, resource);
|
|
17
|
+
}
|
|
18
|
+
hasTool(name) {
|
|
19
|
+
return this.tools.has(name);
|
|
20
|
+
}
|
|
21
|
+
hasResource(uri) {
|
|
22
|
+
return this.resources.has(uri);
|
|
23
|
+
}
|
|
24
|
+
getToolList() {
|
|
25
|
+
return Array.from(this.tools.values()).map(({ name, description }) => ({
|
|
26
|
+
name,
|
|
27
|
+
description,
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
getResourceList() {
|
|
31
|
+
return Array.from(this.resources.values());
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
describe('ToolRegistry', () => {
|
|
35
|
+
let registry;
|
|
36
|
+
beforeEach(() => {
|
|
37
|
+
registry = new TestRegistry();
|
|
38
|
+
});
|
|
39
|
+
describe('registerTool', () => {
|
|
40
|
+
it('registers a tool successfully', () => {
|
|
41
|
+
const tool = {
|
|
42
|
+
name: 'test_tool',
|
|
43
|
+
description: 'A test tool',
|
|
44
|
+
schema: z.object({ input: z.string() }),
|
|
45
|
+
};
|
|
46
|
+
registry.registerTool(tool);
|
|
47
|
+
expect(registry.hasTool('test_tool')).toBe(true);
|
|
48
|
+
});
|
|
49
|
+
it('throws error for duplicate tool registration', () => {
|
|
50
|
+
const tool = {
|
|
51
|
+
name: 'duplicate_tool',
|
|
52
|
+
description: 'First registration',
|
|
53
|
+
schema: z.object({}),
|
|
54
|
+
};
|
|
55
|
+
registry.registerTool(tool);
|
|
56
|
+
expect(() => registry.registerTool(tool)).toThrow("Tool 'duplicate_tool' already registered");
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
describe('registerResource', () => {
|
|
60
|
+
it('registers a resource successfully', () => {
|
|
61
|
+
const resource = {
|
|
62
|
+
uri: 'godot://test',
|
|
63
|
+
name: 'Test Resource',
|
|
64
|
+
description: 'A test resource',
|
|
65
|
+
};
|
|
66
|
+
registry.registerResource(resource);
|
|
67
|
+
expect(registry.hasResource('godot://test')).toBe(true);
|
|
68
|
+
});
|
|
69
|
+
it('throws error for duplicate resource registration', () => {
|
|
70
|
+
const resource = {
|
|
71
|
+
uri: 'godot://duplicate',
|
|
72
|
+
name: 'Duplicate',
|
|
73
|
+
description: 'First registration',
|
|
74
|
+
};
|
|
75
|
+
registry.registerResource(resource);
|
|
76
|
+
expect(() => registry.registerResource(resource)).toThrow("Resource 'godot://duplicate' already registered");
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
describe('getToolList', () => {
|
|
80
|
+
it('returns empty array when no tools registered', () => {
|
|
81
|
+
expect(registry.getToolList()).toEqual([]);
|
|
82
|
+
});
|
|
83
|
+
it('returns all registered tools', () => {
|
|
84
|
+
registry.registerTool({
|
|
85
|
+
name: 'tool_a',
|
|
86
|
+
description: 'Tool A',
|
|
87
|
+
schema: z.object({}),
|
|
88
|
+
});
|
|
89
|
+
registry.registerTool({
|
|
90
|
+
name: 'tool_b',
|
|
91
|
+
description: 'Tool B',
|
|
92
|
+
schema: z.object({}),
|
|
93
|
+
});
|
|
94
|
+
const list = registry.getToolList();
|
|
95
|
+
expect(list).toHaveLength(2);
|
|
96
|
+
expect(list).toContainEqual({ name: 'tool_a', description: 'Tool A' });
|
|
97
|
+
expect(list).toContainEqual({ name: 'tool_b', description: 'Tool B' });
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
describe('getResourceList', () => {
|
|
101
|
+
it('returns empty array when no resources registered', () => {
|
|
102
|
+
expect(registry.getResourceList()).toEqual([]);
|
|
103
|
+
});
|
|
104
|
+
it('returns all registered resources', () => {
|
|
105
|
+
registry.registerResource({
|
|
106
|
+
uri: 'godot://scene',
|
|
107
|
+
name: 'Scene',
|
|
108
|
+
description: 'Current scene',
|
|
109
|
+
});
|
|
110
|
+
const list = registry.getResourceList();
|
|
111
|
+
expect(list).toHaveLength(1);
|
|
112
|
+
expect(list[0].uri).toBe('godot://scene');
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
//# sourceMappingURL=registry.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.test.js","sourceRoot":"","sources":["../../src/__tests__/registry.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAC1D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,YAAY;IACR,KAAK,GACX,IAAI,GAAG,EAAE,CAAC;IACJ,SAAS,GACf,IAAI,GAAG,EAAE,CAAC;IAEZ,YAAY,CAAC,IAA8D;QACzE,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;YAC9B,MAAM,IAAI,KAAK,CAAC,SAAS,IAAI,CAAC,IAAI,sBAAsB,CAAC,CAAC;QAC5D,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAClC,CAAC;IAED,gBAAgB,CAAC,QAA4D;QAC3E,IAAI,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACrC,MAAM,IAAI,KAAK,CAAC,aAAa,QAAQ,CAAC,GAAG,sBAAsB,CAAC,CAAC;QACnE,CAAC;QACD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC;IAC7C,CAAC;IAED,OAAO,C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AAE,CAAC;YAExC,MAAM,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC;YAC7B,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAC5C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/schema.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { toInputSchema } from '../core/schema.js';
|
|
4
|
+
describe('toInputSchema', () => {
|
|
5
|
+
it('converts simple object schema', () => {
|
|
6
|
+
const schema = z.object({
|
|
7
|
+
name: z.string(),
|
|
8
|
+
});
|
|
9
|
+
const result = toInputSchema(schema);
|
|
10
|
+
expect(result).toHaveProperty('type', 'object');
|
|
11
|
+
expect(result).toHaveProperty('properties');
|
|
12
|
+
expect(result.properties).toHaveProperty('name');
|
|
13
|
+
});
|
|
14
|
+
it('converts schema with optional fields', () => {
|
|
15
|
+
const schema = z.object({
|
|
16
|
+
required_field: z.string(),
|
|
17
|
+
optional_field: z.string().optional(),
|
|
18
|
+
});
|
|
19
|
+
const result = toInputSchema(schema);
|
|
20
|
+
expect(result.required).toContain('required_field');
|
|
21
|
+
expect(result.required).not.toContain('optional_field');
|
|
22
|
+
});
|
|
23
|
+
it('converts schema with descriptions', () => {
|
|
24
|
+
const schema = z.object({
|
|
25
|
+
path: z.string().describe('The file path'),
|
|
26
|
+
});
|
|
27
|
+
const result = toInputSchema(schema);
|
|
28
|
+
const properties = result.properties;
|
|
29
|
+
const pathProp = properties.path;
|
|
30
|
+
expect(pathProp.description).toBe('The file path');
|
|
31
|
+
});
|
|
32
|
+
it('converts nested object schema', () => {
|
|
33
|
+
const schema = z.object({
|
|
34
|
+
node: z.object({
|
|
35
|
+
name: z.string(),
|
|
36
|
+
type: z.string(),
|
|
37
|
+
}),
|
|
38
|
+
});
|
|
39
|
+
const result = toInputSchema(schema);
|
|
40
|
+
const properties = result.properties;
|
|
41
|
+
const nodeProp = properties.node;
|
|
42
|
+
expect(nodeProp.type).toBe('object');
|
|
43
|
+
expect(nodeProp.properties).toHaveProperty('name');
|
|
44
|
+
expect(nodeProp.properties).toHaveProperty('type');
|
|
45
|
+
});
|
|
46
|
+
it('converts boolean schema', () => {
|
|
47
|
+
const schema = z.object({
|
|
48
|
+
enabled: z.boolean(),
|
|
49
|
+
});
|
|
50
|
+
const result = toInputSchema(schema);
|
|
51
|
+
const properties = result.properties;
|
|
52
|
+
const enabledProp = properties.enabled;
|
|
53
|
+
expect(enabledProp.type).toBe('boolean');
|
|
54
|
+
});
|
|
55
|
+
it('removes $schema property from output', () => {
|
|
56
|
+
const schema = z.object({ test: z.string() });
|
|
57
|
+
const result = toInputSchema(schema);
|
|
58
|
+
expect(result).not.toHaveProperty('$schema');
|
|
59
|
+
});
|
|
60
|
+
it('converts empty object schema', () => {
|
|
61
|
+
const schema = z.object({});
|
|
62
|
+
const result = toInputSchema(schema);
|
|
63
|
+
expect(result.type).toBe('object');
|
|
64
|
+
expect(result.properties).toEqual({});
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
//# sourceMappingURL=schema.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.test.js","sourceRoot":"","sources":["../../src/__tests__/schema.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,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AAC,sCAAsC,EAAE,GAAG,EAAE;QAC9C,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QAE9C,MAAM,MAAM,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;QAErC,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;IAC/C,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8BAA8B,EAAE,GAAG,EAAE;QACtC,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAE5B,MAAM,MAAM,GAAG,aAAa,CAAC,MAAM,CAA4B,CAAC;QAEhE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACnC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;IACxC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const RequestSchema: z.ZodObject<{
|
|
3
|
+
id: z.ZodString;
|
|
4
|
+
command: z.ZodString;
|
|
5
|
+
params: z.ZodDefault<z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
|
|
6
|
+
}, "strip", z.ZodTypeAny, {
|
|
7
|
+
id: string;
|
|
8
|
+
command: string;
|
|
9
|
+
params: Record<string, unknown>;
|
|
10
|
+
}, {
|
|
11
|
+
id: string;
|
|
12
|
+
command: string;
|
|
13
|
+
params?: Record<string, unknown> | undefined;
|
|
14
|
+
}>;
|
|
15
|
+
export type Request = z.infer<typeof RequestSchema>;
|
|
16
|
+
export declare const SuccessResponseSchema: z.ZodObject<{
|
|
17
|
+
id: z.ZodString;
|
|
18
|
+
status: z.ZodLiteral<"success">;
|
|
19
|
+
result: z.ZodUnknown;
|
|
20
|
+
}, "strip", z.ZodTypeAny, {
|
|
21
|
+
id: string;
|
|
22
|
+
status: "success";
|
|
23
|
+
result?: unknown;
|
|
24
|
+
}, {
|
|
25
|
+
id: string;
|
|
26
|
+
status: "success";
|
|
27
|
+
result?: unknown;
|
|
28
|
+
}>;
|
|
29
|
+
export declare const ErrorResponseSchema: z.ZodObject<{
|
|
30
|
+
id: z.ZodString;
|
|
31
|
+
status: z.ZodLiteral<"error">;
|
|
32
|
+
error: z.ZodObject<{
|
|
33
|
+
code: z.ZodString;
|
|
34
|
+
message: z.ZodString;
|
|
35
|
+
}, "strip", z.ZodTypeAny, {
|
|
36
|
+
code: string;
|
|
37
|
+
message: string;
|
|
38
|
+
}, {
|
|
39
|
+
code: string;
|
|
40
|
+
message: string;
|
|
41
|
+
}>;
|
|
42
|
+
}, "strip", z.ZodTypeAny, {
|
|
43
|
+
id: string;
|
|
44
|
+
status: "error";
|
|
45
|
+
error: {
|
|
46
|
+
code: string;
|
|
47
|
+
message: string;
|
|
48
|
+
};
|
|
49
|
+
}, {
|
|
50
|
+
id: string;
|
|
51
|
+
status: "error";
|
|
52
|
+
error: {
|
|
53
|
+
code: string;
|
|
54
|
+
message: string;
|
|
55
|
+
};
|
|
56
|
+
}>;
|
|
57
|
+
export declare const ResponseSchema: z.ZodUnion<[z.ZodObject<{
|
|
58
|
+
id: z.ZodString;
|
|
59
|
+
status: z.ZodLiteral<"success">;
|
|
60
|
+
result: z.ZodUnknown;
|
|
61
|
+
}, "strip", z.ZodTypeAny, {
|
|
62
|
+
id: string;
|
|
63
|
+
status: "success";
|
|
64
|
+
result?: unknown;
|
|
65
|
+
}, {
|
|
66
|
+
id: string;
|
|
67
|
+
status: "success";
|
|
68
|
+
result?: unknown;
|
|
69
|
+
}>, z.ZodObject<{
|
|
70
|
+
id: z.ZodString;
|
|
71
|
+
status: z.ZodLiteral<"error">;
|
|
72
|
+
error: z.ZodObject<{
|
|
73
|
+
code: z.ZodString;
|
|
74
|
+
message: z.ZodString;
|
|
75
|
+
}, "strip", z.ZodTypeAny, {
|
|
76
|
+
code: string;
|
|
77
|
+
message: string;
|
|
78
|
+
}, {
|
|
79
|
+
code: string;
|
|
80
|
+
message: string;
|
|
81
|
+
}>;
|
|
82
|
+
}, "strip", z.ZodTypeAny, {
|
|
83
|
+
id: string;
|
|
84
|
+
status: "error";
|
|
85
|
+
error: {
|
|
86
|
+
code: string;
|
|
87
|
+
message: string;
|
|
88
|
+
};
|
|
89
|
+
}, {
|
|
90
|
+
id: string;
|
|
91
|
+
status: "error";
|
|
92
|
+
error: {
|
|
93
|
+
code: string;
|
|
94
|
+
message: string;
|
|
95
|
+
};
|
|
96
|
+
}>]>;
|
|
97
|
+
export type Response = z.infer<typeof ResponseSchema>;
|
|
98
|
+
export type SuccessResponse = z.infer<typeof SuccessResponseSchema>;
|
|
99
|
+
export type ErrorResponse = z.infer<typeof ErrorResponseSchema>;
|
|
100
|
+
export declare function createRequest(command: string, params?: Record<string, unknown>): Request;
|
|
101
|
+
export declare function isSuccessResponse(response: Response): response is SuccessResponse;
|
|
102
|
+
export declare function isErrorResponse(response: Response): response is ErrorResponse;
|
|
103
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../../src/connection/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,aAAa;;;;;;;;;;;;EAIxB,CAAC;AAEH,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAEpD,eAAO,MAAM,qBAAqB;;;;;;;;;;;;EAIhC,CAAC;AAEH,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;EAO9B,CAAC;AAEH,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAAwD,CAAC;AAEpF,MAAM,MAAM,QAAQ,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AACtD,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AACpE,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAEhE,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GAAG,OAAO,CAM5F;AAED,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ,IAAI,eAAe,CAEjF;AAED,wBAAgB,eAAe,CAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ,IAAI,aAAa,CAE7E"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export const RequestSchema = z.object({
|
|
3
|
+
id: z.string(),
|
|
4
|
+
command: z.string(),
|
|
5
|
+
params: z.record(z.unknown()).optional().default({}),
|
|
6
|
+
});
|
|
7
|
+
export const SuccessResponseSchema = z.object({
|
|
8
|
+
id: z.string(),
|
|
9
|
+
status: z.literal('success'),
|
|
10
|
+
result: z.unknown(),
|
|
11
|
+
});
|
|
12
|
+
export const ErrorResponseSchema = z.object({
|
|
13
|
+
id: z.string(),
|
|
14
|
+
status: z.literal('error'),
|
|
15
|
+
error: z.object({
|
|
16
|
+
code: z.string(),
|
|
17
|
+
message: z.string(),
|
|
18
|
+
}),
|
|
19
|
+
});
|
|
20
|
+
export const ResponseSchema = z.union([SuccessResponseSchema, ErrorResponseSchema]);
|
|
21
|
+
export function createRequest(command, params = {}) {
|
|
22
|
+
return {
|
|
23
|
+
id: crypto.randomUUID(),
|
|
24
|
+
command,
|
|
25
|
+
params,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export function isSuccessResponse(response) {
|
|
29
|
+
return response.status === 'success';
|
|
30
|
+
}
|
|
31
|
+
export function isErrorResponse(response) {
|
|
32
|
+
return response.status === 'error';
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../src/connection/protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAC,MAAM,CAAC;IACpC,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;CACrD,CAAC,CAAC;AAIH,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5C,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC;IAC5B,MAAM,EAAE,CAAC,CAAC,OAAO,EAAE;CACpB,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IAC1C,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;IACd,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;IAC1B,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC;QACd,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;QAChB,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;KACpB,CAAC;CACH,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,qBAAqB,EAAE,mBAAmB,CAAC,CAAC,CAAC;AAMpF,MAAM,UAAU,aAAa,CAAC,OAAe,EAAE,SAAkC,EAAE;IACjF,OAAO;QACL,EAAE,EAAE,MAAM,CAAC,UAAU,EAAE;QACvB,OAAO;QACP,MAAM;KACP,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,QAAkB;IAClD,OAAO,QAAQ,CAAC,MAAM,KAAK,SAAS,CAAC;AACvC,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,QAAkB;IAChD,OAAO,QAAQ,CAAC,MAAM,KAAK,OAAO,CAAC;AACrC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { EventEmitter } from 'events';
|
|
2
|
+
export interface GodotConnectionOptions {
|
|
3
|
+
host?: string;
|
|
4
|
+
port?: number;
|
|
5
|
+
autoReconnect?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare class GodotConnection extends EventEmitter {
|
|
8
|
+
private ws;
|
|
9
|
+
private pendingRequests;
|
|
10
|
+
private reconnectAttempt;
|
|
11
|
+
private reconnectTimeout;
|
|
12
|
+
private pingInterval;
|
|
13
|
+
private pongTimeout;
|
|
14
|
+
private isClosing;
|
|
15
|
+
private readonly host;
|
|
16
|
+
private readonly port;
|
|
17
|
+
private readonly autoReconnect;
|
|
18
|
+
constructor(options?: GodotConnectionOptions);
|
|
19
|
+
get isConnected(): boolean;
|
|
20
|
+
get url(): string;
|
|
21
|
+
connect(): Promise<void>;
|
|
22
|
+
disconnect(): void;
|
|
23
|
+
sendCommand<T = unknown>(command: string, params?: Record<string, unknown>): Promise<T>;
|
|
24
|
+
private handleMessage;
|
|
25
|
+
private startPingInterval;
|
|
26
|
+
private stopPingInterval;
|
|
27
|
+
private clearPongTimeout;
|
|
28
|
+
private scheduleReconnect;
|
|
29
|
+
private cleanup;
|
|
30
|
+
}
|
|
31
|
+
export declare function getGodotConnection(): GodotConnection;
|
|
32
|
+
export declare function initializeConnection(): Promise<void>;
|
|
33
|
+
//# sourceMappingURL=websocket.d.ts.map
|
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AAI,OAAO,CAAC,IAAI,CAAC,CAwB1D"}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import WebSocket from 'ws';
|
|
2
|
+
import { EventEmitter } from 'events';
|
|
3
|
+
import { ResponseSchema, createRequest, isSuccessResponse, isErrorResponse, } from './protocol.js';
|
|
4
|
+
import { GodotConnectionError, GodotCommandError, GodotTimeoutError, } from '../utils/errors.js';
|
|
5
|
+
const DEFAULT_PORT = 6550;
|
|
6
|
+
const DEFAULT_HOST = 'localhost';
|
|
7
|
+
const COMMAND_TIMEOUT_MS = 30000;
|
|
8
|
+
const RECONNECT_DELAYS = [1000, 2000, 4000, 8000, 16000, 30000];
|
|
9
|
+
const PING_INTERVAL_MS = 30000;
|
|
10
|
+
const PONG_TIMEOUT_MS = 10000;
|
|
11
|
+
export class GodotConnection extends EventEmitter {
|
|
12
|
+
ws = null;
|
|
13
|
+
pendingRequests = new Map();
|
|
14
|
+
reconnectAttempt = 0;
|
|
15
|
+
reconnectTimeout = null;
|
|
16
|
+
pingInterval = null;
|
|
17
|
+
pongTimeout = null;
|
|
18
|
+
isClosing = false;
|
|
19
|
+
host;
|
|
20
|
+
port;
|
|
21
|
+
autoReconnect;
|
|
22
|
+
constructor(options = {}) {
|
|
23
|
+
super();
|
|
24
|
+
this.host = options.host ?? DEFAULT_HOST;
|
|
25
|
+
this.port = options.port ?? DEFAULT_PORT;
|
|
26
|
+
this.autoReconnect = options.autoReconnect ?? true;
|
|
27
|
+
}
|
|
28
|
+
get isConnected() {
|
|
29
|
+
return this.ws?.readyState === WebSocket.OPEN;
|
|
30
|
+
}
|
|
31
|
+
get url() {
|
|
32
|
+
return `ws://${this.host}:${this.port}`;
|
|
33
|
+
}
|
|
34
|
+
async connect() {
|
|
35
|
+
if (this.isConnected) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
return new Promise((resolve, reject) => {
|
|
39
|
+
this.isClosing = false;
|
|
40
|
+
this.ws = new WebSocket(this.url);
|
|
41
|
+
this.ws.on('open', () => {
|
|
42
|
+
this.reconnectAttempt = 0;
|
|
43
|
+
this.startPingInterval();
|
|
44
|
+
this.emit('connected');
|
|
45
|
+
resolve();
|
|
46
|
+
});
|
|
47
|
+
this.ws.on('message', (data) => {
|
|
48
|
+
this.handleMessage(data.toString());
|
|
49
|
+
});
|
|
50
|
+
this.ws.on('pong', () => {
|
|
51
|
+
this.clearPongTimeout();
|
|
52
|
+
});
|
|
53
|
+
this.ws.on('close', () => {
|
|
54
|
+
this.cleanup();
|
|
55
|
+
this.emit('disconnected');
|
|
56
|
+
if (this.autoReconnect && !this.isClosing) {
|
|
57
|
+
this.scheduleReconnect();
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
this.ws.on('error', (error) => {
|
|
61
|
+
this.emit('error', error);
|
|
62
|
+
if (!this.isConnected) {
|
|
63
|
+
reject(new GodotConnectionError(`Failed to connect: ${error.message}`));
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
disconnect() {
|
|
69
|
+
this.isClosing = true;
|
|
70
|
+
this.cleanup();
|
|
71
|
+
if (this.ws) {
|
|
72
|
+
this.ws.close();
|
|
73
|
+
this.ws = null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async sendCommand(command, params = {}) {
|
|
77
|
+
if (!this.isConnected) {
|
|
78
|
+
throw new GodotConnectionError('Not connected to Godot');
|
|
79
|
+
}
|
|
80
|
+
const request = createRequest(command, params);
|
|
81
|
+
return new Promise((resolve, reject) => {
|
|
82
|
+
const timeoutId = setTimeout(() => {
|
|
83
|
+
this.pendingRequests.delete(request.id);
|
|
84
|
+
reject(new GodotTimeoutError(command, COMMAND_TIMEOUT_MS));
|
|
85
|
+
}, COMMAND_TIMEOUT_MS);
|
|
86
|
+
this.pendingRequests.set(request.id, {
|
|
87
|
+
resolve: resolve,
|
|
88
|
+
reject,
|
|
89
|
+
timeoutId,
|
|
90
|
+
});
|
|
91
|
+
this.ws.send(JSON.stringify(request));
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
handleMessage(data) {
|
|
95
|
+
let response;
|
|
96
|
+
try {
|
|
97
|
+
const parsed = JSON.parse(data);
|
|
98
|
+
response = ResponseSchema.parse(parsed);
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
this.emit('error', new Error(`Invalid response from Godot: ${data}`));
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const pending = this.pendingRequests.get(response.id);
|
|
105
|
+
if (!pending) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
this.pendingRequests.delete(response.id);
|
|
109
|
+
clearTimeout(pending.timeoutId);
|
|
110
|
+
if (isSuccessResponse(response)) {
|
|
111
|
+
pending.resolve(response.result);
|
|
112
|
+
}
|
|
113
|
+
else if (isErrorResponse(response)) {
|
|
114
|
+
pending.reject(new GodotCommandError(response.error.code, response.error.message));
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
startPingInterval() {
|
|
118
|
+
this.stopPingInterval();
|
|
119
|
+
this.pingInterval = setInterval(() => {
|
|
120
|
+
if (this.isConnected) {
|
|
121
|
+
this.ws.ping();
|
|
122
|
+
this.pongTimeout = setTimeout(() => {
|
|
123
|
+
this.emit('error', new Error('Pong timeout - connection may be dead'));
|
|
124
|
+
this.ws?.terminate();
|
|
125
|
+
}, PONG_TIMEOUT_MS);
|
|
126
|
+
}
|
|
127
|
+
}, PING_INTERVAL_MS);
|
|
128
|
+
}
|
|
129
|
+
stopPingInterval() {
|
|
130
|
+
if (this.pingInterval) {
|
|
131
|
+
clearInterval(this.pingInterval);
|
|
132
|
+
this.pingInterval = null;
|
|
133
|
+
}
|
|
134
|
+
this.clearPongTimeout();
|
|
135
|
+
}
|
|
136
|
+
clearPongTimeout() {
|
|
137
|
+
if (this.pongTimeout) {
|
|
138
|
+
clearTimeout(this.pongTimeout);
|
|
139
|
+
this.pongTimeout = null;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
scheduleReconnect() {
|
|
143
|
+
if (this.reconnectTimeout) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const delay = RECONNECT_DELAYS[Math.min(this.reconnectAttempt, RECONNECT_DELAYS.length - 1)];
|
|
147
|
+
this.reconnectAttempt++;
|
|
148
|
+
this.emit('reconnecting', { attempt: this.reconnectAttempt, delay });
|
|
149
|
+
this.reconnectTimeout = setTimeout(async () => {
|
|
150
|
+
this.reconnectTimeout = null;
|
|
151
|
+
try {
|
|
152
|
+
await this.connect();
|
|
153
|
+
}
|
|
154
|
+
catch {
|
|
155
|
+
// connect() will schedule another reconnect on failure
|
|
156
|
+
}
|
|
157
|
+
}, delay);
|
|
158
|
+
}
|
|
159
|
+
cleanup() {
|
|
160
|
+
this.stopPingInterval();
|
|
161
|
+
if (this.reconnectTimeout) {
|
|
162
|
+
clearTimeout(this.reconnectTimeout);
|
|
163
|
+
this.reconnectTimeout = null;
|
|
164
|
+
}
|
|
165
|
+
for (const [id, pending] of this.pendingRequests) {
|
|
166
|
+
clearTimeout(pending.timeoutId);
|
|
167
|
+
pending.reject(new GodotConnectionError('Connection closed'));
|
|
168
|
+
}
|
|
169
|
+
this.pendingRequests.clear();
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
let globalConnection = null;
|
|
173
|
+
export function getGodotConnection() {
|
|
174
|
+
if (!globalConnection) {
|
|
175
|
+
globalConnection = new GodotConnection({
|
|
176
|
+
host: process.env.GODOT_HOST,
|
|
177
|
+
port: process.env.GODOT_PORT ? parseInt(process.env.GODOT_PORT, 10) : undefined,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
return globalConnection;
|
|
181
|
+
}
|
|
182
|
+
export async function initializeConnection() {
|
|
183
|
+
const connection = getGodotConnection();
|
|
184
|
+
connection.on('connected', () => {
|
|
185
|
+
console.error('[godot-mcp] Connected to Godot');
|
|
186
|
+
});
|
|
187
|
+
connection.on('disconnected', () => {
|
|
188
|
+
console.error('[godot-mcp] Disconnected from Godot');
|
|
189
|
+
});
|
|
190
|
+
connection.on('reconnecting', ({ attempt, delay }) => {
|
|
191
|
+
console.error(`[godot-mcp] Reconnecting (attempt ${attempt}) in ${delay}ms...`);
|
|
192
|
+
});
|
|
193
|
+
connection.on('error', (error) => {
|
|
194
|
+
console.error(`[godot-mcp] Connection error: ${error.message}`);
|
|
195
|
+
});
|
|
196
|
+
try {
|
|
197
|
+
await connection.connect();
|
|
198
|
+
}
|
|
199
|
+
catch (error) {
|
|
200
|
+
console.error(`[godot-mcp] Initial connection failed, will retry: ${error}`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
//# sourceMappingURL=websocket.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"websocket.js","sourceRoot":"","sources":["../../src/connection/websocket.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,IAAI,CAAC;AAC3B,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAGL,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,eAAe,GAChB,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,oBAAoB,CAAC;AAE5B,MAAM,YAAY,GAAG,IAAI,CAAC;AAC1B,MAAM,YAAY,GAAG,WAAW,CAAC;AACjC,MAAM,kBAAkB,GAAG,KAAK,CAAC;AACjC,MAAM,gBAAgB,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;AAChE,MAAM,gBAAgB,GAAG,KAAK,CAAC;AAC/B,MAAM,eAAe,GAAG,KAAK,CAAC;AAc9B,MAAM,OAAO,eAAgB,SAAQ,YAAY;IACvC,EAAE,GAAqB,IAAI,CAAC;IAC5B,eAAe,GAAgC,IAAI,GAAG,EAAE,CAAC;IACzD,gBAAgB,GAAG,CAAC,C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AAK,EAAE,CAAC,CAAC;IAC/E,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ResourceDefinition, ToolContext } from './types.js';
|
|
2
|
+
export declare function defineResource(config: {
|
|
3
|
+
uri: string;
|
|
4
|
+
name: string;
|
|
5
|
+
description: string;
|
|
6
|
+
mimeType: string;
|
|
7
|
+
handler: (ctx: ToolContext) => Promise<string>;
|
|
8
|
+
}): ResourceDefinition;
|
|
9
|
+
//# sourceMappingURL=define-resource.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-resource.d.ts","sourceRoot":"","sources":["../../src/core/define-resource.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAElE,wBAAgB,cAAc,CAAC,MAAM,EAAE;IACrC,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,CAAC,GAAG,EAAE,WAAW,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CAChD,GAAG,kBAAkB,CAErB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-resource.js","sourceRoot":"","sources":["../../src/core/define-resource.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,cAAc,CAAC,MAM9B;IACC,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { z } from 'zod';
|
|
2
|
+
import type { ToolDefinition, ToolContext } from './types.js';
|
|
3
|
+
export declare function defineTool<TSchema extends z.ZodType>(config: {
|
|
4
|
+
name: string;
|
|
5
|
+
description: string;
|
|
6
|
+
schema: TSchema;
|
|
7
|
+
execute: (args: z.infer<TSchema>, ctx: ToolContext) => Promise<string>;
|
|
8
|
+
}): ToolDefinition<TSchema>;
|
|
9
|
+
//# sourceMappingURL=define-tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"define-tool.d.ts","sourceRoot":"","sources":["../../src/core/define-tool.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9D,wBAAgB,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE;IAC5D,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,GAAG,EAAE,WAAW,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;CACxE,GAAG,cAAc,CAAC,OAAO,CAAC,CAE1B"}
|