Skip to content

Commit 7b968d9

Browse files
committed
Update sample code with correct type annotations
1 parent 9ae4df8 commit 7b968d9

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ from dataclasses import dataclass
152152
from fake_database import Database # Replace with your actual DB type
153153

154154
from mcp.server.fastmcp import Context, FastMCP
155+
from mcp.server.session import ServerSessionT
155156

156157
# Create a named server
157158
mcp = FastMCP("My App")
@@ -183,7 +184,7 @@ mcp = FastMCP("My App", lifespan=app_lifespan)
183184

184185
# Access type-safe lifespan context in tools
185186
@mcp.tool()
186-
def query_db(ctx: Context) -> str:
187+
def query_db(ctx: Context[ServerSessionT, AppContext]) -> str:
187188
"""Tool that uses initialized resources"""
188189
db = ctx.request_context.lifespan_context["db"]
189190
return db.query()

0 commit comments

Comments
 (0)