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

Method initialized

mcp/server.go:1045–1073  ·  view source on GitHub ↗

TODO: (nit) move all ServerSession methods below the ServerSession declaration.

(ctx context.Context, params *InitializedParams)

Source from the content-addressed store, hash-verified

1043
1044// TODO: (nit) move all ServerSession methods below the ServerSession declaration.
1045func (ss *ServerSession) initialized(ctx context.Context, params *InitializedParams) (Result, error) {
1046 if params == nil {
1047 // Since we use nilness to signal 'initialized' state, we must ensure that
1048 // params are non-nil.
1049 params = new(InitializedParams)
1050 }
1051 var wasInit, wasInitd bool
1052 ss.updateState(func(state *ServerSessionState) {
1053 wasInit = state.InitializeParams != nil
1054 wasInitd = state.InitializedParams != nil
1055 if wasInit && !wasInitd {
1056 state.InitializedParams = params
1057 }
1058 })
1059
1060 if !wasInit {
1061 ss.server.opts.Logger.Error("initialized before initialize")
1062 return nil, fmt.Errorf("%q before %q", notificationInitialized, methodInitialize)
1063 }
1064 if wasInitd {
1065 ss.server.opts.Logger.Error("duplicate initialized notification")
1066 return nil, fmt.Errorf("duplicate %q received", notificationInitialized)
1067 }
1068 if h := ss.server.opts.InitializedHandler; h != nil {
1069 h(ctx, serverRequestFor(ss, params))
1070 }
1071 ss.server.opts.Logger.Info("session initialized")
1072 return nil, nil
1073}
1074
1075func (s *Server) callRootsListChangedHandler(ctx context.Context, req *RootsListChangedRequest) (Result, error) {
1076 if h := s.opts.RootsListChangedHandler; h != nil {

Callers

nothing calls this directly

Calls 3

updateStateMethod · 0.95
serverRequestForFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected