@@ -346,13 +346,12 @@ Tools can optionally receive a Context object by including a parameter with the
346346<!-- snippet-source examples/snippets/servers/tool_progress.py -->
347347``` python
348348from mcp.server.mcpserver import Context, MCPServer
349- from mcp.server.session import ServerSession
350349
351350mcp = MCPServer(name = " Progress Example" )
352351
353352
354353@mcp.tool ()
355- 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 :
356355 """ Execute a task with progress updates."""
357356 await ctx.info(f " Starting: { task_name} " )
358357
@@ -694,13 +693,12 @@ The Context object provides the following capabilities:
694693<!-- snippet-source examples/snippets/servers/tool_progress.py -->
695694``` python
696695from mcp.server.mcpserver import Context, MCPServer
697- from mcp.server.session import ServerSession
698696
699697mcp = MCPServer(name = " Progress Example" )
700698
701699
702700@mcp.tool ()
703- 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 :
704702 """ Execute a task with progress updates."""
705703 await ctx.info(f " Starting: { task_name} " )
706704
@@ -826,7 +824,6 @@ import uuid
826824from pydantic import BaseModel, Field
827825
828826from mcp.server.mcpserver import Context, MCPServer
829- from mcp.server.session import ServerSession
830827from mcp.shared.exceptions import UrlElicitationRequiredError
831828from mcp.types import ElicitRequestURLParams
832829
@@ -844,7 +841,7 @@ class BookingPreferences(BaseModel):
844841
845842
846843@mcp.tool ()
847- async def book_table (date : str , time : str , party_size : int , ctx : Context[ServerSession, None ] ) -> str :
844+ async def book_table (date : str , time : str , party_size : int , ctx : Context) -> str :
848845 """ Book a table with date availability check.
849846
850847 This demonstrates form mode elicitation for collecting non-sensitive user input.
@@ -868,7 +865,7 @@ async def book_table(date: str, time: str, party_size: int, ctx: Context[ServerS
868865
869866
870867@mcp.tool ()
871- async def secure_payment (amount : float , ctx : Context[ServerSession, None ] ) -> str :
868+ async def secure_payment (amount : float , ctx : Context) -> str :
872869 """ Process a secure payment requiring URL confirmation.
873870
874871 This demonstrates URL mode elicitation using ctx.elicit_url() for
@@ -892,7 +889,7 @@ async def secure_payment(amount: float, ctx: Context[ServerSession, None]) -> st
892889
893890
894891@mcp.tool ()
895- async def connect_service (service_name : str , ctx : Context[ServerSession, None ] ) -> str :
892+ async def connect_service (service_name : str , ctx : Context) -> str :
896893 """ Connect to a third-party service requiring OAuth authorization.
897894
898895 This demonstrates the "throw error" pattern using UrlElicitationRequiredError.
@@ -933,14 +930,13 @@ Tools can interact with LLMs through sampling (generating text):
933930<!-- snippet-source examples/snippets/servers/sampling.py -->
934931``` python
935932from mcp.server.mcpserver import Context, MCPServer
936- from mcp.server.session import ServerSession
937933from mcp.types import SamplingMessage, TextContent
938934
939935mcp = MCPServer(name = " Sampling Example" )
940936
941937
942938@mcp.tool ()
943- async def generate_poem (topic : str , ctx : Context[ServerSession, None ] ) -> str :
939+ async def generate_poem (topic : str , ctx : Context) -> str :
944940 """ Generate a poem using LLM sampling."""
945941 prompt = f " Write a short poem about { topic} "
946942
@@ -970,13 +966,12 @@ Tools can send logs and notifications through the context:
970966<!-- snippet-source examples/snippets/servers/notifications.py -->
971967``` python
972968from mcp.server.mcpserver import Context, MCPServer
973- from mcp.server.session import ServerSession
974969
975970mcp = MCPServer(name = " Notifications Example" )
976971
977972
978973@mcp.tool ()
979- async def process_data (data : str , ctx : Context[ServerSession, None ] ) -> str :
974+ async def process_data (data : str , ctx : Context) -> str :
980975 """ Process data with logging."""
981976 # Different log levels
982977 await ctx.debug(f " Debug: Processing ' { data} ' " )
0 commit comments