Merge pull request #43 from modelcontextprotocol/davidsp/request_context

Return a specific server session instance of request context
This commit is contained in:
David Soria Parra 2024-11-11 21:19:24 +00:00 • committed by GitHub
commit 41a6157aee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 4 deletions

View file

@ -84,7 +84,7 @@ async def sse_client(
case "message": case "message":
try: try:
message = types.JSONRPCMessage.model_validate_json( # noqa: E501 message = types.JSONRPCMessage.model_validate_json( # noqa: E501
sse.data sse.data
) )
logger.debug( logger.debug(

View file

@ -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()