Skip to content

[Feature Request]: Add index check before query #287

Open
@Crushdada

Description

@Crushdada

Feature: Index Check Before Query

To improve query performance and prevent slow queries, add an indexCheck environment variable to MCP Server. When indexCheck=true, all MongoDB queries (find, aggregate, update, etc.) will first use explain('queryPlanner') to check if the query will hit an index. If not, the query is rejected and a friendly error message is returned, prompting the user to optimize the query or add an index. This feature helps avoid accidental collection scans and protects database performance.

Key Points:

  • Controlled by MDB_MCP_INDEX_CHECK environment variable

  • Automatically checks index usage with explain('queryPlanner') before executing queries

  • If no index is used, returns an error and does not execute the query

  • Applies to all query operations (find, aggregate, update, etc.)

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions