@akiojin/unity-mcp-server 2.40.2 → 2.40.4

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 (93) hide show
  1. package/README.md +21 -0
  2. package/bin/unity-mcp-server +1 -1
  3. package/package.json +4 -3
  4. package/src/core/codeIndex.js +143 -20
  5. package/src/core/indexWatcher.js +11 -0
  6. package/src/core/server.js +9 -34
  7. package/src/core/sqliteFallback.js +75 -0
  8. package/src/handlers/analysis/AnalyzeSceneContentsToolHandler.js +27 -24
  9. package/src/handlers/analysis/FindByComponentToolHandler.js +4 -1
  10. package/src/handlers/analysis/GetAnimatorStateToolHandler.js +5 -5
  11. package/src/handlers/analysis/GetComponentValuesToolHandler.js +4 -1
  12. package/src/handlers/analysis/GetGameObjectDetailsToolHandler.js +27 -24
  13. package/src/handlers/analysis/GetInputActionsStateToolHandler.js +5 -5
  14. package/src/handlers/analysis/GetObjectReferencesToolHandler.js +4 -1
  15. package/src/handlers/asset/AssetDatabaseManageToolHandler.js +24 -6
  16. package/src/handlers/asset/AssetDependencyAnalyzeToolHandler.js +21 -11
  17. package/src/handlers/asset/AssetImportSettingsManageToolHandler.js +7 -7
  18. package/src/handlers/asset/AssetMaterialCreateToolHandler.js +78 -81
  19. package/src/handlers/asset/AssetMaterialModifyToolHandler.js +57 -61
  20. package/src/handlers/asset/AssetPrefabCreateToolHandler.js +61 -64
  21. package/src/handlers/asset/AssetPrefabExitModeToolHandler.js +9 -13
  22. package/src/handlers/asset/AssetPrefabInstantiateToolHandler.js +110 -116
  23. package/src/handlers/asset/AssetPrefabModifyToolHandler.js +58 -58
  24. package/src/handlers/asset/AssetPrefabOpenToolHandler.js +7 -5
  25. package/src/handlers/asset/AssetPrefabSaveToolHandler.js +13 -6
  26. package/src/handlers/compilation/CompilationGetStateToolHandler.js +4 -3
  27. package/src/handlers/component/ComponentAddToolHandler.js +2 -2
  28. package/src/handlers/component/ComponentGetTypesToolHandler.js +17 -21
  29. package/src/handlers/component/ComponentListToolHandler.js +5 -3
  30. package/src/handlers/component/ComponentModifyToolHandler.js +3 -3
  31. package/src/handlers/component/ComponentRemoveToolHandler.js +2 -2
  32. package/src/handlers/console/ConsoleClearToolHandler.js +36 -46
  33. package/src/handlers/editor/EditorLayersManageToolHandler.js +7 -6
  34. package/src/handlers/editor/EditorTagsManageToolHandler.js +20 -11
  35. package/src/handlers/editor/EditorToolsManageToolHandler.js +2 -2
  36. package/src/handlers/editor/EditorWindowsManageToolHandler.js +6 -5
  37. package/src/handlers/gameobject/GameObjectCreateToolHandler.js +62 -66
  38. package/src/handlers/gameobject/GameObjectDeleteToolHandler.js +9 -9
  39. package/src/handlers/gameobject/GameObjectFindToolHandler.js +13 -11
  40. package/src/handlers/gameobject/GameObjectGetHierarchyToolHandler.js +22 -16
  41. package/src/handlers/input/InputActionAddToolHandler.js +2 -2
  42. package/src/handlers/input/InputActionMapCreateToolHandler.js +2 -2
  43. package/src/handlers/input/InputActionMapRemoveToolHandler.js +2 -2
  44. package/src/handlers/input/InputActionRemoveToolHandler.js +2 -2
  45. package/src/handlers/input/InputBindingAddToolHandler.js +2 -2
  46. package/src/handlers/input/InputBindingCompositeCreateToolHandler.js +2 -2
  47. package/src/handlers/input/InputBindingRemoveAllToolHandler.js +2 -2
  48. package/src/handlers/input/InputBindingRemoveToolHandler.js +2 -2
  49. package/src/handlers/input/InputControlSchemesManageToolHandler.js +2 -2
  50. package/src/handlers/package/PackageManagerToolHandler.js +41 -44
  51. package/src/handlers/package/RegistryConfigToolHandler.js +28 -7
  52. package/src/handlers/playmode/PlaymodeGetStateToolHandler.js +12 -16
  53. package/src/handlers/playmode/PlaymodePauseToolHandler.js +8 -12
  54. package/src/handlers/playmode/PlaymodeWaitForStateToolHandler.js +6 -3
  55. package/src/handlers/scene/GetSceneInfoToolHandler.js +11 -11
  56. package/src/handlers/scene/SceneCreateToolHandler.js +28 -31
  57. package/src/handlers/scene/SceneListToolHandler.js +21 -24
  58. package/src/handlers/scene/SceneLoadToolHandler.js +27 -29
  59. package/src/handlers/scene/SceneSaveToolHandler.js +19 -22
  60. package/src/handlers/screenshot/ScreenshotCaptureToolHandler.js +88 -66
  61. package/src/handlers/script/CodeIndexBuildToolHandler.js +7 -0
  62. package/src/handlers/script/CodeIndexStatusToolHandler.js +4 -3
  63. package/src/handlers/script/CodeIndexUpdateToolHandler.js +24 -14
  64. package/src/handlers/script/ScriptCreateClassToolHandler.js +44 -9
  65. package/src/handlers/script/ScriptPackagesListToolHandler.js +91 -91
  66. package/src/handlers/script/ScriptRefactorRenameToolHandler.js +80 -71
  67. package/src/handlers/script/ScriptRemoveSymbolToolHandler.js +21 -7
  68. package/src/handlers/script/ScriptSearchToolHandler.js +299 -266
  69. package/src/handlers/script/ScriptSymbolsGetToolHandler.js +88 -79
  70. package/src/handlers/settings/SettingsGetToolHandler.js +28 -13
  71. package/src/handlers/settings/SettingsUpdateToolHandler.js +20 -6
  72. package/src/handlers/ui/UIClickElementToolHandler.js +87 -96
  73. package/src/handlers/ui/UIFindElementsToolHandler.js +45 -55
  74. package/src/handlers/ui/UIGetElementStateToolHandler.js +35 -43
  75. package/src/handlers/ui/UISetElementValueToolHandler.js +42 -49
  76. package/src/handlers/ui/UISimulateInputToolHandler.js +134 -136
  77. package/src/handlers/video/VideoCaptureForToolHandler.js +24 -7
  78. package/src/lsp/LspRpcClient.js +24 -12
  79. package/src/tools/analysis/analyzeSceneContents.js +85 -85
  80. package/src/tools/analysis/findByComponent.js +73 -73
  81. package/src/tools/analysis/getAnimatorState.js +287 -287
  82. package/src/tools/analysis/getComponentValues.js +161 -161
  83. package/src/tools/analysis/getGameObjectDetails.js +138 -138
  84. package/src/tools/analysis/getInputActionsState.js +291 -291
  85. package/src/tools/analysis/getObjectReferences.js +72 -72
  86. package/src/tools/input/inputActionsEditor.js +522 -474
  87. package/src/tools/scene/createScene.js +98 -97
  88. package/src/tools/scene/getSceneInfo.js +82 -81
  89. package/src/tools/scene/listScenes.js +70 -69
  90. package/src/tools/scene/loadScene.js +108 -106
  91. package/src/tools/scene/saveScene.js +78 -77
  92. package/src/tools/system/ping.js +9 -12
  93. package/src/utils/validators.js +2 -2
