-
Notifications
You must be signed in to change notification settings - Fork 508
Harden MCP tool parameter handling + add material workflow tests (TDD) #343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5bf0bed
Add TDD tests for MCP material management issues
dsarno 2a1a1fe
Refine TDD tests to focus on actual MCP tool parameter parsing issues
dsarno cd0e628
Fix port discovery protocol mismatch
dsarno 3c74783
Merge fix/port-discovery-protocol into tdd/material-management-tests
dsarno 3efc57c
Resolve merge: unify manage_gameobject param coercion and schema wide…
dsarno 1bdbeb8
Tests: add MaterialParameterToolTests; merge port probe fix; widen to…
dsarno dbd5cf6
refactor: extract JSON coercion helper; docs + exception narrowing\nf…
dsarno f9756ea
chore(tests): track MCPToolParameterTests.cs.meta to keep GUID stable
dsarno c004994
test: decouple MaterialParameterToolTests with helpers (no inter-test…
dsarno File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| using Newtonsoft.Json.Linq; | ||
| using UnityEngine; | ||
|
|
||
| namespace MCPForUnity.Editor.Tools | ||
| { | ||
| internal static class JsonUtil | ||
| { | ||
| /// <summary> | ||
| /// If @params[paramName] is a JSON string, parse it to a JObject in-place. | ||
| /// Logs a warning on parse failure and leaves the original value. | ||
| /// </summary> | ||
| internal static void CoerceJsonStringParameter(JObject @params, string paramName) | ||
| { | ||
| if (@params == null || string.IsNullOrEmpty(paramName)) return; | ||
| var token = @params[paramName]; | ||
| if (token != null && token.Type == JTokenType.String) | ||
| { | ||
| try | ||
| { | ||
| var parsed = JObject.Parse(token.ToString()); | ||
| @params[paramName] = parsed; | ||
| } | ||
| catch (Newtonsoft.Json.JsonReaderException e) | ||
| { | ||
| Debug.LogWarning($"[MCP] Could not parse '{paramName}' JSON string: {e.Message}"); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
...Projects/UnityMCPTests/Assets/Editor.meta → ...jects/UnityMCPTests/Assets/Materials.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Also validate parsed type is a dict.
Parsing a valid JSON array/string would slip through; ensure the result is a dict before proceeding.
if isinstance(component_properties, str): try: component_properties = json.loads(component_properties) ctx.info("manage_gameobject: coerced component_properties from JSON string to dict") except json.JSONDecodeError as e: return {"success": False, "message": f"Invalid JSON in component_properties: {e}"} + if component_properties is not None and not isinstance(component_properties, dict): + return {"success": False, "message": "component_properties must be a JSON object (dict)."}📝 Committable suggestion
🤖 Prompt for AI Agents