Skip to content

Commit aae91be

Browse files
committed
.
1 parent 41325b8 commit aae91be

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

mcp/client.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,18 +142,18 @@ type ClientSession struct {
142142
client *Client
143143
initializeResult *InitializeResult
144144
keepaliveCancel context.CancelFunc
145-
sessionIDFunc func() string
145+
mcpConn Connection
146146
}
147147

148-
func (cs *ClientSession) setSessionIDFunc(f func() string) {
149-
cs.sessionIDFunc = f
148+
func (cs *ClientSession) setConn(c Connection) {
149+
cs.mcpConn = c
150150
}
151151

152152
func (cs *ClientSession) ID() string {
153-
if cs.sessionIDFunc == nil {
153+
if cs.mcpConn == nil {
154154
return ""
155155
}
156-
return cs.sessionIDFunc()
156+
return cs.mcpConn.SessionID()
157157
}
158158

159159
// Close performs a graceful close of the connection, preventing new requests

mcp/server.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -496,23 +496,23 @@ func (ss *ServerSession) NotifyProgress(ctx context.Context, params *ProgressNot
496496
type ServerSession struct {
497497
server *Server
498498
conn *jsonrpc2.Connection
499-
sessionIDFunc func() string
499+
mcpConn Connection
500500
mu sync.Mutex
501501
logLevel LoggingLevel
502502
initializeParams *InitializeParams
503503
initialized bool
504504
keepaliveCancel context.CancelFunc
505505
}
506506

507-
func (ss *ServerSession) setSessionIDFunc(f func() string) {
508-
ss.sessionIDFunc = f
507+
func (ss *ServerSession) setConn(c Connection) {
508+
ss.mcpConn = c
509509
}
510510

511511
func (ss *ServerSession) ID() string {
512-
if ss.sessionIDFunc == nil {
512+
if ss.mcpConn == nil {
513513
return ""
514514
}
515-
return ss.sessionIDFunc()
515+
return ss.mcpConn.SessionID()
516516
}
517517

518518
// Ping pings the client.

mcp/sse.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ type sseServerConn struct {
264264
}
265265

266266
// TODO(jba): get the session ID. (Not urgent because SSE transports have been removed from the spec.)
267-
func (s sseServerConn) sessionID() string { return "" }
267+
func (s sseServerConn) SessionID() string { return "" }
268268

269269
// Read implements jsonrpc2.Reader.
270270
func (s sseServerConn) Read(ctx context.Context) (JSONRPCMessage, error) {
@@ -522,7 +522,7 @@ type sseClientConn struct {
522522
}
523523

524524
// TODO(jba): get the session ID. (Not urgent because SSE transports have been removed from the spec.)
525-
func (c *sseClientConn) sessionID() string { return "" }
525+
func (c *sseClientConn) SessionID() string { return "" }
526526

527527
func (c *sseClientConn) isDone() bool {
528528
c.mu.Lock()

mcp/streamable.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func NewStreamableServerTransport(sessionID string) *StreamableServerTransport {
161161
}
162162
}
163163

164-
func (t *StreamableServerTransport) sessionID() string {
164+
func (t *StreamableServerTransport) SessionID() string {
165165
return t.id
166166
}
167167

@@ -642,7 +642,7 @@ type streamableClientConn struct {
642642
err error
643643
}
644644

645-
func (c *streamableClientConn) sessionID() string {
645+
func (c *streamableClientConn) SessionID() string {
646646
c.mu.Lock()
647647
defer c.mu.Unlock()
648648
return c._sessionID

mcp/transport.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type Connection interface {
5050
Read(context.Context) (JSONRPCMessage, error)
5151
Write(context.Context, JSONRPCMessage) error
5252
Close() error // may be called concurrently by both peers
53-
sessionID() string
53+
SessionID() string
5454
}
5555

5656
// A StdioTransport is a [Transport] that communicates over stdin/stdout using
@@ -95,7 +95,7 @@ type binder[T handler] interface {
9595

9696
type handler interface {
9797
handle(ctx context.Context, req *JSONRPCRequest) (any, error)
98-
setSessionIDFunc(func() string) // so Sessions can get the session ID
98+
setConn(Connection)
9999
}
100100

101101
func connect[H handler](ctx context.Context, t Transport, b binder[H]) (H, error) {
@@ -126,7 +126,7 @@ func connect[H handler](ctx context.Context, t Transport, b binder[H]) (H, error
126126
},
127127
})
128128
assert(preempter.conn != nil, "unbound preempter")
129-
h.setSessionIDFunc(conn.sessionID)
129+
h.setConn(conn)
130130
return h, nil
131131
}
132132

@@ -203,7 +203,7 @@ type loggingConn struct {
203203
w io.Writer
204204
}
205205

206-
func (c *loggingConn) sessionID() string { return c.delegate.sessionID() }
206+
func (c *loggingConn) SessionID() string { return c.delegate.SessionID() }
207207

208208
// loggingReader is a stream middleware that logs incoming messages.
209209
func (s *loggingConn) Read(ctx context.Context) (JSONRPCMessage, error) {
@@ -290,7 +290,7 @@ func newIOConn(rwc io.ReadWriteCloser) *ioConn {
290290
}
291291
}
292292

293-
func (c *ioConn) sessionID() string { return "" }
293+
func (c *ioConn) SessionID() string { return "" }
294294

295295
// addBatch records a msgBatch for an incoming batch payload.
296296
// It returns an error if batch is malformed, containing previously seen IDs.

0 commit comments

Comments
 (0)