CoplayDev/unity-mcp · error · FileNotFoundError

Could not find Packages/manifest.json from current directory

Error message

Could not find Packages/manifest.json from current directory. Use --manifest to specify a path.

What it means

Raised by find_manifest in mcp_source.py when no Packages/manifest.json is found by walking up from the current working directory. mcp_source.py edits the Unity package manifest to switch the MCP for Unity package source, so it must locate a Unity project root.

Source

Thrown at mcp_source.py:79

def detect_branch(repo: pathlib.Path) -> str:
    return run_git(repo, "rev-parse", "--abbrev-ref", "HEAD")


def detect_origin(repo: pathlib.Path) -> str:
    url = run_git(repo, "remote", "get-url", "origin")
    return normalize_origin_to_https(url)


def find_manifest(explicit: str | None) -> pathlib.Path:
    if explicit:
        return pathlib.Path(explicit).resolve()
    # Walk up from CWD looking for Packages/manifest.json
    cur = pathlib.Path.cwd().resolve()
    for parent in [cur, *cur.parents]:
        candidate = parent / "Packages" / "manifest.json"
        if candidate.exists():
            return candidate
    raise FileNotFoundError(
        "Could not find Packages/manifest.json from current directory. Use --manifest to specify a path.")


def read_json(path: pathlib.Path) -> dict:
    with path.open("r", encoding="utf-8") as f:
        return json.load(f)


def write_json(path: pathlib.Path, data: dict) -> None:
    with path.open("w", encoding="utf-8") as f:
        json.dump(data, f, indent=2)
        f.write("\n")


def build_options(repo_root: pathlib.Path, branch: str, origin_https: str):
    upstream_main = "https://github.com/CoplayDev/unity-mcp.git?path=/MCPForUnity#main"
    upstream_beta = "https://github.com/CoplayDev/unity-mcp.git?path=/MCPForUnity#beta"
    # Ensure origin is https

View on GitHub (pinned to c21bf496bc)

Solutions

  1. Run the script from inside the Unity project directory (the one containing Packages/manifest.json).
  2. Pass --manifest /path/to/UnityProject/Packages/manifest.json explicitly.
  3. Verify the target project actually has a Packages/manifest.json (i.e., is a real Unity project).

Example fix

# before (run from repo root)
python mcp_source.py main
# after
python mcp_source.py main --manifest /abs/path/UnityProject/Packages/manifest.json
Defensive patterns

Strategy: validation

Validate before calling

import pathlib
cur = pathlib.Path.cwd().resolve()
manifest = next((p/'Packages'/'manifest.json' for p in [cur,*cur.parents] if (p/'Packages'/'manifest.json').exists()), None)
if manifest is None and not args.manifest:
    raise SystemExit('No Packages/manifest.json found; pass --manifest')

Type guard

def is_unity_project_dir(p: pathlib.Path) -> bool:
    return (p / 'Packages' / 'manifest.json').exists()

Try / catch

try:
    manifest = find_manifest(args.manifest)
except FileNotFoundError as e:
    print(e); sys.exit(1)

Prevention

When it happens

Trigger: The script is run from a directory that is not inside (nor a parent of) a Unity project, and --manifest was not supplied. The walk over [cwd, *cwd.parents] finds no Packages/manifest.json.

Common situations: Running mcp_source.py from the MCP-for-Unity repo root instead of from within a Unity project; CWD is a temp/build dir; the Unity project uses a non-standard layout without a Packages folder.

Related errors


AI-assisted analysis of CoplayDev/unity-mcp@c21bf496bc (2026-08-13). Data as JSON: /api/errors/ebe4dd7dd6a47fe0. Report an issue: GitHub.