coplay-mcp-server 1.4.1__tar.gz

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 (31) hide show
  1. coplay_mcp_server-1.4.1/.gitignore +175 -0
  2. coplay_mcp_server-1.4.1/.python-version +1 -0
  3. coplay_mcp_server-1.4.1/LICENSE +21 -0
  4. coplay_mcp_server-1.4.1/PKG-INFO +70 -0
  5. coplay_mcp_server-1.4.1/README.md +40 -0
  6. coplay_mcp_server-1.4.1/TOOL_GENERATION.md +170 -0
  7. coplay_mcp_server-1.4.1/build_hooks.py +39 -0
  8. coplay_mcp_server-1.4.1/coplay_mcp_server/__init__.py +3 -0
  9. coplay_mcp_server-1.4.1/coplay_mcp_server/code_generator.py +370 -0
  10. coplay_mcp_server-1.4.1/coplay_mcp_server/generated_tools/.gitignore +4 -0
  11. coplay_mcp_server-1.4.1/coplay_mcp_server/generated_tools/__init__.py +4 -0
  12. coplay_mcp_server-1.4.1/coplay_mcp_server/generated_tools/agent_tool_tools.py +347 -0
  13. coplay_mcp_server-1.4.1/coplay_mcp_server/generated_tools/coplay_tool_tools.py +58 -0
  14. coplay_mcp_server-1.4.1/coplay_mcp_server/generated_tools/image_tool_tools.py +146 -0
  15. coplay_mcp_server-1.4.1/coplay_mcp_server/generated_tools/input_action_tool_tools.py +718 -0
  16. coplay_mcp_server-1.4.1/coplay_mcp_server/generated_tools/package_tool_tools.py +240 -0
  17. coplay_mcp_server-1.4.1/coplay_mcp_server/generated_tools/profiler_functions_tools.py +63 -0
  18. coplay_mcp_server-1.4.1/coplay_mcp_server/generated_tools/scene_view_functions_tools.py +58 -0
  19. coplay_mcp_server-1.4.1/coplay_mcp_server/generated_tools/screenshot_tool_tools.py +87 -0
  20. coplay_mcp_server-1.4.1/coplay_mcp_server/generated_tools/snapping_functions_tools.py +409 -0
  21. coplay_mcp_server-1.4.1/coplay_mcp_server/generated_tools/ui_functions_tools.py +419 -0
  22. coplay_mcp_server-1.4.1/coplay_mcp_server/generated_tools/unity_functions_tools.py +1643 -0
  23. coplay_mcp_server-1.4.1/coplay_mcp_server/image_utils.py +96 -0
  24. coplay_mcp_server-1.4.1/coplay_mcp_server/process_discovery.py +168 -0
  25. coplay_mcp_server-1.4.1/coplay_mcp_server/server.py +236 -0
  26. coplay_mcp_server-1.4.1/coplay_mcp_server/unity_client.py +342 -0
  27. coplay_mcp_server-1.4.1/docs/Publishing.md +214 -0
  28. coplay_mcp_server-1.4.1/docs/PublishingWorkflows.md +117 -0
  29. coplay_mcp_server-1.4.1/docs/TestPyPI-Installation.md +38 -0
  30. coplay_mcp_server-1.4.1/pyproject.toml +55 -0
  31. coplay_mcp_server-1.4.1/uv.lock +1206 -0
@@ -0,0 +1,175 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py,cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ #Pipfile.lock
96
+
97
+ # poetry
98
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102
+ #poetry.lock
103
+
104
+ # pdm
105
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106
+ #pdm.lock
107
+ # pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108
+ # in version control.
109
+ # https://pdm.fming.dev/#use-with-ide
110
+ .pdm.toml
111
+
112
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113
+ __pypackages__/
114
+
115
+ # Celery stuff
116
+ celerybeat-schedule
117
+ celerybeat.pid
118
+
119
+ # SageMath parsed files
120
+ *.sage.py
121
+
122
+ # Environments
123
+ .env
124
+ .venv
125
+ env/
126
+ venv/
127
+ ENV/
128
+ env.bak/
129
+ venv.bak/
130
+
131
+ # Spyder project settings
132
+ .spyderproject
133
+ .spyproject
134
+
135
+ # Rope project settings
136
+ .ropeproject
137
+
138
+ # mkdocs documentation
139
+ /site
140
+
141
+ # mypy
142
+ .mypy_cache/
143
+ .dmypy.json
144
+ dmypy.json
145
+
146
+ # Pyre type checker
147
+ .pyre/
148
+
149
+ # pytype static type analyzer
150
+ .pytype/
151
+
152
+ # Cython debug symbols
153
+ cython_debug/
154
+
155
+ # PyCharm
156
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157
+ # be added to the global gitignore or merged into this project gitignore. For a PyCharm
158
+ # project, it is recommended to ignore the entire .idea directory.
159
+ .idea/
160
+
161
+ # VS Code
162
+ .vscode/
163
+
164
+ # Logs
165
+ logs/
166
+ *.log
167
+
168
+ # OS generated files
169
+ .DS_Store
170
+ .DS_Store?
171
+ ._*
172
+ .Spotlight-V100
173
+ .Trashes
174
+ ehthumbs.db
175
+ Thumbs.db
@@ -0,0 +1 @@
1
+ 3.11
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Coplay Dev
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,70 @@
1
+ Metadata-Version: 2.4
2
+ Name: coplay-mcp-server
3
+ Version: 1.4.1
4
+ Summary: A Model Context Protocol (MCP) server for Coplay, providing Unity integration capabilities
5
+ Project-URL: Homepage, https://coplay.dev/
6
+ Project-URL: Repository, https://github.com/CoplayDev/coplay-unity-plugin
7
+ Project-URL: Documentation, https://docs.coplay.dev/
8
+ Project-URL: Issues, https://github.com/CoplayDev/coplay-unity-plugin/issues
9
+ Author-email: Coplay Dev <dev@coplay.com>
10
+ Maintainer-email: Coplay Dev <dev@coplay.com>
11
+ License: MIT
12
+ License-File: LICENSE
13
+ Keywords: coplay,mcp,model-context-protocol,unity,unity-editor
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Topic :: Games/Entertainment
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Requires-Python: >=3.11
23
+ Requires-Dist: aiofiles>=24.1.0
24
+ Requires-Dist: anyio>=4.10.0
25
+ Requires-Dist: fastmcp>=2.0.0
26
+ Requires-Dist: psutil>=7.0.0
27
+ Requires-Dist: pydantic>=2.11.7
28
+ Requires-Dist: watchdog>=6.0.0
29
+ Description-Content-Type: text/markdown
30
+
31
+ # Coplay MCP Server
32
+
33
+ A Model Context Protocol (MCP) server for Coplay, providing Unity Editor integration capabilities through MCP tools.
34
+
35
+ ## Features
36
+
37
+ - **Schema-Based Tool Registration**: Dynamically registers tools from JSON schema files, ensuring compatibility with Backend's AssistantMode.NORMAL
38
+ - **Unity Project Discovery**: Automatically discover running Unity Editor instances and their project roots
39
+ - **Unity Editor State**: Retrieve current Unity Editor state and scene hierarchy information
40
+ - **Script Execution**: Execute arbitrary C# scripts within the Unity Editor
41
+ - **Log Management**: Access and filter Unity console logs
42
+ - **GameObject Hierarchy**: List and filter GameObjects in the scene hierarchy
43
+ - **Task Creation**: Create new Coplay tasks directly from MCP clients
44
+ - **Parameter Validation**: Automatic parameter validation and type conversion based on tool schemas
45
+ - **Version Compatibility**: Tools are locked to specific schema versions, ensuring compatibility with Unity plugin versions
46
+
47
+ ## Usage
48
+
49
+ ### As an MCP server
50
+
51
+ Add to your MCP client configuration:
52
+
53
+ ```json
54
+ {
55
+ "mcpServers": {
56
+ "coplay-mcp": {
57
+ "autoApprove": [],
58
+ "disabled": false,
59
+ "timeout": 60,
60
+ "type": "stdio",
61
+ "command": "uvx",
62
+ "args": [
63
+ "coplay-mcp-server@latest"
64
+ ]
65
+ }
66
+ }
67
+ }
68
+ ```
69
+
70
+
@@ -0,0 +1,40 @@
1
+ # Coplay MCP Server
2
+
3
+ A Model Context Protocol (MCP) server for Coplay, providing Unity Editor integration capabilities through MCP tools.
4
+
5
+ ## Features
6
+
7
+ - **Schema-Based Tool Registration**: Dynamically registers tools from JSON schema files, ensuring compatibility with Backend's AssistantMode.NORMAL
8
+ - **Unity Project Discovery**: Automatically discover running Unity Editor instances and their project roots
9
+ - **Unity Editor State**: Retrieve current Unity Editor state and scene hierarchy information
10
+ - **Script Execution**: Execute arbitrary C# scripts within the Unity Editor
11
+ - **Log Management**: Access and filter Unity console logs
12
+ - **GameObject Hierarchy**: List and filter GameObjects in the scene hierarchy
13
+ - **Task Creation**: Create new Coplay tasks directly from MCP clients
14
+ - **Parameter Validation**: Automatic parameter validation and type conversion based on tool schemas
15
+ - **Version Compatibility**: Tools are locked to specific schema versions, ensuring compatibility with Unity plugin versions
16
+
17
+ ## Usage
18
+
19
+ ### As an MCP server
20
+
21
+ Add to your MCP client configuration:
22
+
23
+ ```json
24
+ {
25
+ "mcpServers": {
26
+ "coplay-mcp": {
27
+ "autoApprove": [],
28
+ "disabled": false,
29
+ "timeout": 60,
30
+ "type": "stdio",
31
+ "command": "uvx",
32
+ "args": [
33
+ "coplay-mcp-server@latest"
34
+ ]
35
+ }
36
+ }
37
+ }
38
+ ```
39
+
40
+
@@ -0,0 +1,170 @@
1
+ # MCP Tool Code Generation
2
+
3
+ This document explains the automated code generation system for MCP tools from JSON schema files.
4
+
5
+ ## Overview
6
+
7
+ The Coplay MCP Server uses an automated code generation approach to expose tool functions with proper parameter descriptions. Instead of manually defining each tool, we generate Python functions from JSON schema files located in the Backend project.
8
+
9
+ ## How It Works
10
+
11
+ 1. **Schema Source**: Tool schemas are read from `Backend/coplay/tool_schemas/` directory
12
+ 2. **Code Generation**: The `code_generator.py` script processes these schemas and generates Python files
13
+ 3. **Parameter Descriptions**: Each parameter gets proper `Annotated` type hints with descriptions from the schema
14
+ 4. **MCP Registration**: Generated functions are automatically registered with the MCP server
15
+
16
+ ## Generated Files
17
+
18
+ Generated files are located in `coplay_mcp_server/generated_tools/` and include:
19
+
20
+ - `unity_functions_tools.py` - Unity Editor manipulation tools (34 tools)
21
+ - `image_tool_tools.py` - Image generation and editing tools (1 tool)
22
+ - `coplay_tool_tools.py` - Coplay-specific tools (1 tool)
23
+ - `agent_tool_tools.py` - Agent management tools (6 tools)
24
+ - `package_tool_tools.py` - Unity package management (7 tools)
25
+ - `input_action_tool_tools.py` - Unity Input System tools (13 tools)
26
+ - `ui_functions_tools.py` - Unity UI tools (6 tools)
27
+ - `snapping_functions_tools.py` - Object snapping tools (4 tools)
28
+ - `scene_view_functions_tools.py` - Scene view controls (1 tool)
29
+ - `profiler_functions_tools.py` - Unity Profiler tools (2 tools)
30
+ - `screenshot_tool_tools.py` - Screenshot capture tools (2 tools)
31
+
32
+ **Total: 85 tools generated**
33
+
34
+ ## Automatic Code Generation
35
+
36
+ ### Pre-Build Hook
37
+
38
+ Code generation runs automatically during the build process via a Hatchling build hook:
39
+
40
+ ```bash
41
+ # When building the package, tools are automatically generated
42
+ uv build
43
+ ```
44
+
45
+ ### Manual Generation
46
+
47
+ You can also run code generation manually:
48
+
49
+ ```bash
50
+ # Using the script command
51
+ uv run coplay-generate-tools
52
+
53
+ # Or directly
54
+ uv run python -m coplay_mcp_server.code_generator
55
+ ```
56
+
57
+ ## Generated Code Structure
58
+
59
+ Each generated tool function follows this pattern:
60
+
61
+ ```python
62
+ async def create_gameobject(
63
+ name: Annotated[str, """The name of the new GameObject."""],
64
+ primitive_type: Annotated[Optional[str], """Optional. Type of primitive to create."""] = None,
65
+ position: Annotated[str, """Comma-separated position coordinates (e.g., 'x,y,z')."""],
66
+ # ... more parameters
67
+ ) -> Any:
68
+ """Creates a new GameObject in the Unity scene."""
69
+ try:
70
+ # Parameter validation and Unity RPC call
71
+ params = {}
72
+ if name is not None:
73
+ params['name'] = str(name)
74
+ # ... prepare other parameters
75
+
76
+ result = await _unity_client.execute_request('create_gameobject', params)
77
+ return result
78
+ except Exception as e:
79
+ raise RuntimeError(f"Tool execution failed for create_gameobject: {e}")
80
+ ```
81
+
82
+ ## Key Features
83
+
84
+ ### Parameter Descriptions
85
+ - Each parameter uses `Annotated[Type, """description"""]` for rich type information
86
+ - Descriptions come directly from the JSON schema files
87
+ - Required vs optional parameters are properly handled
88
+ - Parameter ordering ensures required parameters come before optional ones
89
+
90
+ ### Error Handling
91
+ - Comprehensive try/catch blocks for each tool
92
+ - Detailed error messages with tool name and context
93
+ - Graceful fallback if Unity client is unavailable
94
+
95
+ ### Logging
96
+ - Debug logging for tool execution
97
+ - Parameter logging for troubleshooting
98
+ - Build-time logging for code generation process
99
+
100
+ ## Schema File Format
101
+
102
+ The code generator expects JSON schema files in this format:
103
+
104
+ ```json
105
+ [
106
+ {
107
+ "type": "function",
108
+ "function": {
109
+ "name": "create_gameobject",
110
+ "description": "Creates a new GameObject in the Unity scene.",
111
+ "parameters": {
112
+ "type": "object",
113
+ "properties": {
114
+ "name": {
115
+ "type": "string",
116
+ "description": "The name of the new GameObject."
117
+ },
118
+ "position": {
119
+ "type": "string",
120
+ "description": "Comma-separated position coordinates (e.g., 'x,y,z')."
121
+ }
122
+ },
123
+ "required": ["name", "position"]
124
+ }
125
+ }
126
+ }
127
+ ]
128
+ ```
129
+
130
+ ## Adding New Tools
131
+
132
+ To add new tools:
133
+
134
+ 1. **Update Schema**: Add your tool definition to the appropriate JSON schema file in `Backend/coplay/tool_schemas/`
135
+ 2. **Regenerate**: Run `uv run coplay-generate-tools` or build the package
136
+ 3. **Test**: The new tool will be automatically available in the MCP server
137
+
138
+ ## Configuration
139
+
140
+ The code generator can be configured by modifying `coplay_mcp_server/code_generator.py`:
141
+
142
+ - `SCHEMA_FILES`: List of schema files to process
143
+ - `_find_backend_path()`: Logic for finding the Backend directory
144
+ - Type mapping in `_get_python_type_annotation()`
145
+
146
+ ## Benefits
147
+
148
+ 1. **Single Source of Truth**: Schema files in Backend project define all tools
149
+ 2. **Rich Parameter Descriptions**: MCP clients can show detailed parameter help
150
+ 3. **Type Safety**: Proper Python type hints for better IDE support
151
+ 4. **Automatic Updates**: Tools stay in sync with schema changes
152
+ 5. **Build Integration**: No manual steps required for deployment
153
+ 6. **Maintainability**: Centralized tool definitions reduce duplication
154
+
155
+ ## Troubleshooting
156
+
157
+ ### Code Generation Fails
158
+ - Check that Backend directory exists and contains `coplay/tool_schemas/`
159
+ - Verify schema files are valid JSON
160
+ - Check build logs for specific error messages
161
+
162
+ ### Missing Tools
163
+ - Ensure the schema file is listed in `SCHEMA_FILES`
164
+ - Verify the schema follows the expected format
165
+ - Check that `register_tools()` is called in `server.py`
166
+
167
+ ### Parameter Issues
168
+ - Verify parameter types in schema match expected Python types
169
+ - Check required vs optional parameter definitions
170
+ - Ensure parameter descriptions don't contain problematic characters
@@ -0,0 +1,39 @@
1
+ """Build hooks for Hatchling to run code generation before building."""
2
+
3
+ import logging
4
+ import sys
5
+ from pathlib import Path
6
+ from hatchling.builders.hooks.plugin.interface import BuildHookInterface
7
+
8
+
9
+ class CustomBuildHook(BuildHookInterface):
10
+ """Custom build hook to run code generation before building."""
11
+
12
+ PLUGIN_NAME = 'custom'
13
+
14
+ def initialize(self, version, build_data):
15
+ """Initialize build hook - run code generation before building."""
16
+ print("Running MCP tool code generation as pre-build step...")
17
+
18
+ try:
19
+ # Import and run the code generator
20
+ sys.path.insert(0, str(Path(__file__).parent))
21
+ from coplay_mcp_server.code_generator import MCPToolCodeGenerator
22
+
23
+ # Set up logging for the build process
24
+ logging.basicConfig(level=logging.INFO, format="[BUILD] %(message)s")
25
+
26
+ # Run code generation
27
+ generator = MCPToolCodeGenerator()
28
+ generator.generate_all_tools()
29
+
30
+ print("MCP tool code generation completed successfully!")
31
+
32
+ except Exception as e:
33
+ print(f"Error during code generation: {e}")
34
+ # Don't fail the build if code generation fails, just warn
35
+ print("Warning: Code generation failed, using existing generated files if available")
36
+
37
+ def finalize(self, version, build_data, artifact_path):
38
+ """Finalize build hook - cleanup if needed."""
39
+ pass
@@ -0,0 +1,3 @@
1
+ """Coplay MCP Server - Unity Editor integration via MCP protocol."""
2
+
3
+ __version__ = "1.4.1"