Skip to content

Conversation

fennb
Copy link
Contributor

@fennb fennb commented Oct 12, 2025

Add missing annotations support for resources and resource templates in FastMCP server (using pattern consistent with tool annotations implementation pattern).

Changes:

  • Add annotations field to Resource base class and FunctionResource
  • Add annotations field to ResourceTemplate class
  • Thread annotations parameter through all factory methods (from_function)
  • Update FastMCP.resource() decorator to accept annotations parameter
  • Pass annotations through in list_resources() and list_resource_templates()
  • Ensure resources created from templates inherit template annotations
  • Add test coverage for resource annotations, template annotations, and validation

Motivation and Context

The MCP protocol specification already defines Annotations (with audience and priority fields) for resources and resource templates at the protocol level (mcp.types). Tools in FastMCP already have full annotations support, but resources and resource templates were missing this capability, preventing developers from providing metadata hints about resource priority and intended audience to MCP clients.

This change enables developers to specify annotations when defining resources, allowing clients to make better decisions about resource presentation and usage based on these hints.

How Has This Been Tested?

Added test coverage including:

  • Resources with and without annotations (backward compatibility)
  • Templates with and without annotations
  • Resources created from annotated templates inherit annotations correctly
  • FastMCP decorator integration with list_resources() and list_resource_templates()
  • Annotations validation constraints (priority range 0.0-1.0, valid audience roles)

Breaking Changes

None. Annotations are optional throughout the implementation, maintaining full backward compatibility with 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

Add annotations support for resources and resource templates in FastMCP, following the existing tool annotations implementation pattern.

Changes:
- Add annotations field to Resource base class and FunctionResource
- Add annotations field to ResourceTemplate class
- Thread annotations parameter through all factory methods (from_function)
- Update FastMCP.resource() decorator to accept annotations parameter
- Pass annotations through in list_resources() and list_resource_templates()
- Ensure resources created from templates inherit template annotations
- Add test coverage for resource annotations, template annotations, and validation
@felixweinberger felixweinberger added needs maintainer action Potentially serious issue - needs proactive fix and maintainer attention enhancement New feature or request labels Oct 13, 2025
@felixweinberger felixweinberger removed the needs maintainer action Potentially serious issue - needs proactive fix and maintainer attention label Oct 14, 2025
@felixweinberger felixweinberger merged commit cd7253c into modelcontextprotocol:main Oct 14, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants