Skip to content

fix: return ResponseCallTool to prevent MCP error -32600#781

Closed
tianlang0704 wants to merge 2 commits into
IvanMurzak:mainfrom
tianlang0704:fix/script-execute-mcp-error-32600
Closed

fix: return ResponseCallTool to prevent MCP error -32600#781
tianlang0704 wants to merge 2 commits into
IvanMurzak:mainfrom
tianlang0704:fix/script-execute-mcp-error-32600

Conversation

@tianlang0704
Copy link
Copy Markdown
Contributor

#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.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Execute return type from SerializedMember? to ResponseCallTool and add the McpPlugin.Common.Model using.
  • 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 a ResponseCallTool.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
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't encounter Tool_Reflection.MethodCall so need @IvanMurzak to suggest if we need to apply similar fix to this tool?

@IvanMurzak
Copy link
Copy Markdown
Owner

@tianlang0704 what AI agent does produce the error with this tool?

@tianlang0704
Copy link
Copy Markdown
Contributor Author

The tool used was Kilo Code extension for VSCode.

@tianlang0704 tianlang0704 force-pushed the fix/script-execute-mcp-error-32600 branch from f322151 to 059b07d Compare May 27, 2026 11:04
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
@tianlang0704 tianlang0704 force-pushed the fix/script-execute-mcp-error-32600 branch from 059b07d to ff74d42 Compare May 27, 2026 11:14
@tianlang0704 tianlang0704 requested a review from Copilot May 27, 2026 11:20
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comment on lines 160 to +170

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
@tianlang0704
Copy link
Copy Markdown
Contributor Author

Sorry my bad, this is an over-complicated solution, let me close this, more simpler and clearer solution is here #783

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants