@@ -141,6 +141,7 @@ func TestMCPServer_Capabilities(t *testing.T) {
141
141
})
142
142
}
143
143
}
144
+
144
145
func TestMCPServer_Tools (t * testing.T ) {
145
146
tests := []struct {
146
147
name string
@@ -207,14 +208,14 @@ func TestMCPServer_Tools(t *testing.T) {
207
208
assert .Equal (t , "notifications/tools/list_changed" , notifications [0 ].Notification .Method )
208
209
// One for DeleteTools
209
210
assert .Equal (t , "notifications/tools/list_changed" , notifications [1 ].Notification .Method )
210
-
211
+
211
212
// Expect a successful response with an empty list of tools
212
213
resp , ok := toolsList .(mcp.JSONRPCResponse )
213
214
assert .True (t , ok , "Expected JSONRPCResponse, got %T" , toolsList )
214
-
215
+
215
216
result , ok := resp .Result .(mcp.ListToolsResult )
216
217
assert .True (t , ok , "Expected ListToolsResult, got %T" , resp .Result )
217
-
218
+
218
219
assert .Empty (t , result .Tools , "Expected empty tools list" )
219
220
},
220
221
},
@@ -660,7 +661,7 @@ func TestMCPServer_HandleMethodsWithoutCapabilities(t *testing.T) {
660
661
"name": "test-tool"
661
662
}
662
663
}` ,
663
- options : []ServerOption {}, // No capabilities at all
664
+ options : []ServerOption {}, // No capabilities at all
664
665
expectedErr : mcp .METHOD_NOT_FOUND ,
665
666
},
666
667
{
@@ -673,7 +674,7 @@ func TestMCPServer_HandleMethodsWithoutCapabilities(t *testing.T) {
673
674
"name": "test-prompt"
674
675
}
675
676
}` ,
676
- options : []ServerOption {}, // No capabilities at all
677
+ options : []ServerOption {}, // No capabilities at all
677
678
expectedErr : mcp .METHOD_NOT_FOUND ,
678
679
},
679
680
{
@@ -686,7 +687,7 @@ func TestMCPServer_HandleMethodsWithoutCapabilities(t *testing.T) {
686
687
"uri": "test-resource"
687
688
}
688
689
}` ,
689
- options : []ServerOption {}, // No capabilities at all
690
+ options : []ServerOption {}, // No capabilities at all
690
691
expectedErr : mcp .METHOD_NOT_FOUND ,
691
692
},
692
693
}
@@ -707,6 +708,75 @@ func TestMCPServer_HandleMethodsWithoutCapabilities(t *testing.T) {
707
708
}
708
709
}
709
710
711
+ func TestMCPServer_Instructions (t * testing.T ) {
712
+ tests := []struct {
713
+ name string
714
+ instructions string
715
+ validate func (t * testing.T , response mcp.JSONRPCMessage )
716
+ }{
717
+ {
718
+ name : "No instructions" ,
719
+ instructions : "" ,
720
+ validate : func (t * testing.T , response mcp.JSONRPCMessage ) {
721
+ resp , ok := response .(mcp.JSONRPCResponse )
722
+ assert .True (t , ok )
723
+
724
+ initResult , ok := resp .Result .(mcp.InitializeResult )
725
+ assert .True (t , ok )
726
+ assert .Equal (t , "" , initResult .Instructions )
727
+ },
728
+ },
729
+ {
730
+ name : "With instructions" ,
731
+ instructions : "These are test instructions for the client." ,
732
+ validate : func (t * testing.T , response mcp.JSONRPCMessage ) {
733
+ resp , ok := response .(mcp.JSONRPCResponse )
734
+ assert .True (t , ok )
735
+
736
+ initResult , ok := resp .Result .(mcp.InitializeResult )
737
+ assert .True (t , ok )
738
+ assert .Equal (t , "These are test instructions for the client." , initResult .Instructions )
739
+ },
740
+ },
741
+ {
742
+ name : "With multiline instructions" ,
743
+ instructions : "Line 1\n Line 2\n Line 3" ,
744
+ validate : func (t * testing.T , response mcp.JSONRPCMessage ) {
745
+ resp , ok := response .(mcp.JSONRPCResponse )
746
+ assert .True (t , ok )
747
+
748
+ initResult , ok := resp .Result .(mcp.InitializeResult )
749
+ assert .True (t , ok )
750
+ assert .Equal (t , "Line 1\n Line 2\n Line 3" , initResult .Instructions )
751
+ },
752
+ },
753
+ }
754
+
755
+ for _ , tt := range tests {
756
+ t .Run (tt .name , func (t * testing.T ) {
757
+ var server * MCPServer
758
+ if tt .instructions == "" {
759
+ server = NewMCPServer ("test-server" , "1.0.0" )
760
+ } else {
761
+ server = NewMCPServer ("test-server" , "1.0.0" , WithInstructions (tt .instructions ))
762
+ }
763
+
764
+ message := mcp.JSONRPCRequest {
765
+ JSONRPC : "2.0" ,
766
+ ID : 1 ,
767
+ Request : mcp.Request {
768
+ Method : "initialize" ,
769
+ },
770
+ }
771
+ messageBytes , err := json .Marshal (message )
772
+ assert .NoError (t , err )
773
+
774
+ response := server .HandleMessage (context .Background (), messageBytes )
775
+ tt .validate (t , response )
776
+ })
777
+ }
778
+ }
779
+
710
780
func createTestServer () * MCPServer {
711
781
server := NewMCPServer ("test-server" , "1.0.0" ,
712
782
WithResourceCapabilities (true , true ),
0 commit comments