Skip to content

fix: enable arrays and boolean data to be structured data. #528

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

Closed
wants to merge 4 commits into from

Conversation

tlgimenes
Copy link

@tlgimenes tlgimenes commented May 21, 2025

Replaces .object to .any on CallToolResultSchema to enable arrays and boolean on structuredContent

Motivation and Context

Hi folks! I have some mcps and I'd love to migrate them to using the new structuredContent for mcp output. Turns out that when migrating these MCPs I've noticed some of my tools return either and array or a boolean value. When this is the case I currently get an error from zod schema validation.

This PR addresses this issue by allowing .any() type on structuredContent

How Has This Been Tested?

Breaking Changes

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

@bhosmer-ant
Copy link
Contributor

Hi @tlgimenes - great that you're looking to migrate to structured output!

Totally understand your motivations for suggesting this change, but we actually thought pretty carefully about the object restriction (which btw is in the MCP specification - the TypeScript SDK is just following the spec here).

The motivation for the restriction is that the convention of always returning objects is pervasive for remote endpoints - e.g. it's baked into a bunch of off-the-shelf deserialization libraries - and simplifies parsing/validation pipelines, etc. Ultimately the ROI of the added generality wasn't compelling, given the complexity burden on implementors and the fact that it doesn't appear to be part of the standard repertoire in practice.

For tools that want to return non-objects (primitive values, lists, etc.), a typical convention is to wrap the values in a single-property object, e.g. {result: <value>}. This is how we handle the situation in FastMCP in the Python SDK, for example.

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.

2 participants