Skip to main content
Glama
TrueOleg

MCP Mac Apps Server

by TrueOleg

mongodb_delete_document

Remove documents from a MongoDB collection using a JSON filter. Specify database, collection, and filter criteria to delete matching records.

Instructions

Удаляет документ(ы) из коллекции по фильтру

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseNameYesИмя базы данных
collectionNameYesИмя коллекции
filterYesJSON строка с фильтром для удаления

Implementation Reference

  • The handler function for 'mongodb_delete_document' tool. Connects to MongoDB using getMongoClient, parses the filter JSON, executes deleteMany on the specified collection, returns content with the number of deleted documents.
    private async mongodbDeleteDocument(
      databaseName: string,
      collectionName: string,
      filterJson: string
    ) {
      const client = await this.getMongoClient();
      try {
        const db = client.db(databaseName);
        const collection = db.collection(collectionName);
        const filter = JSON.parse(filterJson);
        const result = await collection.deleteMany(filter);
        
        return {
          content: [
            {
              type: "text",
              text: `Удалено документов: ${result.deletedCount}`,
            },
          ],
        };
      } catch (error) {
        throw new Error(
          `Ошибка удаления документа: ${error instanceof Error ? error.message : String(error)}`
        );
      } finally {
        await client.close();
      }
    }
  • Input schema definition for the 'mongodb_delete_document' tool in the list of tools returned by ListToolsRequestHandler.
    {
      name: "mongodb_delete_document",
      description: "Удаляет документ(ы) из коллекции по фильтру",
      inputSchema: {
        type: "object",
        properties: {
          databaseName: {
            type: "string",
            description: "Имя базы данных",
          },
          collectionName: {
            type: "string",
            description: "Имя коллекции",
          },
          filter: {
            type: "string",
            description: "JSON строка с фильтром для удаления",
          },
        },
        required: ["databaseName", "collectionName", "filter"],
      },
    },
  • src/index.ts:374-379 (registration)
    Registration/dispatch in the CallToolRequestHandler switch statement that invokes the mongodbDeleteDocument handler.
    case "mongodb_delete_document":
      return await this.mongodbDeleteDocument(
        args?.databaseName as string,
        args?.collectionName as string,
        args?.filter as string
      );
  • Python implementation of the mongodb_delete_document handler function. Parses filter JSON, performs delete_many, returns deleted count. Note: dispatch is commented out in handle_request.
    def mongodb_delete_document(
        database_name: str, collection_name: str, filter_json: str
    ) -> str:
        """Deletes document(s) by filter"""
        client = MongoClient(MONGODB_URI)
        try:
            db = client[database_name]
            collection = db[collection_name]
            filter_dict = json.loads(filter_json)
            result = collection.delete_many(filter_dict)
            return f"Deleted documents: {result.deleted_count}"
        except Exception as e:
            raise Exception(f"Error deleting document: {str(e)}")
        finally:
            client.close()
  • Input schema for 'mongodb_delete_document' in the Python get_tools() function.
    {
        "name": "mongodb_delete_document",
        "description": "Deletes document(s) from collection by filter",
        "inputSchema": {
            "type": "object",
            "properties": {
                "databaseName": {
                    "type": "string",
                    "description": "Database name",
                },
                "collectionName": {
                    "type": "string",
                    "description": "Collection name",
                },
                "filter": {
                    "type": "string",
                    "description": "JSON string with deletion filter",
                },
            },
            "required": ["databaseName", "collectionName", "filter"],
        },
    },
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool deletes document(s) based on a filter, implying a destructive mutation, but doesn't specify critical details: whether it requires authentication, the effect on data (permanent deletion), rate limits, or what happens if the filter matches multiple documents (e.g., bulk deletion). This is a significant gap for a destructive tool with zero annotation coverage.

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, efficient sentence in Russian ('Удаляет документ(ы) из коллекции по фильтру'), directly stating the purpose without unnecessary words. It's front-loaded with the core action, making it easy to parse. Every part of the sentence contributes to understanding the tool's function.

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 the tool's complexity (destructive operation with 3 parameters) and lack of annotations or output schema, the description is incomplete. It doesn't cover behavioral aspects like safety, permissions, or output format, nor does it provide usage context. For a deletion tool, this leaves critical gaps that could lead to misuse or confusion by an AI agent.

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%, with all three parameters ('databaseName', 'collectionName', 'filter') documented in the schema. The description adds minimal value beyond the schema, only implying that 'filter' is used for deletion without explaining its JSON format or semantics. Baseline 3 is appropriate as the schema handles most documentation, but the description doesn't compensate with additional insights.

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 ('удаляет' - deletes) and the resource ('документ(ы) из коллекции' - document(s) from a collection), specifying it operates based on a filter. It distinguishes from siblings like 'mongodb_delete_collection' by focusing on documents rather than collections. However, it doesn't explicitly differentiate from other deletion tools beyond the resource scope.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., database/collection must exist), exclusions (e.g., not for bulk deletions without a filter), or compare to siblings like 'mongodb_delete_collection' for collection-level operations. Usage is implied by the action but lacks explicit context.

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/TrueOleg/MCP-expirements'

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