Skip to main content
Glama
ricleedo

MCP Server Boilerplate

by ricleedo

mongo-create-document

Insert JSON documents into MongoDB collections by specifying database, collection, and document data for data storage operations.

Instructions

Create a new document in a MongoDB collection

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseYesDatabase name
collectionYesCollection name
documentYesDocument to insert as JSON object

Implementation Reference

  • Handler function that ensures MongoDB connection, retrieves the collection, inserts the document using insertOne, and returns a success message with the inserted ID or throws an error.
    async ({ database: dbName, collection: collectionName, document }) => {
      try {
        const db = await ensureConnection(dbName);
        const collection: Collection = db.collection(collectionName);
        
        const result = await collection.insertOne(document);
        
        return {
          content: [
            {
              type: "text",
              text: `Document created successfully with ID: ${result.insertedId}`,
            },
          ],
        };
      } catch (error) {
        throw new Error(`Failed to create document: ${error instanceof Error ? error.message : 'Unknown error'}`);
      }
    }
  • Zod input schema defining the required parameters: database name, collection name, and document object.
    database: z.string().describe("Database name"),
    collection: z.string().describe("Collection name"),
    document: z.record(z.any()).describe("Document to insert as JSON object"),
  • src/index.ts:102-129 (registration)
    Registration of the 'mongo-create-document' tool using server.tool(), including name, description, input schema, and handler function.
    server.tool(
      "mongo-create-document",
      "Create a new document in a MongoDB collection",
      {
        database: z.string().describe("Database name"),
        collection: z.string().describe("Collection name"),
        document: z.record(z.any()).describe("Document to insert as JSON object"),
      },
      async ({ database: dbName, collection: collectionName, document }) => {
        try {
          const db = await ensureConnection(dbName);
          const collection: Collection = db.collection(collectionName);
          
          const result = await collection.insertOne(document);
          
          return {
            content: [
              {
                type: "text",
                text: `Document created successfully with ID: ${result.insertedId}`,
              },
            ],
          };
        } catch (error) {
          throw new Error(`Failed to create document: ${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 creates a document but fails to mention critical details like required permissions, whether the operation is idempotent, how errors are handled, or what the response looks like. For a mutation tool with zero annotation coverage, this leaves significant gaps in understanding its 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, efficient sentence that directly states the tool's function without any unnecessary words. It's front-loaded with the core purpose and avoids redundancy, 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 as a mutation operation with no annotations and no output schema, the description is insufficient. It doesn't explain what happens on success or failure, return values, or error conditions. For a create operation in a database context, more contextual information is needed to make it complete for 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?

The input schema has 100% description coverage, clearly documenting all three required parameters (database, collection, document). The description adds no additional semantic information beyond what the schema provides, such as format examples or constraints, so it meets the baseline for high schema coverage without enhancing parameter understanding.

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 ('Create a new document') and resource ('in a MongoDB collection'), making the purpose immediately understandable. However, it doesn't explicitly distinguish this tool from its sibling 'mongo-update-document' or explain when to use one versus the other, 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-update-document' or other siblings. It lacks any context about prerequisites, error conditions, or typical use cases, offering only the basic function without operational guidance.

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