Skip to content

Commit 2b23af4

Browse files
dsarnoclaude
andauthored
Fix/script path assets prefix and ctx warn bug (#453)
* Fix script path handling and FastMCP Context API usage 1. Fix script path doubling when Assets prefix is used - ManageScript.TryResolveUnderAssets now properly handles both Assets and Assets/ prefixes - Previously, paths like Assets/Script.cs would create files at Assets/Assets/Script.cs - Now correctly strips the prefix and creates files at the intended location 2. Fix FastMCP Context API call in manage_asset - Changed ctx.warn() to ctx.warning() to match FastMCP Context API - Fixes AttributeError when manage_asset encounters property parse errors - Affects ScriptableObject creation and other asset operations with invalid properties * Fix manage_asset error handling to use ctx.error Changed ctx.warning to ctx.error for property parse errors in manage_asset tool to properly handle error cases. This ensures parse errors are reported as errors rather than warnings, and fixes compatibility with FastMCP Context API. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <[email protected]> --------- Co-authored-by: Claude Sonnet 4.5 <[email protected]>
1 parent 237b26e commit 2b23af4

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

MCPForUnity/Editor/Tools/ManageScript.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,17 @@ private static bool TryResolveUnderAssets(string relDir, out string fullPathDir,
6565
// Normalize caller path: allow both "Scripts/..." and "Assets/Scripts/..."
6666
string rel = (relDir ?? "Scripts").Replace('\\', '/').Trim();
6767
if (string.IsNullOrEmpty(rel)) rel = "Scripts";
68-
if (rel.StartsWith("Assets/", StringComparison.OrdinalIgnoreCase)) rel = rel.Substring(7);
68+
69+
// Handle both "Assets" and "Assets/" prefixes
70+
if (rel.Equals("Assets", StringComparison.OrdinalIgnoreCase))
71+
{
72+
rel = string.Empty;
73+
}
74+
else if (rel.StartsWith("Assets/", StringComparison.OrdinalIgnoreCase))
75+
{
76+
rel = rel.Substring(7);
77+
}
78+
6979
rel = rel.TrimStart('/');
7080

7181
string targetDir = Path.Combine(assets, rel).Replace('\\', '/');

Server/src/services/tools/manage_asset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ async def _normalize_properties(raw: dict[str, Any] | str | None) -> tuple[dict[
8080

8181
properties, parse_error = await _normalize_properties(properties)
8282
if parse_error:
83-
await ctx.warn(parse_error)
83+
await ctx.error(parse_error)
8484
return {"success": False, "message": parse_error}
8585

8686
# Coerce numeric inputs defensively

0 commit comments

Comments
 (0)