Skip to content

refactor(mcp): delete dead legacy MCP registrar code - #3118

Merged
Sinity merged 3 commits into
masterfrom
feature/mcp/retire-legacy-registrars
Jul 18, 2026
Merged

Sinity merged 3 commits into
masterfrom
feature/mcp/retire-legacy-registrars

Conversation

@Sinity

@Sinity Sinity commented Jul 18, 2026

Copy link
Copy Markdown
Owner

Summary

Deletes the ~7,000 lines of MCP registrar code and declarations that were
made fully dead weight by the six-tool cutover (#3095) but never removed —
the retired per-operation registrar modules, their glue, and an inert
~103-row legacy declaration table.

Problem

#3095 replaced the ~97-tool MCP surface with query/read/get/explain/
context/status plus the privileged write/judge/run/maintenance
transactions. The tool registrations were removed (no role registers the
old per-operation tools), but ~2,480 lines of registrar-module code, ~1,000
more dead lines in server_tools.py, and an inert ~103-row legacy
declaration table in registry.py were left sitting in the tree unused.

Solution

  • Deleted server_context_tools.py, server_insight_tools.py,
    server_maintenance_tools.py, server_mutation_tools.py,
    server_personal_state_tools.py (2,480 lines) — relocated
    _build_mcp_scope_filter into server_cutover.py's maintenance()
    dispatch before deleting its source file.
  • Gutted server_tools.py to its 19-line register_tools() shim.
  • polylogue/mcp/declarations/registry.py: deleted the dead _TOOL_ROWS
    table (distinct from the live _CUTOVER_TOOL_ROWS) and its exclusively-
    supporting machinery (_WORKFLOW_COVERAGE, _PROMPT_ALTERNATIVES,
    _RESOURCE_ALTERNATIVES, _DISCOVERY, _CONTINUATION, _TARGET_ROUTE,
    _OBSERVED_USE, _validate_inventory_tables, _family_id, the
    never-called _build_declaration) — confirmed none of it feeds
    MCP_TOOL_DECLARATIONS, which is built exclusively from
    _CUTOVER_TOOL_ROWS. Kept _ToolRow/_compatibility/_python_parity,
    which _cutover_declaration still uses. 3,716 → 528 lines.
  • Repointed six operations/specs.py code_refs from the deleted
    server_mutation_tools.py/server_personal_state_tools.py functions to
    server_cutover._dispatch_write.
  • Rewrote two test_mcp_call_log.py tests to AST-parse server_cutover.py
    instead of the deleted per-tool modules, and deleted a third
    (test_every_session_tool_forwards_telemetry_identity) whose glob-scan
    premise — many individually-named @mcp.tool() functions, each with its
    own async_safe_call — no longer holds now that write()/maintenance()
    collapse ~20 former per-operation tools into one dispatch with one call
    site; the two rewritten parametrized tests already cover the same
    telemetry-forwarding invariant for the collapsed shape.
  • Renamed test_query_tool_schema_derivation.py →
    test_query_request_contracts.py, dropping 8 tests whose premise
    (deriving schemas from the deleted register_query_tools) no longer
    applies; kept 5 tests exercising MCPSessionQueryRequest/payload builders
    directly.
  • Regenerated docs/plans/topology-target.yaml /
    docs/topology-status.md; marked architecture-hotspots.md rows 8a/8b
    resolved.

Verification

  • devtools test tests/unit/mcp/ tests/unit/verification/test_code_refs_resolve.py
    — 368 passed (the code-refs drift gate is the main risk surface for this
    diff).
  • devtools verify --quick — all static gates green (also re-ran on push
    via the pre-push hook).
  • mypy --strict / ruff clean on every touched file.
  • devtools verify --all: surfaced a large body of pre-existing
    baseline failures unrelated to this diff — MCP tool-name test debt from
    fix(mcp): harden six-tool cutover — session correlation, status(operation), SessionStart preamble #3095 in files outside tests/unit/mcp/ (_tools["list_sessions"],
    _tools["search"], _tools["cost_outlook"], _tools["maintenance_preview"]
    still referenced by ~6 test files), plus unrelated CLI/migration drift
    from other recent master commits (no_color_requested() signature drift,
    a stale migration-count assertion). None reproduce from clearing stale
    fixture caches; none touch any file this diff modifies. Tracking the
    MCP-tool-name debt as an immediate follow-up PR; filing the unrelated
    drift separately rather than expanding this PR's scope.

