modelcontextprotocol / modelcontextprotocol/python-sdk
find_context_parameter treats a Context return annotation as a parameter
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 24.3k
- Forks
- 4k
- Merge médio
- 1d 1h
- PRs com merge (30d)
- 31
Descrição
Initial checks
- I tested the current
mainbranch (6e30452). - I searched existing issues and pull requests for this behavior.
Description
find_context_parameter() iterates over every entry returned by typing.get_type_hints(). That mapping includes the function return annotation under the special key "return", even though it is not a parameter.
As a result, a tool, prompt, or resource function whose return annotation is Context (or a union containing Context) is incorrectly recorded as having a context parameter named "return". The SDK later attempts to inject context as a keyword argument with that name, which can produce an unexpected-keyword error when the callable is invoked.
Expected: context detection only examines actual function parameters and ignores the return annotation.
Example code
from mcp.server.mcpserver import Context
from mcp.server.mcpserver.utilities.context_injection import find_context_parameter
def fn(value: int) -> Context:
...
print(find_context_parameter(fn)) # current: "return"; expected: None
Environment
- Python 3.12
- MCP Python SDK
mainat6e30452
I used AI assistance while investigating this issue and reviewed and reproduced the behavior locally.
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece em mcp/server/mcpserver/utilities/context_injection.py, em find_context_parameter(), e reproduza o exemplo com uma anotação de retorno Context. Confirme que a detecção examina apenas parâmetros reais, ignora a anotação "return" e não relata mais "return" como o parâmetro de contexto.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- python
- Domínio
- api, backend
- Tipo de issue
- Bug
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Status de atividade
- Ativa
- Clareza
- Claramente especificada
- Facilidade para iniciantes
- 78/100