modelcontextprotocol / modelcontextprotocol/python-sdk
It is not possible to define a Resource that takes only the Context parameter as an argument.
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 24.3k
- Forks
- 4k
- Merge medio
- 1 d 1 h
- PR fusionados (30 d)
- 31
Descripción
Initial Checks
- I confirm that I'm using the latest version of MCP Python SDK
- I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue
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
- Fix the parameter validation logic to exclude Context parameters when determining if a resource should be a template
- Update the
Resource.read()method signature to accept an optional context parameter - 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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con la validación de parámetros del decorador FastMCP.resource() e inspecciona cómo se clasifican las funciones Context-only. Después, sigue Resource.read() y las implementaciones de recursos existentes para actualizar la firma de llamada de forma coherente; se considera terminado cuando los recursos Context-only aparecen en la lista de recursos y se puede acceder a ellos sin romper los recursos existentes.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- api
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 42/100