Skip to main content
Glama

MongoDB MCP Server

Official
by mongodb-js
dropCollection.test.ts2.81 kB
import { describeWithMongoDB, validateAutoConnectBehavior } from "../mongodbHelpers.js"; import { expect, it } from "vitest"; import { getResponseContent, databaseCollectionParameters, validateToolMetadata, validateThrowsForInvalidArguments, databaseCollectionInvalidArgs, } from "../../../helpers.js"; describeWithMongoDB("dropCollection tool", (integration) => { validateToolMetadata( integration, "drop-collection", "Removes a collection or view from the database. The method also removes any indexes associated with the dropped collection.", databaseCollectionParameters ); validateThrowsForInvalidArguments(integration, "drop-collection", databaseCollectionInvalidArgs); it("can drop non-existing collection", async () => { await integration.connectMcpClient(); const response = await integration.mcpClient().callTool({ name: "drop-collection", arguments: { database: integration.randomDbName(), collection: "coll1", }, }); const content = getResponseContent(response.content); expect(content).toContain( `Successfully dropped collection "coll1" from database "${integration.randomDbName()}"` ); const collections = await integration.mongoClient().db(integration.randomDbName()).listCollections().toArray(); expect(collections).toHaveLength(0); }); it("removes the collection if it exists", async () => { await integration.connectMcpClient(); await integration.mongoClient().db(integration.randomDbName()).createCollection("coll1"); await integration.mongoClient().db(integration.randomDbName()).createCollection("coll2"); const response = await integration.mcpClient().callTool({ name: "drop-collection", arguments: { database: integration.randomDbName(), collection: "coll1", }, }); const content = getResponseContent(response.content); expect(content).toContain( `Successfully dropped collection "coll1" from database "${integration.randomDbName()}"` ); const collections = await integration.mongoClient().db(integration.randomDbName()).listCollections().toArray(); expect(collections).toHaveLength(1); expect(collections[0]?.name).toBe("coll2"); }); validateAutoConnectBehavior(integration, "drop-collection", () => { return { args: { database: integration.randomDbName(), collection: "coll1", }, expectedResponse: `Successfully dropped collection "coll1" from database "${integration.randomDbName()}"`, }; }); });

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mongodb-js/mongodb-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server