@@ -16,6 +16,7 @@ import (
1616 "sync/atomic"
1717
1818 "github.com/modelcontextprotocol/go-sdk/internal/jsonrpc2"
19+ "github.com/modelcontextprotocol/go-sdk/jsonrpc"
1920)
2021
2122const (
@@ -157,12 +158,12 @@ func (h *StreamableHTTPHandler) ServeHTTP(w http.ResponseWriter, req *http.Reque
157158func NewStreamableServerTransport (sessionID string ) * StreamableServerTransport {
158159 return & StreamableServerTransport {
159160 id : sessionID ,
160- incoming : make (chan JSONRPCMessage , 10 ),
161+ incoming : make (chan jsonrpc. Message , 10 ),
161162 done : make (chan struct {}),
162163 outgoingMessages : make (map [streamID ][]* streamableMsg ),
163164 signals : make (map [streamID ]chan struct {}),
164- requestStreams : make (map [JSONRPCID ]streamID ),
165- streamRequests : make (map [streamID ]map [JSONRPCID ]struct {}),
165+ requestStreams : make (map [jsonrpc. ID ]streamID ),
166+ streamRequests : make (map [streamID ]map [jsonrpc. ID ]struct {}),
166167 }
167168}
168169
@@ -176,7 +177,7 @@ type StreamableServerTransport struct {
176177 nextStreamID atomic.Int64 // incrementing next stream ID
177178
178179 id string
179- incoming chan JSONRPCMessage // messages from the client to the server
180+ incoming chan jsonrpc. Message // messages from the client to the server
180181
181182 mu sync.Mutex
182183
@@ -226,7 +227,7 @@ type StreamableServerTransport struct {
226227 // Lifecycle: requestStreams persists for the duration of the session.
227228 //
228229 // TODO(rfindley): clean up once requests are handled.
229- requestStreams map [JSONRPCID ]streamID
230+ requestStreams map [jsonrpc. ID ]streamID
230231
231232 // streamRequests tracks the set of unanswered incoming RPCs for each logical
232233 // stream.
@@ -237,7 +238,7 @@ type StreamableServerTransport struct {
237238 // Lifecycle: streamRequests values persist as until the requests have been
238239 // replied to by the server. Notably, NOT until they are sent to an HTTP
239240 // response, as delivery is not guaranteed.
240- streamRequests map [streamID ]map [JSONRPCID ]struct {}
241+ streamRequests map [streamID ]map [jsonrpc. ID ]struct {}
241242}
242243
243244type streamID int64
@@ -271,7 +272,7 @@ func (s *StreamableServerTransport) Connect(context.Context) (Connection, error)
271272// 2. Expose a 'HandlerTransport' interface that allows transports to provide
272273// a handler middleware, so that we don't hard-code this behavior in
273274// ServerSession.handle.
274- // 3. Add a `func ForRequest(context.Context) JSONRPCID ` accessor that lets
275+ // 3. Add a `func ForRequest(context.Context) jsonrpc.ID ` accessor that lets
275276// any transport access the incoming request ID.
276277//
277278// For now, by giving only the StreamableServerTransport access to the request
@@ -340,9 +341,9 @@ func (t *StreamableServerTransport) servePOST(w http.ResponseWriter, req *http.R
340341 http .Error (w , fmt .Sprintf ("malformed payload: %v" , err ), http .StatusBadRequest )
341342 return
342343 }
343- requests := make (map [JSONRPCID ]struct {})
344+ requests := make (map [jsonrpc. ID ]struct {})
344345 for _ , msg := range incoming {
345- if req , ok := msg .(* JSONRPCRequest ); ok && req .ID .IsValid () {
346+ if req , ok := msg .(* jsonrpc. Request ); ok && req .ID .IsValid () {
346347 requests [req .ID ] = struct {}{}
347348 }
348349 }
@@ -352,7 +353,7 @@ func (t *StreamableServerTransport) servePOST(w http.ResponseWriter, req *http.R
352353 signal := make (chan struct {}, 1 )
353354 t .mu .Lock ()
354355 if len (requests ) > 0 {
355- t .streamRequests [id ] = make (map [JSONRPCID ]struct {})
356+ t .streamRequests [id ] = make (map [jsonrpc. ID ]struct {})
356357 }
357358 for reqID := range requests {
358359 t .requestStreams [reqID ] = id
@@ -484,7 +485,7 @@ func parseEventID(eventID string) (sid streamID, idx int, ok bool) {
484485}
485486
486487// Read implements the [Connection] interface.
487- func (t * StreamableServerTransport ) Read (ctx context.Context ) (JSONRPCMessage , error ) {
488+ func (t * StreamableServerTransport ) Read (ctx context.Context ) (jsonrpc. Message , error ) {
488489 select {
489490 case <- ctx .Done ():
490491 return nil , ctx .Err ()
@@ -499,10 +500,10 @@ func (t *StreamableServerTransport) Read(ctx context.Context) (JSONRPCMessage, e
499500}
500501
501502// Write implements the [Connection] interface.
502- func (t * StreamableServerTransport ) Write (ctx context.Context , msg JSONRPCMessage ) error {
503+ func (t * StreamableServerTransport ) Write (ctx context.Context , msg jsonrpc. Message ) error {
503504 // Find the incoming request that this write relates to, if any.
504- var forRequest , replyTo JSONRPCID
505- if resp , ok := msg .(* JSONRPCResponse ); ok {
505+ var forRequest , replyTo jsonrpc. ID
506+ if resp , ok := msg .(* jsonrpc. Response ); ok {
506507 // If the message is a response, it relates to its request (of course).
507508 forRequest = resp .ID
508509 replyTo = resp .ID
@@ -511,7 +512,7 @@ func (t *StreamableServerTransport) Write(ctx context.Context, msg JSONRPCMessag
511512 // ongoing request. This may not be the case if the request way made with
512513 // an unrelated context.
513514 if v := ctx .Value (idContextKey {}); v != nil {
514- forRequest = v .(JSONRPCID )
515+ forRequest = v .(jsonrpc. ID )
515516 }
516517 }
517518
@@ -661,7 +662,7 @@ func (c *streamableClientConn) SessionID() string {
661662}
662663
663664// Read implements the [Connection] interface.
664- func (s * streamableClientConn ) Read (ctx context.Context ) (JSONRPCMessage , error ) {
665+ func (s * streamableClientConn ) Read (ctx context.Context ) (jsonrpc. Message , error ) {
665666 select {
666667 case <- ctx .Done ():
667668 return nil , ctx .Err ()
@@ -673,7 +674,7 @@ func (s *streamableClientConn) Read(ctx context.Context) (JSONRPCMessage, error)
673674}
674675
675676// Write implements the [Connection] interface.
676- func (s * streamableClientConn ) Write (ctx context.Context , msg JSONRPCMessage ) error {
677+ func (s * streamableClientConn ) Write (ctx context.Context , msg jsonrpc. Message ) error {
677678 s .mu .Lock ()
678679 if s .err != nil {
679680 s .mu .Unlock ()
@@ -709,7 +710,7 @@ func (s *streamableClientConn) Write(ctx context.Context, msg JSONRPCMessage) er
709710 return nil
710711}
711712
712- func (s * streamableClientConn ) postMessage (ctx context.Context , sessionID string , msg JSONRPCMessage ) (string , error ) {
713+ func (s * streamableClientConn ) postMessage (ctx context.Context , sessionID string , msg jsonrpc. Message ) (string , error ) {
713714 data , err := jsonrpc2 .EncodeMessage (msg )
714715 if err != nil {
715716 return "" , err
0 commit comments