MongoDB MCP Server
by jonfreeland
geo_query
Execute geospatial queries on a MongoDB collection.
Supports:
- Finding points near a location
- Finding documents within a polygon, circle, or box
- Calculating distances between points
- GeoJSON and legacy coordinate pair formats
Requirements:
- Collection must have a geospatial index (2dsphere recommended)
- Coordinates should follow MongoDB conventions (longitude first, then latitude)
Examples:
- Find locations near a point (2 miles radius): use_mcp_tool with server_name: "mongodb", tool_name: "geo_query", arguments: { "collection": "restaurants", "operation": "near", "point": [-73.9667, 40.78], "maxDistance": 3218.69, // 2 miles in meters "distanceField": "distance" }
- Find locations within a polygon: use_mcp_tool with server_name: "mongodb", tool_name: "geo_query", arguments: { "collection": "properties", "operation": "geoWithin", "geometry": { "type": "Polygon", "coordinates": [ [[-73.958, 40.8], [-73.94, 40.79], [-73.95, 40.76], [-73.97, 40.76], [-73.958, 40.8]] ] } }
Input Schema
Name | Required | Description | Default |
---|---|---|---|
additionalFilter | No | Additional MongoDB query criteria to combine with geospatial query | |
collection | Yes | Collection name | |
database | No | Database name (optional if default database is configured) | |
distanceField | No | Field to store calculated distances (for near/nearSphere queries) | |
geometry | No | GeoJSON geometry for geoWithin/geoIntersects queries | |
limit | No | Maximum number of results to return | |
locationField | No | Field containing geospatial data (default: "location") | |
maxDistance | No | Maximum distance in meters for near/nearSphere queries | |
minDistance | No | Minimum distance in meters for near/nearSphere queries | |
operation | Yes | Geospatial operation to perform | |
point | No | Point coordinates [longitude, latitude] for near/nearSphere queries | |
spherical | No | Calculate distances on a sphere (Earth) rather than flat plane |