refactor: split RequestContext between server and client (#1987)
This commit is contained in:
parent
050aeb6456
commit
b1f7eec3cd
1 changed files with 210 additions and 212 deletions
|
|
@ -5,7 +5,6 @@ from contextlib import asynccontextmanager
|
|||
from dataclasses import dataclass
|
||||
|
||||
from mcp.server.mcpserver import Context, MCPServer
|
||||
from mcp.server.session import ServerSession
|
||||
|
||||
|
||||
# Mock database class for example
|
||||
|
|
@ -51,7 +50,7 @@ mcp = MCPServer("My App", lifespan=app_lifespan)
|
|||
|
||||
# Access type-safe lifespan context in tools
|
||||
@mcp.tool()
|
||||
def query_db(ctx: Context[ServerSession, AppContext]) -> str:
|
||||
def query_db(ctx: Context[AppContext]) -> str:
|
||||
"""Tool that uses initialized resources."""
|
||||
db = ctx.request_context.lifespan_context.db
|
||||
return db.query()
|
||||
|
|
|
|||
Loading…
Reference in a new issue