Skip to main content
Glama
yaoxiaolinglong

MCP-MongoDB-MySQL-Server

mongodb_find

Query documents in a MongoDB collection using filters, sorting, and pagination to retrieve specific data.

Instructions

Find documents in a MongoDB collection

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
collectionYesCollection name
filterNoMongoDB query filter
limitNoMaximum number of documents to return
skipNoNumber of documents to skip
sortNoSort criteria

Implementation Reference

  • Executes the mongodb_find tool: ensures MongoDB connection, validates collection name, constructs filter and options (limit, skip, sort), performs find query on the collection, and returns results as JSON string.
    private async handleMongoDBFind(args: any) {
      await this.ensureMongoConnection();
    
      if (!args.collection) {
        throw new McpError(ErrorCode.InvalidParams, 'Collection name is required');
      }
    
      try {
        const collection = this.mongoDB!.collection(args.collection);
        const filter = args.filter || {};
        const options: any = {};
        
        if (args.limit) options.limit = args.limit;
        if (args.skip) options.skip = args.skip;
        if (args.sort) options.sort = args.sort;
    
        const documents = await collection.find(filter, options).toArray();
        return {
          content: [
            {
              type: 'text',
              text: JSON.stringify(documents, null, 2),
            },
          ],
        };
      } catch (error) {
        throw new McpError(
          ErrorCode.InternalError,
          `Failed to find documents: ${getErrorMessage(error)}`
        );
      }
    }
  • Defines the input schema for the mongodb_find tool, specifying parameters like collection (required), filter, limit, skip, and sort (all optional).
    inputSchema: {
      type: 'object',
      properties: {
        collection: {
          type: 'string',
          description: 'Collection name',
        },
        filter: {
          type: 'object',
          description: 'MongoDB query filter',
          optional: true
        },
        limit: {
          type: 'number',
          description: 'Maximum number of documents to return',
          optional: true
        },
        skip: {
          type: 'number',
          description: 'Number of documents to skip',
          optional: true
        },
        sort: {
          type: 'object',
          description: 'Sort criteria',
          optional: true
        }
      },
      required: ['collection'],
    },
  • src/index.ts:408-441 (registration)
    Registers the mongodb_find tool in the MCP server's tools list, providing name, description, and input schema for the ListTools request.
    {
      name: 'mongodb_find',
      description: 'Find documents in a MongoDB collection',
      inputSchema: {
        type: 'object',
        properties: {
          collection: {
            type: 'string',
            description: 'Collection name',
          },
          filter: {
            type: 'object',
            description: 'MongoDB query filter',
            optional: true
          },
          limit: {
            type: 'number',
            description: 'Maximum number of documents to return',
            optional: true
          },
          skip: {
            type: 'number',
            description: 'Number of documents to skip',
            optional: true
          },
          sort: {
            type: 'object',
            description: 'Sort criteria',
            optional: true
          }
        },
        required: ['collection'],
      },
    },
  • src/index.ts:556-557 (registration)
    Switch case in the CallToolRequestSchema handler that routes mongodb_find tool calls to the handleMongoDBFind method.
    case 'mongodb_find':
      return await this.handleMongoDBFind(request.params.arguments);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden for behavioral disclosure. While 'find' implies a read operation, it doesn't specify whether this requires specific permissions, what happens with large result sets, whether it's paginated, or what the return format looks like. For a database query tool with zero annotation coverage, this leaves significant behavioral questions unanswered.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that gets straight to the point with zero wasted words. It's appropriately sized for a basic find operation and front-loads the essential information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given this is a database query tool with no annotations, no output schema, and complex parameters (including nested objects for filter and sort), the description is insufficient. It doesn't explain what the tool returns, how errors are handled, or provide any context about MongoDB-specific behavior. The description should do more to compensate for the lack of structured metadata.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so all parameters are documented in the schema. The description doesn't add any parameter semantics beyond what the schema already provides - it doesn't explain MongoDB query syntax, sort format, or provide examples. The baseline of 3 is appropriate when the schema does all the parameter documentation work.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'find' and resource 'documents in a MongoDB collection', making the purpose immediately understandable. It distinguishes from obvious siblings like mongodb_insert, mongodb_update, and mongodb_delete by specifying a read operation. However, it doesn't explicitly differentiate from query or execute tools that might also retrieve data.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. There's no mention of when to choose mongodb_find over query, execute, or other data retrieval methods. It also doesn't indicate prerequisites like needing an established connection first.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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