@@ -55,6 +55,7 @@ func TestMCPServer_Capabilities(t *testing.T) {
55
55
options : []ServerOption {
56
56
WithResourceCapabilities (true , true ),
57
57
WithPromptCapabilities (true ),
58
+ WithToolCapabilities (true ),
58
59
WithLogging (),
59
60
},
60
61
validate : func (t * testing.T , response mcp.JSONRPCMessage ) {
@@ -73,8 +74,8 @@ func TestMCPServer_Capabilities(t *testing.T) {
73
74
assert .Equal (t , "1.0.0" , initResult .ServerInfo .Version )
74
75
75
76
assert .NotNil (t , initResult .Capabilities .Resources )
76
- // Resources capabilities are now always false for subscribe and true for listChanged
77
- assert .False (t , initResult .Capabilities .Resources .Subscribe )
77
+
78
+ assert .True (t , initResult .Capabilities .Resources .Subscribe )
78
79
assert .True (t , initResult .Capabilities .Resources .ListChanged )
79
80
80
81
assert .NotNil (t , initResult .Capabilities .Prompts )
@@ -83,6 +84,43 @@ func TestMCPServer_Capabilities(t *testing.T) {
83
84
assert .NotNil (t , initResult .Capabilities .Tools )
84
85
assert .True (t , initResult .Capabilities .Tools .ListChanged )
85
86
87
+ assert .NotNil (t , initResult .Capabilities .Logging )
88
+ },
89
+ },
90
+ {
91
+ name : "Specific capabilities" ,
92
+ options : []ServerOption {
93
+ WithResourceCapabilities (true , false ),
94
+ WithPromptCapabilities (true ),
95
+ WithToolCapabilities (false ),
96
+ WithLogging (),
97
+ },
98
+ validate : func (t * testing.T , response mcp.JSONRPCMessage ) {
99
+ resp , ok := response .(mcp.JSONRPCResponse )
100
+ assert .True (t , ok )
101
+
102
+ initResult , ok := resp .Result .(mcp.InitializeResult )
103
+ assert .True (t , ok )
104
+
105
+ assert .Equal (
106
+ t ,
107
+ mcp .LATEST_PROTOCOL_VERSION ,
108
+ initResult .ProtocolVersion ,
109
+ )
110
+ assert .Equal (t , "test-server" , initResult .ServerInfo .Name )
111
+ assert .Equal (t , "1.0.0" , initResult .ServerInfo .Version )
112
+
113
+ assert .NotNil (t , initResult .Capabilities .Resources )
114
+
115
+ assert .True (t , initResult .Capabilities .Resources .Subscribe )
116
+ assert .False (t , initResult .Capabilities .Resources .ListChanged )
117
+
118
+ assert .NotNil (t , initResult .Capabilities .Prompts )
119
+ assert .True (t , initResult .Capabilities .Prompts .ListChanged )
120
+
121
+ assert .NotNil (t , initResult .Capabilities .Tools )
122
+ assert .False (t , initResult .Capabilities .Tools .ListChanged )
123
+
86
124
assert .NotNil (t , initResult .Capabilities .Logging )
87
125
},
88
126
},
@@ -600,14 +638,10 @@ func TestMCPServer_HandleUndefinedHandlers(t *testing.T) {
600
638
}
601
639
602
640
func TestMCPServer_HandleMethodsWithoutCapabilities (t * testing.T ) {
603
- server := NewMCPServer (
604
- "test-server" ,
605
- "1.0.0" ,
606
- )
607
-
608
641
tests := []struct {
609
642
name string
610
643
message string
644
+ options []ServerOption
611
645
expectedErr int
612
646
}{
613
647
{
@@ -620,6 +654,9 @@ func TestMCPServer_HandleMethodsWithoutCapabilities(t *testing.T) {
620
654
"name": "test-tool"
621
655
}
622
656
}` ,
657
+ options : []ServerOption {
658
+ WithToolCapabilities (false ),
659
+ },
623
660
expectedErr : mcp .METHOD_NOT_FOUND ,
624
661
},
625
662
{
@@ -632,6 +669,9 @@ func TestMCPServer_HandleMethodsWithoutCapabilities(t *testing.T) {
632
669
"name": "test-prompt"
633
670
}
634
671
}` ,
672
+ options : []ServerOption {
673
+ WithPromptCapabilities (false ),
674
+ },
635
675
expectedErr : mcp .METHOD_NOT_FOUND ,
636
676
},
637
677
{
@@ -644,12 +684,16 @@ func TestMCPServer_HandleMethodsWithoutCapabilities(t *testing.T) {
644
684
"uri": "test-resource"
645
685
}
646
686
}` ,
687
+ options : []ServerOption {
688
+ WithResourceCapabilities (false , false ),
689
+ },
647
690
expectedErr : mcp .METHOD_NOT_FOUND ,
648
691
},
649
692
}
650
693
651
694
for _ , tt := range tests {
652
695
t .Run (tt .name , func (t * testing.T ) {
696
+ server := NewMCPServer ("test-server" , "1.0.0" , tt .options ... )
653
697
response := server .HandleMessage (
654
698
context .Background (),
655
699
[]byte (tt .message ),
0 commit comments