MongoDB MCP Server

query

Execute a read-only query on a collection using MongoDB query syntax.

Supports both JSON and CSV output formats:

  • Use outputFormat="json" for standard JSON (default)
  • Use outputFormat="csv" for comma-separated values export

Best Practices:

  • Use projections to fetch only needed fields
  • Add limits for large collections
  • Use sort for consistent ordering

Example - Standard Query: use_mcp_tool with server_name: "mongodb", tool_name: "query", arguments: { "collection": "users", "filter": { "age": { "$gte": 21 } }, "projection": { "name": 1, "email": 1 }, "sort": { "name": 1 }, "limit": 100 }

Example - CSV Export: use_mcp_tool with server_name: "mongodb", tool_name: "query", arguments: { "collection": "users", "filter": { "active": true }, "outputFormat": "csv", "formatOptions": { "includeHeaders": true, "delimiter": "," } }

Input Schema

NameRequiredDescriptionDefault
collectionYesCollection name
databaseNoDatabase name (optional if default database is configured)
filterYesMongoDB query filter using standard MongoDB operators ($eq, $gt, $in, etc.)
formatOptionsNoFormat-specific options
limitNoMaximum number of documents to return (optional)
outputFormatNoOutput format for results (json or csv)
projectionNoMongoDB projection to specify fields to return (optional)
sortNoMongoDB sort specification (optional)

Input Schema (JSON Schema)

{ "properties": { "collection": { "description": "Collection name", "type": "string" }, "database": { "description": "Database name (optional if default database is configured)", "type": "string" }, "filter": { "description": "MongoDB query filter using standard MongoDB operators ($eq, $gt, $in, etc.)", "type": "object" }, "formatOptions": { "description": "Format-specific options", "properties": { "delimiter": { "description": "CSV delimiter character (default: comma)", "type": "string" }, "includeHeaders": { "description": "Whether to include header row in CSV (default: true)", "type": "boolean" } }, "type": "object" }, "limit": { "description": "Maximum number of documents to return (optional)", "maximum": 1000, "minimum": 1, "type": "number" }, "outputFormat": { "description": "Output format for results (json or csv)", "enum": [ "json", "csv" ], "type": "string" }, "projection": { "description": "MongoDB projection to specify fields to return (optional)", "type": "object" }, "sort": { "description": "MongoDB sort specification (optional)", "type": "object" } }, "required": [ "collection", "filter" ], "type": "object" }