mcpforunityserver 8.2.3__py3-none-any.whl

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 (65) hide show
  1. __init__.py +0 -0
  2. core/__init__.py +0 -0
  3. core/config.py +56 -0
  4. core/logging_decorator.py +37 -0
  5. core/telemetry.py +533 -0
  6. core/telemetry_decorator.py +164 -0
  7. main.py +411 -0
  8. mcpforunityserver-8.2.3.dist-info/METADATA +222 -0
  9. mcpforunityserver-8.2.3.dist-info/RECORD +65 -0
  10. mcpforunityserver-8.2.3.dist-info/WHEEL +5 -0
  11. mcpforunityserver-8.2.3.dist-info/entry_points.txt +2 -0
  12. mcpforunityserver-8.2.3.dist-info/licenses/LICENSE +21 -0
  13. mcpforunityserver-8.2.3.dist-info/top_level.txt +8 -0
  14. models/__init__.py +4 -0
  15. models/models.py +56 -0
  16. models/unity_response.py +47 -0
  17. routes/__init__.py +0 -0
  18. services/__init__.py +0 -0
  19. services/custom_tool_service.py +339 -0
  20. services/registry/__init__.py +22 -0
  21. services/registry/resource_registry.py +53 -0
  22. services/registry/tool_registry.py +51 -0
  23. services/resources/__init__.py +81 -0
  24. services/resources/active_tool.py +47 -0
  25. services/resources/custom_tools.py +57 -0
  26. services/resources/editor_state.py +42 -0
  27. services/resources/layers.py +29 -0
  28. services/resources/menu_items.py +34 -0
  29. services/resources/prefab_stage.py +39 -0
  30. services/resources/project_info.py +39 -0
  31. services/resources/selection.py +55 -0
  32. services/resources/tags.py +30 -0
  33. services/resources/tests.py +55 -0
  34. services/resources/unity_instances.py +122 -0
  35. services/resources/windows.py +47 -0
  36. services/tools/__init__.py +76 -0
  37. services/tools/batch_execute.py +78 -0
  38. services/tools/debug_request_context.py +71 -0
  39. services/tools/execute_custom_tool.py +38 -0
  40. services/tools/execute_menu_item.py +29 -0
  41. services/tools/find_in_file.py +174 -0
  42. services/tools/manage_asset.py +129 -0
  43. services/tools/manage_editor.py +63 -0
  44. services/tools/manage_gameobject.py +240 -0
  45. services/tools/manage_material.py +95 -0
  46. services/tools/manage_prefabs.py +62 -0
  47. services/tools/manage_scene.py +75 -0
  48. services/tools/manage_script.py +602 -0
  49. services/tools/manage_shader.py +64 -0
  50. services/tools/read_console.py +115 -0
  51. services/tools/run_tests.py +108 -0
  52. services/tools/script_apply_edits.py +998 -0
  53. services/tools/set_active_instance.py +112 -0
  54. services/tools/utils.py +60 -0
  55. transport/__init__.py +0 -0
  56. transport/legacy/port_discovery.py +329 -0
  57. transport/legacy/stdio_port_registry.py +65 -0
  58. transport/legacy/unity_connection.py +785 -0
  59. transport/models.py +62 -0
  60. transport/plugin_hub.py +412 -0
  61. transport/plugin_registry.py +123 -0
  62. transport/unity_instance_middleware.py +141 -0
  63. transport/unity_transport.py +103 -0
  64. utils/module_discovery.py +55 -0
  65. utils/reload_sentinel.py +9 -0
