Skip to main content
Glama

MongoDB MCP Server for LLMs

by vivek1612
MIT License
109
  • Apple
find.ts1.59 kB
import { db } from "../../mongodb/client.js"; import { BaseTool, ToolParams } from "../base/tool.js"; export interface FindParams extends ToolParams { collection: string; filter?: Record<string, unknown>; limit?: number; projection?: Record<string, unknown>; } export class FindTool extends BaseTool<FindParams> { name = "find"; description = "Query documents in a collection using MongoDB query syntax"; inputSchema = { type: "object" as const, properties: { collection: { type: "string", description: "Name of the collection to query", }, filter: { type: "object", description: "MongoDB query filter", default: {}, }, limit: { type: "number", description: "Maximum documents to return", default: 10, minimum: 1, maximum: 1000, }, projection: { type: "object", description: "Fields to include/exclude", default: {}, }, }, required: ["collection"], }; async execute(params: FindParams) { try { const collection = this.validateCollection(params.collection); const results = await db .collection(collection) .find(params.filter || {}) .project(params.projection || {}) .limit(Math.min(params.limit || 10, 1000)) .toArray(); return { content: [ { type: "text" as const, text: JSON.stringify(results, 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