Skip to main content
Glama

MongoDB MCP Server for LLMs

by vivek1612
MIT License
109
  • Apple
create-index.ts1.3 kB
import { BaseTool, ToolParams } from "../base/tool.js"; import { IndexDirection } from "mongodb"; import { db } from "../../mongodb/client.js"; interface CreateIndexParams extends ToolParams { collection: string; indexSpec: { [key: string]: IndexDirection }; [key: string]: unknown; } export class CreateIndexTool extends BaseTool<CreateIndexParams> { name = "createIndex"; description = "Create a new index on a collection"; inputSchema = { type: "object" as const, properties: { collection: { type: "string", description: "Name of the collection", }, indexSpec: { type: "object", description: "Index specification (e.g., { field: 1 } for ascending index)", }, }, required: ["collection", "indexSpec"], }; async execute(params: CreateIndexParams) { try { const collection = this.validateCollection(params.collection); const indexName = await db .collection(collection) .createIndex(params.indexSpec); return { content: [ { type: "text" as const, text: JSON.stringify({ indexName }, null, 2), }, ], isError: false, }; } catch (error) { return this.handleError(error); } } }

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/vivek1612/mongodb-mcp'

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