@@ -208,7 +208,7 @@ from contextlib import asynccontextmanager
208208from dataclasses import dataclass
209209
210210from mcp.server.fastmcp import Context, FastMCP
211- from mcp.server.session import ServerSession
211+ from mcp.server.session import ServerTransportSession
212212
213213
214214# Mock database class for example
@@ -254,7 +254,7 @@ mcp = FastMCP("My App", lifespan=app_lifespan)
254254
255255# Access type-safe lifespan context in tools
256256@mcp.tool ()
257- def query_db (ctx : Context[ServerSession , AppContext]) -> str :
257+ def query_db (ctx : Context[ServerTransportSession , AppContext]) -> str :
258258 """ Tool that uses initialized resources."""
259259 db = ctx.request_context.lifespan_context.db
260260 return db.query()
@@ -326,13 +326,13 @@ Tools can optionally receive a Context object by including a parameter with the
326326<!-- snippet-source examples/snippets/servers/tool_progress.py -->
327327``` python
328328from mcp.server.fastmcp import Context, FastMCP
329- from mcp.server.session import ServerSession
329+ from mcp.server.session import ServerTransportSession
330330
331331mcp = FastMCP(name = " Progress Example" )
332332
333333
334334@mcp.tool ()
335- async def long_running_task (task_name : str , ctx : Context[ServerSession , None ], steps : int = 5 ) -> str :
335+ async def long_running_task (task_name : str , ctx : Context[ServerTransportSession , None ], steps : int = 5 ) -> str :
336336 """ Execute a task with progress updates."""
337337 await ctx.info(f " Starting: { task_name} " )
338338
@@ -674,13 +674,13 @@ The Context object provides the following capabilities:
674674<!-- snippet-source examples/snippets/servers/tool_progress.py -->
675675``` python
676676from mcp.server.fastmcp import Context, FastMCP
677- from mcp.server.session import ServerSession
677+ from mcp.server.session import ServerTransportSession
678678
679679mcp = FastMCP(name = " Progress Example" )
680680
681681
682682@mcp.tool ()
683- async def long_running_task (task_name : str , ctx : Context[ServerSession , None ], steps : int = 5 ) -> str :
683+ async def long_running_task (task_name : str , ctx : Context[ServerTransportSession , None ], steps : int = 5 ) -> str :
684684 """ Execute a task with progress updates."""
685685 await ctx.info(f " Starting: { task_name} " )
686686
@@ -798,7 +798,7 @@ Request additional information from users. This example shows an Elicitation dur
798798from pydantic import BaseModel, Field
799799
800800from mcp.server.fastmcp import Context, FastMCP
801- from mcp.server.session import ServerSession
801+ from mcp.server.session import ServerTransportSession
802802
803803mcp = FastMCP(name = " Elicitation Example" )
804804
@@ -814,7 +814,7 @@ class BookingPreferences(BaseModel):
814814
815815
816816@mcp.tool ()
817- async def book_table (date : str , time : str , party_size : int , ctx : Context[ServerSession , None ]) -> str :
817+ async def book_table (date : str , time : str , party_size : int , ctx : Context[ServerTransportSession , None ]) -> str :
818818 """ Book a table with date availability check."""
819819 # Check if date is available
820820 if date == " 2024-12-25" :
@@ -888,13 +888,13 @@ Tools can send logs and notifications through the context:
888888<!-- snippet-source examples/snippets/servers/notifications.py -->
889889``` python
890890from mcp.server.fastmcp import Context, FastMCP
891- from mcp.server.session import ServerSession
891+ from mcp.server.session import ServerTransportSession
892892
893893mcp = FastMCP(name = " Notifications Example" )
894894
895895
896896@mcp.tool ()
897- async def process_data (data : str , ctx : Context[ServerSession , None ]) -> str :
897+ async def process_data (data : str , ctx : Context[ServerTransportSession , None ]) -> str :
898898 """ Process data with logging."""
899899 # Different log levels
900900 await ctx.debug(f " Debug: Processing ' { data} ' " )
@@ -2038,6 +2038,7 @@ import os
20382038from pydantic import AnyUrl
20392039
20402040from mcp import ClientSession, StdioServerParameters, types
2041+ from mcp.client.session import ClientTransportSession
20412042from mcp.client.stdio import stdio_client
20422043from mcp.shared.context import RequestContext
20432044
@@ -2051,7 +2052,7 @@ server_params = StdioServerParameters(
20512052
20522053# Optional: create a sampling callback
20532054async def handle_sampling_message (
2054- context : RequestContext[ClientSession , None ], params : types.CreateMessageRequestParams
2055+ context : RequestContext[ClientTransportSession , None ], params : types.CreateMessageRequestParams
20552056) -> types.CreateMessageResult:
20562057 print (f " Sampling request: { params.messages} " )
20572058 return types.CreateMessageResult(
@@ -2169,6 +2170,7 @@ import os
21692170
21702171from mcp import ClientSession, StdioServerParameters
21712172from mcp.client.stdio import stdio_client
2173+ from mcp.client.transport_session import ClientTransportSession
21722174from mcp.shared.metadata_utils import get_display_name
21732175
21742176# Create server parameters for stdio connection
@@ -2179,7 +2181,7 @@ server_params = StdioServerParameters(
21792181)
21802182
21812183
2182- async def display_tools (session : ClientSession ):
2184+ async def display_tools (session : ClientTransportSession ):
21832185 """ Display available tools with human-readable names"""
21842186 tools_response = await session.list_tools()
21852187
@@ -2191,7 +2193,7 @@ async def display_tools(session: ClientSession):
21912193 print (f " { tool.description} " )
21922194
21932195
2194- async def display_resources (session : ClientSession ):
2196+ async def display_resources (session : ClientTransportSession ):
21952197 """ Display available resources with human-readable names"""
21962198 resources_response = await session.list_resources()
21972199
0 commit comments