File tree Expand file tree Collapse file tree 2 files changed +65
-0
lines changed Expand file tree Collapse file tree 2 files changed +65
-0
lines changed Original file line number Diff line number Diff line change @@ -528,6 +528,60 @@ describe("tool()", () => {
528
528
] )
529
529
} ) ;
530
530
531
+ /***
532
+ * Test: Tool self removal
533
+ */
534
+ test ( "should remove tool when using tool.remove()" , async ( ) => {
535
+ const mcpServer = new McpServer ( {
536
+ name : "test server" ,
537
+ version : "1.0" ,
538
+ } ) ;
539
+
540
+ // Register initial tool
541
+ const tool = mcpServer . tool ( "test" , async ( ) => ( {
542
+ content : [
543
+ {
544
+ type : "text" ,
545
+ text : "Test response" ,
546
+ } ,
547
+ ] ,
548
+ } ) ) ;
549
+
550
+ expect ( mcpServer [ '_registeredTools' ] [ 'test' ] ) . toBeDefined ( ) ;
551
+
552
+ // Now delete the tool
553
+ tool . remove ( ) ;
554
+
555
+ expect ( mcpServer [ '_registeredTools' ] [ 'test' ] ) . toBeUndefined ( ) ;
556
+ } ) ;
557
+
558
+ /***
559
+ * Test: Tool server removal
560
+ */
561
+ test ( "should remove tool when using server.removeTool(...)" , async ( ) => {
562
+ const mcpServer = new McpServer ( {
563
+ name : "test server" ,
564
+ version : "1.0" ,
565
+ } ) ;
566
+
567
+ // Register initial tool
568
+ mcpServer . tool ( "test" , async ( ) => ( {
569
+ content : [
570
+ {
571
+ type : "text" ,
572
+ text : "Test response" ,
573
+ } ,
574
+ ] ,
575
+ } ) ) ;
576
+
577
+ expect ( mcpServer [ '_registeredTools' ] [ 'test' ] ) . toBeDefined ( ) ;
578
+
579
+ // Now delete the tool
580
+ mcpServer . removeTool ( "test" ) ;
581
+
582
+ expect ( mcpServer [ '_registeredTools' ] [ 'test' ] ) . toBeUndefined ( ) ;
583
+ } ) ;
584
+
531
585
/***
532
586
* Test: Tool Registration with Parameters
533
587
*/
Original file line number Diff line number Diff line change @@ -955,6 +955,17 @@ export class McpServer {
955
955
) ;
956
956
}
957
957
958
+ /**
959
+ * Removes a tool from the server by name.
960
+ * Does nothing if the tool is not registered.
961
+ */
962
+ removeTool ( name : string ) {
963
+ const tool = this . _registeredTools [ name ] ;
964
+ if ( tool ) {
965
+ tool . update ( { name : null } ) ;
966
+ }
967
+ } ;
968
+
958
969
/**
959
970
* Registers a zero-argument prompt `name`, which will run the given function when the client calls it.
960
971
*/
You can’t perform that action at this time.
0 commit comments