@akiojin/unity-mcp-server 2.40.2 → 2.40.3

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 (90) hide show
  1. package/README.md +21 -0
  2. package/bin/unity-mcp-server +1 -1
  3. package/package.json +1 -1
  4. package/src/core/codeIndex.js +64 -15
  5. package/src/core/server.js +3 -34
  6. package/src/handlers/analysis/AnalyzeSceneContentsToolHandler.js +27 -24
  7. package/src/handlers/analysis/FindByComponentToolHandler.js +4 -1
  8. package/src/handlers/analysis/GetAnimatorStateToolHandler.js +5 -5
  9. package/src/handlers/analysis/GetComponentValuesToolHandler.js +4 -1
  10. package/src/handlers/analysis/GetGameObjectDetailsToolHandler.js +27 -24
  11. package/src/handlers/analysis/GetInputActionsStateToolHandler.js +5 -5
  12. package/src/handlers/analysis/GetObjectReferencesToolHandler.js +4 -1
  13. package/src/handlers/asset/AssetDatabaseManageToolHandler.js +24 -6
  14. package/src/handlers/asset/AssetDependencyAnalyzeToolHandler.js +21 -11
  15. package/src/handlers/asset/AssetImportSettingsManageToolHandler.js +7 -7
  16. package/src/handlers/asset/AssetMaterialCreateToolHandler.js +78 -81
  17. package/src/handlers/asset/AssetMaterialModifyToolHandler.js +57 -61
  18. package/src/handlers/asset/AssetPrefabCreateToolHandler.js +61 -64
  19. package/src/handlers/asset/AssetPrefabExitModeToolHandler.js +9 -13
  20. package/src/handlers/asset/AssetPrefabInstantiateToolHandler.js +110 -116
  21. package/src/handlers/asset/AssetPrefabModifyToolHandler.js +58 -58
  22. package/src/handlers/asset/AssetPrefabOpenToolHandler.js +7 -5
  23. package/src/handlers/asset/AssetPrefabSaveToolHandler.js +13 -6
  24. package/src/handlers/compilation/CompilationGetStateToolHandler.js +4 -3
  25. package/src/handlers/component/ComponentAddToolHandler.js +2 -2
  26. package/src/handlers/component/ComponentGetTypesToolHandler.js +17 -21
  27. package/src/handlers/component/ComponentListToolHandler.js +5 -3
  28. package/src/handlers/component/ComponentModifyToolHandler.js +3 -3
  29. package/src/handlers/component/ComponentRemoveToolHandler.js +2 -2
  30. package/src/handlers/console/ConsoleClearToolHandler.js +36 -46
  31. package/src/handlers/editor/EditorLayersManageToolHandler.js +7 -6
  32. package/src/handlers/editor/EditorTagsManageToolHandler.js +20 -11
  33. package/src/handlers/editor/EditorToolsManageToolHandler.js +2 -2
  34. package/src/handlers/editor/EditorWindowsManageToolHandler.js +6 -5
  35. package/src/handlers/gameobject/GameObjectCreateToolHandler.js +62 -66
  36. package/src/handlers/gameobject/GameObjectDeleteToolHandler.js +9 -9
  37. package/src/handlers/gameobject/GameObjectFindToolHandler.js +13 -11
  38. package/src/handlers/gameobject/GameObjectGetHierarchyToolHandler.js +22 -16
  39. package/src/handlers/input/InputActionAddToolHandler.js +2 -2
  40. package/src/handlers/input/InputActionMapCreateToolHandler.js +2 -2
  41. package/src/handlers/input/InputActionMapRemoveToolHandler.js +2 -2
  42. package/src/handlers/input/InputActionRemoveToolHandler.js +2 -2
  43. package/src/handlers/input/InputBindingAddToolHandler.js +2 -2
  44. package/src/handlers/input/InputBindingCompositeCreateToolHandler.js +2 -2
  45. package/src/handlers/input/InputBindingRemoveAllToolHandler.js +2 -2
  46. package/src/handlers/input/InputBindingRemoveToolHandler.js +2 -2
  47. package/src/handlers/input/InputControlSchemesManageToolHandler.js +2 -2
  48. package/src/handlers/package/PackageManagerToolHandler.js +41 -44
  49. package/src/handlers/package/RegistryConfigToolHandler.js +28 -7
  50. package/src/handlers/playmode/PlaymodeGetStateToolHandler.js +12 -16
  51. package/src/handlers/playmode/PlaymodePauseToolHandler.js +8 -12
  52. package/src/handlers/playmode/PlaymodeWaitForStateToolHandler.js +6 -3
  53. package/src/handlers/scene/GetSceneInfoToolHandler.js +11 -11
  54. package/src/handlers/scene/SceneCreateToolHandler.js +28 -31
  55. package/src/handlers/scene/SceneListToolHandler.js +21 -24
  56. package/src/handlers/scene/SceneLoadToolHandler.js +27 -29
  57. package/src/handlers/scene/SceneSaveToolHandler.js +19 -22
  58. package/src/handlers/screenshot/ScreenshotCaptureToolHandler.js +88 -66
  59. package/src/handlers/script/CodeIndexStatusToolHandler.js +4 -3
  60. package/src/handlers/script/CodeIndexUpdateToolHandler.js +24 -14
  61. package/src/handlers/script/ScriptCreateClassToolHandler.js +44 -9
  62. package/src/handlers/script/ScriptPackagesListToolHandler.js +91 -91
  63. package/src/handlers/script/ScriptRefactorRenameToolHandler.js +80 -71
  64. package/src/handlers/script/ScriptRemoveSymbolToolHandler.js +21 -7
  65. package/src/handlers/script/ScriptSearchToolHandler.js +299 -266
  66. package/src/handlers/script/ScriptSymbolsGetToolHandler.js +88 -79
  67. package/src/handlers/settings/SettingsGetToolHandler.js +28 -13
  68. package/src/handlers/settings/SettingsUpdateToolHandler.js +20 -6
  69. package/src/handlers/ui/UIClickElementToolHandler.js +87 -96
  70. package/src/handlers/ui/UIFindElementsToolHandler.js +45 -55
  71. package/src/handlers/ui/UIGetElementStateToolHandler.js +35 -43
  72. package/src/handlers/ui/UISetElementValueToolHandler.js +42 -49
  73. package/src/handlers/ui/UISimulateInputToolHandler.js +134 -136
  74. package/src/handlers/video/VideoCaptureForToolHandler.js +24 -7
  75. package/src/lsp/LspRpcClient.js +24 -12
  76. package/src/tools/analysis/analyzeSceneContents.js +85 -85
  77. package/src/tools/analysis/findByComponent.js +73 -73
  78. package/src/tools/analysis/getAnimatorState.js +287 -287
  79. package/src/tools/analysis/getComponentValues.js +161 -161
  80. package/src/tools/analysis/getGameObjectDetails.js +138 -138
  81. package/src/tools/analysis/getInputActionsState.js +291 -291
  82. package/src/tools/analysis/getObjectReferences.js +72 -72
  83. package/src/tools/input/inputActionsEditor.js +522 -474
  84. package/src/tools/scene/createScene.js +98 -97
  85. package/src/tools/scene/getSceneInfo.js +82 -81
  86. package/src/tools/scene/listScenes.js +70 -69
  87. package/src/tools/scene/loadScene.js +108 -106
  88. package/src/tools/scene/saveScene.js +78 -77
  89. package/src/tools/system/ping.js +9 -12
  90. package/src/utils/validators.js +2 -2
