@@ -3,7 +3,6 @@ package mcp
3
3
import (
4
4
"context"
5
5
"fmt"
6
- "slices"
7
6
8
7
"github.com/modelcontextprotocol/go-sdk/mcp"
9
8
)
@@ -21,66 +20,36 @@ type Client interface {
21
20
Close () error
22
21
}
23
22
24
- func allSessions (server * mcp.Server , callback func (session * mcp.ServerSession )) {
25
- for session := range server .Sessions () {
26
- callback (session )
27
- }
28
- }
29
-
30
- func serverNotifications (server * mcp.Server ) * mcp.ClientOptions {
23
+ func stdioNotifications (serverSession * mcp.ServerSession ) * mcp.ClientOptions {
31
24
return & mcp.ClientOptions {
32
25
CreateMessageHandler : func (ctx context.Context , session * mcp.ClientSession , params * mcp.CreateMessageParams ) (* mcp.CreateMessageResult , error ) {
33
26
// Handle create messages if needed
34
27
return nil , fmt .Errorf ("create messages not supported" )
35
28
},
36
29
ToolListChangedHandler : func (ctx context.Context , session * mcp.ClientSession , params * mcp.ToolListChangedParams ) {
37
- // Handle tool list changes if needed
38
- if server != nil {
39
- sessions := slices .Collect (server .Sessions ())
40
- mcp .NotifySessions (sessions , "notifications/tools/list_changed" , params )
30
+ if serverSession != nil {
31
+ mcp .HandleNotify (ctx , serverSession , "notifications/tools/list_changed" , params )
41
32
}
42
33
},
43
34
ResourceListChangedHandler : func (ctx context.Context , session * mcp.ClientSession , params * mcp.ResourceListChangedParams ) {
44
- if server != nil {
45
- sessions := slices .Collect (server .Sessions ())
46
- mcp .NotifySessions (sessions , "notifications/resources/list_changed" , params )
35
+ if serverSession != nil {
36
+ mcp .HandleNotify (ctx , serverSession , "notifications/resources/list_changed" , params )
47
37
}
48
38
},
49
39
PromptListChangedHandler : func (ctx context.Context , session * mcp.ClientSession , params * mcp.PromptListChangedParams ) {
50
- if server != nil {
51
- sessions := slices .Collect (server .Sessions ())
52
- mcp .NotifySessions (sessions , "notifications/prompts/list_changed" , params )
40
+ if serverSession != nil {
41
+ mcp .HandleNotify (ctx , serverSession , "notifications/prompts/list_changed" , params )
53
42
}
54
43
},
55
44
ProgressNotificationHandler : func (ctx context.Context , session * mcp.ClientSession , params * mcp.ProgressNotificationParams ) {
56
- allSessions (server , func (session * mcp.ServerSession ) {session .NotifyProgress (ctx , params )})
57
- },
58
- LoggingMessageHandler : func (ctx context.Context , session * mcp.ClientSession , params * mcp.LoggingMessageParams ) {
59
- allSessions (server , func (session * mcp.ServerSession ) {session .Log (ctx , params )})
60
- },
61
- }
62
- }
63
-
64
- func stdioNotifications (serverSession * mcp.ServerSession ) * mcp.ClientOptions {
65
- return & mcp.ClientOptions {
66
- CreateMessageHandler : func (ctx context.Context , session * mcp.ClientSession , params * mcp.CreateMessageParams ) (* mcp.CreateMessageResult , error ) {
67
- // Handle create messages if needed
68
- return nil , fmt .Errorf ("create messages not supported" )
69
- },
70
- ToolListChangedHandler : func (ctx context.Context , session * mcp.ClientSession , params * mcp.ToolListChangedParams ) {
71
- mcp .HandleNotify (ctx , serverSession , "notifications/tools/list_changed" , params )
72
- },
73
- ResourceListChangedHandler : func (ctx context.Context , session * mcp.ClientSession , params * mcp.ResourceListChangedParams ) {
74
- mcp .HandleNotify (ctx , serverSession , "notifications/resources/list_changed" , params )
75
- },
76
- PromptListChangedHandler : func (ctx context.Context , session * mcp.ClientSession , params * mcp.PromptListChangedParams ) {
77
- mcp .HandleNotify (ctx , serverSession , "notifications/prompts/list_changed" , params )
78
- },
79
- ProgressNotificationHandler : func (ctx context.Context , session * mcp.ClientSession , params * mcp.ProgressNotificationParams ) {
80
- serverSession .NotifyProgress (ctx , params )
45
+ if serverSession != nil {
46
+ serverSession .NotifyProgress (ctx , params )
47
+ }
81
48
},
82
49
LoggingMessageHandler : func (ctx context.Context , session * mcp.ClientSession , params * mcp.LoggingMessageParams ) {
83
- serverSession .Log (ctx , params )
50
+ if serverSession != nil {
51
+ serverSession .Log (ctx , params )
52
+ }
84
53
},
85
54
}
86
55
}
0 commit comments