Ref polylogue-t46.8

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai

coderabbitai Bot commented Jul 18, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@Sinity, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 12 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: c4f165fe-b8ca-461e-af2c-e65a110ef2a4

📥 Commits

Reviewing files that changed from the base of the PR and between a53785b and 5d28a6e.

📒 Files selected for processing (16)
  • docs/architecture-hotspots.md
  • docs/plans/topology-target.yaml
  • docs/topology-status.md
  • polylogue/mcp/declarations/registry.py
  • polylogue/mcp/query_contracts.py
  • polylogue/mcp/server_context_tools.py
  • polylogue/mcp/server_cutover.py
  • polylogue/mcp/server_insight_tools.py
  • polylogue/mcp/server_maintenance_tools.py
  • polylogue/mcp/server_mutation_tools.py
  • polylogue/mcp/server_personal_state_tools.py
  • polylogue/mcp/server_tools.py
  • polylogue/operations/import_contracts.py
  • polylogue/operations/specs.py
  • tests/unit/mcp/test_mcp_call_log.py
  • tests/unit/mcp/test_query_request_contracts.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/mcp/retire-legacy-registrars

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sinity and others added 3 commits July 18, 2026 19:24
Ref polylogue-t46.8

Problem: the six-tool MCP cutover (#3095) replaced the ~97-tool
registration surface with query/read/get/explain/context/status plus
the privileged write/judge/run/maintenance transactions, but left the
old per-operation registrar modules, their glue, and an inert ~103-row
legacy declaration table sitting in the tree unused.

What changed:
- Deleted server_context_tools.py, server_insight_tools.py,
  server_maintenance_tools.py, server_mutation_tools.py,
  server_personal_state_tools.py (2,480 lines) — no role registers
  them; register_tools() only calls register_cutover_read_tools/
  register_cutover_privileged_tools.
- Relocated _build_mcp_scope_filter from server_maintenance_tools.py
  into server_cutover.py's maintenance() dispatch before deleting the
  source file.
- Gutted server_tools.py to its 19-line register_tools() shim.
- polylogue/mcp/declarations/registry.py: deleted the dead ~103-row
  _TOOL_ROWS table and its exclusively-supporting machinery
  (_WORKFLOW_COVERAGE, _PROMPT_ALTERNATIVES, _RESOURCE_ALTERNATIVES,
  _DISCOVERY, _CONTINUATION, _TARGET_ROUTE, _OBSERVED_USE,
  _validate_inventory_tables, _family_id, the never-called
  _build_declaration) — none of it fed MCP_TOOL_DECLARATIONS, which is
  built exclusively from the live _CUTOVER_TOOL_ROWS. Kept _ToolRow,
  _compatibility, and _python_parity, which _cutover_declaration still
  uses. 3716 -> 528 lines.
- Repointed six operations/specs.py code_refs from the deleted
  server_mutation_tools.py/server_personal_state_tools.py functions to
  server_cutover._dispatch_write.
- Rewrote two test_mcp_call_log.py tests to AST-parse server_cutover.py
  instead of the deleted per-tool modules, and deleted a third
  (test_every_session_tool_forwards_telemetry_identity) whose glob-scan
  premise — many individually-named @mcp.tool() functions, each with
  its own async_safe_call — no longer holds now that write()/
  maintenance() collapse ~20 former per-operation tools into one
  dispatch with one call site; the two rewritten parametrized tests
  already cover the same telemetry-forwarding invariant for the
  collapsed shape.
- Renamed test_query_tool_schema_derivation.py ->
  test_query_request_contracts.py, dropping 8 tests whose premise
  (deriving schemas from the deleted register_query_tools) no longer
  applies; kept 5 tests exercising MCPSessionQueryRequest/payload
  builders directly.
- Regenerated docs/plans/topology-target.yaml and
  docs/topology-status.md (devtools render topology-projection /
  topology-status) to drop the five deleted files' rows.
- Marked architecture-hotspots.md rows 8a/8b resolved.

Verification: devtools test tests/unit/mcp/
tests/unit/verification/test_code_refs_resolve.py (368 passed);
devtools verify --quick (all static gates green); mypy --strict and
ruff clean on every touched file.

Note: devtools verify --all surfaced a large body of pre-existing
baseline failures unrelated to this diff (MCP tool-name test debt from
drift from other recent master commits) — none reproduce from clearing
stale fixture caches, none touch any file this diff modifies. Tracked
separately, not fixed here to keep this PR's boundary to dead-code
deletion.

Co-Authored-By: Claude <[email protected]>
The prior commit's git add invocation listed the stale rename source
path alongside the new path in one call; git aborted the whole
invocation on the missing pathspec, so the previous commit silently
kept the file's pre-trim content (still importing the deleted
register_query_tools). This lands the actual trimmed content that was
already verified passing before the previous commit.