@@ -14,7 +14,8 @@ export class GameObjectGetHierarchyToolHandler extends BaseToolHandler {
14
14
  properties: {
15
15
  rootPath: {
16
16
  type: 'string',
17
- description: 'Path to GameObject whose children will be the root of the returned hierarchy (e.g., "/Team_0" returns Team_0\'s children). If not specified, returns scene root objects.'
17
+ description:
18
+ 'Path to GameObject whose children will be the root of the returned hierarchy (e.g., "/Team_0" returns Team_0\'s children). If not specified, returns scene root objects.'
18
19
  },
19
20
  includeInactive: {
20
21
  type: 'boolean',
@@ -22,16 +23,19 @@ export class GameObjectGetHierarchyToolHandler extends BaseToolHandler {
22
23
  },
23
24
  maxDepth: {
24
25
  type: 'number',
25
- description: 'Maximum depth to traverse from the root. 0=immediate children only (default), 1=children+grandchildren, 2=children+grandchildren+great-grandchildren, etc. (-1 for unlimited)',
26
+ description:
27
+ 'Maximum depth to traverse from the root. 0=immediate children only (default), 1=children+grandchildren, 2=children+grandchildren+great-grandchildren, etc. (-1 for unlimited)',
26
28
  minimum: -1
27
29
  },
28
30
  includeComponents: {
29
31
  type: 'boolean',
30
- description: 'Include component information (default: false). WARNING: Significantly increases response size - use with small maxObjects values.'
32
+ description:
33
+ 'Include component information (default: false). WARNING: Significantly increases response size - use with small maxObjects values.'
31
34
  },
32
35
  includeTransform: {
33
36
  type: 'boolean',
34
- description: 'Include transform information (default: false). WARNING: Increases response size - use with small maxObjects values.'
37
+ description:
38
+ 'Include transform information (default: false). WARNING: Increases response size - use with small maxObjects values.'
35
39
  },
36
40
  includeTags: {
37
41
  type: 'boolean',
@@ -43,18 +47,20 @@ export class GameObjectGetHierarchyToolHandler extends BaseToolHandler {
43
47
  },
44
48
  nameOnly: {
45
49
  type: 'boolean',
46
- description: 'Return only names and paths for minimal data size (default: false). RECOMMENDED for large hierarchies to reduce token usage.'
50
+ description:
51
+ 'Return only names and paths for minimal data size (default: false). RECOMMENDED for large hierarchies to reduce token usage.'
47
52
  },
48
53
  maxObjects: {
49
54
  type: 'number',
50
- description: 'Maximum number of objects to include in response. Unity default: 100 (-1 for unlimited). RECOMMENDED: 10-50 for detailed info, 100-500 for nameOnly mode to avoid MCP token limits',
55
+ description:
56
+ 'Maximum number of objects to include in response. Unity default: 100 (-1 for unlimited). RECOMMENDED: 10-50 for detailed info, 100-500 for nameOnly mode to avoid MCP token limits',
51
57
  minimum: -1
52
58
  }
53
59
  },
54
60
  required: []
55
61
  }
56
62
  );
57
-
63
+
58
64
  this.unityConnection = unityConnection;
59
65
  }
