modelcontextprotocol / modelcontextprotocol/python-sdk

It is not possible to define a Resource that takes only the Context parameter as an argument.

Open
#1,405 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug improves spec compliance P2 ready for work
Dominant language
Python
Stars
24.3k
Forks
4k
Avg merge
1d 1h
Merged PRs (30d)
31

Description

Initial Checks
Description

Problem

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.

Expected Behavior

Resources with only a Context parameter should be registered as regular resources, not template resources.

Current Behavior

Resources with only a Context parameter are incorrectly registered as template resources, causing them to not appear in the resource list and fail when accessed.

Root Cause

The parameter validation logic in the FastMCP.resource() decorator doesn't properly distinguish between effective function parameters and Context parameters. It treats any function with parameters as a potential template resource, even when the only parameter is a Context.

Solution

  1. Fix the parameter validation logic to exclude Context parameters when determining if a resource should be a template
  2. Update the Resource.read() method signature to accept an optional context parameter
  3. Update all resource implementations to support the new signature

This change maintains full backward compatibility while enabling context-only resources.

Example Code
@mcp.resource("resource://user_profile")
def get_user_profile(ctx: Context) -> str:
    # Something Code ...
Python & MCP Python SDK
Python 3.13.5
MCP Python SDK v1.15.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the FastMCP.resource() decorator's parameter validation and inspect how Context-only functions are classified. Then trace Resource.read() and the existing resource implementations to update the call signature consistently; done means Context-only resources appear in the resource list and can be accessed without breaking existing resources.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.