Skip to content

Commit be8022e

Browse files
committed
Add server.removeTool('name')
1 parent e0de082 commit be8022e

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

src/server/mcp.test.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,60 @@ describe('tool()', () => {
505505
]);
506506
});
507507

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+
508562
/***
509563
* Test: Tool Registration with Parameters
510564
*/

src/server/mcp.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,17 @@ export class McpServer {
816816
);
817817
}
818818

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+
819830
/**
820831
* Registers a zero-argument prompt `name`, which will run the given function when the client calls it.
821832
*/

0 commit comments

Comments
 (0)