Skip to main content
Glama
yaoxiaolinglong

MCP-MongoDB-MySQL-Server

mongodb_update

Update documents in a MongoDB collection using query filters and update operations to modify specific data entries.

Instructions

Update documents in a MongoDB collection

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
collectionYesCollection name
filterYesMongoDB query filter
updateYesMongoDB update operations
manyNoUpdate multiple documents if true

Implementation Reference

  • The handler function that executes the MongoDB update operation. Ensures MongoDB connection, validates arguments, performs updateOne or updateMany based on the 'many' flag, and returns the result.
    private async handleMongoDBUpdate(args: any) {
      await this.ensureMongoConnection();
    
      if (!args.collection || !args.filter || !args.update) {
        throw new McpError(ErrorCode.InvalidParams, 'Collection name, filter, and update are required');
      }
    
      try {
        const collection = this.mongoDB!.collection(args.collection);
        let result;
        
        if (args.many) {
          result = await collection.updateMany(args.filter, args.update);
        } else {
          result = await collection.updateOne(args.filter, args.update);
        }
        
        return {
          content: [
            {
              type: 'text',
              text: `Successfully updated ${result.modifiedCount} documents`,
            },
          ],
        };
      } catch (error) {
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to update documents: ${getErrorMessage(error)}`
        );
      }
    }
  • Input schema for the mongodb_update tool, defining required properties: collection, filter, update, and optional many boolean.
    inputSchema: {
      type: 'object',
      properties: {
        collection: {
          type: 'string',
          description: 'Collection name',
        },
        filter: {
          type: 'object',
          description: 'MongoDB query filter',
        },
        update: {
          type: 'object',
          description: 'MongoDB update operations',
        },
        many: {
          type: 'boolean',
          description: 'Update multiple documents if true',
          optional: true
        }
      },
      required: ['collection', 'filter', 'update'],
    },
  • src/index.ts:463-489 (registration)
    Registration of the mongodb_update tool in the list of tools returned by ListToolsRequest, including name, description, and input schema.
    {
      name: 'mongodb_update',
      description: 'Update documents in a MongoDB collection',
      inputSchema: {
        type: 'object',
        properties: {
          collection: {
            type: 'string',
            description: 'Collection name',
          },
          filter: {
            type: 'object',
            description: 'MongoDB query filter',
          },
          update: {
            type: 'object',
            description: 'MongoDB update operations',
          },
          many: {
            type: 'boolean',
            description: 'Update multiple documents if true',
            optional: true
          }
        },
        required: ['collection', 'filter', 'update'],
      },
    },
  • src/index.ts:560-561 (registration)
    Dispatch registration in the CallToolRequest handler switch statement, routing calls to the handleMongoDBUpdate method.
    case 'mongodb_update':
      return await this.handleMongoDBUpdate(request.params.arguments);
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 updates documents but fails to mention critical details like required permissions, whether updates are atomic or reversible, potential side effects on data integrity, or error handling. This leaves significant gaps for a mutation tool.

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 with zero wasted words. It's front-loaded with the core purpose and appropriately sized for the tool's complexity, making it easy to parse quickly.

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 (a mutation operation with nested objects and no output schema) and lack of annotations, the description is incomplete. It doesn't cover behavioral aspects like safety, permissions, or return values, which are crucial for an update tool in a database context.

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?

The schema description coverage is 100%, so the schema already documents all parameters ('collection', 'filter', 'update', 'many') adequately. The description adds no additional meaning beyond what the schema provides, such as examples or usage context, which aligns with the baseline score for high schema coverage.

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 ('Update') and resource ('documents in a MongoDB collection'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'mongodb_delete' or 'mongodb_insert' beyond the verb, which prevents a perfect score.

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 sibling tools like 'mongodb_insert' for creating documents or 'mongodb_delete' for removing them, nor does it specify prerequisites such as needing a connection first.

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

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