Commit 42d782e
feat(mcp)!: migrate catalog call sites to typed cache + decommission CatalogCache (#472 Phase D)
Phase D of the cache-unification effort. Migrates ~33 catalog read
call sites from the legacy ``CatalogCache`` to ``TypedCacheEngine``
via the ``CatalogQueries`` adapter (``services.typed_cache.catalog``)
and decommissions the legacy modules.
Source migration:
- Foundation tools: ``items``, ``inventory``, ``customers``,
``reference``, ``reporting``, ``orders``, ``manufacturing_orders``,
``sales_orders``, ``purchase_orders``, ``stock_transfers`` all
call ``services.typed_cache.catalog.*(Cached*Class, ...)`` instead
of ``services.cache.*(EntityType, ...)``. Dict access (``v["sku"]``)
flips to attribute access (``v.sku``) with an ``_attr`` helper
bridging dict / attrs / SQLModel call shapes in helper paths that
may receive either a cache row or an API-fallback attrs model.
- Decorator ``@cache_read`` keys off the ``Cached*`` SQLModel class
(e.g. ``CachedVariant``) instead of an ``EntityType`` enum value;
fans out to typed-cache sync helpers only. Legacy ``@cache_write``
/ ``mark_dirty`` mechanism removed — typed cache pulls incremental
deltas via ``updated_at_min`` on every ``@cache_read``-decorated
call, so explicit invalidation is no longer needed.
- ``resolve_entity_name`` takes a ``Cached*`` class plus the
``CatalogQueries`` adapter; tolerates both rows and dicts during
the transition.
- ``Services`` dataclass: ``cache`` field removed; only ``client``
and ``typed_cache`` remain. Lifespan in ``server.py`` initializes
only the typed cache.
- ``services.typed_cache.catalog`` is now the only catalog read
path; the inline negative-lookup cache in reporting tightened to
``if variant_id not in variant_cache`` so ``None`` stays a valid
cached negative result.
Decommission:
- Delete ``katana_mcp/cache.py`` (~870 LOC) and ``katana_mcp/cache_sync.py``.
- Delete ``tests/test_cache.py`` and ``tests/test_cache_sync.py``.
- ``EntityType`` enum disappears with ``cache.py``.
Soft-state filter opt-ins on direct-lookup paths:
- ``get_by_id`` / ``get_by_sku`` callers that need to surface
archived or soft-deleted rows for inspection (e.g. ``check_inventory``
on an archived SKU, ``modify_*`` flows resolving a tombstoned entity)
pass ``include_archived=True`` / ``include_deleted=True`` explicitly,
matching the legacy cache's "show every row regardless of soft-state"
semantics for direct lookups. The search-list paths
(``smart_search`` / ``search_fuzzy`` / ``get_all``) keep the
adapter's filtered defaults — the papercut fix from #472 Phase B.
Tests:
- ``conftest.create_mock_context`` exposes the six ``CatalogQueries``
methods on ``lifespan_ctx.typed_cache.catalog``; legacy
``lifespan_ctx.cache`` removed.
- All ~13 mock test files migrated. Mock helpers accept ``**_kw`` to
swallow the adapter's ``include_archived`` / ``include_deleted``
kwargs. ``CachedCustomer`` / ``CachedSupplier`` / ``CachedLocation``
/ ``CachedVariant`` factories replace dict-shaped fixtures.
Docs:
- ADR-0018 status flipped — the "follow-up epic" is complete; the
dual-cache rollout section is now historical.
- ``architecture.md`` cache section rewritten for the single-cache
reality; "Adding a new tool" checklist updated to direct
contributors at ``@cache_read(CachedEntity)``.
- CLAUDE.md "Known Pitfalls" updated — the cache-ID uniqueness note
no longer points at the retired ``CatalogCache``; the soft-state
flags note now describes the ``CatalogQueries`` adapter wiring.
BREAKING CHANGE: ``Services.cache`` field removed.
``katana_mcp.cache`` and ``katana_mcp.cache_sync`` modules removed.
``EntityType`` enum removed. Third-party consumers of
``katana_mcp_server`` that touched any of these will need to migrate
to ``services.typed_cache.catalog`` and the ``Cached*`` SQLModel
classes from ``katana_public_api_client.models_pydantic._generated``.
Closes #472.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 63359e1 commit 42d782e
38 files changed
Lines changed: 1518 additions & 2941 deletions
File tree
- katana_mcp_server
- docs
- adr
- src/katana_mcp
- resources
- services
- tools
- foundation
- typed_cache
- tests
- integration
- resources
- tools
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
170 | 172 | | |
171 | | - | |
172 | | - | |
| 173 | + | |
| 174 | + | |
173 | 175 | | |
174 | 176 | | |
175 | 177 | | |
| |||
243 | 245 | | |
244 | 246 | | |
245 | 247 | | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
256 | | - | |
257 | | - | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
258 | 260 | | |
259 | 261 | | |
260 | 262 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
9 | 17 | | |
10 | 18 | | |
11 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
35 | | - | |
36 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| |||
82 | 83 | | |
83 | 84 | | |
84 | 85 | | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
94 | 95 | | |
95 | 96 | | |
96 | 97 | | |
| |||
116 | 117 | | |
117 | 118 | | |
118 | 119 | | |
119 | | - | |
120 | 120 | | |
| 121 | + | |
121 | 122 | | |
122 | 123 | | |
123 | 124 | | |
124 | 125 | | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
| 126 | + | |
130 | 127 | | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
138 | 131 | | |
139 | 132 | | |
140 | 133 | | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
146 | 145 | | |
147 | | - | |
148 | | - | |
149 | | - | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
216 | | - | |
217 | | - | |
218 | | - | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
219 | 223 | | |
220 | 224 | | |
221 | 225 | | |
| |||
0 commit comments