python-sdk icon indicating copy to clipboard operation
python-sdk copied to clipboard

add Tool.outputSchema and CallToolResult.structuredContent

Open davemssavage opened this issue 8 months ago • 4 comments

Enable tool to return structured content and output schema.

Motivation and Context

As per discussion in https://github.com/modelcontextprotocol/modelcontextprotocol/pull/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)
  • [x] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to change)
  • [ ] Documentation update

Checklist

  • [x] I have read the MCP Documentation
  • [x] My code follows the repository's style guidelines
  • [x] New and existing tests pass locally
  • [x] 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 avatar May 11 '25 13:05 davemssavage

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

davemssavage avatar May 17 '25 16:05 davemssavage

Note failed test appears to be due to https://github.com/modelcontextprotocol/python-sdk/issues/744

davemssavage avatar May 19 '25 09:05 davemssavage

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 😬

bhosmer-ant avatar May 21 '25 03:05 bhosmer-ant

@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 https://github.com/modelcontextprotocol/python-sdk/pull/628 for your consideration and https://github.com/modelcontextprotocol/python-sdk/issues/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.

davemssavage avatar May 21 '25 07:05 davemssavage

@davemssavage fyi I'm going to go ahead and bring this over the finish line - thanks again for all your work!

bhosmer-ant avatar Jun 17 '25 12:06 bhosmer-ant

@davemssavage fyi I'm going to go ahead and bring this over the finish line - thanks again for all your work!

No problem, I got distracted, glad to be of help

davemssavage avatar Jun 27 '25 18:06 davemssavage

Already merged in #993

davemssavage avatar Jun 27 '25 18:06 davemssavage