fix: return ResponseCallTool to prevent MCP error -32600#781
fix: return ResponseCallTool to prevent MCP error -32600#781tianlang0704 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes MCP error -32600 (Tool script-execute has an output schema but did not return structured content) raised when a dynamically executed script returns void/null. The fix changes Tool_Script.Execute to return ResponseCallTool instead of SerializedMember?, so the dispatcher receives a non-null response in every branch — including a friendly message for void scripts.
Changes:
- Change
Executereturn type fromSerializedMember?toResponseCallTooland add theMcpPlugin.Common.Modelusing. - Return
ResponseCallTool.Success(...)for null/void results with an explanatory message. - For non-null results, JSON-serialize the
SerializedMember/reflector.Serialize(...)payload and pass it as the message of aResponseCallTool.Success.
| "provide the method body. Unity objects (GameObject, Component, etc.) can be passed as " + | ||
| "parameters using their Ref types (GameObjectRef, ComponentRef, etc.) or directly by type.")] | ||
| public static SerializedMember? Execute | ||
| public static ResponseCallTool Execute |
There was a problem hiding this comment.
I didn't encounter Tool_Reflection.MethodCall so need @IvanMurzak to suggest if we need to apply similar fix to this tool?
|
@tianlang0704 what AI agent does produce the error with this tool? |
|
The tool used was Kilo Code extension for VSCode. |
f322151 to
059b07d
Compare
Changed Tool_Script.Execute return type from SerializedMember? to ResponseCallTool to ensure structured content is always returned. When script returns void, now returns a success message instead of null. Uses reflector's JsonSerializer to preserve custom converters for Unity types (Vector2/3/4, Color, Quaternion, EntityId, GameObjectRef, etc). This fixes MCP error -32600 which occurs when a tool has output schema but returns null.
…output - Added ScriptExecuteResponse data model in AIGD namespace - Changed return type to ResponseCallValueTool<ScriptExecuteResponse> - Use Success() for void results, SuccessStructured() for non-void - Uses reflector.JsonSerializer to preserve custom converters for Unity types - Maintains output schema and StructuredContent for MCP clients
059b07d to
ff74d42
Compare
|
|
||
| return reflector.Serialize( | ||
| var serialized = reflector.Serialize( | ||
| obj: result, | ||
| logger: logger); | ||
|
|
||
| return ResponseCallValueTool<ScriptExecuteResponse> | ||
| .SuccessStructured(jsonSerializer.SerializeToNode(new ScriptExecuteResponse | ||
| { | ||
| Result = serialized, | ||
| Message = "Script executed successfully." | ||
| })); |
| "provide the method body. Unity objects (GameObject, Component, etc.) can be passed as " + | ||
| "parameters using their Ref types (GameObjectRef, ComponentRef, etc.) or directly by type.")] | ||
| public static SerializedMember? Execute | ||
| public static ResponseCallValueTool<ScriptExecuteResponse> Execute |
|
Sorry my bad, this is an over-complicated solution, let me close this, more simpler and clearer solution is here #783 |
#779
Changed Tool_Script.Execute return type from SerializedMember? to ResponseCallTool to ensure structured content is always returned. When script returns void, now returns a success message instead of null. This fixes MCP error -32600 which occurs when a tool has output schema but returns null.