@@ -38,20 +38,14 @@ async def handle_sse(request):
38
38
from uuid import UUID , uuid4
39
39
40
40
import anyio
41
+ from anyio .streams .memory import MemoryObjectReceiveStream , MemoryObjectSendStream
41
42
from pydantic import ValidationError
42
43
from sse_starlette import EventSourceResponse
43
44
from starlette .requests import Request
44
45
from starlette .responses import Response
45
46
from starlette .types import Receive , Scope , Send
46
47
47
48
import mcp .types as types
48
- from mcp .shared .session import (
49
- ReadStream ,
50
- ReadStreamWriter ,
51
- WriteStream ,
52
- WriteStreamReader ,
53
- )
54
- from mcp .types import MessageFrame
55
49
56
50
logger = logging .getLogger (__name__ )
57
51
@@ -69,7 +63,9 @@ class SseServerTransport:
69
63
"""
70
64
71
65
_endpoint : str
72
- _read_stream_writers : dict [UUID , ReadStreamWriter ]
66
+ _read_stream_writers : dict [
67
+ UUID , MemoryObjectSendStream [types .JSONRPCMessage | Exception ]
68
+ ]
73
69
74
70
def __init__ (self , endpoint : str ) -> None :
75
71
"""
@@ -89,11 +85,11 @@ async def connect_sse(self, scope: Scope, receive: Receive, send: Send):
89
85
raise ValueError ("connect_sse can only handle HTTP requests" )
90
86
91
87
logger .debug ("Setting up SSE connection" )
92
- read_stream : ReadStream
93
- read_stream_writer : ReadStreamWriter
88
+ read_stream : MemoryObjectReceiveStream [ types . JSONRPCMessage | Exception ]
89
+ read_stream_writer : MemoryObjectSendStream [ types . JSONRPCMessage | Exception ]
94
90
95
- write_stream : WriteStream
96
- write_stream_reader : WriteStreamReader
91
+ write_stream : MemoryObjectSendStream [ types . JSONRPCMessage ]
92
+ write_stream_reader : MemoryObjectReceiveStream [ types . JSONRPCMessage ]
97
93
98
94
read_stream_writer , read_stream = anyio .create_memory_object_stream (0 )
99
95
write_stream , write_stream_reader = anyio .create_memory_object_stream (0 )
@@ -176,4 +172,4 @@ async def handle_post_message(
176
172
logger .debug (f"Sending message to writer: { message } " )
177
173
response = Response ("Accepted" , status_code = 202 )
178
174
await response (scope , receive , send )
179
- await writer .send (MessageFrame ( message = message , raw = request ) )
175
+ await writer .send (message )
0 commit comments