File tree 2 files changed +24
-12
lines changed
simple-prompt/mcp_simple_prompt
simple-resource/mcp_simple_resource
2 files changed +24
-12
lines changed Original file line number Diff line number Diff line change @@ -90,17 +90,23 @@ async def get_prompt(
90
90
if transport == "sse" :
91
91
from mcp .server .sse import SseServerTransport
92
92
from starlette .applications import Starlette
93
+ from starlette .responses import Response
93
94
from starlette .routing import Mount , Route
94
95
95
96
sse = SseServerTransport ("/messages/" )
96
97
97
98
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
- )
99
+ with anyio .CancelScope () as cancel_scope :
100
+ async with sse .connect_sse (
101
+ request .scope ,
102
+ request .receive ,
103
+ request ._send ,
104
+ lambda : cancel_scope .cancel (),
105
+ ) as streams :
106
+ await app .run (
107
+ streams [0 ], streams [1 ], app .create_initialization_options ()
108
+ )
109
+ return Response (status_code = 200 )
104
110
105
111
starlette_app = Starlette (
106
112
debug = True ,
Original file line number Diff line number Diff line change @@ -46,17 +46,23 @@ async def read_resource(uri: FileUrl) -> str | bytes:
46
46
if transport == "sse" :
47
47
from mcp .server .sse import SseServerTransport
48
48
from starlette .applications import Starlette
49
+ from starlette .responses import Response
49
50
from starlette .routing import Mount , Route
50
51
51
52
sse = SseServerTransport ("/messages/" )
52
53
53
54
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
- )
55
+ with anyio .CancelScope () as cancel_scope :
56
+ async with sse .connect_sse (
57
+ request .scope ,
58
+ request .receive ,
59
+ request ._send ,
60
+ lambda : cancel_scope .cancel (),
61
+ ) as streams :
62
+ await app .run (
63
+ streams [0 ], streams [1 ], app .create_initialization_options ()
64
+ )
65
+ return Response (status_code = 200 )
60
66
61
67
starlette_app = Starlette (
62
68
debug = True ,
You can’t perform that action at this time.
0 commit comments