@@ -1,9 +1,9 @@
1
1
  import { BaseToolHandler } from '../base/BaseToolHandler.js';
2
- import {
3
- getInputActionsStateToolDefinition,
4
- analyzeInputActionsAssetToolDefinition,
5
- getInputActionsStateHandler,
6
- analyzeInputActionsAssetHandler
2
+ import {
3
+ getInputActionsStateToolDefinition,
4
+ analyzeInputActionsAssetToolDefinition,
5
+ getInputActionsStateHandler,
6
+ analyzeInputActionsAssetHandler
7
7
  } from '../../tools/analysis/getInputActionsState.js';
8
8
 
9
9
  export class GetInputActionsStateToolHandler extends BaseToolHandler {
@@ -1,5 +1,8 @@
1
1
  import { BaseToolHandler } from '../base/BaseToolHandler.js';
2
- import { getObjectReferencesToolDefinition, getObjectReferencesHandler } from '../../tools/analysis/getObjectReferences.js';
2
+ import {
3
+ getObjectReferencesToolDefinition,
4
+ getObjectReferencesHandler
5
+ } from '../../tools/analysis/getObjectReferences.js';
3
6
 
4
7
  /**
5
8
  * Handler for the analysis_object_references_get tool
@@ -13,7 +13,16 @@ export class AssetDatabaseManageToolHandler extends BaseToolHandler {
13
13
  properties: {
14
14
  action: {
15
15
  type: 'string',
16
- enum: ['find_assets', 'get_asset_info', 'create_folder', 'delete_asset', 'move_asset', 'copy_asset', 'refresh', 'save'],
16
+ enum: [
17
+ 'find_assets',
18
+ 'get_asset_info',
19
+ 'create_folder',
20
+ 'delete_asset',
21
+ 'move_asset',
22
+ 'copy_asset',
23
+ 'refresh',
24
+ 'save'
25
+ ],
17
26
  description: 'The action to perform'
18
27
  },
19
28
  filter: {
@@ -53,7 +62,16 @@ export class AssetDatabaseManageToolHandler extends BaseToolHandler {
53
62
  throw new Error('action is required');
54
63
  }
55
64
 
56
- const validActions = ['find_assets', 'get_asset_info', 'create_folder', 'delete_asset', 'move_asset', 'copy_asset', 'refresh', 'save'];
65
+ const validActions = [
66
+ 'find_assets',
67
+ 'get_asset_info',
68
+ 'create_folder',
69
+ 'delete_asset',
70
+ 'move_asset',
71
+ 'copy_asset',
72
+ 'refresh',
73
+ 'save'
74
+ ];
57
75
  if (!validActions.includes(params.action)) {
58
76
  throw new Error(`action must be one of: ${validActions.join(', ')}`);
59
77
  }
@@ -123,7 +141,7 @@ export class AssetDatabaseManageToolHandler extends BaseToolHandler {
123
141
 
124
142
  async execute(params) {
125
143
  this.validate(params);
126
-
144
+
127
145
  if (!this.unityConnection.isConnected()) {
128
146
  await this.unityConnection.connect();
129
147
  }
@@ -184,8 +202,8 @@ export class AssetDatabaseManageToolHandler extends BaseToolHandler {
184
202
  }
185
203
  },
186
204
  {
187
- input: {
188
- action: 'move_asset',
205
+ input: {
206
+ action: 'move_asset',
189
207
  fromPath: 'Assets/icon.png',
190
208
  toPath: 'Assets/Textures/icon.png'
191
209
  },
@@ -218,4 +236,4 @@ export class AssetDatabaseManageToolHandler extends BaseToolHandler {
218
236
  }
219
237
  ];
220
238
  }
221
- }
239
+ }
@@ -13,7 +13,14 @@ export class AssetDependencyAnalyzeToolHandler extends BaseToolHandler {
13
13
  properties: {
14
14
  action: {
15
15
  type: 'string',
16
- enum: ['get_dependencies', 'get_dependents', 'analyze_circular', 'find_unused', 'analyze_size_impact', 'validate_references'],
16
+ enum: [
17
+ 'get_dependencies',
18
+ 'get_dependents',
19
+ 'analyze_circular',
20
+ 'find_unused',
21
+ 'analyze_size_impact',
22
+ 'validate_references'
23
+ ],
17
24
  description: 'The analysis action to perform'
18
25
  },
19
26
  assetPath: {
@@ -40,7 +47,14 @@ export class AssetDependencyAnalyzeToolHandler extends BaseToolHandler {
40
47
  throw new Error('action is required');
41
48
  }
42
49
 
43
- const validActions = ['get_dependencies', 'get_dependents', 'analyze_circular', 'find_unused', 'analyze_size_impact', 'validate_references'];
50
+ const validActions = [
51
+ 'get_dependencies',
52
+ 'get_dependents',
53
+ 'analyze_circular',
54
+ 'find_unused',
55
+ 'analyze_size_impact',
56
+ 'validate_references'
57
+ ];
44
58
  if (!validActions.includes(params.action)) {
45
59
  throw new Error(`action must be one of: ${validActions.join(', ')}`);
46
60
  }
@@ -51,11 +65,11 @@ export class AssetDependencyAnalyzeToolHandler extends BaseToolHandler {
51
65
  if (params.assetPath === undefined || params.assetPath === null) {
52
66
  throw new Error(`assetPath is required for ${params.action} action`);
53
67
  }
54
-
68
+
55
69
  if (params.assetPath === '') {
56
70
  throw new Error('assetPath cannot be empty');
57
71
  }
58
-
72
+
59
73
  // Validate assetPath starts with "Assets/"
60
74
  if (!params.assetPath.startsWith('Assets/')) {
61
75
  throw new Error('assetPath must start with "Assets/"');
@@ -65,7 +79,7 @@ export class AssetDependencyAnalyzeToolHandler extends BaseToolHandler {
65
79
 
66
80
  async execute(params) {
67
81
  this.validate(params);
68
-
82
+
69
83
  if (!this.unityConnection.isConnected()) {
70
84
  await this.unityConnection.connect();
71
85
  }
@@ -124,11 +138,7 @@ export class AssetDependencyAnalyzeToolHandler extends BaseToolHandler {
124
138
  action: 'analyze_circular',
125
139
  circularDependencies: [
126
140
  {
127
- cycle: [
128
- 'Assets/Scripts/A.cs',
129
- 'Assets/Scripts/B.cs',
130
- 'Assets/Scripts/A.cs'
131
- ],
141
+ cycle: ['Assets/Scripts/A.cs', 'Assets/Scripts/B.cs', 'Assets/Scripts/A.cs'],
132
142
  length: 3,
133
143
  severity: 'warning'
134
144
  }
@@ -198,4 +208,4 @@ export class AssetDependencyAnalyzeToolHandler extends BaseToolHandler {
198
208
  }
199
209
  ];
200
210
  }
201
- }
211
+ }
@@ -71,7 +71,7 @@ export class AssetImportSettingsManageToolHandler extends BaseToolHandler {
71
71
  if (params.preset === undefined || params.preset === null) {
72
72
  throw new Error('preset is required for apply_preset action');
73
73
  }
74
-
74
+
75
75
  if (params.preset === '') {
76
76
  throw new Error('preset cannot be empty');
77
77
  }
@@ -80,7 +80,7 @@ export class AssetImportSettingsManageToolHandler extends BaseToolHandler {
80
80
 
81
81
  async execute(params) {
82
82
  this.validate(params);
83
-
83
+
84
84
  if (!this.unityConnection.isConnected()) {
85
85
  await this.unityConnection.connect();
86
86
  }
@@ -112,8 +112,8 @@ export class AssetImportSettingsManageToolHandler extends BaseToolHandler {
112
112
  }
113
113
  },
114
114
  {
115
- input: {
116
- action: 'modify',
115
+ input: {
116
+ action: 'modify',
117
117
  assetPath: 'Assets/Textures/icon.png',
118
118
  settings: {
119
119
  maxTextureSize: 1024,
@@ -136,8 +136,8 @@ export class AssetImportSettingsManageToolHandler extends BaseToolHandler {
136
136
  }
137
137
  },
138
138
  {
139
- input: {
140
- action: 'apply_preset',
139
+ input: {
140
+ action: 'apply_preset',
141
141
  assetPath: 'Assets/Textures/icon.png',
142
142
  preset: 'UI_Sprite'
143
143
  },
@@ -167,4 +167,4 @@ export class AssetImportSettingsManageToolHandler extends BaseToolHandler {
167
167
  }
168
168
  ];
169
169
  }
170
- }
170
+ }
@@ -1,96 +1,93 @@
1
1
  import { BaseToolHandler } from '../base/BaseToolHandler.js';
2
2
 
3
3
  export class AssetMaterialCreateToolHandler extends BaseToolHandler {
4
- constructor(unityConnection) {
5
- super(
6
- 'asset_material_create',
7
- 'Create a material asset with a shader and property overrides (optional copyFrom).',
8
- {
9
- type: 'object',
10
- properties: {
11
- materialPath: {
12
- type: 'string',
13
- description: 'Asset path for the material. Must start with Assets/ and end with .mat.'
14
- },
15
- shader: {
16
- type: 'string',
17
- description: 'Shader to use (e.g., Standard, Unlit/Color, Universal Render Pipeline/Lit).'
18
- },
19
- properties: {
20
- type: 'object',
21
- description: 'Material property overrides (e.g., {"_Color":[1,0,0,1], "_Metallic":0.5}).'
22
- },
23
- copyFrom: {
24
- type: 'string',
25
- description: 'Optional: path to an existing material to clone before applying overrides.'
26
- },
27
- overwrite: {
28
- type: 'boolean',
29
- description: 'If true, overwrite existing material at the path.'
30
- }
31
- },
32
- required: ['materialPath']
33
- }
34
- );
35
- this.unityConnection = unityConnection;
36
- }
4
+ constructor(unityConnection) {
5
+ super(
6
+ 'asset_material_create',
7
+ 'Create a material asset with a shader and property overrides (optional copyFrom).',
8
+ {
9
+ type: 'object',
10
+ properties: {
11
+ materialPath: {
12
+ type: 'string',
13
+ description: 'Asset path for the material. Must start with Assets/ and end with .mat.'
14
+ },
15
+ shader: {
16
+ type: 'string',
17
+ description:
18
+ 'Shader to use (e.g., Standard, Unlit/Color, Universal Render Pipeline/Lit).'
19
+ },
20
+ properties: {
21
+ type: 'object',
22
+ description:
23
+ 'Material property overrides (e.g., {"_Color":[1,0,0,1], "_Metallic":0.5}).'
24
+ },
25
+ copyFrom: {
26
+ type: 'string',
27
+ description:
28
+ 'Optional: path to an existing material to clone before applying overrides.'
29
+ },
30
+ overwrite: {
31
+ type: 'boolean',
32
+ description: 'If true, overwrite existing material at the path.'
33
+ }
34
+ },
35
+ required: ['materialPath']
36
+ }
37
+ );
38
+ this.unityConnection = unityConnection;
39
+ }
37
40
 
38
- validate(params) {
39
- // Call parent validation for required fields
40
- super.validate(params);
41
+ validate(params) {
42
+ // Call parent validation for required fields
43
+ super.validate(params);
41
44
 
42
- const { materialPath, shader, properties, copyFrom } = params;
45
+ const { materialPath, shader, properties, copyFrom } = params;
43
46
 
44
- // Validate materialPath format
45
- if (!materialPath.startsWith('Assets/') || !materialPath.endsWith('.mat')) {
46
- throw new Error('materialPath must start with Assets/ and end with .mat');
47
- }
47
+ // Validate materialPath format
48
+ if (!materialPath.startsWith('Assets/') || !materialPath.endsWith('.mat')) {
49
+ throw new Error('materialPath must start with Assets/ and end with .mat');
50
+ }
48
51
 
49
- // Validate shader when provided
50
- if (shader !== undefined && shader === '') {
51
- throw new Error('shader cannot be empty when provided');
52
- }
52
+ // Validate shader when provided
53
+ if (shader !== undefined && shader === '') {
54
+ throw new Error('shader cannot be empty when provided');
55
+ }
53
56
 
54
- // Validate properties when provided
55
- if (properties !== undefined) {
56
- if (typeof properties !== 'object' || properties === null) {
57
- throw new Error('properties must be an object');
58
- }
59
- }
57
+ // Validate properties when provided
58
+ if (properties !== undefined) {
59
+ if (typeof properties !== 'object' || properties === null) {
60
+ throw new Error('properties must be an object');
61
+ }
62
+ }
60
63
 
61
- // Validate copyFrom when provided
62
- if (copyFrom !== undefined) {
63
- if (copyFrom === '') {
64
- throw new Error('copyFrom cannot be empty when provided');
65
- }
66
- if (!copyFrom.startsWith('Assets/') || !copyFrom.endsWith('.mat')) {
67
- throw new Error('copyFrom must be a valid material path (Assets/.../.mat)');
68
- }
69
- }
64
+ // Validate copyFrom when provided
65
+ if (copyFrom !== undefined) {
66
+ if (copyFrom === '') {
67
+ throw new Error('copyFrom cannot be empty when provided');
68
+ }
69
+ if (!copyFrom.startsWith('Assets/') || !copyFrom.endsWith('.mat')) {
70
+ throw new Error('copyFrom must be a valid material path (Assets/.../.mat)');
71
+ }
70
72
  }
73
+ }
71
74
 
72
- async execute(params) {
73
- const {
74
- materialPath,
75
- shader,
76
- properties,
77
- copyFrom,
78
- overwrite
79
- } = params;
75
+ async execute(params) {
76
+ const { materialPath, shader, properties, copyFrom, overwrite } = params;
80
77
 
81
- // Ensure connected
82
- if (!this.unityConnection.isConnected()) {
83
- await this.unityConnection.connect();
84
- }
78
+ // Ensure connected
79
+ if (!this.unityConnection.isConnected()) {
80
+ await this.unityConnection.connect();
81
+ }
85
82
 
86
- const result = await this.unityConnection.sendCommand('create_material', {
87
- materialPath,
88
- shader,
89
- properties,
90
- copyFrom,
91
- overwrite
92
- });
83
+ const result = await this.unityConnection.sendCommand('create_material', {
84
+ materialPath,
85
+ shader,
86
+ properties,
87
+ copyFrom,
88
+ overwrite
89
+ });
93
90
 
94
- return result;
95
- }
91
+ return result;
92
+ }
96
93
  }
@@ -1,76 +1,72 @@
1
1
  import { BaseToolHandler } from '../base/BaseToolHandler.js';
2
2
 
3
3
  export class AssetMaterialModifyToolHandler extends BaseToolHandler {
4
- constructor(unityConnection) {
5
- super(
6
- 'asset_material_modify',
7
- 'Modify a material by updating property values and/or changing the shader.',
8
- {
9
- type: 'object',
10
- properties: {
11
- materialPath: {
12
- type: 'string',
13
- description: 'Asset path to the material. Must start with Assets/ and end with .mat.'
14
- },
15
- properties: {
16
- type: 'object',
17
- description: 'Property updates (e.g., {"_Color":[1,0,0,1], "_Metallic":0.5}).'
18
- },
19
- shader: {
20
- type: 'string',
21
- description: 'Optional: change the shader (e.g., Standard, Unlit/Color).'
22
- }
23
- },
24
- required: ['materialPath', 'properties']
25
- }
26
- );
27
- this.unityConnection = unityConnection;
28
- }
4
+ constructor(unityConnection) {
5
+ super(
6
+ 'asset_material_modify',
7
+ 'Modify a material by updating property values and/or changing the shader.',
8
+ {
9
+ type: 'object',
10
+ properties: {
11
+ materialPath: {
12
+ type: 'string',
13
+ description: 'Asset path to the material. Must start with Assets/ and end with .mat.'
14
+ },
15
+ properties: {
16
+ type: 'object',
17
+ description: 'Property updates (e.g., {"_Color":[1,0,0,1], "_Metallic":0.5}).'
18
+ },
19
+ shader: {
20
+ type: 'string',
21
+ description: 'Optional: change the shader (e.g., Standard, Unlit/Color).'
22
+ }
23
+ },
24
+ required: ['materialPath', 'properties']
25
+ }
26
+ );
27
+ this.unityConnection = unityConnection;
28
+ }
29
29
 
30
- validate(params) {
31
- // Call parent validation for required fields
32
- super.validate(params);
30
+ validate(params) {
31
+ // Call parent validation for required fields
32
+ super.validate(params);
33
33
 
34
- const { materialPath, properties, shader } = params;
34
+ const { materialPath, properties, shader } = params;
35
35
 
36
- // Validate materialPath format
37
- if (!materialPath.startsWith('Assets/') || !materialPath.endsWith('.mat')) {
38
- throw new Error('materialPath must start with Assets/ and end with .mat');
39
- }
36
+ // Validate materialPath format
37
+ if (!materialPath.startsWith('Assets/') || !materialPath.endsWith('.mat')) {
38
+ throw new Error('materialPath must start with Assets/ and end with .mat');
39
+ }
40
40
 
41
- // Validate properties
42
- if (typeof properties !== 'object' || properties === null || Array.isArray(properties)) {
43
- throw new Error('properties must be an object');
44
- }
41
+ // Validate properties
42
+ if (typeof properties !== 'object' || properties === null || Array.isArray(properties)) {
43
+ throw new Error('properties must be an object');
44
+ }
45
45
 
46
- if (Object.keys(properties).length === 0) {
47
- throw new Error('properties cannot be empty');
48
- }
46
+ if (Object.keys(properties).length === 0) {
47
+ throw new Error('properties cannot be empty');
48
+ }
49
49
 
50
- // Validate shader when provided
51
- if (shader !== undefined && shader === '') {
52
- throw new Error('shader cannot be empty when provided');
53
- }
50
+ // Validate shader when provided
51
+ if (shader !== undefined && shader === '') {
52
+ throw new Error('shader cannot be empty when provided');
54
53
  }
54
+ }
55
55
 
56
- async execute(params) {
57
- const {
58
- materialPath,
59
- properties,
60
- shader
61
- } = params;
56
+ async execute(params) {
57
+ const { materialPath, properties, shader } = params;
62
58
 
63
- // Ensure connected
64
- if (!this.unityConnection.isConnected()) {
65
- await this.unityConnection.connect();
66
- }
59
+ // Ensure connected
60
+ if (!this.unityConnection.isConnected()) {
61
+ await this.unityConnection.connect();
62
+ }
67
63
 
68
- const result = await this.unityConnection.sendCommand('modify_material', {
69
- materialPath,
70
- properties,
71
- shader
72
- });
64
+ const result = await this.unityConnection.sendCommand('modify_material', {
65
+ materialPath,
66
+ properties,
67
+ shader
68
+ });
73
69
 
74
- return result;
75
- }
70
+ return result;
71
+ }
76
72
  }
@@ -1,78 +1,75 @@
1
1
  import { BaseToolHandler } from '../base/BaseToolHandler.js';
2
2
 
3
3
  export class AssetPrefabCreateToolHandler extends BaseToolHandler {
4
- constructor(unityConnection) {
5
- super(
6
- 'asset_prefab_create',
7
- 'Create a prefab from a GameObject path or create an empty prefab at a target asset path.',
8
- {
9
- type: 'object',
10
- properties: {
11
- gameObjectPath: {
12
- type: 'string',
13
- description: 'Scene path to convert (e.g., "/Root/Player"). Mutually exclusive with createFromTemplate.'
14
- },
15
- prefabPath: {
16
- type: 'string',
17
- description: 'Asset path for the prefab. Must start with Assets/ and end with .prefab.'
18
- },
19
- createFromTemplate: {
20
- type: 'boolean',
21
- description: 'If true, create an empty prefab (no source GameObject) (default: false).'
22
- },
23
- overwrite: {
24
- type: 'boolean',
25
- description: 'If true, overwrite existing prefab at the destination path (default: false).'
26
- }
27
- },
28
- required: ['prefabPath']
29
- }
30
- );
31
- this.unityConnection = unityConnection;
32
- }
4
+ constructor(unityConnection) {
5
+ super(
6
+ 'asset_prefab_create',
7
+ 'Create a prefab from a GameObject path or create an empty prefab at a target asset path.',
8
+ {
9
+ type: 'object',
10
+ properties: {
11
+ gameObjectPath: {
12
+ type: 'string',
13
+ description:
14
+ 'Scene path to convert (e.g., "/Root/Player"). Mutually exclusive with createFromTemplate.'
15
+ },
16
+ prefabPath: {
17
+ type: 'string',
18
+ description: 'Asset path for the prefab. Must start with Assets/ and end with .prefab.'
19
+ },
20
+ createFromTemplate: {
21
+ type: 'boolean',
22
+ description: 'If true, create an empty prefab (no source GameObject) (default: false).'
23
+ },
24
+ overwrite: {
25
+ type: 'boolean',
26
+ description:
27
+ 'If true, overwrite existing prefab at the destination path (default: false).'
28
+ }
29
+ },
30
+ required: ['prefabPath']
31
+ }
32
+ );
33
+ this.unityConnection = unityConnection;
34
+ }
33
35
 
34
- validate(params) {
35
- // Call parent validation for required fields
36
- super.validate(params);
36
+ validate(params) {
37
+ // Call parent validation for required fields
38
+ super.validate(params);
37
39
 
38
- const { prefabPath, gameObjectPath, createFromTemplate } = params;
40
+ const { prefabPath, gameObjectPath, createFromTemplate } = params;
39
41
 
40
- // Validate prefabPath format
41
- if (!prefabPath.startsWith('Assets/') || !prefabPath.endsWith('.prefab')) {
42
- throw new Error('prefabPath must start with Assets/ and end with .prefab');
43
- }
42
+ // Validate prefabPath format
43
+ if (!prefabPath.startsWith('Assets/') || !prefabPath.endsWith('.prefab')) {
44
+ throw new Error('prefabPath must start with Assets/ and end with .prefab');
45
+ }
44
46
 
45
- // Validate gameObjectPath when provided
46
- if (gameObjectPath !== undefined && gameObjectPath === '') {
47
- throw new Error('gameObjectPath cannot be empty when provided');
48
- }
47
+ // Validate gameObjectPath when provided
48
+ if (gameObjectPath !== undefined && gameObjectPath === '') {
49
+ throw new Error('gameObjectPath cannot be empty when provided');
50
+ }
49
51
 
50
- // Validate mutually exclusive options
51
- if (gameObjectPath && createFromTemplate) {
52
- throw new Error('Cannot specify both gameObjectPath and createFromTemplate');
53
- }
52
+ // Validate mutually exclusive options
53
+ if (gameObjectPath && createFromTemplate) {
54
+ throw new Error('Cannot specify both gameObjectPath and createFromTemplate');
54
55
  }
56
+ }
55
57
 
56
- async execute(params) {
57
- const {
58
- gameObjectPath,
59
- prefabPath,
60
- createFromTemplate = false,
61
- overwrite = false
62
- } = params;
58
+ async execute(params) {
59
+ const { gameObjectPath, prefabPath, createFromTemplate = false, overwrite = false } = params;
63
60
 
64
- // Ensure connected
65
- if (!this.unityConnection.isConnected()) {
66
- await this.unityConnection.connect();
67
- }
61
+ // Ensure connected
62
+ if (!this.unityConnection.isConnected()) {
63
+ await this.unityConnection.connect();
64
+ }
68
65
 
69
- const result = await this.unityConnection.sendCommand('create_prefab', {
70
- gameObjectPath,
71
- prefabPath,
72
- createFromTemplate,
73
- overwrite
74
- });
66
+ const result = await this.unityConnection.sendCommand('create_prefab', {
67
+ gameObjectPath,
68
+ prefabPath,
69
+ createFromTemplate,
70
+ overwrite
71
+ });
75
72
 
76
- return result;
77
- }
73
+ return result;
74
+ }
78
75
  }