MongoDB MCP Server
by jonfreeland
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
Name | Required | Description | Default |
---|---|---|---|
collection | Yes | Collection name | |
database | No | Database name (optional if default database is configured) | |
filter | Yes | MongoDB query filter using standard MongoDB operators ($eq, $gt, $in, etc.) | |
formatOptions | No | Format-specific options | |
limit | No | Maximum number of documents to return (optional) | |
outputFormat | No | Output format for results (json or csv) | |
projection | No | MongoDB projection to specify fields to return (optional) | |
sort | No | MongoDB sort specification (optional) |