Skip to main content
Glama

MCP-MongoDB-MySQL-Server

mongodb_delete

Remove documents from a MongoDB collection using a query filter, with options to delete single or multiple records, via the MCP-MongoDB-MySQL-Server.

Instructions

Delete documents from a MongoDB collection

Input Schema

NameRequiredDescriptionDefault
collectionYesCollection name
filterYesMongoDB query filter
manyNoDelete multiple documents if true

Input Schema (JSON Schema)

{ "properties": { "collection": { "description": "Collection name", "type": "string" }, "filter": { "description": "MongoDB query filter", "type": "object" }, "many": { "description": "Delete multiple documents if true", "optional": true, "type": "boolean" } }, "required": [ "collection", "filter" ], "type": "object" }

Implementation Reference

  • The handler function that executes the mongodb_delete tool. It ensures MongoDB connection, validates inputs, performs deleteOne or deleteMany based on 'many' flag, and returns the count of deleted documents.
    private async handleMongoDBDelete(args: any) { await this.ensureMongoConnection(); if (!args.collection || !args.filter) { throw new McpError(ErrorCode.InvalidParams, 'Collection name and filter are required'); } try { const collection = this.mongoDB!.collection(args.collection); let result; if (args.many) { result = await collection.deleteMany(args.filter); } else { result = await collection.deleteOne(args.filter); } return { content: [ { type: 'text', text: `Successfully deleted ${result.deletedCount} documents`, }, ], }; } catch (error) { throw new McpError( ErrorCode.InternalError, `Failed to delete documents: ${getErrorMessage(error)}` ); }
  • src/index.ts:490-512 (registration)
    Registration of the 'mongodb_delete' tool in the listTools response, including name, description, and input schema definition.
    { name: 'mongodb_delete', description: 'Delete documents from a MongoDB collection', inputSchema: { type: 'object', properties: { collection: { type: 'string', description: 'Collection name', }, filter: { type: 'object', description: 'MongoDB query filter', }, many: { type: 'boolean', description: 'Delete multiple documents if true', optional: true } }, required: ['collection', 'filter'], }, },
  • Input schema for the mongodb_delete tool defining required collection and filter objects, optional many boolean.
    inputSchema: { type: 'object', properties: { collection: { type: 'string', description: 'Collection name', }, filter: { type: 'object', description: 'MongoDB query filter', }, many: { type: 'boolean', description: 'Delete multiple documents if true', optional: true } }, required: ['collection', 'filter'], },
  • src/index.ts:562-563 (registration)
    Dispatcher case in CallToolRequest handler that routes 'mongodb_delete' calls to the handleMongoDBDelete method.
    case 'mongodb_delete': return await this.handleMongoDBDelete(request.params.arguments);

Other Tools

Related Tools

Latest Blog Posts

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/yaoxiaolinglong/mcp-mongodb-mysql-server'

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