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].
| 1105 | // Call [ServerSession.Close] to close the connection, or await client |
| 1106 | // termination with [ServerSession.Wait]. |
| 1107 | type 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 | |
| 1123 | func (ss *ServerSession) updateState(mut func(*ServerSessionState)) { |
| 1124 | ss.mu.Lock() |
nothing calls this directly
no outgoing calls
no test coverage detected