Skip to content

Commit 558f923

Browse files
authored
Allow the MCP server to be run by uvx remotely (#336)
* feat: add entry point script and additional Python modules to server package Now we can run this server with `uvx` * refactor: improve package version detection to support both installed and development environments * refactor: simplify release workflow by removing server packaging step
1 parent e3e5485 commit 558f923

File tree

4 files changed

+41
-26
lines changed

4 files changed

+41
-26
lines changed

.github/workflows/bump-version.yml

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -109,19 +109,7 @@ jobs:
109109
git tag -a "$TAG" -m "Version ${NEW_VERSION}"
110110
git push origin "$TAG"
111111
112-
- name: Package server for release
113-
env:
114-
NEW_VERSION: ${{ steps.compute.outputs.new_version }}
115-
shell: bash
116-
run: |
117-
set -euo pipefail
118-
cd MCPForUnity
119-
zip -r ../mcp-for-unity-server-v${NEW_VERSION}.zip UnityMcpServer~
120-
cd ..
121-
ls -lh mcp-for-unity-server-v${NEW_VERSION}.zip
122-
echo "Server package created: mcp-for-unity-server-v${NEW_VERSION}.zip"
123-
124-
- name: Create GitHub release with server artifact
112+
- name: Create GitHub release
125113
env:
126114
NEW_VERSION: ${{ steps.compute.outputs.new_version }}
127115
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -130,8 +118,7 @@ jobs:
130118
set -euo pipefail
131119
TAG="v${NEW_VERSION}"
132120
133-
# Create release
121+
# Create release with auto-generated notes
134122
gh release create "$TAG" \
135123
--title "v${NEW_VERSION}" \
136-
--notes "Release v${NEW_VERSION}" \
137-
"mcp-for-unity-server-v${NEW_VERSION}.zip#MCP Server v${NEW_VERSION}"
124+
--generate-notes

MCPForUnity/UnityMcpServer~/src/pyproject.toml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,23 @@ dev = [
1717
"pytest-asyncio>=0.23",
1818
]
1919

20+
[project.scripts]
21+
mcp-for-unity = "server:main"
22+
2023
[build-system]
2124
requires = ["setuptools>=64.0.0", "wheel"]
2225
build-backend = "setuptools.build_meta"
2326

2427
[tool.setuptools]
25-
py-modules = ["config", "server", "unity_connection"]
26-
packages = ["tools"]
28+
py-modules = [
29+
"config",
30+
"models",
31+
"module_discovery",
32+
"port_discovery",
33+
"reload_sentinel",
34+
"server",
35+
"telemetry",
36+
"telemetry_decorator",
37+
"unity_connection"
38+
]
39+
packages = ["tools", "resources", "registry"]

MCPForUnity/UnityMcpServer~/src/server.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ def asset_creation_strategy() -> str:
189189
)
190190

191191

192+
def main():
193+
"""Entry point for uvx and console scripts."""
194+
mcp.run(transport='stdio')
195+
196+
192197
# Run the server
193198
if __name__ == "__main__":
194-
mcp.run(transport='stdio')
199+
main()

MCPForUnity/UnityMcpServer~/src/telemetry.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import contextlib
1111
from dataclasses import dataclass
1212
from enum import Enum
13-
import importlib
13+
from importlib import import_module, metadata
1414
import json
1515
import logging
1616
import os
@@ -38,12 +38,22 @@
3838

3939
def get_package_version() -> str:
4040
"""
41-
Open pyproject.toml and parse version
42-
We use the tomli library instead of tomllib to support Python 3.10
41+
Get package version in different ways:
42+
1. First we try the installed metadata - this is because uvx is used on the asset store
43+
2. If that fails, we try to read from pyproject.toml - this is available for users who download via Git
44+
Default is "unknown", but that should never happen
4345
"""
44-
with open("pyproject.toml", "rb") as f:
45-
data = tomli.load(f)
46-
return data["project"]["version"]
46+
try:
47+
return metadata.version("MCPForUnityServer")
48+
except Exception:
49+
# Fallback for development: read from pyproject.toml
50+
try:
51+
pyproject_path = Path(__file__).parent / "pyproject.toml"
52+
with open(pyproject_path, "rb") as f:
53+
data = tomli.load(f)
54+
return data["project"]["version"]
55+
except Exception:
56+
return "unknown"
4757

4858

4959
MCP_VERSION = get_package_version()
@@ -100,7 +110,7 @@ def __init__(self):
100110
"MCPForUnity.UnityMcpServer.src.config",
101111
):
102112
try:
103-
mod = importlib.import_module(modname)
113+
mod = import_module(modname)
104114
server_config = getattr(mod, "config", None)
105115
if server_config is not None:
106116
break

0 commit comments

Comments
 (0)