Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

add Tool.outputSchema and CallToolResult.structuredContent #685

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

Open
wants to merge 23 commits into
base: main
Choose a base branch
Loading
from

Conversation

davemssavage
Copy link

@davemssavage davemssavage commented May 11, 2025

Enable tool to return structured content and output schema.

Motivation and Context

As per discussion in modelcontextprotocol/modelcontextprotocol#371 there are use cases where being able to know the schema of a tool is useful prior to calling it. This patch implements the behaviour specified.

In addition it allows for an extensible validation mechanism to be introduced on the client side. The default behaviour is to check the response conforms to the schema that is cached by the client but leaves the door open to other validation options and different caching techniques.

How Has This Been Tested?

Local unit testing only so far, some testing with deployed server locally

Breaking Changes

None

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

Updates to documentation will be required if this patch is approved

@davemssavage davemssavage marked this pull request as draft May 11, 2025 13:28
@davemssavage davemssavage changed the title WIP: add tool outputSchema and DataContent type to support structured content WIP: add Tool.outputSchema and CallToolResult.structuredContent May 16, 2025
@davemssavage davemssavage changed the title WIP: add Tool.outputSchema and CallToolResult.structuredContent add Tool.outputSchema and CallToolResult.structuredContent May 17, 2025
@davemssavage davemssavage marked this pull request as ready for review May 17, 2025 16:35
@davemssavage
Copy link
Author

Tagging @bhosmer-ant I took a pass refactoring my previous merge request to this repo to support modelcontextprotocol/modelcontextprotocol#371 there's definitely some rough edges happy to discuss potential improvments.

],
],
schema_func: Callable[..., dict[str, Any] | None] | None = None,
Copy link
Author

Choose a reason for hiding this comment

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

This is rather clunky, however I could think of no other way to maintain backwards compatibility with current python sdk that just assumes the function returns the result and not a protocol result as per the typescript version of this sdk which allows for a slightly cleaner implementation

@davemssavage davemssavage marked this pull request as draft May 18, 2025 19:15
@davemssavage davemssavage marked this pull request as ready for review May 18, 2025 19:38
@davemssavage
Copy link
Author

Note failed test appears to be due to #744

@bhosmer-ant
Copy link
Contributor

Hi @davemssavage - really appreciate your work on this! Will be checking it out shortly, but meanwhile wanted to let you know it hasn't fallen off the map 😬

@davemssavage
Copy link
Author

@bhosmer-ant no problem, just experimenting at the moment, but this feature is really useful in my experiments!

Whilst I have your attention could I also highlight #628 for your consideration and #744 which is a bug that seems to be on main branch, the problem there is quite subtle, not least because it is intermittent so frustrating to test.

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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.