Title: Add dependency injection support to MCPServer · Issue #2054 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: Add dependency injection support to MCPServer · Issue #2054 · modelcontextprotocol/python-sdk
X Title: Add dependency injection support to MCPServer · Issue #2054 · modelcontextprotocol/python-sdk
Description: From the V2 checklist in #1253: Create dependency injection in MCPServer. MCPServer currently has no built-in mechanism for injecting dependencies (database connections, auth services, configuration objects, etc.) into tool, resource, an...
Open Graph Description: From the V2 checklist in #1253: Create dependency injection in MCPServer. MCPServer currently has no built-in mechanism for injecting dependencies (database connections, auth services, configuratio...
X Description: From the V2 checklist in #1253: Create dependency injection in MCPServer. MCPServer currently has no built-in mechanism for injecting dependencies (database connections, auth services, configuratio...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/2054
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add dependency injection support to MCPServer","articleBody":"From the V2 checklist in #1253:\n\n\u003e Create dependency injection in `MCPServer`.\n\nMCPServer currently has no built-in mechanism for injecting dependencies (database connections, auth services, configuration objects, etc.) into tool, resource, and prompt handlers. The existing `Context` parameter injection is specific to the MCP request context and does not cover arbitrary user-defined dependencies.\n\nA DI system — similar to FastAPI's `Depends()` — would allow:\n\n- Declaring dependencies as handler parameters that the framework resolves automatically\n- Sharing expensive resources (DB pools, HTTP clients) across handlers without global state\n- Making handlers more testable by swapping dependencies in tests\n- Composing dependencies (dependencies that depend on other dependencies)\n\n### Related but distinct issues\n- #1684 — Refactoring contextvars into explicit parameters (context passing, not general DI)\n- #1695 — Revisiting Context injection mechanism (closed, about the `Context` type specifically)\n\n### Open questions\n- Should this follow FastAPI's `Depends()` pattern exactly, or adapt it for MCP's handler signatures?\n- How does this interact with the `Context` parameter and lifespan state?\n- Should dependencies be scoped per-request, per-session, or per-server?\n\nRef: Kludex's V2 checklist in #1253","author":{"url":"https://github.com/maxisbey","@type":"Person","name":"maxisbey"},"datePublished":"2026-02-13T14:08:20.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/2054/python-sdk/issues/2054"}
| 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:f6cf6cb0-d506-b81c-d027-95baeeb0bc78 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C856:50E3E:15EE97:1E070B:6A6111C2 |
| html-safe-nonce | 79b30a188156d43e828350e6897e0f4f2ba0fe5974722c7cf0a3d0947157a454 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDODU2OjUwRTNFOjE1RUU5NzoxRTA3MEI6NkE2MTExQzIiLCJ2aXNpdG9yX2lkIjoiNzMwNDc3MDkwNDQwMDEzODY5MCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 8e6fcbbc4f59c3dc7ca1e61a5a2883bab81305ca47d4a809bd7369c744821394 |
| hovercard-subject-tag | issue:3937356857 |
| 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/2054/issue_layout |
| twitter:image | https://opengraph.githubassets.com/96d90dddf49f73c2b311fc3fe7939a89e87796a69ec5d80eb24e23cb97a85892/modelcontextprotocol/python-sdk/issues/2054 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/96d90dddf49f73c2b311fc3fe7939a89e87796a69ec5d80eb24e23cb97a85892/modelcontextprotocol/python-sdk/issues/2054 |
| og:image:alt | From the V2 checklist in #1253: Create dependency injection in MCPServer. MCPServer currently has no built-in mechanism for injecting dependencies (database connections, auth services, configuratio... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | maxisbey |
| hostname | github.com |
| expected-hostname | github.com |
| None | f6dfd8e93b1f2b4f7bf96e6f6cd7edcd48360b75fee4f2ff9f611032fce38ec2 |
| 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 | 731b2ebd4784c28b421dc5f41abecd2dbac357f2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width