Skip to content

MongoDB: Alert Safe Mode prompts on every read query; let confirmed reads skip confirmation #3290

Closed

Description

@shanegrouber

Summary

On a MongoDB connection set to Alert, every query asks for confirmation, including plain find and aggregate reads. I understand why: MongoDB can't open a read-only session, so MongoDBPlugin.supportsReadOnlyMode = false, and DefaultExecutionGate.resolveEffectiveWrite treats every statement as a write. The Safe Mode docs describe this under "What always counts as a write".

Repro: on a MongoDB connection set to Alert, run db.c.aggregate([{"$limit": 1}, {"$project": {"_id": 1}}]) in the query editor. It asks for confirmation even though QueryClassifier classifies it as .safe. The same query sent through the MCP server (execute_query) also asks for confirmation. That connection's AI policy is "Ask each time", though, so I can't tell whether the MCP prompt comes from Safe Mode or from the AI policy.

In practice, Alert is unusable for day-to-day reads on a production Mongo connection. The remaining choices are to confirm every query or to switch to Silent and lose the write check entirely. Read-Only isn't an option either, because on Mongo it blocks reads too.

Request

Let Safe Mode use QueryClassifier's verdict for MongoDB statements it classifies as .safe, so Alert (and Safe Mode) only confirm writes, as they already do on SQL drivers. If you'd rather not change the default, a per-connection opt-in like "Trust read classification" would work too.

Classifier issues that would need fixing first

mongoClassification in QueryClassifier.swift currently reports common reads as writes. I checked these through the MCP server on a connection set to read-only for external clients; each "write" was refused with "Connection is read only for external clients":

# Query Expected Actual
T0 db.c.aggregate([{"$limit": 1}, {"$project": {"_id": 1}}]) read read ✅
T1 db.c.aggregate([{"$match": {"k": {"$nin": ["x"]}}}]) read write ❌
T2 db.c.aggregate([{"$project": {"m": {"$mergeObjects": [{"a": 1}, {"b": 2}]}}}]) read write ❌
T3 db.c.aggregate([{"$project": {"o": "$outcome"}}]) read write ❌
T4 db.c.aggregate([...]).toArray() read write ❌
T5 db.c.find({}, {"_id": 1}).limit(1) read write ❌

Causes:

  • T1: bracketedMethodNames treats any [ followed by a quote as a bracket method call, so ["x"] inside $in/$nin yields a method named x. It's not in mongoReadMethods, so the query counts as a write. Only treating [ as a method call when it directly follows an identifier or ) would keep the db.c["deleteMany"] protection.
  • T2/T3: lowered.contains("$out") || lowered.contains("$merge") is a substring check. It matches $mergeObjects and any field path that starts with out. Matching only the stage keys ("$out":, $merge:) would fix it.
  • T4/T5: cursor methods such as toArray, limit, skip, sort, pretty, itcount, next, hasNext, batchSize, projection, hint, maxTimeMS, collation and comment aren't in mongoReadMethods.

These also affect MCP/AI clients today. On a connection that's read-only for external clients, ordinary aggregates get refused as writes.

Environment: TablePro 0.78.0, macOS 15.5 (Darwin 24.5), MongoDB Atlas.

Activity

  1. datlechin commented on Oct 8, 2026

    @datlechin
    Member

    Thank you @shanegrouber for reporting, I'm checking it right now

  2. self-assigned this
    on Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions