Skip to content

Conversation

@aharvard
Copy link
Collaborator

Summary

The MCP spec defines structuredContent as optional (field may be absent), not nullable:

structuredContent?: { [key: string]: unknown }

Without skip_serializing_if, serde serializes Option::None as null in JSON, but Zod's .optional() schema accepts undefined (field absent) and rejects null.

This was causing Zod validation errors in MCP Apps when calling tools that don't return structured content.

Changes

Added #[serde(skip_serializing_if = "Option::is_none")] to structured_content field in CallToolResponse so the field is omitted from JSON when None, aligning with the MCP spec.

Related

Fixes #6454

See: #6454 (comment)

The MCP spec defines structuredContent as optional (field may be absent),
not nullable. Zod's .optional() schema accepts undefined but rejects null.

Without skip_serializing_if, serde serializes Option::None as null,
causing Zod validation errors in MCP Apps when calling tools.

Fixes #6454
Copilot AI review requested due to automatic review settings January 14, 2026 15:01
Copy link
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

This PR fixes a serialization issue where structured_content in MCP tool responses was being serialized as null instead of being omitted when absent, causing Zod validation errors in MCP Apps.

Changes:

  • Added #[serde(skip_serializing_if = "Option::is_none")] to the structured_content field in CallToolResponse to align with the MCP spec

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.

MCP Apps: Tool Calling from UI is broken

3 participants