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
main
Marcus Sanatan 2025-10-22 17:36:24 -04:00 committed by GitHub
parent e3e5485d39
commit 558f9232d3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 41 additions and 26 deletions

View File

@ -109,19 +109,7 @@ jobs:
git tag -a "$TAG" -m "Version ${NEW_VERSION}" git tag -a "$TAG" -m "Version ${NEW_VERSION}"
git push origin "$TAG" git push origin "$TAG"
- name: Package server for release - name: Create GitHub release
env:
NEW_VERSION: ${{ steps.compute.outputs.new_version }}
shell: bash
run: |
set -euo pipefail
cd MCPForUnity
zip -r ../mcp-for-unity-server-v${NEW_VERSION}.zip UnityMcpServer~
cd ..
ls -lh mcp-for-unity-server-v${NEW_VERSION}.zip
echo "Server package created: mcp-for-unity-server-v${NEW_VERSION}.zip"
- name: Create GitHub release with server artifact
env: env:
NEW_VERSION: ${{ steps.compute.outputs.new_version }} NEW_VERSION: ${{ steps.compute.outputs.new_version }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@ -130,8 +118,7 @@ jobs:
set -euo pipefail set -euo pipefail
TAG="v${NEW_VERSION}" TAG="v${NEW_VERSION}"
# Create release # Create release with auto-generated notes
gh release create "$TAG" \ gh release create "$TAG" \
--title "v${NEW_VERSION}" \ --title "v${NEW_VERSION}" \
--notes "Release v${NEW_VERSION}" \ --generate-notes
"mcp-for-unity-server-v${NEW_VERSION}.zip#MCP Server v${NEW_VERSION}"

View File

@ -17,10 +17,23 @@ dev = [
"pytest-asyncio>=0.23", "pytest-asyncio>=0.23",
] ]
[project.scripts]
mcp-for-unity = "server:main"
[build-system] [build-system]
requires = ["setuptools>=64.0.0", "wheel"] requires = ["setuptools>=64.0.0", "wheel"]
build-backend = "setuptools.build_meta" build-backend = "setuptools.build_meta"
[tool.setuptools] [tool.setuptools]
py-modules = ["config", "server", "unity_connection"] py-modules = [
packages = ["tools"] "config",
"models",
"module_discovery",
"port_discovery",
"reload_sentinel",
"server",
"telemetry",
"telemetry_decorator",
"unity_connection"
]
packages = ["tools", "resources", "registry"]

View File

@ -189,6 +189,11 @@ def asset_creation_strategy() -> str:
) )
def main():
"""Entry point for uvx and console scripts."""
mcp.run(transport='stdio')
# Run the server # Run the server
if __name__ == "__main__": if __name__ == "__main__":
mcp.run(transport='stdio') main()

View File

@ -10,7 +10,7 @@ Fire-and-forget telemetry sender with a single background worker.
import contextlib import contextlib
from dataclasses import dataclass from dataclasses import dataclass
from enum import Enum from enum import Enum
import importlib from importlib import import_module, metadata
import json import json
import logging import logging
import os import os
@ -38,12 +38,22 @@ logger = logging.getLogger("unity-mcp-telemetry")
def get_package_version() -> str: def get_package_version() -> str:
""" """
Open pyproject.toml and parse version Get package version in different ways:
We use the tomli library instead of tomllib to support Python 3.10 1. First we try the installed metadata - this is because uvx is used on the asset store
2. If that fails, we try to read from pyproject.toml - this is available for users who download via Git
Default is "unknown", but that should never happen
""" """
with open("pyproject.toml", "rb") as f: try:
return metadata.version("MCPForUnityServer")
except Exception:
# Fallback for development: read from pyproject.toml
try:
pyproject_path = Path(__file__).parent / "pyproject.toml"
with open(pyproject_path, "rb") as f:
data = tomli.load(f) data = tomli.load(f)
return data["project"]["version"] return data["project"]["version"]
except Exception:
return "unknown"
MCP_VERSION = get_package_version() MCP_VERSION = get_package_version()
@ -100,7 +110,7 @@ class TelemetryConfig:
"MCPForUnity.UnityMcpServer.src.config", "MCPForUnity.UnityMcpServer.src.config",
): ):
try: try:
mod = importlib.import_module(modname) mod = import_module(modname)
server_config = getattr(mod, "config", None) server_config = getattr(mod, "config", None)
if server_config is not None: if server_config is not None:
break break