MCPcopy Create free account
hub / github.com/modelcontextprotocol/go-sdk / bind

Method bind

mcp/server.go:977–988  ·  view source on GitHub ↗

bind implements the binder[*ServerSession] interface, so that Servers can be connected using [connect].

(mcpConn Connection, conn *jsonrpc2.Connection, state *ServerSessionState, onClose func())

Source from the content-addressed store, hash-verified

975// bind implements the binder[*ServerSession] interface, so that Servers can
976// be connected using [connect].
977func (s *Server) bind(mcpConn Connection, conn *jsonrpc2.Connection, state *ServerSessionState, onClose func()) *ServerSession {
978 assert(mcpConn != nil && conn != nil, "nil connection")
979 ss := &ServerSession{conn: conn, mcpConn: mcpConn, server: s, onClose: onClose}
980 if state != nil {
981 ss.state = *state
982 }
983 s.mu.Lock()
984 s.sessions = append(s.sessions, ss)
985 s.mu.Unlock()
986 s.opts.Logger.Info("server session connected", "session_id", ss.ID())
987 return ss
988}
989
990// disconnect implements the binder[*ServerSession] interface, so that
991// Servers can be connected using [connect].

Callers

nothing calls this directly

Calls 2

IDMethod · 0.95
assertFunction · 0.85

Tested by

no test coverage detected