Skip to main content
Glama

MCP-MongoDB-MySQL-Server

mongodb_create_collection

Create a new collection in MongoDB with specified name and optional settings using the MCP server for efficient database management.

Instructions

Create a new collection in MongoDB

Input Schema

NameRequiredDescriptionDefault
collectionYesCollection name
optionsNoCollection options

Input Schema (JSON Schema)

{ "properties": { "collection": { "description": "Collection name", "type": "string" }, "options": { "description": "Collection options", "optional": true, "type": "object" } }, "required": [ "collection" ], "type": "object" }

Implementation Reference

  • The handler function that executes the mongodb_create_collection tool. It ensures the MongoDB connection, validates the collection name, creates the collection using db.createCollection(), handles errors, and returns a success message.
    private async handleMongoDBCreateCollection(args: any) { await this.ensureMongoConnection(); if (!args.collection) { throw new McpError(ErrorCode.InvalidParams, 'Collection name is required'); } try { await this.mongoDB!.createCollection(args.collection, args.options || {}); return { content: [ { type: 'text', text: `Collection ${args.collection} created successfully`, }, ], }; } catch (error) { throw new McpError( ErrorCode.InternalError, `Failed to create collection: ${getErrorMessage(error)}` ); } }
  • src/index.ts:513-531 (registration)
    Registration of the mongodb_create_collection tool in the ListTools handler, specifying name, description, and input schema.
    { name: 'mongodb_create_collection', description: 'Create a new collection in MongoDB', inputSchema: { type: 'object', properties: { collection: { type: 'string', description: 'Collection name', }, options: { type: 'object', description: 'Collection options', optional: true } }, required: ['collection'], }, }
  • Input schema for the mongodb_create_collection tool, defining required 'collection' parameter and optional 'options'.
    inputSchema: { type: 'object', properties: { collection: { type: 'string', description: 'Collection name', }, options: { type: 'object', description: 'Collection options', optional: true } }, required: ['collection'], },
  • src/index.ts:564-565 (registration)
    Dispatch case in the CallToolRequest handler that routes to the mongodb_create_collection handler function.
    case 'mongodb_create_collection': return await this.handleMongoDBCreateCollection(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