modelcontextprotocol / modelcontextprotocol/python-sdk

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

Offen
#1,405 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug improves spec compliance P2 ready for work
Vorherrschende Sprache
Python
Sterne
24.3k
Forks
4k
Ø Merge
1 T. 1 Std.
Gemergte PRs (30 T.)
31

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit der Parameterprüfung des Decorators FastMCP.resource() und untersuche, wie Context-only-Funktionen klassifiziert werden. Verfolge anschließend Resource.read() und die vorhandenen Ressourcenimplementierungen, um die Aufrufsignatur konsistent zu aktualisieren; abgeschlossen ist die Aufgabe, wenn Context-only-Ressourcen in der Ressourcenliste erscheinen und auf sie zugegriffen werden kann, ohne bestehende Ressourcen zu beeinträchtigen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
api
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
42/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.