Skip to content

Commit e0f195f

Browse files
committed
update examples
1 parent dfa7c6a commit e0f195f

File tree

2 files changed

+20
-12
lines changed
  • examples/servers

2 files changed

+20
-12
lines changed

examples/servers/simple-prompt/mcp_simple_prompt/server.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,16 @@ async def get_prompt(
9595
sse = SseServerTransport("/messages/")
9696

9797
async def handle_sse(request):
98-
async with sse.connect_sse(
99-
request.scope, request.receive, request._send
100-
) as streams:
101-
await app.run(
102-
streams[0], streams[1], app.create_initialization_options()
103-
)
98+
with anyio.CancelScope() as cancel_scope:
99+
async with sse.connect_sse(
100+
request.scope,
101+
request.receive,
102+
request._send,
103+
lambda: cancel_scope.cancel(),
104+
) as streams:
105+
await app.run(
106+
streams[0], streams[1], app.create_initialization_options()
107+
)
104108

105109
starlette_app = Starlette(
106110
debug=True,

examples/servers/simple-resource/mcp_simple_resource/server.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,16 @@ async def read_resource(uri: FileUrl) -> str | bytes:
5151
sse = SseServerTransport("/messages/")
5252

5353
async def handle_sse(request):
54-
async with sse.connect_sse(
55-
request.scope, request.receive, request._send
56-
) as streams:
57-
await app.run(
58-
streams[0], streams[1], app.create_initialization_options()
59-
)
54+
with anyio.CancelScope() as cancel_scope:
55+
async with sse.connect_sse(
56+
request.scope,
57+
request.receive,
58+
request._send,
59+
lambda: cancel_scope.cancel(),
60+
) as streams:
61+
await app.run(
62+
streams[0], streams[1], app.create_initialization_options()
63+
)
6064

6165
starlette_app = Starlette(
6266
debug=True,

0 commit comments

Comments
 (0)