fix: only subscribe when server advertises capability (#1221)

This commit is contained in:
Yaroslav 2026-09-01 14:43:23 +02:00 • committed by GitHub
commit 8227246472
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -334,13 +334,17 @@ func (c *Client) Connect(ctx context.Context, t Transport, opts *ClientSessionOp
subscribeParams := &SubscriptionsListenParams{
Notifications: &NotificationSubscriptions{},
}
if c.opts.ToolListChangedHandler != nil {
caps := discRes.Capabilities
if caps == nil {
caps = &ServerCapabilities{}
}
if c.opts.ToolListChangedHandler != nil && caps.Tools != nil && caps.Tools.ListChanged {
subscribeParams.Notifications.ToolsListChanged = true
}
if c.opts.PromptListChangedHandler != nil {
if c.opts.PromptListChangedHandler != nil && caps.Prompts != nil && caps.Prompts.ListChanged {
subscribeParams.Notifications.PromptsListChanged = true
}
if c.opts.ResourceListChangedHandler != nil {
if c.opts.ResourceListChangedHandler != nil && caps.Resources != nil && caps.Resources.ListChanged {
subscribeParams.Notifications.ResourcesListChanged = true
}
if subscribeParams.Notifications.ToolsListChanged ||