Skip to main content
Glama
TrueOleg

MCP Mac Apps Server

by TrueOleg

mongodb_insert_document

Insert JSON documents into MongoDB collections from macOS applications. Specify database, collection, and document data to add records to your database.

Instructions

Вставляет документ в коллекцию

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseNameYesИмя базы данных
collectionNameYesИмя коллекции
documentYesJSON строка с документом для вставки

Implementation Reference

  • Python implementation of the mongodb_insert_document tool handler using pymongo to insert a single document into a MongoDB collection.
    def mongodb_insert_document(
        database_name: str, collection_name: str, document_json: str
    ) -> str:
        """Inserts document into collection"""
        client = MongoClient(MONGODB_URI)
        try:
            db = client[database_name]
            collection = db[collection_name]
            document = json.loads(document_json)
            result = collection.insert_one(document)
            return f'Document successfully inserted into collection "{collection_name}". ID: {result.inserted_id}'
        except Exception as e:
            raise Exception(f"Error inserting document: {str(e)}")
        finally:
            client.close()
  • TypeScript implementation of the mongodb_insert_document tool handler using MongoDB Node.js driver to insert a single document into a collection.
    private async mongodbInsertDocument(
      databaseName: string,
      collectionName: string,
      documentJson: string
    ) {
      const client = await this.getMongoClient();
      try {
        const db = client.db(databaseName);
        const collection = db.collection(collectionName);
        const document = JSON.parse(documentJson);
        const result = await collection.insertOne(document);
        
        return {
          content: [
            {
              type: "text",
              text: `Документ успешно вставлен в коллекцию "${collectionName}". ID: ${result.insertedId}`,
            },
          ],
        };
      } catch (error) {
        throw new Error(
          `Ошибка вставки документа: ${error instanceof Error ? error.message : String(error)}`
        );
      } finally {
        await client.close();
      }
    }
  • Input schema for mongodb_insert_document tool in the Python server's tools list.
        "name": "mongodb_insert_document",
        "description": "Inserts document into collection",
        "inputSchema": {
            "type": "object",
            "properties": {
                "databaseName": {
                    "type": "string",
                    "description": "Database name",
                },
                "collectionName": {
                    "type": "string",
                    "description": "Collection name",
                },
                "document": {
                    "type": "string",
                    "description": "JSON string with document to insert",
                },
            },
            "required": ["databaseName", "collectionName", "document"],
        },
    },
  • Input schema for mongodb_insert_document tool in the TypeScript server's tools list.
    name: "mongodb_insert_document",
    description: "Вставляет документ в коллекцию",
    inputSchema: {
      type: "object",
      properties: {
        databaseName: {
          type: "string",
          description: "Имя базы данных",
        },
        collectionName: {
          type: "string",
          description: "Имя коллекции",
        },
        document: {
          type: "string",
          description: "JSON строка с документом для вставки",
        },
      },
      required: ["databaseName", "collectionName", "document"],
    },
  • src/index.ts:359-364 (registration)
    Tool call dispatch/registration in the TypeScript server's CallToolRequest handler switch statement.
    case "mongodb_insert_document":
      return await this.mongodbInsertDocument(
        args?.databaseName as string,
        args?.collectionName as string,
        args?.document as string
      );

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/TrueOleg/MCP-expirements'

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