@@ -252,22 +252,27 @@ func TestToolsForToolset(t *testing.T) {
252252 }
253253}
254254
255- func TestAddDeprecatedToolAliases (t * testing.T ) {
255+ func TestWithDeprecatedToolAliases (t * testing.T ) {
256256 tools := []ServerTool {
257257 mockTool ("new_name" , "toolset1" , true ),
258258 }
259259
260260 tsg := NewToolsetGroup (tools , nil , nil )
261- tsg .AddDeprecatedToolAliases (map [string ]string {
261+ tsgWithAliases := tsg .WithDeprecatedToolAliases (map [string ]string {
262262 "old_name" : "new_name" ,
263263 "get_issue" : "issue_read" ,
264264 })
265265
266- if len (tsg .deprecatedAliases ) != 2 {
267- t .Errorf ("expected 2 aliases, got %d" , len (tsg .deprecatedAliases ))
266+ // Original should be unchanged (immutable)
267+ if len (tsg .deprecatedAliases ) != 0 {
268+ t .Errorf ("original should have 0 aliases, got %d" , len (tsg .deprecatedAliases ))
268269 }
269- if tsg .deprecatedAliases ["old_name" ] != "new_name" {
270- t .Errorf ("expected alias 'old_name' -> 'new_name', got '%s'" , tsg .deprecatedAliases ["old_name" ])
270+
271+ if len (tsgWithAliases .deprecatedAliases ) != 2 {
272+ t .Errorf ("expected 2 aliases, got %d" , len (tsgWithAliases .deprecatedAliases ))
273+ }
274+ if tsgWithAliases .deprecatedAliases ["old_name" ] != "new_name" {
275+ t .Errorf ("expected alias 'old_name' -> 'new_name', got '%s'" , tsgWithAliases .deprecatedAliases ["old_name" ])
271276 }
272277}
273278
@@ -277,10 +282,10 @@ func TestResolveToolAliases(t *testing.T) {
277282 mockTool ("some_tool" , "toolset1" , true ),
278283 }
279284
280- tsg := NewToolsetGroup (tools , nil , nil )
281- tsg . AddDeprecatedToolAliases (map [string ]string {
282- "get_issue" : "issue_read" ,
283- })
285+ tsg := NewToolsetGroup (tools , nil , nil ).
286+ WithDeprecatedToolAliases (map [string ]string {
287+ "get_issue" : "issue_read" ,
288+ })
284289
285290 // Test resolving a mix of aliases and canonical names
286291 input := []string {"get_issue" , "some_tool" }
@@ -384,10 +389,10 @@ func TestWithToolsResolvesAliases(t *testing.T) {
384389 mockTool ("issue_read" , "toolset1" , true ),
385390 }
386391
387- tsg := NewToolsetGroup (tools , nil , nil )
388- tsg . AddDeprecatedToolAliases (map [string ]string {
389- "get_issue" : "issue_read" ,
390- })
392+ tsg := NewToolsetGroup (tools , nil , nil ).
393+ WithDeprecatedToolAliases (map [string ]string {
394+ "get_issue" : "issue_read" ,
395+ })
391396
392397 // Using deprecated alias should resolve to canonical name
393398 filtered := tsg .WithToolsets ([]string {}).WithTools ([]string {"get_issue" })
@@ -593,10 +598,10 @@ func TestForMCPRequest_ToolsCall_DeprecatedAlias(t *testing.T) {
593598 mockTool ("list_commits" , "repos" , true ),
594599 }
595600
596- tsg := NewToolsetGroup (tools , nil , nil )
597- tsg . AddDeprecatedToolAliases (map [string ]string {
598- "old_get_me" : "get_me" ,
599- })
601+ tsg := NewToolsetGroup (tools , nil , nil ).
602+ WithDeprecatedToolAliases (map [string ]string {
603+ "old_get_me" : "get_me" ,
604+ })
600605
601606 // Request using the deprecated alias
602607 filtered := tsg .ForMCPRequest (MCPMethodToolsCall , "old_get_me" )
@@ -1033,3 +1038,35 @@ func TestFeatureFlagPrompts(t *testing.T) {
10331038 t .Errorf ("Expected 2 prompts with checker, got %d" , len (filtered .AvailablePrompts (context .Background ())))
10341039 }
10351040}
1041+
1042+ func TestServerToolHasHandler (t * testing.T ) {
1043+ // Tool with handler
1044+ toolWithHandler := mockTool ("has_handler" , "toolset1" , true )
1045+ if ! toolWithHandler .HasHandler () {
1046+ t .Error ("Expected HasHandler() to return true for tool with handler" )
1047+ }
1048+
1049+ // Tool without handler
1050+ toolWithoutHandler := ServerTool {
1051+ Tool : mcp.Tool {Name : "no_handler" },
1052+ Toolset : testToolsetMetadata ("toolset1" ),
1053+ }
1054+ if toolWithoutHandler .HasHandler () {
1055+ t .Error ("Expected HasHandler() to return false for tool without handler" )
1056+ }
1057+ }
1058+
1059+ func TestServerToolHandlerPanicOnNil (t * testing.T ) {
1060+ tool := ServerTool {
1061+ Tool : mcp.Tool {Name : "no_handler" },
1062+ Toolset : testToolsetMetadata ("toolset1" ),
1063+ }
1064+
1065+ defer func () {
1066+ if r := recover (); r == nil {
1067+ t .Error ("Expected Handler() to panic when HandlerFunc is nil" )
1068+ }
1069+ }()
1070+
1071+ tool .Handler (nil )
1072+ }
0 commit comments