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

Struct ServerSession

mcp/server.go:1107–1121  ·  view source on GitHub ↗

A ServerSession is a logical connection from a single MCP client. Its methods can be used to send requests or notifications to the client. Create a session by calling [Server.Connect]. Call [ServerSession.Close] to close the connection, or await client termination with [ServerSession.Wait].

Source from the content-addressed store, hash-verified

1105// Call [ServerSession.Close] to close the connection, or await client
1106// termination with [ServerSession.Wait].
1107type ServerSession struct {
1108 // Ensure that onClose is called at most once.
1109 // We defensively use an atomic CompareAndSwap rather than a sync.Once, in case the
1110 // onClose callback triggers a re-entrant call to Close.
1111 calledOnClose atomic.Bool
1112 onClose func()
1113
1114 server *Server
1115 conn *jsonrpc2.Connection
1116 mcpConn Connection
1117 keepaliveCancel context.CancelFunc
1118
1119 mu sync.Mutex
1120 state ServerSessionState
1121}
1122
1123func (ss *ServerSession) updateState(mut func(*ServerSessionState)) {
1124 ss.mu.Lock()

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected