@@ -463,14 +463,14 @@ describe("tool()", () => {
463
463
) ;
464
464
465
465
// new api
466
- mcpServer . tool (
466
+ mcpServer . registerTool (
467
467
"test (new api)" ,
468
- {
469
- inputSchema : { name : z . string ( ) , value : z . number ( ) } ,
470
- callback : async ( { name , value } ) => ( {
471
- content : [ { type : "text" , text : ` ${ name } : ${ value } ` } ] ,
472
- } ) ,
473
- }
468
+ {
469
+ inputSchema : { name : z . string ( ) , value : z . number ( ) } ,
470
+ } ,
471
+ async ( { name , value } ) => ( {
472
+ content : [ { type : "text" , text : ` ${ name } : ${ value } ` } ] ,
473
+ } )
474
474
) ;
475
475
476
476
const [ clientTransport , serverTransport ] =
@@ -525,17 +525,20 @@ describe("tool()", () => {
525
525
} ) ) ;
526
526
527
527
// new api
528
- mcpServer . tool ( "test (new api)" , {
529
- description : "Test description" ,
530
- callback : async ( ) => ( {
528
+ mcpServer . registerTool (
529
+ "test (new api)" ,
530
+ {
531
+ description : "Test description" ,
532
+ } ,
533
+ async ( ) => ( {
531
534
content : [
532
535
{
533
536
type : "text" as const ,
534
537
text : "Test response" ,
535
538
} ,
536
539
] ,
537
540
} )
538
- } ) ;
541
+ ) ;
539
542
540
543
541
544
const [ clientTransport , serverTransport ] =
@@ -582,17 +585,20 @@ describe("tool()", () => {
582
585
] ,
583
586
} ) ) ;
584
587
585
- mcpServer . tool ( "test (new api)" , {
586
- annotations : { title : "Test Tool" , readOnlyHint : true } ,
587
- callback : async ( ) => ( {
588
+ mcpServer . registerTool (
589
+ "test (new api)" ,
590
+ {
591
+ annotations : { title : "Test Tool" , readOnlyHint : true } ,
592
+ } ,
593
+ async ( ) => ( {
588
594
content : [
589
595
{
590
596
type : "text" as const ,
591
597
text : "Test response" ,
592
598
} ,
593
599
] ,
594
- } ) ,
595
- } ) ;
600
+ } )
601
+ ) ;
596
602
597
603
const [ clientTransport , serverTransport ] =
598
604
InMemoryTransport . createLinkedPair ( ) ;
@@ -638,13 +644,16 @@ describe("tool()", () => {
638
644
} )
639
645
) ;
640
646
641
- mcpServer . tool ( "test (new api)" , {
642
- inputSchema : { name : z . string ( ) } ,
643
- annotations : { title : "Test Tool" , readOnlyHint : true } ,
644
- callback : async ( { name } ) => ( {
647
+ mcpServer . registerTool (
648
+ "test (new api)" ,
649
+ {
650
+ inputSchema : { name : z . string ( ) } ,
651
+ annotations : { title : "Test Tool" , readOnlyHint : true } ,
652
+ } ,
653
+ async ( { name } ) => ( {
645
654
content : [ { type : "text" , text : `Hello, ${ name } !` } ]
646
655
} )
647
- } ) ;
656
+ ) ;
648
657
649
658
const [ clientTransport , serverTransport ] =
650
659
InMemoryTransport . createLinkedPair ( ) ;
@@ -694,14 +703,17 @@ describe("tool()", () => {
694
703
} )
695
704
) ;
696
705
697
- mcpServer . tool ( "test (new api)" , {
698
- description : "A tool with everything" ,
699
- inputSchema : { name : z . string ( ) } ,
700
- annotations : { title : "Complete Test Tool" , readOnlyHint : true , openWorldHint : false } ,
701
- callback : async ( { name } ) => ( {
706
+ mcpServer . registerTool (
707
+ "test (new api)" ,
708
+ {
709
+ description : "A tool with everything" ,
710
+ inputSchema : { name : z . string ( ) } ,
711
+ annotations : { title : "Complete Test Tool" , readOnlyHint : true , openWorldHint : false } ,
712
+ } ,
713
+ async ( { name } ) => ( {
702
714
content : [ { type : "text" , text : `Hello, ${ name } !` } ]
703
715
} )
704
- } ) ;
716
+ ) ;
705
717
706
718
const [ clientTransport , serverTransport ] =
707
719
InMemoryTransport . createLinkedPair ( ) ;
@@ -757,14 +769,17 @@ describe("tool()", () => {
757
769
} )
758
770
) ;
759
771
760
- mcpServer . tool ( "test (new api)" , {
761
- description : "A tool with everything but empty params" ,
762
- inputSchema : { } ,
763
- annotations : { title : "Complete Test Tool with empty params" , readOnlyHint : true , openWorldHint : false } ,
764
- callback : async ( ) => ( {
772
+ mcpServer . registerTool (
773
+ "test (new api)" ,
774
+ {
775
+ description : "A tool with everything but empty params" ,
776
+ inputSchema : { } ,
777
+ annotations : { title : "Complete Test Tool with empty params" , readOnlyHint : true , openWorldHint : false } ,
778
+ } ,
779
+ async ( ) => ( {
765
780
content : [ { type : "text" as const , text : "Test response" } ]
766
781
} )
767
- } ) ;
782
+ ) ;
768
783
769
784
const [ clientTransport , serverTransport ] =
770
785
InMemoryTransport . createLinkedPair ( ) ;
@@ -834,20 +849,23 @@ describe("tool()", () => {
834
849
} ) ,
835
850
) ;
836
851
837
- mcpServer . tool ( "test (new api)" , {
838
- inputSchema : {
839
- name : z . string ( ) ,
840
- value : z . number ( ) ,
852
+ mcpServer . registerTool (
853
+ "test (new api)" ,
854
+ {
855
+ inputSchema : {
856
+ name : z . string ( ) ,
857
+ value : z . number ( ) ,
858
+ } ,
841
859
} ,
842
- callback : async ( { name, value } ) => ( {
860
+ async ( { name, value } ) => ( {
843
861
content : [
844
862
{
845
863
type : "text" ,
846
864
text : `${ name } : ${ value } ` ,
847
865
} ,
848
866
] ,
849
- } ) ,
850
- } ) ;
867
+ } )
868
+ ) ;
851
869
852
870
const [ clientTransport , serverTransport ] =
853
871
InMemoryTransport . createLinkedPair ( ) ;
@@ -958,7 +976,7 @@ describe("tool()", () => {
958
976
) ;
959
977
960
978
// Register a tool with outputSchema
961
- mcpServer . tool (
979
+ mcpServer . registerTool (
962
980
"test" ,
963
981
{
964
982
description : "Test tool with structured output" ,
@@ -970,14 +988,14 @@ describe("tool()", () => {
970
988
resultType : z . string ( ) ,
971
989
timestamp : z . string ( )
972
990
} ,
973
- callback : async ( { input } ) => ( {
974
- structuredContent : {
975
- processedInput : input ,
976
- resultType : "structured" ,
977
- timestamp : "2023-01-01T00:00:00Z"
978
- } ,
979
- } ) ,
980
991
} ,
992
+ async ( { input } ) => ( {
993
+ structuredContent : {
994
+ processedInput : input ,
995
+ resultType : "structured" ,
996
+ timestamp : "2023-01-01T00:00:00Z"
997
+ } ,
998
+ } )
981
999
) ;
982
1000
983
1001
const [ clientTransport , serverTransport ] =
@@ -1061,7 +1079,7 @@ describe("tool()", () => {
1061
1079
) ;
1062
1080
1063
1081
// Register a tool with outputSchema that returns invalid data
1064
- mcpServer . tool (
1082
+ mcpServer . registerTool (
1065
1083
"test" ,
1066
1084
{
1067
1085
description : "Test tool with invalid structured output" ,
@@ -1073,15 +1091,15 @@ describe("tool()", () => {
1073
1091
resultType : z . string ( ) ,
1074
1092
timestamp : z . string ( )
1075
1093
} ,
1076
- callback : async ( { input } ) => ( {
1077
- structuredContent : {
1078
- processedInput : input ,
1079
- resultType : "structured" ,
1080
- // Missing required 'timestamp' field
1081
- someExtraField : "unexpected" // Extra field not in schema
1082
- } ,
1083
- } ) ,
1084
1094
} ,
1095
+ async ( { input } ) => ( {
1096
+ structuredContent : {
1097
+ processedInput : input ,
1098
+ resultType : "structured" ,
1099
+ // Missing required 'timestamp' field
1100
+ someExtraField : "unexpected" // Extra field not in schema
1101
+ } ,
1102
+ } )
1085
1103
) ;
1086
1104
1087
1105
const [ clientTransport , serverTransport ] =
0 commit comments