CoplayDev/unity-mcp · error · ValueError
No version found in package.json
Error message
No version found in package.json
What it means
Raised as ValueError by load_package_version() when MCPForUnity/package.json exists and parses as valid JSON, but either has no "version" key at all or the key's value is falsy (null, empty string). The script cannot proceed without a version to propagate to the other files.
Source
Thrown at tools/update_versions.py:54
REPO_ROOT = Path(__file__).resolve().parents[1]
PACKAGE_JSON = REPO_ROOT / "MCPForUnity" / "package.json"
MANIFEST_JSON = REPO_ROOT / "manifest.json"
PYPROJECT_TOML = REPO_ROOT / "Server" / "pyproject.toml"
SERVER_README = REPO_ROOT / "Server" / "README.md"
ROOT_README = REPO_ROOT / "README.md"
ZH_README = REPO_ROOT / "docs" / "i18n" / "README-zh.md"
def load_package_version() -> str:
"""Load version from package.json."""
if not PACKAGE_JSON.exists():
raise FileNotFoundError(f"Package file not found: {PACKAGE_JSON}")
package_data = json.loads(PACKAGE_JSON.read_text(encoding="utf-8"))
version = package_data.get("version")
if not version:
raise ValueError("No version found in package.json")
return version
def update_package_json(new_version: str, dry_run: bool = False) -> bool:
"""Update version in MCPForUnity/package.json."""
if not PACKAGE_JSON.exists():
print(f"Warning: {PACKAGE_JSON.relative_to(REPO_ROOT)} not found")
return False
package_data = json.loads(PACKAGE_JSON.read_text(encoding="utf-8"))
current_version = package_data.get("version", "unknown")
if current_version == new_version:
print(f"✓ {PACKAGE_JSON.relative_to(REPO_ROOT)} already at v{new_version}")
return False
print(View on GitHub (pinned to c21bf496bc)
Solutions
- Open MCPForUnity/package.json and confirm a top-level "version" key exists with a semver string, e.g. "version": "9.2.0".
- If the field is missing, add it. If it is null/empty, set it to the current release version.
- Validate the JSON with python3 -c "import json; print(json.load(open('MCPForUnity/package.json')).get('version'))" to confirm the key resolves.
- Alternatively, pass --version to update_versions.py to bypass auto-detection entirely.
Example fix
// before — MCPForUnity/package.json
{
"name": "io.coplay.mcpforunity"
}
// after
{
"name": "io.coplay.mcpforunity",
"version": "9.2.0"
} Defensive patterns
Strategy: validation
Validate before calling
import json
from pathlib import Path
data = json.loads(Path("MCPForUnity/package.json").read_text())
version = data.get("version")
if not version:
raise SystemExit("package.json has no 'version' field. Set it before running.")
print(f"Detected version: {version}") Type guard
def has_valid_version(package_path: Path) -> bool:
try:
data = json.loads(package_path.read_text(encoding="utf-8"))
except (OSError, json.JSONDecodeError):
return False
return bool(data.get("version")) Prevention
- Ensure package.json always has a top-level "version" key after merges.
- Validate package.json with a JSON linter or schema check before running the script.
- Pass --version explicitly in CI to avoid depending on auto-detection.
When it happens
Trigger: package.json was hand-edited and the version field was deleted or commented out (JSON has no comments, but a broken edit can leave it absent); a code generator or merge conflict produced a package.json without the version field; the field exists but is set to null or "".
Common situations: A merge conflict in package.json left the version field unresolved or removed; an automated tool rewrote package.json and dropped the version key; the file is a template or stub that was never populated.
Related errors
- Package file not found: {PACKAGE_JSON}
- Failed to write config file '{path}': {ex.Message}
- The selected uvx executable does not exist
- The selected Claude CLI executable does not exist
- Invalid MCP base URL: {baseUrl}
AI-assisted analysis of CoplayDev/unity-mcp@c21bf496bc (2026-08-13).
Data as JSON: /api/errors/22db0bc89b3637fa.
Report an issue: GitHub.