Skip to content

Conversation

0Delta
Copy link

@0Delta 0Delta commented Sep 26, 2025

Add support for context-only resources

Motivation and Context

#1405

Currently, it is not possible to define a Resource that takes only the Context parameter as an argument. When attempting to create such a resource, the registration logic incorrectly classifies it as a template resource instead of a regular resource.

This limitation prevents developers from creating resources that need access to server session context but don't require dynamic URI components, reducing flexibility in resource design.

How Has This Been Tested?

  • Added comprehensive unit tests for context-only resource functionality
  • Added integration tests to verify correct resource registration
  • All existing resource tests continue to pass (22/22 tests passed)
  • Tested with example context-only resource implementation
  • Verified backward compatibility with existing resource definitions

Breaking Changes

No breaking changes. The context parameter in Resource.read() method is optional with default None. All existing resource implementations continue to work unchanged.

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

@0Delta 0Delta requested review from a team and ochafik September 26, 2025 13:18
@0Delta 0Delta force-pushed the context_only_resource_fn branch from 2986dff to dcad00e Compare September 26, 2025 13:21
@0Delta 0Delta force-pushed the context_only_resource_fn branch from dcad00e to cbcdec5 Compare September 26, 2025 13:47
@felixweinberger felixweinberger added needs motivation When a PR is submitted without clear intent or motivation for the changes. and removed needs motivation When a PR is submitted without clear intent or motivation for the changes. labels Sep 26, 2025
Copy link
Contributor

@felixweinberger felixweinberger left a comment

Choose a reason for hiding this comment

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

Hi @0Delta thank you for this contribution - are you running into this limitation with a concrete application you're trying to implement? If so would you be able to provide some additional details as a motivating example for this change?

@0Delta
Copy link
Author

0Delta commented Sep 26, 2025

Hi @felixweinberger.
Specifically, I wanted to define a simple resource like the one below and display logs within it.

from mcp.server.fastmcp import Context, FastMCP
mcp = FastMCP()


@mcp.resource("resource://user_profile")
def get_user_profile(ctx: Context) -> str:
    ctx.info("Fetching user profile")
    return "Profile data for user..."

When I tried to display this in Inspector, Inspector mistakenly thought it needed arguments and wouldn't run.

image

@0Delta
Copy link
Author

0Delta commented Sep 26, 2025

This resource should be recognized as just a Resource, not a template, right?

@felixweinberger felixweinberger added the needs more eyes Needs alignment among maintainers whether this is something we want to add label Sep 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs more eyes Needs alignment among maintainers whether this is something we want to add needs motivation When a PR is submitted without clear intent or motivation for the changes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants