feat(fastmcp): add include_in_context parameter to resource decorator#1677
Closed
rinaldofesta wants to merge 2 commits intomodelcontextprotocol:mainfrom
Closed
feat(fastmcp): add include_in_context parameter to resource decorator#1677rinaldofesta wants to merge 2 commits intomodelcontextprotocol:mainfrom
rinaldofesta wants to merge 2 commits intomodelcontextprotocol:mainfrom
Conversation
Add a user-friendly include_in_context boolean parameter to the @resource decorator that automatically sets priority=1.0 in annotations, making it easier for users to mark resources for context inclusion without manually managing annotation objects. Changes: - Add include_in_context parameter to resource decorator - Automatically create Annotations(priority=1.0) when enabled - Override explicit priority when include_in_context=True - Preserve other annotation fields (audience) - Support both regular and template resources - Update docstring with new parameter documentation - Add comprehensive test coverage (6 new tests) The parameter provides a simple API for context inclusion: @mcp.resource("resource://data", include_in_context=True) def get_data(): return "important data"
Contributor
|
I responded on #1657 (not sure where the discussion should accrue) but I see this as introducing a new problem (two kwargs for one outcome, one of which has misleading effect) rather than solving an existing one. |
Contributor
|
Thanks for the contribution! Unfortunately I'll be closing the PR as per #1657 (comment) Basically, this is already supported in both the spec and framework as is, I don't think we need to have it hardcoded as an arg in the decorators. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a user-friendly
include_in_contextboolean parameter to the@resourcedecorator that automatically setspriority=1.0in annotations. This simplifies marking resources for context inclusion without requiring users to manually create and manageAnnotationsobjects.Closes #1657
Motivation
Currently, users must create an
Annotationsobject to set resource priority for context inclusion:This PR introduces a simpler API:
Implementation
include_in_context=True, automatically setspriority=1.0audienceChanges
FastMCP.resource()decorator to acceptinclude_in_contextparameterpriority=1.0when enabledTest Plan
include_in_context=Truesets priority to 1.0include_in_context=Falsedoesn't affect annotations