modelcontextprotocol / modelcontextprotocol/python-sdk

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

Aperta
#1,405 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug improves spec compliance P2 ready for work
Lingua principale
Python
Stelle
24.3k
Fork
4k
Merge medio
1g 1h
PR unite (30g)
31

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia con la convalida dei parametri del decorator FastMCP.resource() e analizza come vengono classificate le funzioni Context-only. Quindi segui Resource.read() e le implementazioni delle risorse esistenti per aggiornare la firma della chiamata in modo coerente; il lavoro è completo quando le risorse Context-only compaiono nell’elenco delle risorse e sono accessibili senza compromettere le risorse esistenti.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
api
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
42/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.