From 2b23af45a2e4da83033bde78eb338e8381f64f92 Mon Sep 17 00:00:00 2001 From: dsarno Date: Wed, 10 Dec 2025 20:09:16 -0800 Subject: [PATCH] Fix/script path assets prefix and ctx warn bug (#453) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --------- Co-authored-by: Claude Sonnet 4.5 --- MCPForUnity/Editor/Tools/ManageScript.cs | 12 +++++++++++- Server/src/services/tools/manage_asset.py | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/MCPForUnity/Editor/Tools/ManageScript.cs b/MCPForUnity/Editor/Tools/ManageScript.cs index 3745ec7..03da19d 100644 --- a/MCPForUnity/Editor/Tools/ManageScript.cs +++ b/MCPForUnity/Editor/Tools/ManageScript.cs @@ -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('\\', '/'); diff --git a/Server/src/services/tools/manage_asset.py b/Server/src/services/tools/manage_asset.py index c9c4b5a..e7264ea 100644 --- a/Server/src/services/tools/manage_asset.py +++ b/Server/src/services/tools/manage_asset.py @@ -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