MongoDB MCP Server

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:

  1. 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" }
  2. 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

NameRequiredDescriptionDefault
additionalFilterNoAdditional MongoDB query criteria to combine with geospatial query
collectionYesCollection name
databaseNoDatabase name (optional if default database is configured)
distanceFieldNoField to store calculated distances (for near/nearSphere queries)
geometryNoGeoJSON geometry for geoWithin/geoIntersects queries
limitNoMaximum number of results to return
locationFieldNoField containing geospatial data (default: "location")
maxDistanceNoMaximum distance in meters for near/nearSphere queries
minDistanceNoMinimum distance in meters for near/nearSphere queries
operationYesGeospatial operation to perform
pointNoPoint coordinates [longitude, latitude] for near/nearSphere queries
sphericalNoCalculate distances on a sphere (Earth) rather than flat plane

Input Schema (JSON Schema)

{ "properties": { "additionalFilter": { "description": "Additional MongoDB query criteria to combine with geospatial query", "type": "object" }, "collection": { "description": "Collection name", "type": "string" }, "database": { "description": "Database name (optional if default database is configured)", "type": "string" }, "distanceField": { "description": "Field to store calculated distances (for near/nearSphere queries)", "type": "string" }, "geometry": { "description": "GeoJSON geometry for geoWithin/geoIntersects queries", "type": "object" }, "limit": { "description": "Maximum number of results to return", "maximum": 1000, "minimum": 1, "type": "number" }, "locationField": { "description": "Field containing geospatial data (default: \"location\")", "type": "string" }, "maxDistance": { "description": "Maximum distance in meters for near/nearSphere queries", "type": "number" }, "minDistance": { "description": "Minimum distance in meters for near/nearSphere queries", "type": "number" }, "operation": { "description": "Geospatial operation to perform", "enum": [ "near", "geoWithin", "geoIntersects", "nearSphere" ], "type": "string" }, "point": { "description": "Point coordinates [longitude, latitude] for near/nearSphere queries", "items": { "type": "number" }, "type": "array" }, "spherical": { "description": "Calculate distances on a sphere (Earth) rather than flat plane", "type": "boolean" } }, "required": [ "collection", "operation" ], "type": "object" }