Initial checks
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
main at 6e30452
I used AI assistance while investigating this issue and reviewed and reproduced the behavior locally.
Initial checks
mainbranch (6e30452).Description
find_context_parameter()iterates over every entry returned bytyping.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 containingContext) 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
Environment
mainat6e30452I used AI assistance while investigating this issue and reviewed and reproduced the behavior locally.