Skip to main content
Glama
CaptainCrouton89

MCP Server Boilerplate

mongo-delete-document

Remove documents from MongoDB collections using query filters. Specify database, collection, and filter criteria to delete single or multiple documents as needed.

Instructions

Delete documents from a MongoDB collection

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseYesDatabase name
collectionYesCollection name
filterYesQuery filter to match documents to delete
deleteManyNoWhether to delete multiple documents (default: false)

Implementation Reference

  • The async handler function that connects to the MongoDB database, gets the collection, and executes deleteOne or deleteMany based on the deleteMany parameter, returning the number of deleted documents.
    async ({ database: dbName, collection: collectionName, filter, deleteMany = false }) => {
      try {
        const db = await ensureConnection(dbName);
        const collection: Collection = db.collection(collectionName);
        
        const result = deleteMany
          ? await collection.deleteMany(filter)
          : await collection.deleteOne(filter);
        
        return {
          content: [
            {
              type: "text",
              text: `Delete operation completed. Deleted ${result.deletedCount} document(s)`,
            },
          ],
        };
      } catch (error) {
        throw new Error(`Failed to delete document(s): ${error instanceof Error ? error.message : 'Unknown error'}`);
      }
    }
  • Zod schema defining the input parameters: database, collection, filter (required), and optional deleteMany flag.
    {
      database: z.string().describe("Database name"),
      collection: z.string().describe("Collection name"),
      filter: z.record(z.any()).describe("Query filter to match documents to delete"),
      deleteMany: z.boolean().optional().describe("Whether to delete multiple documents (default: false)"),
    },
  • src/index.ts:201-231 (registration)
    The server.tool() call that registers the 'mongo-delete-document' tool with its description, input schema, and handler function.
    server.tool(
      "mongo-delete-document",
      "Delete documents from a MongoDB collection",
      {
        database: z.string().describe("Database name"),
        collection: z.string().describe("Collection name"),
        filter: z.record(z.any()).describe("Query filter to match documents to delete"),
        deleteMany: z.boolean().optional().describe("Whether to delete multiple documents (default: false)"),
      },
      async ({ database: dbName, collection: collectionName, filter, deleteMany = false }) => {
        try {
          const db = await ensureConnection(dbName);
          const collection: Collection = db.collection(collectionName);
          
          const result = deleteMany
            ? await collection.deleteMany(filter)
            : await collection.deleteOne(filter);
          
          return {
            content: [
              {
                type: "text",
                text: `Delete operation completed. Deleted ${result.deletedCount} document(s)`,
              },
            ],
          };
        } catch (error) {
          throw new Error(`Failed to delete document(s): ${error instanceof Error ? error.message : 'Unknown error'}`);
        }
      }
    );
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It states 'Delete documents' which implies a destructive mutation, but doesn't disclose critical behaviors: whether deletion is permanent, if it requires specific permissions, what happens on empty filter matches, or error handling. For a destructive tool with zero annotation coverage, this is a significant gap in safety and operational context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, direct sentence with zero wasted words. It's front-loaded with the core action and resource, making it highly efficient. Every word earns its place by conveying essential purpose without redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given this is a destructive tool with no annotations and no output schema, the description is incomplete. It lacks behavioral context (e.g., permanence, permissions), usage guidelines, and output expectations. While the schema covers parameters well, the overall context for safe and effective use is insufficient.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all 4 parameters (database, collection, filter, deleteMany). The description adds no additional parameter semantics beyond what's in the schema—it doesn't explain filter syntax, default behaviors, or provide examples. Baseline 3 is appropriate when the schema does all the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Delete') and resource ('documents from a MongoDB collection'), making the purpose immediately understandable. It distinguishes this as a deletion tool among siblings like create, find, update, and aggregate. However, it doesn't specify whether it deletes one or many documents by default, which could be more precise.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. It doesn't mention prerequisites like database/collection existence, compare with mongo-update-document for modifications, or warn about irreversible deletion. The agent must infer usage from the tool name and context alone.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/CaptainCrouton89/mongo-mcp'

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