Skip to main content
Glama
ricleedo

MCP Server Boilerplate

by ricleedo

mongo-update-document

Modify documents in a MongoDB collection by specifying database, collection, filter criteria, and update operations to apply changes to data.

Instructions

Update documents in a MongoDB collection

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseYesDatabase name
collectionYesCollection name
filterYesQuery filter to match documents to update
updateYesUpdate operations as JSON object
updateManyNoWhether to update multiple documents (default: false)

Implementation Reference

  • Executes the MongoDB update operation: connects to the database, gets the collection, and calls updateOne or updateMany based on the updateMany flag, returning the result counts.
    async ({ database: dbName, collection: collectionName, filter, update, updateMany = false }) => {
      try {
        const db = await ensureConnection(dbName);
        const collection: Collection = db.collection(collectionName);
        
        const result = updateMany 
          ? await collection.updateMany(filter, update)
          : await collection.updateOne(filter, update);
        
        return {
          content: [
            {
              type: "text",
              text: `Update operation completed. Matched: ${result.matchedCount}, Modified: ${result.modifiedCount}`,
            },
          ],
        };
      } catch (error) {
        throw new Error(`Failed to update document(s): ${error instanceof Error ? error.message : 'Unknown error'}`);
      }
    }
  • Input schema using Zod validators for the tool parameters: database, collection, filter, update, and optional updateMany.
    {
      database: z.string().describe("Database name"),
      collection: z.string().describe("Collection name"),
      filter: z.record(z.any()).describe("Query filter to match documents to update"),
      update: z.record(z.any()).describe("Update operations as JSON object"),
      updateMany: z.boolean().optional().describe("Whether to update multiple documents (default: false)"),
    },
  • src/index.ts:168-199 (registration)
    Registers the mongo-update-document tool with the MCP server, including name, description, input schema, and handler function.
    server.tool(
      "mongo-update-document",
      "Update documents in 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 update"),
        update: z.record(z.any()).describe("Update operations as JSON object"),
        updateMany: z.boolean().optional().describe("Whether to update multiple documents (default: false)"),
      },
      async ({ database: dbName, collection: collectionName, filter, update, updateMany = false }) => {
        try {
          const db = await ensureConnection(dbName);
          const collection: Collection = db.collection(collectionName);
          
          const result = updateMany 
            ? await collection.updateMany(filter, update)
            : await collection.updateOne(filter, update);
          
          return {
            content: [
              {
                type: "text",
                text: `Update operation completed. Matched: ${result.matchedCount}, Modified: ${result.modifiedCount}`,
              },
            ],
          };
        } catch (error) {
          throw new Error(`Failed to update document(s): ${error instanceof Error ? error.message : 'Unknown error'}`);
        }
      }
    );
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 such as required permissions, whether updates are atomic or reversible, potential side effects, or error handling. This leaves significant gaps in understanding the tool's behavior.

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 no wasted words, making it highly concise and front-loaded. It efficiently conveys the core purpose without unnecessary elaboration.

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 complexity of a mutation tool with no annotations and no output schema, the description is insufficient. It lacks details on return values, error conditions, or behavioral nuances, leaving the agent with incomplete information for safe and effective use.

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 input schema has 100% description coverage, clearly documenting all parameters. The description adds no additional meaning beyond what the schema provides, such as examples or constraints. Since the schema does the heavy lifting, the baseline score of 3 is appropriate.

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 evident. However, it does not distinguish this tool from its sibling 'mongo-create-document' or 'mongo-delete-document' in terms of specific use cases or scope, 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 like 'mongo-create-document' or 'mongo-delete-document', nor does it mention prerequisites or contextual cues. It lacks explicit instructions for selection among siblings, leaving usage ambiguous.

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/ricleedo/mongo-boilerplate-mcp'

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