AssetLens MCP Server
Scans a Unity project's Assets/ and ProjectSettings, indexing assets, file fingerprints, and GUID references in SQLite; provides tools for project registration/scanning, unused/duplicate/largest asset reports, path search, reference and dependency lookup, summaries, and JSONL dataset export.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
AssetLens
AssetLens 在本机扫描 Unity 工程的 Assets/ 目录,把资产、文件内容指纹和 GUID 引用写入 SQLite。CLI 和 MCP stdio 服务共用 assetlens/query.py,可以在命令行复核模型查到的结果。
安装
需要 Windows 和 Python 3.11 或更新版本。在含有 pyproject.toml 的目录打开 PowerShell,运行以下命令。py -3 --version 可查看当前 Python 3 版本。
py -3 -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install -e ".[mcp,test]"只使用 CLI 时可用 python -m pip install -e . 安装。CLI 的运行依赖全部来自 Python 标准库。安装完整版会额外引入 mcp[cli] 和 pytest。
Related MCP server: Unity MCP Server
三条命令快速开始
从仓库根目录运行。将第一条命令中的路径替换为自己的 Unity 工程根目录即可扫描实际项目。根目录应同时含有 Assets/ 和 ProjectSettings/。
assetlens projects add demo .\tests\fixtures\MiniUnity
assetlens scan demo
assetlens report unused --project demo --type texture --json示例工程中,两个 prefab 都引用了 Art/Cookie.png。Art/Unused.png 的内容与它相同,但 GUID 不同且没有引用指向它。第三条命令返回以下对象。
{"project":"demo","count":1,"items":[{"path":"Art/Unused.png","type":"texture","size_bytes":69,"guid":"55555555555555555555555555555555","reason":"no_incoming_ref"}],"next_offset":null,"excluded":{"editor_script":0,"resources_dynamic":0,"scene_root":0}}CLI 与脚本
命令 | 结果 |
| 注册本地工程,同名同路径可重复执行。 |
| 查看已注册工程及上次成功扫描时间。 |
| 刷新单个工程,或用 |
| 按原因筛选有 GUID、静态入边数为零的资产,默认显示 |
| 按文件指纹列出重复组、成员数和成员路径。 |
| 按磁盘上的源文件字节数降序列出资产。 |
| 查看资产数量、文件大小、类型分布及引用统计。 |
| 按路径的子串或 glob 搜索资产,查询范围包含已有入边的资产。 |
| 查看哪些资产直接引用目标。 |
| 沿出边查找直接和间接依赖,返回工程内可定位的资产。 |
| 导出该工程的全部资产,每个资产占一行。 |
path 使用相对于 Assets/ 的路径和正斜杠,例如 Scenes/Entry.unity。root_path 标识工程所在位置,导出目的地标识本机文件。数据库中只有一个工程时可省略 --project。有多个工程时,报告、搜索、引用查询和导出用 --project NAME 选择工程。
所有子命令均支持 --db PATH 和 --json,既可放在子命令前也可放在其后。数据库优先使用 --db 指定的位置,其次读取 ASSETLENS_DB 环境变量,默认位于 %LOCALAPPDATA%\AssetLens\assetlens.db。CLI 与 MCP 使用同一个数据库路径即可共享扫描结果。
启用 --json 后,标准输出恰好包含一个 JSON 对象,可直接交给 jq。错误对象含 error 字段。退出码 0 表示成功,1 表示参数、数据或 I/O 错误,2 表示目标未找到。查询成功但没有匹配行时,items 为空,退出码仍为 0。
assetlens report unused --project demo --type texture --json | jq -r '.items[].path'
assetlens refs Art/Cookie.png --project demo --json
assetlens deps Scenes/Entry.unity --project demo --json
assetlens export dataset --project demo --out .\demo.jsonl --json列表中的 count 表示本页条数。将 next_offset 作为下一次查询的 --offset,直到得到 null。重复报告按组分页,组内 count 是该组文件总数,每页最多预览 100 条成员路径。如果某组的 paths_truncated 为 true,可在导出的 JSONL 中按组的 md5 和 size_bytes 筛出完整成员。
JSONL 每行含 project、guid、path、type、size_bytes、mtime、md5、refs_in 和 refs_out。mtime 为源文件上次修改的 Unix 时间戳,单位为秒。导出成功后会替换同名目标文件。目标应位于已注册工程的 Assets/ 目录之外,且与索引数据库使用不同路径。
未引用资产的分类
每项结果的 reason 在查询时按下表从上到下计算。命中第一条后即停止。例如 Resources/Editor/Tool.cs 归入 editor_script。目录规则匹配完整路径段,包含 Assets/ 下的第一层目录。EditorTools/Tool.cs 不会因目录名的前缀而命中 Editor。
优先级 | 路径条件 |
|
1 | 任意一级目录名为 |
|
2 | 任意一级目录名为 |
|
3 | 文件扩展名为 |
|
4 | 其余零入边资产 |
|
默认报告中的 excluded 分别列出前三类的资产数,计数范围是当前工程中符合 --type 的全部零入边候选,先计数再分页。--include-all 显示四类,--reason R 只显示指定类别。同时传入两者时以 --reason 为准。这两种查询的 excluded 都是 {}。count、items 和 next_offset 始终对应筛选后的页。
assetlens report unused --project demo --include-all --json
assetlens report unused --project demo --reason scene_root --json搜索资产路径
普通文本在整个 Assets/ 相对路径中做大小写不敏感的子串匹配。查询中含 * 或 ? 时按 glob 匹配路径。PowerShell 中可用单引号包住模式。结果按 path 排序,每项含 path、type、size_bytes、guid、refs_in 和 refs_out,可用 --type 缩小范围,再用 --limit、--offset 翻页。没有匹配项时,items 为空且退出码为 0。
assetlens search cookie --type texture --project demo --json
assetlens search 'Art/*.png' --type texture --project demo --limit 1 --offset 0 --json第一条命令找到 Art/Cookie.png。它已有两个 prefab 引用,也会出现在搜索结果中。
MCP stdio 配置
将下面的配置合并到 MCP 客户端的 mcpServers 中。将 command 替换为已安装完整版 AssetLens 的 Python 绝对路径。客户端通过标准输入输出启动 python -m assetlens.mcp_server。如果 CLI 使用了自定义数据库,在配置中加入同一绝对路径的 env.ASSETLENS_DB。
{
"mcpServers": {
"assetlens": {
"command": "C:\\work\\AssetLens\\.venv\\Scripts\\python.exe",
"args": ["-m", "assetlens.mcp_server"],
"type": "stdio"
}
}
}连接后先调用 list_projects,参数为 {}。完成快速开始示例后应能看到 demo。随后调用 find_unused,传入 {"project":"demo","type":"texture"} 即可复核 CLI 示例。传入 reason 或 include_all 可调整同一套筛选规则。调用 search_assets 并传入 {"project":"demo","query":"Art/*.png","type":"texture"} 可以列出两张示例贴图及其引用计数。
服务提供 list_projects、scan_project、find_unused、search_assets、find_duplicates、largest_assets、who_references、asset_summary、export_dataset 九个工具。scan_project 接受注册名或工程根目录,首次按路径扫描时使用目录名注册。列表工具接受 offset,每次最多 100 条,largest_assets 默认 10 条。工具返回 JSON 字符串,业务错误返回 {"error":"原因"}。export_dataset 将完整数据写入文件,响应仅包含导出信息。
索引范围与已知限制
仅遍历
Assets/。扫描跳过.meta本身、目录Library/、Temp/、obj/、.git/、Logs/、Build/和链接资产。每次扫描重新读取文件内容。单个工程的索引在事务中替换,重复 GUID 等扫描错误会保留上一次成功的结果。资产类型按扩展名归入
prefab、material、texture、audio、animation、controller、script、model、font或other。场景.unity归入other,可作为deps的起点。缺失或无效.meta的文件也计入大小和重复分析,guid为null,无法通过它建边。Unity 的文本序列化包含
%YAML头和!u!标签。扫描器直接从.prefab、.unity、.mat、.asset、.anim等文本资产匹配 GUID。同一源资产多次引用同一目标只算一条边。指向包、内置资源或已缺失资产的 GUID 仍计入refs_out,扫描结果的unresolved_refs给出此类未在当前Assets/内解析的边数。文件大小衡量源文件占用。构建包大小和运行时显存取决于 Unity 的导入与压缩设置。重复分析使用源文件内容的 MD5 和字节数,未考虑
.meta中的导入参数,合并前应核对其 GUID 引用与导入设置。
真实工程上的误报来源与默认过滤策略
在一次 Cloudbreak Post 工程扫描中,292 个资产共有 536 条引用。旧报告列出了 159 个零入边资产,其中 67 个位于 Editor/ 下,编辑器可以直接调用这些工具。另有 35 个位于 Resources/ 下,可由 Resources.Load 按名称加载,还有 3 个 .unity 场景可作为构建或运行入口。默认报告按上述顺序过滤这三类,因此本次快照显示 54 条(159 − 67 − 35 − 3)。--include-all 可查看全部 159 条及其分类。
其余 54 条仍需结合项目的实际加载方式复核。二进制序列化和脚本按名称加载也可能使正在使用的资产显示为零入边。
运行测试
python -m pytest -qtests/fixtures/MiniUnity 含 1 个场景、2 个 prefab、2 张内容相同的贴图及各自的 .meta。测试核对入边和出边、孤儿贴图、重复文件、重扫后的工程隔离、循环依赖、CLI 退出码和 JSONL 导出。测试另建临时工程核对四类 reason、默认排除计数,以及搜索的子串、glob、类型过滤和分页。安装 MCP 依赖后,还会通过真实 stdio 子进程调用工具。
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
Related MCP Connectors
Your org's AI agents, tasks, runs, search, and brain files as MCP tools and resources.
Read-only MCP tools for AI agent discovery, structured resources, and NIULAI information.
OCR, transcription, file extraction, and image generation for AI agents via MCP.
Nifty's MCP server — exposes tasks, projects, messages, and files as tools for AI agents.
Related MCP Servers
- AlicenseCqualityBmaintenanceProvides AI assistants with structured access to Unity project metadata, build settings, and agent documentation directly from the filesystem. It enables querying project details and scene configurations without requiring the Unity Editor to be running.156363 npm7MIT
- AlicenseNot gradedqualityNot gradedmaintenanceExposes Unity Editor project context and manipulation tools to AI coding agents, enabling automated scene hierarchy analysis, script inspection, and asset management. It supports both read and write operations including GameObject editing, component configuration, and animation authoring within the Unity environment.2-
- FlicenseNot gradedqualityDmaintenanceEnables AI assistants to search and analyze Unity project assets, including references and dependencies, via the Model Context Protocol.-
- AlicenseNot gradedqualityCmaintenanceIndexes Unity projects into a SQLite database and exposes 23 MCP tools for Claude to explore scenes, prefabs, scripts, and assets via structured queries.2MIT