60
66
 
@@ -65,7 +71,7 @@ export class GameObjectGetHierarchyToolHandler extends BaseToolHandler {
65
71
  */
66
72
  validate(params) {
67
73
  super.validate(params);
68
-
74
+
69
75
  // Validate maxDepth
70
76
  if (params.maxDepth !== undefined) {
71
77
  const depth = Number(params.maxDepth);
@@ -73,7 +79,7 @@ export class GameObjectGetHierarchyToolHandler extends BaseToolHandler {
73
79
  throw new Error('maxDepth must be -1 or a positive number');
74
80
  }
75
81
  }
76
-
82
+
77
83
  // Validate maxObjects
78
84
  if (params.maxObjects !== undefined) {
79
85
  const maxObjects = Number(params.maxObjects);
@@ -93,21 +99,21 @@ export class GameObjectGetHierarchyToolHandler extends BaseToolHandler {
93
99
  if (!this.unityConnection.isConnected()) {
94
100
  await this.unityConnection.connect();
95
101
  }
96
-
102
+
97
103
  // Send get_hierarchy command
98
104
  const result = await this.unityConnection.sendCommand('get_hierarchy', params);
99
-
105
+
100
106
  // Check for errors from Unity
101
107
  if (result.error) {
102
108
  throw new Error(result.error);
103
109
  }
104
-
110
+
105
111
  // Add helpful summary
106
112
  if (result.hierarchy) {
107
113
  result.totalObjects = this.countObjects(result.hierarchy);
108
114
  result.summary = `Scene "${result.sceneName}" contains ${result.totalObjects} GameObject${result.totalObjects !== 1 ? 's' : ''} (${result.objectCount} at root level)`;
109
115
  }
110
-
116
+
111
117
  return result;
112
118
  }
113
119
 
@@ -118,15 +124,15 @@ export class GameObjectGetHierarchyToolHandler extends BaseToolHandler {
118
124
  */
119
125
  countObjects(hierarchy) {
120
126
  let count = 0;
121
-
127
+
122
128
  for (const node of hierarchy) {
123
129
  count++; // Count this node
124
-
130
+
125
131
  if (node.children && Array.isArray(node.children)) {
126
132
  count += this.countObjects(node.children);
127
133
  }
128
134
  }
129
-
135
+
130
136
  return count;
131
137
  }
132
138
  }
@@ -1,7 +1,7 @@
1
1
  import { BaseToolHandler } from '../base/BaseToolHandler.js';
2
2
  import {
3
- addInputActionToolDefinition,
4
- addInputActionHandler
3
+ addInputActionToolDefinition,
4
+ addInputActionHandler
5
5
  } from '../../tools/input/inputActionsEditor.js';
6
6
 
7
7
  export class InputActionAddToolHandler extends BaseToolHandler {
@@ -1,7 +1,7 @@
1
1
  import { BaseToolHandler } from '../base/BaseToolHandler.js';
2
2
  import {
3
- createActionMapToolDefinition,
4
- createActionMapHandler
3
+ createActionMapToolDefinition,
4
+ createActionMapHandler
5
5
  } from '../../tools/input/inputActionsEditor.js';
6
6
 
7
7
  export class InputActionMapCreateToolHandler extends BaseToolHandler {
@@ -1,7 +1,7 @@
1
1
  import { BaseToolHandler } from '../base/BaseToolHandler.js';
2
2
  import {
3
- removeActionMapToolDefinition,
4
- removeActionMapHandler
3
+ removeActionMapToolDefinition,
4
+ removeActionMapHandler
5
5
  } from '../../tools/input/inputActionsEditor.js';
6
6
 
7
7
  export class InputActionMapRemoveToolHandler extends BaseToolHandler {
@@ -1,7 +1,7 @@
1
1
  import { BaseToolHandler } from '../base/BaseToolHandler.js';
2
2
  import {
3
- removeInputActionToolDefinition,
4
- removeInputActionHandler
3
+ removeInputActionToolDefinition,
4
+ removeInputActionHandler
5
5
  } from '../../tools/input/inputActionsEditor.js';
6
6
 
7
7
  export class InputActionRemoveToolHandler extends BaseToolHandler {
@@ -1,7 +1,7 @@
1
1
  import { BaseToolHandler } from '../base/BaseToolHandler.js';
2
2
  import {
3
- addInputBindingToolDefinition,
4
- addInputBindingHandler
3
+ addInputBindingToolDefinition,
4
+ addInputBindingHandler
5
5
  } from '../../tools/input/inputActionsEditor.js';
6
6
 
7
7
  export class InputBindingAddToolHandler extends BaseToolHandler {
@@ -1,7 +1,7 @@
1
1
  import { BaseToolHandler } from '../base/BaseToolHandler.js';
2
2
  import {
3
- createCompositeBindingToolDefinition,
4
- createCompositeBindingHandler
3
+ createCompositeBindingToolDefinition,
4
+ createCompositeBindingHandler
5
5
  } from '../../tools/input/inputActionsEditor.js';
6
6
 
7
7
  export class InputBindingCompositeCreateToolHandler extends BaseToolHandler {
@@ -1,7 +1,7 @@
1
1
  import { BaseToolHandler } from '../base/BaseToolHandler.js';
2
2
  import {
3
- removeAllBindingsToolDefinition,
4
- removeAllBindingsHandler
3
+ removeAllBindingsToolDefinition,
4
+ removeAllBindingsHandler
5
5
  } from '../../tools/input/inputActionsEditor.js';
6
6
 
7
7
  export class InputBindingRemoveAllToolHandler extends BaseToolHandler {
@@ -1,7 +1,7 @@
1
1
  import { BaseToolHandler } from '../base/BaseToolHandler.js';
2
2
  import {
3
- removeInputBindingToolDefinition,
4
- removeInputBindingHandler
3
+ removeInputBindingToolDefinition,
4
+ removeInputBindingHandler
5
5
  } from '../../tools/input/inputActionsEditor.js';
6
6
 
7
7
  export class InputBindingRemoveToolHandler extends BaseToolHandler {
@@ -1,7 +1,7 @@
1
1
  import { BaseToolHandler } from '../base/BaseToolHandler.js';
2
2
  import {
3
- manageControlSchemesToolDefinition,
4
- manageControlSchemesHandler
3
+ manageControlSchemesToolDefinition,
4
+ manageControlSchemesHandler
5
5
  } from '../../tools/input/inputActionsEditor.js';
6
6
 
7
7
  export class InputControlSchemesManageToolHandler extends BaseToolHandler {
@@ -7,50 +7,46 @@ import { BaseToolHandler } from '../base/BaseToolHandler.js';
7
7
 
8
8
  export default class PackageManagerToolHandler extends BaseToolHandler {
9
9
  constructor(unityConnection) {
10
- super(
11
- 'package_manage',
12
- 'Manage Unity packages - search, install, remove, and list packages',
13
- {
14
- type: 'object',
15
- properties: {
16
- action: {
17
- type: 'string',
18
- enum: ['search', 'list', 'install', 'remove', 'info', 'recommend'],
19
- description: 'The package operation to perform'
20
- },
21
- keyword: {
22
- type: 'string',
23
- description: 'Search keyword (for search action)'
24
- },
25
- packageId: {
26
- type: 'string',
27
- description: 'Package ID to install (e.g., com.unity.textmeshpro)'
28
- },
29
- packageName: {
30
- type: 'string',
31
- description: 'Package name to remove or get info'
32
- },
33
- version: {
34
- type: 'string',
35
- description: 'Specific version to install (optional)'
36
- },
37
- category: {
38
- type: 'string',
39
- enum: ['essential', 'rendering', 'tools', 'networking', 'mobile'],
40
- description: 'Category for recommendations'
41
- },
42
- includeBuiltIn: {
43
- type: 'boolean',
44
- description: 'Include built-in packages in list (default: false)'
45
- },
46
- limit: {
47
- type: 'number',
48
- description: 'Maximum number of search results (default: 20)'
49
- }
10
+ super('package_manage', 'Manage Unity packages - search, install, remove, and list packages', {
11
+ type: 'object',
12
+ properties: {
13
+ action: {
14
+ type: 'string',
15
+ enum: ['search', 'list', 'install', 'remove', 'info', 'recommend'],
16
+ description: 'The package operation to perform'
50
17
  },
51
- required: ['action']
52
- }
53
- );
18
+ keyword: {
19
+ type: 'string',
20
+ description: 'Search keyword (for search action)'
21
+ },
22
+ packageId: {
23
+ type: 'string',
24
+ description: 'Package ID to install (e.g., com.unity.textmeshpro)'
25
+ },
26
+ packageName: {
27
+ type: 'string',
28
+ description: 'Package name to remove or get info'
29
+ },
30
+ version: {
31
+ type: 'string',
32
+ description: 'Specific version to install (optional)'
33
+ },
34
+ category: {
35
+ type: 'string',
36
+ enum: ['essential', 'rendering', 'tools', 'networking', 'mobile'],
37
+ description: 'Category for recommendations'
38
+ },
39
+ includeBuiltIn: {
40
+ type: 'boolean',
41
+ description: 'Include built-in packages in list (default: false)'
42
+ },
43
+ limit: {
44
+ type: 'number',
45
+ description: 'Maximum number of search results (default: 20)'
46
+ }
47
+ },
48
+ required: ['action']
49
+ });
54
50
  this.unityConnection = unityConnection;
55
51
  }
56
52
 
@@ -180,7 +176,8 @@ export default class PackageManagerToolHandler extends BaseToolHandler {
180
176
  packages: result.packages,
181
177
  allPackages: result.allPackages,
182
178
  message: result.message || 'Package recommendations retrieved'
183
- }; }
179
+ };
180
+ }
184
181
  }
185
182
 
186
183
  truncateDescription(description) {
@@ -61,7 +61,8 @@ export default class RegistryConfigToolHandler extends BaseToolHandler {
61
61
  if (!registryName) throw new Error('Registry name is required for remove action');
62
62
  break;
63
63
  case 'add_scope':
64
- if (!registryName || !scope) throw new Error('Registry name and scope are required for add_scope action');
64
+ if (!registryName || !scope)
65
+ throw new Error('Registry name and scope are required for add_scope action');
65
66
  break;
66
67
  }
67
68
  }
@@ -180,18 +181,38 @@ export default class RegistryConfigToolHandler extends BaseToolHandler {
180
181
  scope: pkg.scope
181
182
  })),
182
183
  message: result.message || `Recommendations for ${result.registry}`
183
- }; }
184
+ };
185
+ }
184
186
  }
185
187
 
186
188
  static getExamples() {
187
189
  return [
188
190
  { description: 'List configured registries', input: { action: 'list' } },
189
- { description: 'Add OpenUPM registry with popular scopes', input: { action: 'add_openupm', autoAddPopular: true } },
190
- { description: 'Add OpenUPM with custom scopes', input: { action: 'add_openupm', scopes: ['com.cysharp', 'com.neuecc', 'jp.keijiro'], autoAddPopular: false } },
191
- { description: 'Add Unity NuGet registry', input: { action: 'add_nuget', autoAddPopular: true } },
192
- { description: 'Add scope to existing registry', input: { action: 'add_scope', registryName: 'OpenUPM', scope: 'com.yasirkula' } },
191
+ {
192
+ description: 'Add OpenUPM registry with popular scopes',
193
+ input: { action: 'add_openupm', autoAddPopular: true }
194
+ },
195
+ {
196
+ description: 'Add OpenUPM with custom scopes',
197
+ input: {
198
+ action: 'add_openupm',
199
+ scopes: ['com.cysharp', 'com.neuecc', 'jp.keijiro'],
200
+ autoAddPopular: false
201
+ }
202
+ },
203
+ {
204
+ description: 'Add Unity NuGet registry',
205
+ input: { action: 'add_nuget', autoAddPopular: true }
206
+ },
207
+ {
208
+ description: 'Add scope to existing registry',
209
+ input: { action: 'add_scope', registryName: 'OpenUPM', scope: 'com.yasirkula' }
210
+ },
193
211
  { description: 'Remove a registry', input: { action: 'remove', registryName: 'OpenUPM' } },
194
- { description: 'Get recommended packages for OpenUPM', input: { action: 'recommend', registry: 'openupm' } },
212
+ {
213
+ description: 'Get recommended packages for OpenUPM',
214
+ input: { action: 'recommend', registry: 'openupm' }
215
+ },
195
216
  { description: 'Get all registry recommendations', input: { action: 'recommend' } }
196
217
  ];
197
218
  }
@@ -5,23 +5,19 @@ import { BaseToolHandler } from '../base/BaseToolHandler.js';
5
5
  */
6
6
  export class PlaymodeGetStateToolHandler extends BaseToolHandler {
7
7
  constructor(unityConnection) {
8
- super(
9
- 'playmode_get_state',
10
- 'Get current Unity editor state including play mode status',
11
- {
12
- type: 'object',
13
- properties: {
14
- waitFor: {
15
- type: 'object',
16
- properties: { isPlaying: { type: 'boolean' } },
17
- required: ['isPlaying']
18
- },
19
- timeoutMs: { type: 'number' },
20
- pollMs: { type: 'number' }
8
+ super('playmode_get_state', 'Get current Unity editor state including play mode status', {
9
+ type: 'object',
10
+ properties: {
11
+ waitFor: {
12
+ type: 'object',
13
+ properties: { isPlaying: { type: 'boolean' } },
14
+ required: ['isPlaying']
21
15
  },
22
- required: []
23
- }
24
- );
16
+ timeoutMs: { type: 'number' },
17
+ pollMs: { type: 'number' }
18
+ },
19
+ required: []
20
+ });
25
21
  this.unityConnection = unityConnection;
26
22
  // 軽量なソフトキャッシュ(単発取得時のみ使用)
27
23
  this._last = { t: 0, state: null };
@@ -5,15 +5,11 @@ import { BaseToolHandler } from '../base/BaseToolHandler.js';
5
5
  */
6
6
  export class PlaymodePauseToolHandler extends BaseToolHandler {
7
7
  constructor(unityConnection) {
8
- super(
9
- 'playmode_pause',
10
- 'Pause or resume Unity play mode',
11
- {
12
- type: 'object',
13
- properties: {},
14
- required: []
15
- }
16
- );
8
+ super('playmode_pause', 'Pause or resume Unity play mode', {
9
+ type: 'object',
10
+ properties: {},
11
+ required: []
12
+ });
17
13
  this.unityConnection = unityConnection;
18
14
  }
19
15
 
@@ -27,17 +23,17 @@ export class PlaymodePauseToolHandler extends BaseToolHandler {
27
23
  if (!this.unityConnection.isConnected()) {
28
24
  throw new Error('Unity connection not available');
29
25
  }
30
-
26
+
31
27
  // Send pause command to Unity
32
28
  const result = await this.unityConnection.sendCommand('pause_game', params);
33
-
29
+
34
30
  // Check for Unity-side errors
35
31
  if (result.status === 'error') {
36
32
  const error = new Error(result.error);
37
33
  error.code = 'UNITY_ERROR';
38
34
  throw error;
39
35
  }
40
-
36
+
41
37
  // Return the result with state information
42
38
  return result;
43
39
  }
@@ -26,7 +26,9 @@ export class PlaymodeWaitForStateToolHandler extends BaseToolHandler {
26
26
  const start = Date.now();
27
27
  for (;;) {
28
28
  if (!this.unityConnection.isConnected()) {
29
- try { await this.unityConnection.connect(); } catch {}
29
+ try {
30
+ await this.unityConnection.connect();
31
+ } catch {}
30
32
  }
31
33
  try {
32
34
  const state = await this.unityConnection.sendCommand('playmode_get_state', {});
@@ -36,10 +38,11 @@ export class PlaymodeWaitForStateToolHandler extends BaseToolHandler {
36
38
  } catch {}
37
39
  await new Promise(r => setTimeout(r, pollMs));
38
40
  if (timeoutMs != null && Date.now() - start > timeoutMs) {
39
- const state = this.unityConnection.isConnected() ? await this.unityConnection.sendCommand('get_editor_state', {}).catch(() => ({})) : {};
41
+ const state = this.unityConnection.isConnected()
42
+ ? await this.unityConnection.sendCommand('get_editor_state', {}).catch(() => ({}))
43
+ : {};
40
44
  return { status: 'timeout', state, waitedMs: Date.now() - start };
41
45
  }
42
46
  }
43
47
  }
44
48
  }
45
-
@@ -5,16 +5,16 @@ import { getSceneInfoToolDefinition, getSceneInfoHandler } from '../../tools/sce
5
5
  * Handler for get_scene_info tool
6
6
  */
7
7
  export class GetSceneInfoToolHandler extends BaseToolHandler {
8
- constructor(unityConnection) {
9
- super(
10
- getSceneInfoToolDefinition.name,
11
- getSceneInfoToolDefinition.description,
12
- getSceneInfoToolDefinition.inputSchema
13
- );
14
- this.unityConnection = unityConnection;
15
- }
8
+ constructor(unityConnection) {
9
+ super(
10
+ getSceneInfoToolDefinition.name,
11
+ getSceneInfoToolDefinition.description,
12
+ getSceneInfoToolDefinition.inputSchema
13
+ );
14
+ this.unityConnection = unityConnection;
15
+ }
16
16
 
17
- async execute(args) {
18
- return getSceneInfoHandler(this.unityConnection, args);
19
- }
17
+ async execute(args) {
18
+ return getSceneInfoHandler(this.unityConnection, args);
19
+ }
20
20
  }
@@ -5,32 +5,29 @@ import { BaseToolHandler } from '../base/BaseToolHandler.js';
5
5
  */
6
6
  export class SceneCreateToolHandler extends BaseToolHandler {
7
7
  constructor(unityConnection) {
8
- super(
9
- 'scene_create',
10
- 'Create a new scene (optionally load it and add to build settings).',
11
- {
12
- type: 'object',
13
- properties: {
14
- sceneName: {
15
- type: 'string',
16
- description: 'Name of the scene to create'
17
- },
18
- path: {
19
- type: 'string',
20
- description: 'Path where the scene should be saved (e.g., "Assets/Scenes/"). If not specified, defaults to "Assets/Scenes/"'
21
- },
22
- loadScene: {
23
- type: 'boolean',
24
- description: 'Whether to load the scene after creation (default: true)'
25
- },
26
- addToBuildSettings: {
27
- type: 'boolean',
28
- description: 'Whether to add the scene to build settings (default: false)'
29
- }
8
+ super('scene_create', 'Create a new scene (optionally load it and add to build settings).', {
9
+ type: 'object',
10
+ properties: {
11
+ sceneName: {
12
+ type: 'string',
13
+ description: 'Name of the scene to create'
30
14
  },
31
- required: ['sceneName']
32
- }
33
- );
15
+ path: {
16
+ type: 'string',
17
+ description:
18
+ 'Path where the scene should be saved (e.g., "Assets/Scenes/"). If not specified, defaults to "Assets/Scenes/"'
19
+ },
20
+ loadScene: {
21
+ type: 'boolean',
22
+ description: 'Whether to load the scene after creation (default: true)'
23
+ },
24
+ addToBuildSettings: {
25
+ type: 'boolean',
26
+ description: 'Whether to add the scene to build settings (default: false)'
27
+ }
28
+ },
29
+ required: ['sceneName']
30
+ });
34
31
  this.unityConnection = unityConnection;
35
32
  }
36
33
 
@@ -41,12 +38,12 @@ export class SceneCreateToolHandler extends BaseToolHandler {
41
38
  */
42
39
  validate(params) {
43
40
  super.validate(params);
44
-
41
+
45
42
  // Additional validation for scene name
46
43
  if (!params.sceneName || params.sceneName.trim() === '') {
47
44
  throw new Error('Scene name cannot be empty');
48
45
  }
49
-
46
+
50
47
  // Check for invalid characters in scene name
51
48
  if (params.sceneName.includes('/') || params.sceneName.includes('\\')) {
52
49
  throw new Error('Scene name contains invalid characters');
@@ -63,17 +60,17 @@ export class SceneCreateToolHandler extends BaseToolHandler {
63
60
  if (!this.unityConnection.isConnected()) {
64
61
  throw new Error('Unity connection not available');
65
62
  }
66
-
63
+
67
64
  // Send command to Unity
68
65
  const result = await this.unityConnection.sendCommand('create_scene', params);
69
-
66
+
70
67
  // Check for Unity-side errors
71
68
  if (result.status === 'error') {
72
69
  const error = new Error(result.error);
73
70
  error.code = 'UNITY_ERROR';
74
71
  throw error;
75
72
  }
76
-
73
+
77
74
  // Handle undefined or null results from Unity
78
75
  if (result.result === undefined || result.result === null) {
79
76
  return {
@@ -85,7 +82,7 @@ export class SceneCreateToolHandler extends BaseToolHandler {
85
82
  message: 'Scene creation completed but Unity returned no details'
86
83
  };
87
84
  }
88
-
85
+
89
86
  return result.result;
90
87
  }
91
88
  }