@@ -0,0 +1,222 @@
1
+ Metadata-Version: 2.4
2
+ Name: mcpforunityserver
3
+ Version: 8.2.3
4
+ Summary: MCP for Unity Server: A Unity package for Unity Editor integration via the Model Context Protocol (MCP).
5
+ Author-email: Marcus Sanatan <msanatan@gmail.com>, David Sarno <david.sarno@gmail.com>, Wu Shutong <martinwfire@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Repository, https://github.com/CoplayDev/unity-mcp.git
8
+ Project-URL: Issues, https://github.com/CoplayDev/unity-mcp/issues
9
+ Keywords: mcp,unity,ai,model context protocol,gamedev,unity3d,automation,llm,agent
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Natural Language :: English
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Programming Language :: Python :: Implementation :: CPython
21
+ Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Classifier: Topic :: Games/Entertainment
24
+ Classifier: Topic :: Software Development :: Code Generators
25
+ Requires-Python: >=3.10
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ Requires-Dist: httpx>=0.27.2
29
+ Requires-Dist: fastmcp<2.13.2,>=2.13.0
30
+ Requires-Dist: mcp>=1.16.0
31
+ Requires-Dist: pydantic>=2.12.0
32
+ Requires-Dist: tomli>=2.3.0
33
+ Requires-Dist: fastapi>=0.104.0
34
+ Requires-Dist: uvicorn>=0.35.0
35
+ Provides-Extra: dev
36
+ Requires-Dist: pytest>=8.0.0; extra == "dev"
37
+ Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
38
+ Dynamic: license-file
39
+
40
+ # MCP for Unity Server
41
+
42
+ [![MCP](https://badge.mcpx.dev?status=on 'MCP Enabled')](https://modelcontextprotocol.io/introduction)
43
+ [![python](https://img.shields.io/badge/Python-3.10+-3776AB.svg?style=flat&logo=python&logoColor=white)](https://www.python.org)
44
+ [![License](https://img.shields.io/badge/License-MIT-red.svg 'MIT License')](https://opensource.org/licenses/MIT)
45
+ [![Discord](https://img.shields.io/badge/discord-join-red.svg?logo=discord&logoColor=white)](https://discord.gg/y4p8KfzrN4)
46
+
47
+ Model Context Protocol server for Unity Editor integration. Control Unity through natural language using AI assistants like Claude, Cursor, and more.
48
+
49
+ **Maintained by [Coplay](https://www.coplay.dev/?ref=unity-mcp)** - This project is not affiliated with Unity Technologies.
50
+
51
+ 💬 **Join our community:** [Discord Server](https://discord.gg/y4p8KfzrN4)
52
+
53
+ **Required:** Install the [Unity MCP Plugin](https://github.com/CoplayDev/unity-mcp?tab=readme-ov-file#-step-1-install-the-unity-package) to connect Unity Editor with this MCP server.
54
+
55
+ ---
56
+
57
+ ## Installation
58
+
59
+ ### Option 1: Using uvx (Recommended)
60
+
61
+ Run directly from GitHub without installation:
62
+
63
+ ```bash
64
+ # HTTP (default)
65
+ uvx --from git+https://github.com/CoplayDev/unity-mcp@v8.2.3#subdirectory=Server \
66
+ mcp-for-unity --transport http --http-url http://localhost:8080
67
+
68
+ # Stdio
69
+ uvx --from git+https://github.com/CoplayDev/unity-mcp@v8.2.3#subdirectory=Server \
70
+ mcp-for-unity --transport stdio
71
+ ```
72
+
73
+ **MCP Client Configuration (HTTP):**
74
+
75
+ ```json
76
+ {
77
+ "mcpServers": {
78
+ "UnityMCP": {
79
+ "url": "http://localhost:8080/mcp"
80
+ }
81
+ }
82
+ }
83
+ ```
84
+
85
+ **MCP Client Configuration (stdio):**
86
+
87
+ ```json
88
+ {
89
+ "mcpServers": {
90
+ "UnityMCP": {
91
+ "command": "uvx",
92
+ "args": [
93
+ "--from",
94
+ "git+https://github.com/CoplayDev/unity-mcp@v8.2.3#subdirectory=Server",
95
+ "mcp-for-unity",
96
+ "--transport",
97
+ "stdio"
98
+ ],
99
+ "type": "stdio"
100
+ }
101
+ }
102
+ }
103
+ ```
104
+
105
+ ### Option 2: Using uv (Local Installation)
106
+
107
+ For local development or custom installations:
108
+
109
+ ```bash
110
+ # Clone the repository
111
+ git clone https://github.com/CoplayDev/unity-mcp.git
112
+ cd unity-mcp/Server
113
+
114
+ # Run with uv (HTTP)
115
+ uv run server.py --transport http --http-url http://localhost:8080
116
+
117
+ # Run with uv (stdio)
118
+ uv run server.py --transport stdio
119
+ ```
120
+
121
+ **MCP Client Configuration (HTTP):**
122
+ ```json
123
+ {
124
+ "mcpServers": {
125
+ "UnityMCP": {
126
+ "url": "http://localhost:8080/mcp"
127
+ }
128
+ }
129
+ }
130
+ ```
131
+
132
+ **MCP Client Configuration (stdio – Windows):**
133
+ ```json
134
+ {
135
+ "mcpServers": {
136
+ "UnityMCP": {
137
+ "command": "uv",
138
+ "args": [
139
+ "run",
140
+ "--directory",
141
+ "C:\\path\\to\\unity-mcp\\Server",
142
+ "server.py",
143
+ "--transport",
144
+ "stdio"
145
+ ]
146
+ }
147
+ }
148
+ }
149
+ ```
150
+
151
+ **MCP Client Configuration (stdio – macOS/Linux):**
152
+ ```json
153
+ {
154
+ "mcpServers": {
155
+ "UnityMCP": {
156
+ "command": "uv",
157
+ "args": [
158
+ "run",
159
+ "--directory",
160
+ "/path/to/unity-mcp/Server",
161
+ "server.py",
162
+ "--transport",
163
+ "stdio"
164
+ ]
165
+ }
166
+ }
167
+ }
168
+ ```
169
+
170
+ ### Option 3: Using Docker
171
+
172
+ ```bash
173
+ docker build -t unity-mcp-server .
174
+ docker run -p 8080:8080 unity-mcp-server --transport http --http-url http://0.0.0.0:8080
175
+ ```
176
+
177
+ Configure your MCP client with `"url": "http://localhost:8080/mcp"`. For stdio-in-docker (rare), run the container with `--transport stdio` and use the same `command`/`args` pattern as the uv examples, wrapping it in `docker run -i ...` if needed.
178
+
179
+ ---
180
+
181
+ ## Configuration
182
+
183
+ The server connects to Unity Editor automatically when both are running. No additional configuration needed.
184
+
185
+ **Environment Variables:**
186
+
187
+ - `DISABLE_TELEMETRY=true` - Opt out of anonymous usage analytics
188
+ - `LOG_LEVEL=DEBUG` - Enable detailed logging (default: INFO)
189
+
190
+ ---
191
+
192
+ ## Example Prompts
193
+
194
+ Once connected, try these commands in your AI assistant:
195
+
196
+ - "Create a 3D player controller with WASD movement"
197
+ - "Add a rotating cube to the scene with a red material"
198
+ - "Create a simple platformer level with obstacles"
199
+ - "Generate a shader that creates a holographic effect"
200
+ - "List all GameObjects in the current scene"
201
+
202
+ ---
203
+
204
+ ## Documentation
205
+
206
+ For complete documentation, troubleshooting, and advanced usage:
207
+
208
+ 📖 **[Full Documentation](https://github.com/CoplayDev/unity-mcp#readme)**
209
+
210
+ ---
211
+
212
+ ## Requirements
213
+
214
+ - **Python:** 3.10 or newer
215
+ - **Unity Editor:** 2021.3 LTS or newer
216
+ - **uv:** Python package manager ([Installation Guide](https://docs.astral.sh/uv/getting-started/installation/))
217
+
218
+ ---
219
+
220
+ ## License
221
+
222
+ MIT License - See [LICENSE](https://github.com/CoplayDev/unity-mcp/blob/main/LICENSE)
@@ -0,0 +1,65 @@
1
+ __init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ main.py,sha256=bjQfzp3c9rAe9TtDr1009ARZ6ULWBPxEBopCRmRyXc8,16316
3
+ core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ core/config.py,sha256=czkTtNji1crQcQbUvmdx4OL7f-RBqkVhj_PtHh-w7rs,1623
5
+ core/logging_decorator.py,sha256=D9CD7rFvQz-MBG-G4inizQj0Ivr6dfc9RBmTrw7q8mI,1383
6
+ core/telemetry.py,sha256=eHjYgzd8f7eTwSwF2Kbi8D4TtJIcdaDjKLeo1c-0hVA,19829
7
+ core/telemetry_decorator.py,sha256=ycSTrzVNCDQHSd-xmIWOpVfKFURPxpiZe_XkOQAGDAo,6705
8
+ mcpforunityserver-8.2.3.dist-info/licenses/LICENSE,sha256=bv5lDJZQEqxBgjjc1rkRbkEwpSIHF-8N-1Od0VnEJFw,1066
9
+ models/__init__.py,sha256=JlscZkGWE9TRmSoBi99v_LSl8OAFNGmr8463PYkXin4,179
10
+ models/models.py,sha256=heXuvdBtdats1SGwW8wKFFHM0qR4hA6A7qETn5s9BZ0,1827
11
+ models/unity_response.py,sha256=oJ1PTsnNc5VBC-9OgM59C0C-R9N-GdmEdmz_yph4GSU,1454
12
+ routes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
+ services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
+ services/custom_tool_service.py,sha256=ZOb6LsOQc3C9n3iLn5b7QaG3WJ25M-Id3WG_iE1YhMY,11960
15
+ services/registry/__init__.py,sha256=QCwcYThvGF0kBt3WR6DBskdyxkegJC7NymEChgJA-YM,470
16
+ services/registry/resource_registry.py,sha256=T_Kznqgvt5kKgV7mU85nb0LlFuB4rg-Tm4Cjhxt-IcI,1467
17
+ services/registry/tool_registry.py,sha256=9tMwOP07JE92QFYUS4KvoysO0qC9pkBD5B79kjRsSPw,1304
18
+ services/resources/__init__.py,sha256=O5heeMcgCswnQX1qG2nNtMeAZIaLut734qD7t5UsA0k,2801
19
+ services/resources/active_tool.py,sha256=YTbsiy_hmnKH2q7IoM7oYD7pJkoveZTszRiL1PlhO9M,1474
20
+ services/resources/custom_tools.py,sha256=8lyryGhN3vD2LwMt6ZyKIp5ONtxdI1nfcCAlYjlfQnQ,1704
21
+ services/resources/editor_state.py,sha256=acrSyMfdulRgYQIn7wKHqKqyw4uED_oUf9GU-4o4GAg,1497
22
+ services/resources/layers.py,sha256=q4UQ5PUVUVhmM5l3oXID1wa_wOWAS8l5BGXadBgFuwY,1080
23
+ services/resources/menu_items.py,sha256=9SNycjwTXoeS1ZHra0Y1fTyCjSEdPCo34JyxtuqauG8,1021
24
+ services/resources/prefab_stage.py,sha256=C3mn3UapKYVOA8QUNmLsYreG5YiXdlvGm9ypHQeKBeQ,1382
25
+ services/resources/project_info.py,sha256=gSVSFfwP0u2FmxSowOkdbNoSSQHxfQtLfndvoCXTVSw,1323
26
+ services/resources/selection.py,sha256=4rI5Bdkes4uxtMc_5jQhUaqUl-iprhIiTWqnOJl8tmg,1839
27
+ services/resources/tags.py,sha256=7EhmQjMotz85DSSr7cVKYIy7LPT5mmPfrEySr1mTE6w,1049
28
+ services/resources/tests.py,sha256=xDvvgesPSU93nLD_ERQopOpkpq69pbMEqmFsJd0jekI,2063
29
+ services/resources/unity_instances.py,sha256=fR0cVopGQnmF41IFDycwlo2XniKstfJWLGobgJeiabE,4348
30
+ services/resources/windows.py,sha256=--QVsb0oyoBpSjK2D4kPcZFSe2zdR-t_KSHP-e2QNoY,1427
31
+ services/tools/__init__.py,sha256=3Qav7fAowZ1_TbDRdZQQQES53gv2lTs-2D7PGECnlbM,2353
32
+ services/tools/batch_execute.py,sha256=_ByjffeXQB9j64mcjaxJmrnbSJrMn0f9_6Zh9BBI_2c,2898
33
+ services/tools/debug_request_context.py,sha256=pk02OGfa_yuc4SWxzTR6lEBo0R4ls2yFXp7sdIVshDM,2531
34
+ services/tools/execute_custom_tool.py,sha256=K2qaO4-FTPz0_3j53hhDP9idjC002ugc8C03FtHGTbY,1376
35
+ services/tools/execute_menu_item.py,sha256=FAC-1v_TwOcy6GSxkogDsVxeRtdap0DsPlIngf8uJdU,1184
36
+ services/tools/find_in_file.py,sha256=xp80lqRN2cdZc3XGJWlCpeQEy6WnwyKOj2l5WiHNx0Q,6379
37
+ services/tools/manage_asset.py,sha256=wvzdqgSKC3dhdLcFOgQj9thNYp16y8RJQNWu3PluDpg,6021
38
+ services/tools/manage_editor.py,sha256=_HZRT-_hBakH0g6p7BpxTv3gWpxsaV6KNGRol-qknwo,3243
39
+ services/tools/manage_gameobject.py,sha256=wGJayE8giHwtOkeNBvjWaN8ecEnBDgGTraJKvVRHSgM,13257
40
+ services/tools/manage_material.py,sha256=wZB2H4orhL6wG9TTnmnk-Lj2Gj_zvg7koxW3t319BLU,3545
41
+ services/tools/manage_prefabs.py,sha256=73XzznjFNOm1SazW_Y7l6uGIE7wosMpAIVQs8xpvK9A,3037
42
+ services/tools/manage_scene.py,sha256=dw2ZkbEKCkLVIMA_KqAJmHXcAc9LJeo83GhhvYJZ0DQ,3192
43
+ services/tools/manage_script.py,sha256=lPA5HcS4Al0RiQVz-S6qahFTcPqsk3GSLLXJWHri8P4,27557
44
+ services/tools/manage_shader.py,sha256=HHnHKh7vLij3p8FAinNsPdZGEKivgwSUTxdgDydfmbs,2882
45
+ services/tools/read_console.py,sha256=JSqi2jSgEB5JUZbVripEjXoeEZC-r8rbG8zBprsnxNQ,4895
46
+ services/tools/run_tests.py,sha256=Aga_yubZUuB_YnJNqBYJEq3nIV5z1u3YoyH4YvXCbuc,3780
47
+ services/tools/script_apply_edits.py,sha256=qPm_PsmsK3mYXnziX_btyk8CaB66LTqpDFA2Y4ebZ4U,47504
48
+ services/tools/set_active_instance.py,sha256=B18Y8Jga0pKsx9mFywXr1tWfy0cJVopIMXYO-UJ1jOU,4136
49
+ services/tools/utils.py,sha256=ILZN7bYb5nZvS-60t6rdTsX6OwDu7mlIN3AXXQsJ8H4,1917
50
+ transport/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
51
+ transport/models.py,sha256=6wp7wsmSaeeJEvUGXPF1m6zuJnxJ1NJlCC4YZ9oQIq0,1226
52
+ transport/plugin_hub.py,sha256=55R00ohrmUI0mk_smc_8BsYTvrQMPX4wwsvqXprj0Vk,15596
53
+ transport/plugin_registry.py,sha256=nW-7O7PN0QUgSWivZTkpAVKKq9ZOe2b2yeIdpaNt_3I,4359
54
+ transport/unity_instance_middleware.py,sha256=a-ULWU9b86w0CbYN3meyLxWGxTBXL5CQmBKZmmQ0xZQ,6197
55
+ transport/unity_transport.py,sha256=dvwCjo2jRvnFXd8ruOL36C8W4P1VIQ91qreS2750lPM,3307
56
+ transport/legacy/port_discovery.py,sha256=qM_mtndbYjAj4qPSZEWVeXFOt5_nKczG9pQqORXTBJ0,12768
57
+ transport/legacy/stdio_port_registry.py,sha256=j4iARuP6wetppNDG8qKeuvo1bJKcSlgEhZvSyl_uf0A,2313
58
+ transport/legacy/unity_connection.py,sha256=ujUX9WX7Gb-fxQveHts3uiepTPzFq8i7-XG7u5gSPuM,32668
59
+ utils/module_discovery.py,sha256=My48ofB1BUqxiBoAZAGbEaLQYdsrDhMm8MayBP_bUSQ,2005
60
+ utils/reload_sentinel.py,sha256=s1xMWhl-r2XwN0OUbiUv_VGUy8TvLtV5bkql-5n2DT0,373
61
+ mcpforunityserver-8.2.3.dist-info/METADATA,sha256=OgSQ7AOFOMi03YLWBKxF0jB-96_4RCTcegiXj23njII,6313
62
+ mcpforunityserver-8.2.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
63
+ mcpforunityserver-8.2.3.dist-info/entry_points.txt,sha256=vCtkqw-J9t4pj7JwUZcB54_keVx7DpAR3fYzK6i-s6g,44
64
+ mcpforunityserver-8.2.3.dist-info/top_level.txt,sha256=YKU5e5dREMfCnoVpmlsTm9bku7oqnrzSZ9FeTgjoxJw,58
65
+ mcpforunityserver-8.2.3.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ mcp-for-unity = main:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 CoplayDev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,8 @@
1
+ __init__
2
+ core
3
+ main
4
+ models
5
+ routes
6
+ services
7
+ transport
8
+ utils
models/__init__.py ADDED
@@ -0,0 +1,4 @@
1
+ from .models import MCPResponse, UnityInstanceInfo
2
+ from .unity_response import normalize_unity_response
3
+
4
+ __all__ = ['MCPResponse', 'UnityInstanceInfo', 'normalize_unity_response']
models/models.py ADDED
@@ -0,0 +1,56 @@
1
+ from typing import Any
2
+ from datetime import datetime
3
+ from pydantic import BaseModel, Field
4
+
5
+
6
+ class MCPResponse(BaseModel):
7
+ success: bool
8
+ message: str | None = None
9
+ error: str | None = None
10
+ data: Any | None = None
11
+ # Optional hint for clients about how to handle the response.
12
+ # Supported values:
13
+ # - "retry": Unity is temporarily reloading; call should be retried politely.
14
+ hint: str | None = None
15
+
16
+
17
+ class ToolParameterModel(BaseModel):
18
+ name: str
19
+ description: str | None = None
20
+ type: str = Field(default="string")
21
+ required: bool = Field(default=True)
22
+ default_value: str | None = None
23
+
24
+
25
+ class ToolDefinitionModel(BaseModel):
26
+ name: str
27
+ description: str | None = None
28
+ structured_output: bool | None = True
29
+ requires_polling: bool | None = False
30
+ poll_action: str | None = "status"
31
+ parameters: list[ToolParameterModel] = Field(default_factory=list)
32
+
33
+
34
+ class UnityInstanceInfo(BaseModel):
35
+ """Information about a Unity Editor instance"""
36
+ id: str # "ProjectName@hash" or fallback to hash
37
+ name: str # Project name extracted from path
38
+ path: str # Full project path (Assets folder)
39
+ hash: str # 8-char hash of project path
40
+ port: int # TCP port
41
+ status: str # "running", "reloading", "offline"
42
+ last_heartbeat: datetime | None = None
43
+ unity_version: str | None = None
44
+
45
+ def to_dict(self) -> dict[str, Any]:
46
+ """Convert to dictionary for JSON serialization"""
47
+ return {
48
+ "id": self.id,
49
+ "name": self.name,
50
+ "path": self.path,
51
+ "hash": self.hash,
52
+ "port": self.port,
53
+ "status": self.status,
54
+ "last_heartbeat": self.last_heartbeat.isoformat() if self.last_heartbeat else None,
55
+ "unity_version": self.unity_version
56
+ }
@@ -0,0 +1,47 @@
1
+ """Utilities for normalizing Unity transport responses."""
2
+ from __future__ import annotations
3
+
4
+ from typing import Any
5
+
6
+
7
+ def normalize_unity_response(response: Any) -> Any:
8
+ """Normalize Unity's {status,result} payloads into MCPResponse shape."""
9
+ if not isinstance(response, dict):
10
+ return response
11
+
12
+ status = response.get("status")
13
+ result = response.get("result") if isinstance(
14
+ response.get("result"), dict) else response.get("result")
15
+
16
+ # Already MCPResponse-shaped
17
+ if "success" in response:
18
+ return response
19
+ if isinstance(result, dict) and "success" in result:
20
+ return result
21
+
22
+ if status is None:
23
+ return response
24
+
25
+ payload = result if isinstance(result, dict) else {}
26
+ success = status == "success"
27
+ message = payload.get("message") or response.get("message")
28
+ error = payload.get("error") or response.get("error")
29
+
30
+ data = payload.get("data")
31
+ if data is None and isinstance(payload, dict) and payload:
32
+ data = {k: v for k, v in payload.items() if k not in {
33
+ "message", "error", "status", "code"}}
34
+ if not data:
35
+ data = None
36
+
37
+ normalized: dict[str, Any] = {
38
+ "success": success,
39
+ "message": message,
40
+ "error": error if not success else None,
41
+ "data": data,
42
+ }
43
+
44
+ if not success and not normalized["error"]:
45
+ normalized["error"] = message or "Unity command failed"
46
+
47
+ return normalized
routes/__init__.py ADDED
File without changes
services/__init__.py ADDED
File without changes