Skip to content

Commit 7b25f8e

Browse files
committed
fix readme
1 parent e522882 commit 7b25f8e

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

README.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ from contextlib import asynccontextmanager
227227
from dataclasses import dataclass
228228

229229
from mcp.server.fastmcp import Context, FastMCP
230-
from mcp.server.session import ServerSession
230+
from mcp.server.transport_session import ServerTransportSession
231231

232232

233233
# Mock database class for example
@@ -273,7 +273,7 @@ mcp = FastMCP("My App", lifespan=app_lifespan)
273273

274274
# Access type-safe lifespan context in tools
275275
@mcp.tool()
276-
def query_db(ctx: Context[ServerSession, AppContext]) -> str:
276+
def query_db(ctx: Context[ServerTransportSession, AppContext]) -> str:
277277
"""Tool that uses initialized resources."""
278278
db = ctx.request_context.lifespan_context.db
279279
return db.query()
@@ -345,13 +345,13 @@ Tools can optionally receive a Context object by including a parameter with the
345345
<!-- snippet-source examples/snippets/servers/tool_progress.py -->
346346
```python
347347
from mcp.server.fastmcp import Context, FastMCP
348-
from mcp.server.session import ServerSession
348+
from mcp.server.transport_session import ServerTransportSession
349349

350350
mcp = FastMCP(name="Progress Example")
351351

352352

353353
@mcp.tool()
354-
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[ServerTransportSession, None], steps: int = 5) -> str:
355355
"""Execute a task with progress updates."""
356356
await ctx.info(f"Starting: {task_name}")
357357

@@ -693,13 +693,13 @@ The Context object provides the following capabilities:
693693
<!-- snippet-source examples/snippets/servers/tool_progress.py -->
694694
```python
695695
from mcp.server.fastmcp import Context, FastMCP
696-
from mcp.server.session import ServerSession
696+
from mcp.server.transport_session import ServerTransportSession
697697

698698
mcp = FastMCP(name="Progress Example")
699699

700700

701701
@mcp.tool()
702-
async def long_running_task(task_name: str, ctx: Context[ServerSession, None], steps: int = 5) -> str:
702+
async def long_running_task(task_name: str, ctx: Context[ServerTransportSession, None], steps: int = 5) -> str:
703703
"""Execute a task with progress updates."""
704704
await ctx.info(f"Starting: {task_name}")
705705

@@ -826,6 +826,7 @@ from pydantic import BaseModel, Field
826826

827827
from mcp.server.fastmcp import Context, FastMCP
828828
from mcp.server.session import ServerSession
829+
from mcp.server.transport_session import ServerTransportSession
829830
from mcp.shared.exceptions import UrlElicitationRequiredError
830831
from mcp.types import ElicitRequestURLParams
831832

@@ -843,7 +844,7 @@ class BookingPreferences(BaseModel):
843844

844845

845846
@mcp.tool()
846-
async def book_table(date: str, time: str, party_size: int, ctx: Context[ServerSession, None]) -> str:
847+
async def book_table(date: str, time: str, party_size: int, ctx: Context[ServerTransportSession, None]) -> str:
847848
"""Book a table with date availability check.
848849
849850
This demonstrates form mode elicitation for collecting non-sensitive user input.
@@ -969,13 +970,13 @@ Tools can send logs and notifications through the context:
969970
<!-- snippet-source examples/snippets/servers/notifications.py -->
970971
```python
971972
from mcp.server.fastmcp import Context, FastMCP
972-
from mcp.server.session import ServerSession
973+
from mcp.server.transport_session import ServerTransportSession
973974

974975
mcp = FastMCP(name="Notifications Example")
975976

976977

977978
@mcp.tool()
978-
async def process_data(data: str, ctx: Context[ServerSession, None]) -> str:
979+
async def process_data(data: str, ctx: Context[ServerTransportSession, None]) -> str:
979980
"""Process data with logging."""
980981
# Different log levels
981982
await ctx.debug(f"Debug: Processing '{data}'")
@@ -2119,7 +2120,7 @@ uv run client
21192120
import asyncio
21202121
import os
21212122

2122-
from mcp import ClientSession, StdioServerParameters, types
2123+
from mcp import ClientSession, ClientTransportSession, StdioServerParameters, types
21232124
from mcp.client.stdio import stdio_client
21242125
from mcp.shared.context import RequestContext
21252126

@@ -2133,7 +2134,7 @@ server_params = StdioServerParameters(
21332134

21342135
# Optional: create a sampling callback
21352136
async def handle_sampling_message(
2136-
context: RequestContext[ClientSession, None], params: types.CreateMessageRequestParams
2137+
context: RequestContext[ClientTransportSession, None], params: types.CreateMessageRequestParams
21372138
) -> types.CreateMessageResult:
21382139
print(f"Sampling request: {params.messages}")
21392140
return types.CreateMessageResult(
@@ -2247,7 +2248,7 @@ uv run display-utilities-client
22472248
import asyncio
22482249
import os
22492250

2250-
from mcp import ClientSession, StdioServerParameters
2251+
from mcp import ClientSession, ClientTransportSession, StdioServerParameters
22512252
from mcp.client.stdio import stdio_client
22522253
from mcp.shared.metadata_utils import get_display_name
22532254

@@ -2259,7 +2260,7 @@ server_params = StdioServerParameters(
22592260
)
22602261

22612262

2262-
async def display_tools(session: ClientSession):
2263+
async def display_tools(session: ClientTransportSession):
22632264
"""Display available tools with human-readable names"""
22642265
tools_response = await session.list_tools()
22652266

@@ -2271,7 +2272,7 @@ async def display_tools(session: ClientSession):
22712272
print(f" {tool.description}")
22722273

22732274

2274-
async def display_resources(session: ClientSession):
2275+
async def display_resources(session: ClientTransportSession):
22752276
"""Display available resources with human-readable names"""
22762277
resources_response = await session.list_resources()
22772278

0 commit comments

Comments
 (0)