@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
@@ -2,121 +2,123 @@
2
2
  * Tool definition for scene_load
3
3
  */
4
4
  export const loadSceneToolDefinition = {
5
- name: 'scene_load',
6
- description: 'Load a scene in Unity',
7
- inputSchema: {
8
- type: 'object',
9
- properties: {
10
- scenePath: {
11
- type: 'string',
12
- description: 'Full path to the scene file (e.g., "Assets/Scenes/MainMenu.unity")'
13
- },
14
- sceneName: {
15
- type: 'string',
16
- description: 'Name of the scene to load (must be in build settings). Use either scenePath or sceneName, not both.'
17
- },
18
- loadMode: {
19
- type: 'string',
20
- enum: ['Single', 'Additive'],
21
- description: 'How to load the scene. Single replaces current scene(s), Additive adds to current scene(s) (default: Single)'
22
- }
23
- },
24
- required: []
25
- }
5
+ name: 'scene_load',
6
+ description: 'Load a scene in Unity',
7
+ inputSchema: {
8
+ type: 'object',
9
+ properties: {
10
+ scenePath: {
11
+ type: 'string',
12
+ description: 'Full path to the scene file (e.g., "Assets/Scenes/MainMenu.unity")'
13
+ },
14
+ sceneName: {
15
+ type: 'string',
16
+ description:
17
+ 'Name of the scene to load (must be in build settings). Use either scenePath or sceneName, not both.'
18
+ },
19
+ loadMode: {
20
+ type: 'string',
21
+ enum: ['Single', 'Additive'],
22
+ description:
23
+ 'How to load the scene. Single replaces current scene(s), Additive adds to current scene(s) (default: Single)'
24
+ }
25
+ },
26
+ required: []
27
+ }
26
28
  };
27
29
 
28
30
  /**
29
31
  * Handler for load_scene tool
30
32
  */
31
33
  export async function loadSceneHandler(unityConnection, args) {
32
- try {
33
- // Check connection
34
- if (!unityConnection.isConnected()) {
35
- return {
36
- content: [
37
- {
38
- type: 'text',
39
- text: 'Failed to load scene: Unity connection not available'
40
- }
41
- ],
42
- isError: true
43
- };
44
- }
45
-
46
- // Validate that either scenePath or sceneName is provided
47
- if (!args.scenePath && !args.sceneName) {
48
- return {
49
- content: [
50
- {
51
- type: 'text',
52
- text: 'Failed to load scene: Either scenePath or sceneName must be provided'
53
- }
54
- ],
55
- isError: true
56
- };
57
- }
34
+ try {
35
+ // Check connection
36
+ if (!unityConnection.isConnected()) {
37
+ return {
38
+ content: [
39
+ {
40
+ type: 'text',
41
+ text: 'Failed to load scene: Unity connection not available'
42
+ }
43
+ ],
44
+ isError: true
45
+ };
46
+ }
58
47
 
59
- // Validate that only one is provided
60
- if (args.scenePath && args.sceneName) {
61
- return {
62
- content: [
63
- {
64
- type: 'text',
65
- text: 'Failed to load scene: Provide either scenePath or sceneName, not both'
66
- }
67
- ],
68
- isError: true
69
- };
70
- }
48
+ // Validate that either scenePath or sceneName is provided
49
+ if (!args.scenePath && !args.sceneName) {
50
+ return {
51
+ content: [
52
+ {
53
+ type: 'text',
54
+ text: 'Failed to load scene: Either scenePath or sceneName must be provided'
55
+ }
56
+ ],
57
+ isError: true
58
+ };
59
+ }
71
60
 
72
- // Validate load mode
73
- if (args.loadMode && !['Single', 'Additive'].includes(args.loadMode)) {
74
- return {
75
- content: [
76
- {
77
- type: 'text',
78
- text: 'Failed to load scene: Invalid load mode. Must be "Single" or "Additive"'
79
- }
80
- ],
81
- isError: true
82
- };
83
- }
61
+ // Validate that only one is provided
62
+ if (args.scenePath && args.sceneName) {
63
+ return {
64
+ content: [
65
+ {
66
+ type: 'text',
67
+ text: 'Failed to load scene: Provide either scenePath or sceneName, not both'
68
+ }
69
+ ],
70
+ isError: true
71
+ };
72
+ }
84
73
 
85
- // Send command to Unity
86
- const result = await unityConnection.sendCommand('scene_load', args);
74
+ // Validate load mode
75
+ if (args.loadMode && !['Single', 'Additive'].includes(args.loadMode)) {
76
+ return {
77
+ content: [
78
+ {
79
+ type: 'text',
80
+ text: 'Failed to load scene: Invalid load mode. Must be "Single" or "Additive"'
81
+ }
82
+ ],
83
+ isError: true
84
+ };
85
+ }
87
86
 
88
- // Handle Unity response
89
- if (result.status === 'error') {
90
- return {
91
- content: [
92
- {
93
- type: 'text',
94
- text: `Failed to load scene: ${result.error}`
95
- }
96
- ],
97
- isError: true
98
- };
99
- }
87
+ // Send command to Unity
88
+ const result = await unityConnection.sendCommand('scene_load', args);
100
89
 
101
- // Success response
102
- return {
103
- content: [
104
- {
105
- type: 'text',
106
- text: result.result.summary || `Scene loaded successfully`
107
- }
108
- ],
109
- isError: false
110
- };
111
- } catch (error) {
112
- return {
113
- content: [
114
- {
115
- type: 'text',
116
- text: `Failed to load scene: ${error.message}`
117
- }
118
- ],
119
- isError: true
120
- };
90
+ // Handle Unity response
91
+ if (result.status === 'error') {
92
+ return {
93
+ content: [
94
+ {
95
+ type: 'text',
96
+ text: `Failed to load scene: ${result.error}`
97
+ }
98
+ ],
99
+ isError: true
100
+ };
121
101
  }
122
- }
102
+
103
+ // Success response
104
+ return {
105
+ content: [
106
+ {
107
+ type: 'text',
108
+ text: result.result.summary || `Scene loaded successfully`
109
+ }
110
+ ],
111
+ isError: false
112
+ };
113
+ } catch (error) {
114
+ return {
115
+ content: [
116
+ {
117
+ type: 'text',
118
+ text: `Failed to load scene: ${error.message}`
119
+ }
120
+ ],
121
+ isError: true
122
+ };
123
+ }
124
+ }
@@ -2,90 +2,91 @@
2
2
  * Tool definition for scene_save
