Skip to main content
Glama
yaoxiaolinglong

MCP-MongoDB-MySQL-Server

mongodb_insert

Insert documents into MongoDB collections through the MCP-MongoDB-MySQL-Server, enabling structured data storage with specified collection names and document arrays.

Instructions

Insert documents into a MongoDB collection

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
collectionYesCollection name
documentsYesDocuments to insert

Implementation Reference

  • The main handler function that executes the mongodb_insert tool by ensuring MongoDB connection, validating inputs, and performing insertMany operation on the specified collection.
    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)}` ); }
  • Defines the input schema for the mongodb_insert tool, specifying required collection name and array of documents.
    inputSchema: { type: 'object', properties: { collection: { type: 'string', description: 'Collection name', }, documents: { type: 'array', items: { type: 'object', }, description: 'Documents to insert', }, }, required: ['collection', 'documents'],
  • src/index.ts:442-462 (registration)
    Registers the mongodb_insert tool in the MCP server's tool list, including name, description, and input schema.
    { 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'], }, },
  • src/index.ts:558-559 (registration)
    Registers the dispatch handler in the switch statement for CallToolRequestSchema, routing mongodb_insert calls to handleMongoDBInsert.
    case 'mongodb_insert': return await this.handleMongoDBInsert(request.params.arguments);

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