Repository navigation
mcp-memgraph: harden read-only mode - #623
Open
katarinasupe wants to merge 3 commits into
Open
katarinasupe wants to merge 3 commits into
katarinasupe wants to merge 3 commits into
Conversation
…d list In read-only mode, queries now run in a read transaction, so Memgraph rejects anything that writes, including write procedures. Queries that can't run in a transaction are allowed only for SHOW and PROFILE of a read query. Reads that only mention a write keyword are no longer refused.
katarinasupe
marked this pull request as draft
October 28, 2026 14:47
A read transaction alone lets through procedures Memgraph flags as reads that write through their own transaction or connection (do.*, periodic.*), code and file procedures, and auth commands. Refuse those and write keywords outside strings and comments before the query runs, strip leading comments (some Memgraph versions crash on a comment before EXPLAIN/PROFILE), and allow DATA DIRECTORY LOCK STATUS. Tests now check that blocked queries leave the database unchanged. The README says read-only mode is best effort.
Match procedures that can write anywhere in the query and under their APOC names, unquote backticked names in the same pass as strings and comments, treat U+180E and zero-width characters as whitespace, and add CLEAR, model training and outbound-request procedures. Keywords after a dot or used as a map key no longer count, so map.merge and n.set are allowed. The README says the text check is not a parser and can be bypassed.
katarinasupe
marked this pull request as ready for review
October 28, 2026 15:21
antejavor
approved these changes
Oct 29, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Read-only mode (the default) only blocked queries containing
CREATE,MERGE,DELETE,REMOVE,SETorDROP. Writes without those words ran: write procedures (schema.assert,refactor.*), admin commands (ANALYZE GRAPH,FREE MEMORY,STORAGE MODE), and procedures flagged as reads that write in their own transaction or touch files and code (do.*,periodic.*,mg.create_module_file+mg.load,csv_utils.*). Reads likeRETURN 'set'were refused.Now, in layers:
SHOW ...,DATA DIRECTORY LOCK STATUSandPROFILEof a read query run.EXPLAIN/PROFILEcrashes Memgraph 3.14).This is still a best-effort guard: the text check is not a Cypher parser, and a custom module flagged as read-only can do anything. The README says so. A sturdier version would check Memgraph's
EXPLAINplan instead of the query text. Known refusals:EXPLAINof a write query,SET SESSION TRACE.Tests compare database state before and after each case (25 blocked, 15 reads) against
memgraph-mage:3.14.0; the full suite passes.