CoplayDev/unity-mcp · error · ArgumentException
'output_folder' must resolve under the project's Assets fold
Error message
'output_folder' must resolve under the project's Assets folder.
What it means
StageUnderAssets validates the user-supplied output_folder via AssetGenPaths.TryGetAssetsFolder, which requires the path to resolve under the project's Assets folder. When an explicit output_folder is given and fails this check, the import is rejected rather than writing outside Assets.
Source
Thrown at MCPForUnity/Editor/Tools/AssetGen/ImportModelFile.cs:84
}
}
private static string ResolveSource(string source)
{
string s = source.Replace('\\', '/');
if (s == "Assets" || s.StartsWith("Assets/")) return AssetGenPaths.ToAbsolute(s);
return s; // absolute path on disk
}
private static string StageUnderAssets(string srcAbs, string baseName, string ext, string outputFolder)
{
string root = !string.IsNullOrWhiteSpace(outputFolder)
? outputFolder
: AssetGenPrefs.OutputRoot + "/Imported";
if (!AssetGenPaths.TryGetAssetsFolder(root, out root))
{
if (!string.IsNullOrWhiteSpace(outputFolder))
throw new ArgumentException("'output_folder' must resolve under the project's Assets folder.");
root = AssetGenPrefs.DefaultOutputRoot + "/Imported";
}
string absRoot = AssetGenPaths.ToAbsolute(root);
Directory.CreateDirectory(absRoot);
string safe = SanitizeName(baseName);
string fileName = safe + ext;
string abs = Path.Combine(absRoot, fileName);
int n = 1;
while (File.Exists(abs)) { fileName = safe + "_" + n++ + ext; abs = Path.Combine(absRoot, fileName); }
File.Copy(srcAbs, abs);
return (root.TrimEnd('/') + "/" + fileName).Replace('\\', '/');
}
private static string SanitizeName(string raw)
{View on GitHub (pinned to c21bf496bc)
Solutions
- Use a path relative to Assets, e.g. 'Assets/Models/Imported' or 'Models/Imported'.
- Omit output_folder to fall back to the default Assets-rooted output location.
- Ensure the path does not use '..' to escape the Assets folder.
Example fix
// before
{ "output_folder": "/tmp/exports" }
// after
{ "output_folder": "Assets/Models/Imported" } Defensive patterns
Strategy: validation
Validate before calling
if (!string.IsNullOrWhiteSpace(outputFolder) && !AssetGenPaths.TryGetAssetsFolder(outputFolder, out _))
{
throw new ArgumentException("'output_folder' must resolve under the project's Assets folder.");
} Prevention
- Pass output_folder relative to Assets (e.g. 'Assets/Models/Imported' or 'Models/Imported').
- Omit output_folder to use the safe default.
- Never pass an absolute OS path or a '..' traversal.
When it happens
Trigger: output_folder is an absolute OS path outside the project; a relative path that escapes Assets via '..'; a path pointing at Packages/ or Library/ instead of Assets.
Common situations: User passes a full disk path expecting a general export; user wants to write outside the project; relative path crafted to traverse out of Assets.
Related errors
- uid required
- provider returned a disallowed file type '.{ext}'
- zipPath required
- Unknown model provider '{id}'.
- Unknown image provider '{id}'.
AI-assisted analysis of CoplayDev/unity-mcp@c21bf496bc (2026-08-13).
Data as JSON: /api/errors/6fec0aaca349f1e6.
Report an issue: GitHub.