Unity API Documentation

内容与创意

by codeturion

为 AI agents 提供准确的 Unity API 文档(2022/2023/6),减少臆造的签名问题。

什么是 Unity API Documentation

为 AI agents 提供准确的 Unity API 文档(2022/2023/6),减少臆造的签名问题。

README

unity-api-mcp

<!-- mcp-name: io.github.Codeturion/unity-api-mcp -->

PyPI Version PyPI Downloads MCP Registry GitHub Stars GitHub Last Commit License: PolyForm Noncommercial Python 3.10+

MCP server that gives AI agents accurate Unity API documentation. Prevents hallucinated signatures, wrong namespaces, and deprecated API usage.

Supports Unity 2022 LTS, 2023, and Unity 6 with separate databases for each version. Works with Claude Code, Cursor, Windsurf, or any MCP-compatible AI tool. No Unity installation required.

Quick Start

Add to your MCP config (.mcp.json, mcp.json, or your tool's MCP settings), setting UNITY_VERSION to match your project:

json
{
  "mcpServers": {
    "unity-api": {
      "command": "uvx",
      "args": ["unity-api-mcp"],
      "env": {
        "UNITY_VERSION": "2022"
      }
    }
  }
}

Valid values: "2022", "2023", or "6".

On first run the server downloads the correct database (~18-24 MB) to ~/.unity-api-mcp/.

How It Works

  1. Version detection. The server figures out which Unity version to serve:
PrioritySourceExample
1UNITY_VERSION env var"2022", "6", or "6000.3.8f1"
2UNITY_PROJECT_PATHReads ProjectSettings/ProjectVersion.txt, maps 2022.3.62f1 to "2022"
3Default"6"
  1. Database download. If the database for that version isn't cached locally, it downloads from GitHub (one time).

  2. Serve. All tool calls query the version-specific SQLite database. Every query returns in <15ms.

Each version has its own database with the correct signatures, deprecation warnings, and member lists for that release.

Tools

ToolPurposeExample
search_unity_apiFind APIs by keyword"Tilemap SetTile", "async load scene"
get_method_signatureExact signatures with all overloadsUnityEngine.Physics.Raycast
get_namespaceResolve using directives"SceneManager" -> using UnityEngine.SceneManagement;
get_class_referenceFull class reference card"InputAction" -> all methods/fields/properties
get_deprecation_warningsCheck if an API is obsolete"WWW" -> Use UnityWebRequest instead

Coverage

All UnityEngine and UnityEditor modules, plus packages parsed from C# source: Input System, Addressables, uGUI, TextMeshPro, AI Navigation, and Netcode.

VersionRecordsDeprecatedModulesSize
Unity 2022 LTS32,00044286 XML + packages18 MB
Unity 202331,38743692 XML18 MB
Unity 642,223516139 XML + packages24 MB

Does not cover third-party assets (DOTween, VContainer, Newtonsoft.Json). For those, rely on project source.

Benchmarks

In a 10-step research workflow, MCP uses 4x fewer tokens than a skilled agent and 11x fewer than a naive agent:

Total Tokens - 10-Step Research Workflow

The gap holds across every question type. MCP wins on simple lookups and complex multi-part research alike:

Hallucination Risk: Grep+Read vs MCP

Even in a realistic hybrid workflow where MCP results are followed up with targeted file reads, it still uses 54% fewer tokens than a skilled agent working without MCP:

Realistic Workflow: MCP + Targeted Read

"Without MCP" estimates assume full file reads. A skilled agent with good tooling may use fewer tokens than shown. What MCP guarantees is a correct, structured answer in 1 call every time.

Per-question breakdown

Token Cost Per Question

<details> <summary>Accuracy</summary>
TestResult
Search top-1 relevance (12 common queries)100%
Namespace resolution (6 key classes)100%
Key class coverage (17 common Unity classes)94% (16/17)

Ranking uses BM25 with tuned column weights (member name 10x, class name 5x) plus core namespace boosting to ensure Object.Instantiate ranks above niche APIs like InstantiationParameters.Instantiate.

</details>

CLAUDE.md Snippet

Add this to your project's CLAUDE.md (or equivalent instructions file). This step is important. Without it, the AI has the tools but won't know when to reach for them.

markdown
## Unity API Lookup (unity-api MCP)

Use the `unity-api` MCP tools to verify Unity API usage instead of guessing. **Do not hallucinate signatures.**

| When | Tool | Example |
|------|------|---------|
| Unsure about a method's parameters or return type | `get_method_signature` | `get_method_signature("UnityEngine.Tilemaps.Tilemap.SetTile")` |
| Need the `using` directive for a type | `get_namespace` | `get_namespace("SceneManager")` |
| Want to see all members on a class | `get_class_reference` | `get_class_reference("InputAction")` |
| Searching for an API by keyword | `search_unity_api` | `search_unity_api("async load scene")` |
| Checking if an API is deprecated | `get_deprecation_warnings` | `get_deprecation_warnings("FindObjectOfType")` |

**Rules:**
- Before writing a Unity API call you haven't used in this conversation, verify the signature with `get_method_signature`
- Before adding a `using` directive, verify with `get_namespace` if unsure
- Covers: all UnityEngine/UnityEditor modules, Input System, Addressables
- Does NOT cover: DOTween, VContainer, Newtonsoft.Json (third-party)

Setup Details

<details> <summary>Auto-detect version from project path</summary>

Instead of setting UNITY_VERSION, you can point to your Unity project. The server reads ProjectSettings/ProjectVersion.txt automatically:

json
{
  "mcpServers": {
    "unity-api": {
      "command": "uvx",
      "args": ["unity-api-mcp"],
      "env": {
        "UNITY_PROJECT_PATH": "/path/to/your/unity-project"
      }
    }
  }
}
</details> <details> <summary>Alternative installation methods</summary>

Using pip install:

bash
pip install unity-api-mcp
json
{
  "mcpServers": {
    "unity-api": {
      "command": "unity-api-mcp",
      "args": [],
      "env": {
        "UNITY_VERSION": "2022"
      }
    }
  }
}
</details> <details> <summary>Environment variables</summary>
VariablePurposeExample
UNITY_VERSIONUnity version to serve2022, 2023, 6, or 6000.3.8f1
UNITY_PROJECT_PATHAuto-detect version from projectF:/Unity Projects/my-project
UNITY_INSTALL_PATHOverride Unity install path (for ingest only)D:/Unity/6000.3.8f1
</details> <details> <summary>Building databases locally</summary>

If you want to build a database from your own Unity installation instead of downloading:

bash
# Install with ingest dependencies
pip install unity-api-mcp[ingest]

# Build for a specific version
python -m unity_api_mcp.ingest --unity-version 6 --unity-install "D:/Unity/6000.3.8f1" --project "F:/Unity Projects/MyProject"
python -m unity_api_mcp.ingest --unity-version 2022 --unity-install "D:/Unity/2022.3.62f1"
python -m unity_api_mcp.ingest --unity-version 2023 --unity-install "D:/Unity/2023.1.22f1"

Databases are written to ~/.unity-api-mcp/unity_docs_{version}.db by default.

</details> <details> <summary>AI-Assisted Setup</summary>

If an AI agent is setting this up for you:

Add unity-api-mcp to my MCP config using uvx with UNITY_VERSION set to match my project, append the CLAUDE.md snippet from the README, and verify with get_namespace("SceneManager").

</details> <details> <summary>Project structure</summary>
code
unity-api-mcp/
├── src/unity_api_mcp/
│   ├── server.py          # MCP server (5 tools)
│   ├── db.py              # SQLite + FTS5 database layer
│   ├── version.py         # Version detection + DB download
│   ├── xml_parser.py      # Parse Unity XML IntelliSense files
│   ├── cs_doc_parser.py   # Parse C# doc comments from package source
│   ├── unity_paths.py     # Locate Unity install + package dirs
│   └── ingest.py          # CLI ingestion pipeline
└── pyproject.toml

Databases are stored in ~/.unity-api-mcp/ (downloaded on first run).

</details>

Troubleshooting

ProblemFix
"Could not download Unity X database"Check internet connection. Or build locally: python -m unity_api_mcp.ingest --unity-version 2022
Wrong API version being servedSet UNITY_VERSION explicitly. Check stderr: unity-api-mcp: serving Unity <version> API docs
Server won't startCheck python --version (needs 3.10+). Check path: which unity-api-mcp or where unity-api-mcp
Third-party packages return no resultsDOTween, VContainer, Newtonsoft.Json are not indexed (third-party, not Unity packages)

See Also

unreal-api-mcp — Same concept for Unreal Engine (C++). Covers UE 5.5, 5.6, and 5.7.

Contact

Need a custom MCP server for your engine or framework? I build MCP tools that cut token waste and prevent hallucinations for AI-assisted game development. If you want something similar for your team's stack, reach out.

fuatcankoseoglu@gmail.com

License

PolyForm Noncommercial 1.0.0

Free to use, fork, modify, and share for any personal or non-commercial purpose. Commercial use requires permission.

常见问题

Unity API Documentation 是什么?

为 AI agents 提供准确的 Unity API 文档(2022/2023/6),减少臆造的签名问题。

相关 Skills

文档共著

by anthropics

Universal
热门

围绕文档、提案、技术规格、决策记录等写作任务,按上下文收集、结构迭代、读者测试三步协作共创,减少信息遗漏,写出更清晰、经得起他人阅读的内容。

写文档、方案或技术规格时容易思路散、信息漏,它用结构化共著流程帮你高效传递上下文、反复打磨内容,还能从读者视角做验证。

内容与创意
未扫描149.6k

内部沟通

by anthropics

Universal
热门

按公司常用模板和语气快速起草内部沟通内容,覆盖 3P 更新、状态报告、领导汇报、项目进展、事故复盘、FAQ 与 newsletter,适合需要统一格式的团队沟通场景。

按公司偏好的模板快速产出状态汇报、领导更新和 FAQ,既省去反复改稿,也让内部沟通更统一、更专业。

内容与创意
未扫描149.6k

平面设计

by anthropics

Universal
热门

先生成视觉哲学,再落地成原创海报、艺术画面或其他静态设计,输出 .png/.pdf,强调构图、色彩与空间表达,适合需要高完成度视觉成品的场景。

做海报、插画或静态视觉稿时,用它能快速产出兼顾美感与版式的PNG/PDF成品,原创设计更省心,也更适合规避版权风险。

内容与创意
未扫描149.6k

相关 MCP Server

免费的加密新闻聚合 MCP,汇集 Bitcoin、Ethereum、DeFi、Solana 与 altcoins 资讯源。

内容与创意
236

by ProfessionalWiki

让 Large Language Model 客户端无缝连接任意 MediaWiki 站点,可创建、更新、搜索页面,并通过 OAuth 2.0 安全管理内容。

内容与创意16 个工具
97

用于Adobe Photoshop自动化的MCP server,让AI assistants直接控制Photoshop。

内容与创意
97

评论