Skip to main content
Glama

MCP-MongoDB-MySQL-Server

mongodb_insert

Add documents to a specified MongoDB collection using a standardized interface for database operations. Input includes collection name and documents to insert.

Instructions

Insert documents into a MongoDB collection

Input Schema

NameRequiredDescriptionDefault
collectionYesCollection name
documentsYesDocuments to insert

Input Schema (JSON Schema)

{ "properties": { "collection": { "description": "Collection name", "type": "string" }, "documents": { "description": "Documents to insert", "items": { "type": "object" }, "type": "array" } }, "required": [ "collection", "documents" ], "type": "object" }

Implementation Reference

  • The main handler function for the mongodb_insert tool. Ensures MongoDB connection, validates input (collection and documents), performs insertMany operation, and returns success message with inserted count.
    private async handleMongoDBInsert(args: any) { await this.ensureMongoConnection(); if (!args.collection || !args.documents) { throw new McpError(ErrorCode.InvalidParams, 'Collection name and documents are required'); } try { const collection = this.mongoDB!.collection(args.collection); const result = await collection.insertMany(args.documents); return { content: [ { type: 'text', text: `Successfully inserted ${result.insertedCount} documents`, }, ], }; } catch (error) { throw new McpError( ErrorCode.InternalError, `Failed to insert documents: ${getErrorMessage(error)}` ); }
  • src/index.ts:442-461 (registration)
    Tool registration in the list of tools provided by ListToolsRequestSchema. Includes the tool name, description, and input schema definition.
    { name: 'mongodb_insert', description: 'Insert documents into a MongoDB collection', inputSchema: { type: 'object', properties: { collection: { type: 'string', description: 'Collection name', }, documents: { type: 'array', items: { type: 'object', }, description: 'Documents to insert', }, }, required: ['collection', 'documents'], },
  • Input schema definition for the mongodb_insert tool, specifying required properties: collection (string) and documents (array of objects).
    inputSchema: { type: 'object', properties: { collection: { type: 'string', description: 'Collection name', }, documents: { type: 'array', items: { type: 'object', }, description: 'Documents to insert', }, }, required: ['collection', 'documents'],

Other Tools

Related 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