@@ -229,7 +229,6 @@ from contextlib import asynccontextmanager
229229from dataclasses import dataclass
230230
231231from mcp.server.fastmcp import Context, FastMCP
232- from mcp.server.session import ServerSession
233232
234233
235234# Mock database class for example
@@ -275,7 +274,7 @@ mcp = FastMCP("My App", lifespan=app_lifespan)
275274
276275# Access type-safe lifespan context in tools
277276@mcp.tool ()
278- def query_db (ctx : Context[ServerSession, AppContext]) -> str :
277+ def query_db (ctx : Context[AppContext]) -> str :
279278 """ Tool that uses initialized resources."""
280279 db = ctx.request_context.lifespan_context.db
281280 return db.query()
@@ -347,13 +346,12 @@ Tools can optionally receive a Context object by including a parameter with the
347346<!-- snippet-source examples/snippets/servers/tool_progress.py -->
348347``` python
349348from mcp.server.fastmcp import Context, FastMCP
350- from mcp.server.session import ServerSession
351349
352350mcp = FastMCP(name = " Progress Example" )
353351
354352
355353@mcp.tool ()
356- async def long_running_task (task_name : str , ctx : Context[ServerSession, None ] , steps : int = 5 ) -> str :
354+ async def long_running_task (task_name : str , ctx : Context, steps : int = 5 ) -> str :
357355 """ Execute a task with progress updates."""
358356 await ctx.info(f " Starting: { task_name} " )
359357
@@ -695,13 +693,12 @@ The Context object provides the following capabilities:
695693<!-- snippet-source examples/snippets/servers/tool_progress.py -->
696694``` python
697695from mcp.server.fastmcp import Context, FastMCP
698- from mcp.server.session import ServerSession
699696
700697mcp = FastMCP(name = " Progress Example" )
701698
702699
703700@mcp.tool ()
704- async def long_running_task (task_name : str , ctx : Context[ServerSession, None ] , steps : int = 5 ) -> str :
701+ async def long_running_task (task_name : str , ctx : Context, steps : int = 5 ) -> str :
705702 """ Execute a task with progress updates."""
706703 await ctx.info(f " Starting: { task_name} " )
707704
@@ -828,7 +825,6 @@ import uuid
828825from pydantic import BaseModel, Field
829826
830827from mcp.server.fastmcp import Context, FastMCP
831- from mcp.server.session import ServerSession
832828from mcp.shared.exceptions import UrlElicitationRequiredError
833829from mcp.types import ElicitRequestURLParams
834830
@@ -846,7 +842,7 @@ class BookingPreferences(BaseModel):
846842
847843
848844@mcp.tool ()
849- async def book_table (date : str , time : str , party_size : int , ctx : Context[ServerSession, None ] ) -> str :
845+ async def book_table (date : str , time : str , party_size : int , ctx : Context) -> str :
850846 """ Book a table with date availability check.
851847
852848 This demonstrates form mode elicitation for collecting non-sensitive user input.
@@ -870,7 +866,7 @@ async def book_table(date: str, time: str, party_size: int, ctx: Context[ServerS
870866
871867
872868@mcp.tool ()
873- async def secure_payment (amount : float , ctx : Context[ServerSession, None ] ) -> str :
869+ async def secure_payment (amount : float , ctx : Context) -> str :
874870 """ Process a secure payment requiring URL confirmation.
875871
876872 This demonstrates URL mode elicitation using ctx.elicit_url() for
@@ -894,7 +890,7 @@ async def secure_payment(amount: float, ctx: Context[ServerSession, None]) -> st
894890
895891
896892@mcp.tool ()
897- async def connect_service (service_name : str , ctx : Context[ServerSession, None ] ) -> str :
893+ async def connect_service (service_name : str , ctx : Context) -> str :
898894 """ Connect to a third-party service requiring OAuth authorization.
899895
900896 This demonstrates the "throw error" pattern using UrlElicitationRequiredError.
@@ -935,14 +931,13 @@ Tools can interact with LLMs through sampling (generating text):
935931<!-- snippet-source examples/snippets/servers/sampling.py -->
936932``` python
937933from mcp.server.fastmcp import Context, FastMCP
938- from mcp.server.session import ServerSession
939934from mcp.types import SamplingMessage, TextContent
940935
941936mcp = FastMCP(name = " Sampling Example" )
942937
943938
944939@mcp.tool ()
945- async def generate_poem (topic : str , ctx : Context[ServerSession, None ] ) -> str :
940+ async def generate_poem (topic : str , ctx : Context) -> str :
946941 """ Generate a poem using LLM sampling."""
947942 prompt = f " Write a short poem about { topic} "
948943
@@ -972,13 +967,12 @@ Tools can send logs and notifications through the context:
972967<!-- snippet-source examples/snippets/servers/notifications.py -->
973968``` python
974969from mcp.server.fastmcp import Context, FastMCP
975- from mcp.server.session import ServerSession
976970
977971mcp = FastMCP(name = " Notifications Example" )
978972
979973
980974@mcp.tool ()
981- async def process_data (data : str , ctx : Context[ServerSession, None ] ) -> str :
975+ async def process_data (data : str , ctx : Context) -> str :
982976 """ Process data with logging."""
983977 # Different log levels
984978 await ctx.debug(f " Debug: Processing ' { data} ' " )
0 commit comments