3
3
  */
4
4
  export const saveSceneToolDefinition = {
5
- name: 'scene_save',
6
- description: 'Save the current scene in Unity',
7
- inputSchema: {
8
- type: 'object',
9
- properties: {
10
- scenePath: {
11
- type: 'string',
12
- description: 'Path where to save the scene. If not provided, saves to current scene path. Required if saveAs is true.'
13
- },
14
- saveAs: {
15
- type: 'boolean',
16
- description: 'Whether to save as a new scene (creates a copy). Default: false'
17
- }
18
- },
19
- required: []
20
- }
5
+ name: 'scene_save',
6
+ description: 'Save the current scene in Unity',
7
+ inputSchema: {
8
+ type: 'object',
9
+ properties: {
10
+ scenePath: {
11
+ type: 'string',
12
+ description:
13
+ 'Path where to save the scene. If not provided, saves to current scene path. Required if saveAs is true.'
14
+ },
15
+ saveAs: {
16
+ type: 'boolean',
17
+ description: 'Whether to save as a new scene (creates a copy). Default: false'
18
+ }
19
+ },
20
+ required: []
21
+ }
21
22
  };
22
23
 
23
24
  /**
24
25
  * Handler for save_scene tool
25
26
  */
26
27
  export async function saveSceneHandler(unityConnection, args) {
27
- try {
28
- // Check connection
29
- if (!unityConnection.isConnected()) {
30
- return {
31
- content: [
32
- {
33
- type: 'text',
34
- text: 'Failed to save scene: Unity connection not available'
35
- }
36
- ],
37
- isError: true
38
- };
39
- }
40
-
41
- // Validate saveAs requires scenePath
42
- if (args.saveAs && !args.scenePath) {
43
- return {
44
- content: [
45
- {
46
- type: 'text',
47
- text: 'Failed to save scene: scenePath is required when saveAs is true'
48
- }
49
- ],
50
- isError: true
51
- };
52
- }
28
+ try {
29
+ // Check connection
30
+ if (!unityConnection.isConnected()) {
31
+ return {
32
+ content: [
33
+ {
34
+ type: 'text',
35
+ text: 'Failed to save scene: Unity connection not available'
36
+ }
37
+ ],
38
+ isError: true
39
+ };
40
+ }
53
41
 
54
- // Send command to Unity
55
- const result = await unityConnection.sendCommand('scene_save', args);
42
+ // Validate saveAs requires scenePath
43
+ if (args.saveAs && !args.scenePath) {
44
+ return {
45
+ content: [
46
+ {
47
+ type: 'text',
48
+ text: 'Failed to save scene: scenePath is required when saveAs is true'
49
+ }
50
+ ],
51
+ isError: true
52
+ };
53
+ }
56
54
 
57
- // Handle Unity response
58
- if (result.status === 'error') {
59
- return {
60
- content: [
61
- {
62
- type: 'text',
63
- text: `Failed to save scene: ${result.error}`
64
- }
65
- ],
66
- isError: true
67
- };
68
- }
55
+ // Send command to Unity
56
+ const result = await unityConnection.sendCommand('scene_save', args);
69
57
 
70
- // Success response
71
- return {
72
- content: [
73
- {
74
- type: 'text',
75
- text: result.result.summary || `Scene saved successfully`
76
- }
77
- ],
78
- isError: false
79
- };
80
- } catch (error) {
81
- return {
82
- content: [
83
- {
84
- type: 'text',
85
- text: `Failed to save scene: ${error.message}`
86
- }
87
- ],
88
- isError: true
89
- };
58
+ // Handle Unity response
59
+ if (result.status === 'error') {
60
+ return {
61
+ content: [
62
+ {
63
+ type: 'text',
64
+ text: `Failed to save scene: ${result.error}`
65
+ }
66
+ ],
67
+ isError: true
68
+ };
90
69
  }
91
- }
70
+
71
+ // Success response
72
+ return {
73
+ content: [
74
+ {
75
+ type: 'text',
76
+ text: result.result.summary || `Scene saved successfully`
77
+ }
78
+ ],
79
+ isError: false
80
+ };
81
+ } catch (error) {
82
+ return {
83
+ content: [
84
+ {
85
+ type: 'text',
86
+ text: `Failed to save scene: ${error.message}`
87
+ }
88
+ ],
89
+ isError: true
90
+ };
91
+ }
92
+ }
@@ -1,7 +1,4 @@
1
- import {
2
- ListToolsRequestSchema,
3
- CallToolRequestSchema
4
- } from '@modelcontextprotocol/sdk/types.js';
1
+ import { ListToolsRequestSchema, CallToolRequestSchema } from '@modelcontextprotocol/sdk/types.js';
5
2
 
