Title: find_context_parameter treats a Context return annotation as a parameter · Issue #3298 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: find_context_parameter treats a Context return annotation as a parameter · Issue #3298 · modelcontextprotocol/python-sdk
X Title: find_context_parameter treats a Context return annotation as a parameter · Issue #3298 · modelcontextprotocol/python-sdk
Description: Initial checks I tested the current main branch (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 i...
Open Graph Description: Initial checks I tested the current main branch (6e30452). I searched existing issues and pull requests for this behavior. Description find_context_parameter() iterates over every entry returned by...
X Description: Initial checks I tested the current main branch (6e30452). I searched existing issues and pull requests for this behavior. Description find_context_parameter() iterates over every entry returned by...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/3298
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"find_context_parameter treats a Context return annotation as a parameter","articleBody":"### Initial checks\n\n- [x] I tested the current `main` branch (`6e30452`).\n- [x] I searched existing issues and pull requests for this behavior.\n\n### Description\n\n`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.\n\nAs 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.\n\nExpected: context detection only examines actual function parameters and ignores the return annotation.\n\n### Example code\n\n```python\nfrom mcp.server.mcpserver import Context\nfrom mcp.server.mcpserver.utilities.context_injection import find_context_parameter\n\ndef fn(value: int) -> Context:\n ...\n\nprint(find_context_parameter(fn)) # current: \"return\"; expected: None\n```\n\n### Environment\n\n- Python 3.12\n- MCP Python SDK `main` at `6e30452`\n\nI used AI assistance while investigating this issue and reviewed and reproduced the behavior locally.\n","author":{"url":"https://github.com/otiscuilei","@type":"Person","name":"otiscuilei"},"datePublished":"2026-08-12T12:19:25Z","url":"https://github.com/modelcontextprotocol/python-sdk/issues/3298"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:cde739ed-6b47-a519-73c0-4fb56a71dfec |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AFEC:19330E:194762E:217BEB1:6B0568AC |
| html-safe-nonce | 1a529e340c0d30382552ff1c9051598a6950a220789786c6790bcb2e4409fb81 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRkVDOjE5MzMwRToxOTQ3NjJFOjIxN0JFQjE6NkIwNTY4QUMiLCJ2aXNpdG9yX2lkIjoiMjg1MDI3NjMxMjQ0NTQ0NjMxNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | b70f4c4e18b87f79cec21c12bdfa978864c88b5d6c80673c210f0a1d443285dc |
| hovercard-subject-tag | issue:5130796572 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/modelcontextprotocol/python-sdk/3298/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7e1c4a57c637edc946740c4bf98b0a095a13c72e9c3b263a62114b4657c10c5f/modelcontextprotocol/python-sdk/issues/3298 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7e1c4a57c637edc946740c4bf98b0a095a13c72e9c3b263a62114b4657c10c5f/modelcontextprotocol/python-sdk/issues/3298 |
| og:image:alt | Initial checks I tested the current main branch (6e30452). I searched existing issues and pull requests for this behavior. Description find_context_parameter() iterates over every entry returned by... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | otiscuilei |
| hostname | github.com |
| expected-hostname | github.com |
| None | 1be5cc09efdd4833c24a4ffa71d698e3999fa09071e159fe14c2c08e41c98331 |
| turbo-cache-control | no-preview |
| go-import | github.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 862584018 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/python-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 862584018 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/python-sdk |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f6d69234e682c947a48074340e69d45d5901de31 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width