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 @@ -505,6 +505,60 @@ describe('tool()', () => {
505
505
] ) ;
506
506
} ) ;
507
507
508
+ /***
509
+ * Test: Tool self removal
510
+ */
511
+ test ( "should remove tool when using tool.remove()" , async ( ) => {
512
+ const mcpServer = new McpServer ( {
513
+ name : "test server" ,
514
+ version : "1.0" ,
515
+ } ) ;
516
+
517
+ // Register initial tool
518
+ const tool = mcpServer . tool ( "test" , async ( ) => ( {
519
+ content : [
520
+ {
521
+ type : "text" ,
522
+ text : "Test response" ,
523
+ } ,
524
+ ] ,
525
+ } ) ) ;
526
+
527
+ expect ( mcpServer [ '_registeredTools' ] [ 'test' ] ) . toBeDefined ( ) ;
528
+
529
+ // Now delete the tool
530
+ tool . remove ( ) ;
531
+
532
+ expect ( mcpServer [ '_registeredTools' ] [ 'test' ] ) . toBeUndefined ( ) ;
533
+ } ) ;
534
+
535
+ /***
536
+ * Test: Tool server removal
537
+ */
538
+ test ( "should remove tool when using server.removeTool(...)" , async ( ) => {
539
+ const mcpServer = new McpServer ( {
540
+ name : "test server" ,
541
+ version : "1.0" ,
542
+ } ) ;
543
+
544
+ // Register initial tool
545
+ mcpServer . tool ( "test" , async ( ) => ( {
546
+ content : [
547
+ {
548
+ type : "text" ,
549
+ text : "Test response" ,
550
+ } ,
551
+ ] ,
552
+ } ) ) ;
553
+
554
+ expect ( mcpServer [ '_registeredTools' ] [ 'test' ] ) . toBeDefined ( ) ;
555
+
556
+ // Now delete the tool
557
+ mcpServer . removeTool ( "test" ) ;
558
+
559
+ expect ( mcpServer [ '_registeredTools' ] [ 'test' ] ) . toBeUndefined ( ) ;
560
+ } ) ;
561
+
508
562
/***
509
563
* Test: Tool Registration with Parameters
510
564
*/
Original file line number Diff line number Diff line change @@ -816,6 +816,17 @@ export class McpServer {
816
816
) ;
817
817
}
818
818
819
+ /**
820
+ * Removes a tool from the server by name.
821
+ * Does nothing if the tool is not registered.
822
+ */
823
+ removeTool ( name : string ) {
824
+ const tool = this . _registeredTools [ name ] ;
825
+ if ( tool ) {
826
+ tool . update ( { name : null } ) ;
827
+ }
828
+ } ;
829
+
819
830
/**
820
831
* Registers a zero-argument prompt `name`, which will run the given function when the client calls it.
821
832
*/
You can’t perform that action at this time.
0 commit comments