|
| 1 | +# Architecture: Python parity for the current MCP tool surface |
| 2 | + |
| 3 | +This document defines the parity boundary tracked by issue #182. |
| 4 | + |
| 5 | +It does not claim that the current Python backend already replaces the Node/MCP runtime. |
| 6 | +Instead, it records which MCP behaviors must match before any later migration removes the |
| 7 | +existing Node path, which differences are acceptable during the current baseline, and which |
| 8 | +tools remain explicit gaps. |
| 9 | + |
| 10 | +## Terms |
| 11 | + |
| 12 | +- Exact-match parity: behavior, safety constraints, and failure semantics must stay aligned |
| 13 | + with the current MCP contract before the Node path can be removed. |
| 14 | +- Acceptable baseline difference: a documented difference that is allowed while the Node/MCP |
| 15 | + path remains the source of truth for that capability. |
| 16 | +- Gap / Node-only: there is no public Python replacement yet; the current MCP tool must stay |
| 17 | + on the Node path. |
| 18 | + |
| 19 | +## Current parity boundary |
| 20 | + |
| 21 | +- Python-covered now: |
| 22 | + - `/retrieve` is the Python-side parity target for `get_context`-style retrieval behavior. |
| 23 | + - `/agent/run` is the Python-side parity target for grounded-answer behavior and explicit |
| 24 | + write refusal semantics. |
| 25 | +- Still Node-owned now: |
| 26 | + - MCP transport, indexer ownership, filesystem read tools, graph/navigation tools, |
| 27 | + metadata/list tools, diagnostics tools, and all explicit write tools. |
| 28 | +- Migration gate: |
| 29 | + - Do not remove the Node/TypeScript path until every `Gap / Node-only` row below has an |
| 30 | + exact-match Python replacement or an explicitly accepted new contract. |
| 31 | + |
| 32 | +## Read tool parity matrix |
| 33 | + |
| 34 | +| Tool | Current Python target | Status | Exact-match requirements before migration | Acceptable baseline differences / current gap | |
| 35 | +| ----------------------------- | ------------------------------------------------------- | --------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| 36 | +| `get_context` | `/retrieve` and the retrieval stage inside `/agent/run` | Partial parity | Preserve scoped candidate filtering (`path_prefix`, `tags_any`, `tags_all`), explicit readiness failures, grounded evidence, and no unrelated fallback when scope removes all candidates. | Response shape differs from MCP `structuredContent`; Python caps `top_k` at `20`; Python does not expose MCP-only fields such as `expand_top_k` or `applied_filters`. | |
| 37 | +| `expand_typed_links_outgoing` | None | Gap / Node-only | Add a Python graph expansion contract that preserves bounded traversal semantics before migration. | No Python graph traversal API exists yet. | |
| 38 | +| `resolve_note` | None | Gap / Node-only | Add a Python note-resolution contract before migration. | No Python resolution endpoint exists yet. | |
| 39 | +| `find_typed_links_incoming` | None | Gap / Node-only | Add a Python incoming-link query contract before migration. | No Python backref query exists yet. | |
| 40 | +| `list_typed_link_rels` | None | Gap / Node-only | Add a Python relation-listing contract before migration. | No Python typed-link relation listing exists yet. | |
| 41 | +| `read_note` | Internal note reads inside `/agent/run` only | Gap / Node-only | Add a public Python note-read contract with the current vault-boundary guarantees before migration. | The current Python backend only reads note excerpts internally; it does not expose the public pagination/change-token contract of `read_note`. | |
| 42 | +| `get_vault_tree` | None | Gap / Node-only | Add a Python vault-tree contract before migration. | No Python vault-tree API exists yet. | |
| 43 | +| `frontmatter_validate` | None | Gap / Node-only | Add a Python validator contract that preserves the current schema and typed-link diagnostic expectations before migration. | No Python frontmatter validation API exists yet. | |
| 44 | +| `find_broken_links` | None | Gap / Node-only | Add a Python broken-link diagnostic contract before migration. | No Python broken-link diagnostic API exists yet. | |
| 45 | +| `search_notes` | None | Gap / Node-only | Add a Python metadata-search contract before migration. | No Python metadata-search API exists yet. | |
| 46 | +| `list_tags` | None | Gap / Node-only | Add a Python tag-listing contract before migration. | No Python tag-listing API exists yet. | |
| 47 | +| `list_keywords` | None | Gap / Node-only | Add a Python keyword-listing contract before migration. | No Python keyword-listing API exists yet. | |
| 48 | +| `get_tool_failure_report` | None | Gap / Node-only | Add a Python diagnostics-report contract before migration. | No Python diagnostics-report API exists yet. | |
| 49 | + |
| 50 | +## Write tool parity matrix |
| 51 | + |
| 52 | +| Tool | Current Python target | Status | Exact-match requirements before migration | Acceptable baseline differences / current gap | |
| 53 | +| -------------------------- | ------------------------------ | --------------- | ---------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- | |
| 54 | +| `capture_note` | `/agent/run` refusal path only | Gap / Node-only | Preserve explicit `apply` gating and current vault-write safety before any Python write path replaces this tool. | The current Python baseline never creates notes. It only returns explicit refusal semantics. | |
| 55 | +| `canonicalize_typed_links` | `/agent/run` refusal path only | Gap / Node-only | Preserve explicit `apply` gating and safe deterministic mutation rules before migration. | The current Python baseline never rewrites typed links. It only returns explicit refusal semantics. | |
| 56 | +| `edit_note` | `/agent/run` refusal path only | Gap / Node-only | Preserve explicit `apply` gating, concurrency guards, and vault-boundary safety before migration. | The current Python baseline never edits notes. It only returns explicit refusal semantics. | |
| 57 | +| `improve_frontmatter` | `/agent/run` refusal path only | Gap / Node-only | Preserve explicit `apply` gating and current frontmatter safety rules before migration. | The current Python baseline never mutates frontmatter. It only returns explicit refusal semantics. | |
| 58 | +| `relocate_note` | `/agent/run` refusal path only | Gap / Node-only | Preserve explicit `apply` gating and current path safety rules before migration. | The current Python baseline never moves notes. It only returns explicit refusal semantics. | |
| 59 | + |
| 60 | +## Safety invariants that must not regress |
| 61 | + |
| 62 | +- Vault boundary: Python note reads must stay within `AILSS_VAULT_PATH`; path traversal or |
| 63 | + absolute-escape attempts must not read outside the configured vault. |
| 64 | +- Write gating: requested writes must fail explicitly unless the future Python path has an |
| 65 | + approved replacement for the current MCP write contract. |
| 66 | +- Failure visibility: missing or invalid local prerequisites must fail explicitly rather than |
| 67 | + silently degrading to unrelated retrieval results. |
| 68 | +- Grounding: Python-generated answers must keep inspectable citations; missing evidence is a |
| 69 | + failure, not a best-effort answer. |
| 70 | + |
| 71 | +## Required failure codes for Python-covered agent flows |
| 72 | + |
| 73 | +- `missing_context` |
| 74 | +- `ambiguous_note_resolution` |
| 75 | +- `grounding_failure` |
| 76 | +- `write_not_allowed` |
| 77 | +- `apply_not_requested` |
| 78 | + |
| 79 | +## Verification currently in repo |
| 80 | + |
| 81 | +- `packages/mcp/test/docs.mcpToolingConsistency.test.ts` |
| 82 | + - Keeps this parity matrix aligned with the live MCP tool surface. |
| 83 | +- `apps/api/tests/test_parity_contract.py` |
| 84 | + - Verifies the documented Python parity-critical behaviors that already exist in the |
| 85 | + baseline. |
| 86 | +- Existing Python route/unit coverage: |
| 87 | + - `apps/api/tests/test_retrieve.py` |
| 88 | + - `apps/api/tests/test_agent.py` |
0 commit comments