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

feat: Add output schema generation for tools and update documentation #757

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 3 commits into
base: main
Choose a base branch
Loading
from

Conversation

PratyushNag
Copy link

Output Schema Support for Tools

This PR adds automatic JSON Schema generation for tool return types, enabling LLMs to understand the structure of data they'll receive from tools.

Motivation and Context

  • Previously, tools only had input schemas but no structured metadata about their outputs
  • This helps LLMs better understand the structure of data they'll receive from tools
  • Particularly valuable for complex return types like Pydantic models and nested structures
  • Improves the developer experience by making tools more self-documenting

How Has This Been Tested?

  • Added comprehensive test suite in test_tool_manager.py with the TestOutputSchema class
  • Tests cover primitive types, Pydantic models, complex nested structures, and generic types
  • Verified integration with FastMCP tool listing
  • Tested with the output_schema_demo.py example which demonstrates various return types

Breaking Changes

  • Non-breaking change - adds functionality without modifying existing behavior
  • Existing tools will automatically gain output schemas based on their return type annotations
  • No changes required to existing code

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

  • The implementation uses Python's type annotations and inspect module to extract return type information
  • For primitive types (str, int, float, bool, dict, list), it maps directly to JSON Schema types
  • For Pydantic models, it leverages Pydantic's built-in JSON Schema generation
  • The feature gracefully handles cases where schema generation isn't possible, falling back to None
  • Updated README.md with comprehensive examples showing different return type scenarios

Fixes #754

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.

Functionality to fetch output schemas as well on list_tools()
1 participant
Morty Proxy This is a proxified and sanitized view of the page, visit original site.