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

Method unsubscribe

mcp/server.go:911–931  ·  view source on GitHub ↗
(ctx context.Context, req *UnsubscribeRequest)

Source from the content-addressed store, hash-verified

909}
910
911func (s *Server) unsubscribe(ctx context.Context, req *UnsubscribeRequest) (*emptyResult, error) {
912 if s.opts.UnsubscribeHandler == nil {
913 return nil, jsonrpc2.ErrMethodNotFound
914 }
915
916 if err := s.opts.UnsubscribeHandler(ctx, req); err != nil {
917 return nil, err
918 }
919
920 s.mu.Lock()
921 defer s.mu.Unlock()
922 if subscribedSessions, ok := s.resourceSubscriptions[req.Params.URI]; ok {
923 delete(subscribedSessions, req.Session)
924 if len(subscribedSessions) == 0 {
925 delete(s.resourceSubscriptions, req.Params.URI)
926 }
927 }
928 s.opts.Logger.Info("resource unsubscribed", "uri", req.Params.URI, "session_id", req.Session.ID())
929
930 return &emptyResult{}, nil
931}
932
933// Run runs the server over the given transport, which must be persistent.
934//

Callers

nothing calls this directly

Calls 1

IDMethod · 0.65

Tested by

no test coverage detected