Skip to content

Commit b126d10

Browse files
committed
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]`
1 parent 99c402d commit b126d10

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/mcp/server/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
logger = logging.getLogger(__name__)
1818

19-
request_ctx: contextvars.ContextVar[RequestContext] = contextvars.ContextVar(
19+
request_ctx: contextvars.ContextVar[RequestContext[ServerSession]] = contextvars.ContextVar(
2020
"request_ctx"
2121
)
2222

@@ -115,7 +115,7 @@ def get_capabilities(
115115
)
116116

117117
@property
118-
def request_context(self) -> RequestContext:
118+
def request_context(self) -> RequestContext[ServerSession]:
119119
"""If called outside of a request context, this will raise a LookupError."""
120120
return request_ctx.get()
121121

0 commit comments

Comments
 (0)