chore-mcp-server-god-module-handler-extraction: extract MCP tool handlers#73
Merged
emp3thy merged 1 commit intoJun 11, 2026
Conversation
…-10 — extract tool handlers from server.py god module
Split the 1617-LOC mcp/server.py into focused modules:
- handlers/ package: one stateless handler class per tool domain
(observations, reflections, episodes, semantics, knowledge, sessions),
merged into a {tool_name: handler} registry by build_registry(), which
raises on duplicate tool names. _call_tool is now a pure lookup.
- tools.py: the 22 Tool() name/schema declarations (unchanged set).
- serializers.py: JSON payload builders for the synthesize tools.
- synth_audit.py: synthesize audit-log append + context manager.
- _util.py: run_best_effort + session-id resolution helpers.
- server.py (378 LOC): wiring only — create_server constructs each
service once, including SemanticMemoryService, previously instantiated
inline in four separate handlers.
Test changes are import-path updates only. README MCP-tools section now
points at tools.py for schemas; other docs unaffected.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟢 Claude BugBot Analysis
No bugs found in the changes. This PR is a pure structural refactoring that extracts tool handlers, serializers, synth-audit helpers, and tool definitions into dedicated modules under better_memory/mcp/. All moved code is behaviorally identical to the originals: default_reasons covers all four outcome enum values, best-effort wrappers are copied verbatim, the registry dispatch correctly delegates to the same handler logic, and both _resolve_session_id and _tool_definitions are actively used in server.py at lines 210 and 277 respectively.
No bugs were detected in this PR.
6 tasks
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.
Extracts the 22 inline tool handlers from the 1617-LOC
better_memory/mcp/server.pygod module into per-domain handler classes (handlers/package: observations, reflections, episodes, semantics, knowledge, sessions) registered via a{tool_name: handler}registry, reducing_call_toolto a pure lookup. Tool name/schema declarations move tomcp/tools.py(set unchanged, 22 tools), JSON payload builders tomcp/serializers.py, the synthesize audit log tomcp/synth_audit.py, andrun_best_effort/session-id helpers tomcp/_util.py. All services — includingSemanticMemoryService, previously instantiated inline in four separate handlers — are now constructed once increate_server()and injected.server.pyis down to 378 LOC of wiring.Closes chore-mcp-server-god-module-handler-extraction-2026-06-10.
Test plan
BETTER_MEMORY_PROJECTcleared — the Ralph executor's env var leaks into project-inference tests; pre-existing, unrelated)ruff check better_memory/mcp tests/mcp: 5 pre-existing errors in untouched test files (clean-tree baseline: 6)pyright better_memory/mcp: 0 errorsPBI bundle:
.ralph/current/chore-mcp-server-god-module-handler-extraction-2026-06-10onralph-queue.🤖 Generated with Claude Code