Skip to content

Commit dfb3b66

Browse files
committed
Update sample code with correct type annotations
1 parent c2ca8e0 commit dfb3b66

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Diff for: README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ from dataclasses import dataclass
161161
from fake_database import Database # Replace with your actual DB type
162162

163163
from mcp.server.fastmcp import Context, FastMCP
164+
from mcp.server.session import ServerSessionT
164165

165166
# Create a named server
166167
mcp = FastMCP("My App")
@@ -192,7 +193,7 @@ mcp = FastMCP("My App", lifespan=app_lifespan)
192193

193194
# Access type-safe lifespan context in tools
194195
@mcp.tool()
195-
def query_db(ctx: Context) -> str:
196+
def query_db(ctx: Context[ServerSessionT, AppContext]) -> str:
196197
"""Tool that uses initialized resources"""
197198
db = ctx.request_context.lifespan_context["db"]
198199
return db.query()

0 commit comments

Comments
 (0)