Verification: devtools test tests/unit/mcp/test_query_request_contracts.py
tests/unit/verification/test_code_refs_resolve.py (207 passed); mypy
--strict and ruff clean.

Co-Authored-By: Claude <[email protected]>
14 unrelated commits landed on master between this branch's creation
and now; topology-target.yaml/topology-status.md track file counts
that drifted as a result. Mechanical regen only.

Co-Authored-By: Claude <[email protected]>
@Sinity
Sinity force-pushed the feature/mcp/retire-legacy-registrars branch from 6fbcfec to 5d28a6e Compare July 18, 2026 17:26
@Sinity
Sinity merged commit 87efae8 into master Jul 18, 2026
3 checks passed
@Sinity
Sinity deleted the feature/mcp/retire-legacy-registrars branch July 18, 2026 17:29
Sinity added a commit that referenced this pull request Jul 18, 2026
…3121)

## Summary

Fixes ~20 tests left broken by the six-tool MCP cutover (#3095) that
still
call individually-named MCP tools which no longer exist, and fixes a
real
production bug (`NameError`) found while doing so in `maintenance()`'s
preview/execute path.

**Stacked on #3118** (dead-code cleanup) — base branch is
`feature/mcp/retire-legacy-registrars`, not `master`. Merge #3118 first.

## Problem

`devtools verify --all` (the first full run since #3095 merged) found

`tests/unit/storage/{test_surface_parity_adapters,test_query_parity}.py`
and
`tests/unit/maintenance/{test_scope_filter_envelope_contract,
test_envelope_contracts,test_scope_filter}.py` still calling

`server._tool_manager._tools["list_sessions"|"search"|"maintenance_preview"]`
— tools retired by the cutover. Deterministic `KeyError` on every run,
confirmed via isolated reruns (not a fixture-cache artifact). Never
caught by
`devtools test tests/unit/mcp/` because these files live outside that
directory, and per-PR CI skips the heavy test suite entirely.

## Solution

- Extended `query()`'s signature and `_query_sessions` with
  `min_messages`/`max_messages`/`min_words`, mirroring the existing
  `origin`/`tag`/`repo`/`since`/`until`/`sort` filters — closes a real
(narrow) parameter gap in `query(projection="sessions", ...)` rather
than
weakening the parity test, since the old `list_sessions` tool supported
  these. Also threaded through `_dispatch_run`'s saved-query replay for
  symmetry.
- Rewired both storage parity files' `_MCPSurface` from
  `_tools["search"]`/`_tools["list_sessions"]` to
`_tools["query"].fn(expression=..., projection="sessions", ...)` — same
  underlying payload-building machinery, response shape unchanged.
- Rewired the three maintenance test files'
`_tools["maintenance_preview"]`
call sites to `_tools["maintenance"].fn(operation="preview", ...)`, and
fixed two registration-presence assertions that were checking for names
  (`maintenance_preview`/`maintenance_execute`) that never existed
  post-cutover — vacuously true, testing nothing.
- **Found and fixed a real production bug**: `server_cutover.py`'s
`_build_mcp_scope_filter` only had `MaintenanceScopeFilter` imported
under
  `TYPE_CHECKING`, but constructs one at runtime — every
`maintenance(operation="preview"/"execute")` call was raising
`NameError`.
  Added the runtime import to the function's existing lazy-import block.
- Marked `test_mcp_cost_outlook_tool_uses_shared_envelope` `xfail`
(`strict=True`, `raises=KeyError`): `cost_outlook` has no
six-tool-surface
  replacement yet — cost/usage rollup MCP wiring needs a design decision
  explicitly deferred this session, tracked in `polylogue-hg97`.

Filed `polylogue-p6rz` for the remaining ~40-file pre-existing failure
list
from the same `--all` run that are **not** MCP-related
(`no_color_requested()`
signature drift, a stale migration-count assertion, `query_units`
telemetry-key naming) — confirmed unrelated by isolated reruns, left
untouched here.

## Verification

- `devtools test tests/unit/mcp/ tests/unit/maintenance/
  tests/unit/storage/test_surface_parity_adapters.py
tests/unit/storage/test_query_parity.py
tests/unit/cost/test_contract_suite.py
tests/unit/verification/test_code_refs_resolve.py` — 576 passed, 1
xfailed.
- `mypy --strict` / `ruff` clean.
- `devtools render all --check` clean.

Ref polylogue-t46.8

Co-authored-by: Claude <[email protected]>
Sinity added a commit that referenced this pull request Jul 18, 2026
## Summary
`status(scope="coordination")` on the six-tool MCP cutover surface
silently returned generic `archive.stats()` instead of coordination
status.

## Problem
`register_cutover_read_tools`'s `status` verb dispatched every scope
except `"operation"` to the same `archive.stats()` projection. An agent
calling `status(scope="coordination")` got archive stats, not
coordination data — discovered while porting polylogue-20d.17's budgeted
component-snapshot protocol to coordination status (#3116).

## Solution
- `status(scope="coordination")` now dispatches to real coordination
logic: compact requests reuse a lazily-constructed
`CoordinationEnvelopeCache` (fingerprint-invalidated on git
HEAD/logs/`.beads/issues.jsonl`/index db-WAL mtimes, per #3116's
substrate), `"detail"` requests bypass the cache and call
`build_coordination_envelope` directly — matching the fresh/detail
semantics the other status scopes already use.
- The cache is constructed lazily inside `register_cutover_read_tools`'s
closure so sessions that never call `status(scope="coordination")` don't
pay `polylogue.coordination`'s import cost.

## Scope note (polylogue-qink AC-3)
qink's AC also asked to "decide and act on
`register_read_tools`/`agent_coordination`'s fate" (the old standalone
MCP tool, unreachable from the live server). That deletion is Lane C's
in-flight six-tool-cutover scope (polylogue-t46.8) and has since landed
on master via #3118 (`refactor(mcp): delete dead legacy MCP registrar
code`) — no action needed here.

## Verification
- `devtools test tests/unit/mcp/test_status_scope_coordination.py` — 2
passed. Drives the live registered `status` tool function end-to-end
(not a hand-built registrar): proves the response is coordination-shaped
with no `"archive"` key (regression for the silent-fallthrough bug), and
that a second compact call hits the warm cache (1 build call across 2
compact + 1 detail invocation) while detail always goes live.
- `mypy --strict polylogue/mcp/server_cutover.py` — clean.
- `devtools verify --quick` — exit 0 (ran pre-commit and pre-push).

Ref polylogue-qink
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant