fix(mcp): refuse config and ack writes in read-only mode (#2103) - #2126
Merged
Conversation
Read-only gated on _MUTATING_TOOLS, which is the palace-write set the peer-writer lease consults to decide which calls need the palace mine lock. Two tools change state without touching the palace, so they are correctly absent from that set and were served on a --read-only server anyway: mempalace_hook_settings rewrites ~/.mempalace/config.json via MempalaceConfig.set_hook_setting, and mempalace_memories_filed_away unlinks ~/.mempalace/hook_state/last_checkpoint on both branches. Add _READ_ONLY_REFUSED_TOOLS and point the dispatch gate and the tools/list filter at it. _MUTATING_TOOLS and the peer-writer path are unchanged: adding the two names there instead would put a config-only tool under the palace lease, so a server that lost the lease to a peer would answer -32001 for a call the lease has no say over. mempalace_reconnect stays reachable on purpose and the comment records why, since clearing ChromaBackend._quarantined_paths lets the reopen rename a segment directory. The two --read-only help strings and the matching row in the remote-server guide said "the mutating tools", which now names the narrower set.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tightens MCP --read-only behavior so the server refuses additional state-changing tools that don’t mutate the palace DB (config writes and hook checkpoint-ack deletion), aligning read-only semantics with the daemon’s write classification and adding targeted regression tests.
Changes:
- Add
_READ_ONLY_REFUSED_TOOLSand gate bothtools/listand dispatch on it (instead of only_MUTATING_TOOLS). - Refuse
mempalace_hook_settingsandmempalace_memories_filed_awayin read-only mode, while keeping the peer-writer lease logic based on_MUTATING_TOOLS. - Expand tests to cover the new read-only refusals and ensure parity with
service.WRITE_TOOLS.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| website/guide/remote-server.md | Updates read-only flag description in the remote server guide. |
| tests/test_mcp_server.py | Adds unit tests asserting the refused set, daemon parity, and lease separation. |
| tests/test_mcp_http_transport.py | Adds HTTP-level tests proving config/ack writes are blocked in read-only mode. |
| mempalace/mcp_server.py | Introduces _READ_ONLY_REFUSED_TOOLS and uses it for read-only list/dispatch gating. |
| mempalace/cli.py | Updates CLI help text for --read-only. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+293
to
+294
| help="Serve a read-only tool surface: the tools that change state are hidden " | ||
| "from tools/list and refused at dispatch (env MEMPALACE_MCP_READ_ONLY)", |
| "--read-only", | ||
| action="store_true", | ||
| help="Expose recall only: mutating tools are hidden and refused", | ||
| help="Expose recall only: tools that change state are hidden and refused", |
| | `--backend` | config/env | Storage backend (e.g. `qdrant`) | | ||
| | `--tls-cert` / `--tls-key` | _(none)_ | PEM cert + key to terminate **TLS natively** (server speaks `https`) | | ||
| | `--read-only` | off | Expose recall only — the mutating tools are hidden and refused | | ||
| | `--read-only` | off | Expose recall only — the tools that change state are hidden and refused | |
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.
Summary
Conflict-resolved merge of #2103 onto current
develop.mempalace_hook_settingsandmempalace_memories_filed_away(state outside palace)Closes #2103.
Test plan