6
3
  /**
7
4
  * Ping tool for testing Unity connection
@@ -22,30 +19,30 @@ export function registerPingTool(server, unityConnection) {
22
19
  required: []
23
20
  }
24
21
  };
25
-
22
+
26
23
  // Register list tools handler
27
24
  server.setRequestHandler(ListToolsRequestSchema, async () => {
28
25
  return {
29
26
  tools: [pingTool]
30
27
  };
31
28
  });
32
-
29
+
33
30
  // Register call tool handler
34
- server.setRequestHandler(CallToolRequestSchema, async (request) => {
31
+ server.setRequestHandler(CallToolRequestSchema, async request => {
35
32
  const { name, arguments: args } = request.params;
36
-
33
+
37
34
  if (name === 'system_ping') {
38
35
  try {
39
36
  // Ensure connected
40
37
  if (!unityConnection.isConnected()) {
41
38
  await unityConnection.connect();
42
39
  }
43
-
40
+
44
41
  // Send ping with optional message
45
42
  const result = await unityConnection.sendCommand('system_ping', {
46
43
  message: args?.message || 'system_ping'
47
44
  });
48
-
45
+
49
46
  return {
50
47
  content: [
51
48
  {
@@ -66,7 +63,7 @@ export function registerPingTool(server, unityConnection) {
66
63
  };
67
64
  }
68
65
  }
69
-
66
+
70
67
  throw new Error(`Tool not found: ${name}`);
71
68
  });
72
- }
69
+ }
@@ -12,7 +12,7 @@ export function validateVector3(obj, name) {
12
12
  if (obj && typeof obj === 'object') {
13
13
  const keys = Object.keys(obj);
14
14
  const validKeys = ['x', 'y', 'z'];
15
-
15
+
16
16
  for (const key of keys) {
17
17
  if (!validKeys.includes(key)) {
18
18
  throw new Error(`${name} must only contain x, y, z properties`);
@@ -87,4 +87,4 @@ export function validateGameObjectPath(path) {
87
87
  if (!path.startsWith('/')) {
88
88
  throw new Error('GameObject path must start with /');
89
89
  }
90
- }
90
+ }