fix(mcp): harden error messages and add read-only server mode#181
fix(mcp): harden error messages and add read-only server mode#181travisbreaks wants to merge 1 commit into
Conversation
Security: - Replace 5 instances of `str(e)` in MCP tool error responses with generic messages. Raw exception strings can leak internal file paths, DB schema details, and ChromaDB internals to MCP clients. - Full exception details are still logged to stderr via logger.exception() for debugging. Read-only mode: - Add `--read-only` CLI flag to mcp_server.py - In read-only mode, write tools (add_drawer, delete_drawer, kg_add, kg_invalidate, diary_write) return a JSON-RPC error and are hidden from tools/list - Read tools continue to work normally Tests: - 4 new tests: read-only blocks writes, allows reads, hides write tools from listing, and error responses don't leak exception strings Co-Authored-By: Tadao <tadao@travisfixes.com>
PR Review: fix(mcp): harden error messages and add read-only server modeExecutive Summary
Affected Areas: Business Impact: Prevents leaking internal paths/schema details to MCP clients; enables safe read-only deployments for shared/demo palaces. Flow Changes: Write tools ( Ratings
PR Health
High Priority Issues(Must fix before merge) 🐛 #1:
|
web3guru888
left a comment
There was a problem hiding this comment.
🔧 Review of #181 — fix(mcp): harden error messages and add read-only server mode
Scope: +131/−12 · 2 file(s) · touches core
⚠️ mempalace/mcp_server.py(modified: +44/−12)tests/test_mcp_server.py(modified: +87/−0)
Technical Analysis
- 🔌 MCP server dispatch changes — verify JSON-RPC compliance and backward compatibility
Issues
⚠️ Touchesmempalace/mcp_server.py— Core MCP server — maintainer guards this closely
Suggestions
- Magic number(s) 32600 — consider extracting to named constant(s)
- 📋 PR checklist: 2/3 completed — 1 item(s) still unchecked
Strengths
- ✅ Includes test coverage
🟡 Needs attention — touches guarded files and has items to address.
🏛️ Reviewed by MemPalace-AGI · Autonomous research system with perfect memory · Showcase: Truth Palace of Atlantis
|
Hi, thanks for the contribution. This PR has merge conflicts with Could you rebase onto If this change is no longer relevant, feel free to close the PR. (This message is part of a periodic backlog pass, sent to all open PRs that match this state.) |
Summary
Error hardening
str(e)in MCP tool error responses with generic messageslogger.exception()for operator debuggingRead-only mode
--read-onlyCLI flag:python -m mempalace.mcp_server --read-onlyadd_drawer,delete_drawer,kg_add,kg_invalidate,diary_write) return a JSON-RPC-32600error in read-only modetools/listin read-only modeThis is useful for shared deployments where the MCP server should expose palace data to AI agents without allowing mutations.
Context
Cherry-picked from the security items in PR #34, which was asked to be split into focused PRs. The error hardening and read-only mode are the remaining unmerged security improvements from that PR.
Test plan
pytest tests/ -vpasses (4 new tests, 114 total)ruff checkandruff format --checkpass🤖 Generated with Claude Code