Skip to content

Commit 734850b

Browse files
committed
Add server.removeTool('name')
1 parent 7d29cee commit 734850b

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
@@ -528,6 +528,60 @@ describe("tool()", () => {
528528
])
529529
});
530530

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+
531585
/***
532586
* Test: Tool Registration with Parameters
533587
*/

src/server/mcp.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,6 +955,17 @@ export class McpServer {
955955
);
956956
}
957957

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

0 commit comments

Comments
 (0)