mirror of
https://github.com/aljazceru/mcp-python-sdk.git
synced 2025-12-20 07:14:24 +01:00
Return a specific server session instance of request context
We currently return a generic instance of RequestContext without a specialization on the Session type. This makes it impossible for servers to typesafe call `list_roots()` and other methods. We now return a specific instance of `RequestContext[ServerSession]`
This commit is contained in:
@@ -16,8 +16,8 @@ from mcp.shared.session import RequestResponder
|
|||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
request_ctx: contextvars.ContextVar[RequestContext] = contextvars.ContextVar(
|
request_ctx: contextvars.ContextVar[RequestContext[ServerSession]] = (
|
||||||
"request_ctx"
|
contextvars.ContextVar("request_ctx")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -115,7 +115,7 @@ class Server:
|
|||||||
)
|
)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def request_context(self) -> RequestContext:
|
def request_context(self) -> RequestContext[ServerSession]:
|
||||||
"""If called outside of a request context, this will raise a LookupError."""
|
"""If called outside of a request context, this will raise a LookupError."""
|
||||||
return request_ctx.get()
|
return request_ctx.get()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user