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
parent
237b26ecb4
commit
2b23af45a2
|
|
@ -65,7 +65,17 @@ namespace MCPForUnity.Editor.Tools
|
|||
// Normalize caller path: allow both "Scripts/..." and "Assets/Scripts/..."
|
||||
string rel = (relDir ?? "Scripts").Replace('\\', '/').Trim();
|
||||
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('/');
|
||||
|
||||
string targetDir = Path.Combine(assets, rel).Replace('\\', '/');
|
||||
|
|
|
|||
|
|
@ -80,7 +80,7 @@ async def manage_asset(
|
|||
|
||||
properties, parse_error = await _normalize_properties(properties)
|
||||
if parse_error:
|
||||
await ctx.warn(parse_error)
|
||||
await ctx.error(parse_error)
|
||||
return {"success": False, "message": parse_error}
|
||||
|
||||
# Coerce numeric inputs defensively
|
||||
|
|
|
|||
Loading…
Reference in New Issue