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 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>
main
dsarno 2025-12-10 20:09:16 -08:00 committed by GitHub
parent 237b26ecb4
commit 2b23af45a2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 2 deletions

View File

@ -65,7 +65,17 @@ namespace MCPForUnity.Editor.Tools
// Normalize caller path: allow both "Scripts/..." and "Assets/Scripts/..." // Normalize caller path: allow both "Scripts/..." and "Assets/Scripts/..."
string rel = (relDir ?? "Scripts").Replace('\\', '/').Trim(); string rel = (relDir ?? "Scripts").Replace('\\', '/').Trim();
if (string.IsNullOrEmpty(rel)) rel = "Scripts"; if (string.IsNullOrEmpty(rel)) rel = "Scripts";
if (rel.StartsWith("Assets/", StringComparison.OrdinalIgnoreCase)) rel = rel.Substring(7);
// Handle both "Assets" and "Assets/" prefixes
if (rel.Equals("Assets", StringComparison.OrdinalIgnoreCase))
{
rel = string.Empty;
}
else if (rel.StartsWith("Assets/", StringComparison.OrdinalIgnoreCase))
{
rel = rel.Substring(7);
}
rel = rel.TrimStart('/'); rel = rel.TrimStart('/');
string targetDir = Path.Combine(assets, rel).Replace('\\', '/'); string targetDir = Path.Combine(assets, rel).Replace('\\', '/');

View File

@ -80,7 +80,7 @@ async def manage_asset(
properties, parse_error = await _normalize_properties(properties) properties, parse_error = await _normalize_properties(properties)
if parse_error: if parse_error:
await ctx.warn(parse_error) await ctx.error(parse_error)
return {"success": False, "message": parse_error} return {"success": False, "message": parse_error}
# Coerce numeric inputs defensively # Coerce numeric inputs defensively