How nlace-com/mcp-supermercados-cl works
1. What this repo is
- A local Model Context Protocol (MCP) server for Chilean supermarkets.
- It is designed to run on the user’s machine over stdio, not as a hosted web service.
- The main architectural goal is to let an LLM ask for products, prices, comparisons, and cart/list operations while keeping sensitive session data on the user’s side.
2. Top-level runtime shape
- src/index.ts is the entrypoint.
- src/server.ts registers the MCP tools and prompts.
- The process is a Node.js ≥ 20 application; the repo is built and tested with TypeScript.
- Communication with the client is MCP-native, including progress notifications for long operations.
3. Core domain layer
- src/core/ holds the normalized business model and shared algorithms.
- It contains types, error shaping, normalization, formatting, matching, comparison, cache, opportunity ranking, and list building.
- This layer is where the repo enforces a unified product schema across all supermarket chains, including separate normal and member prices, unit-price normalization, and bundle handling.
4. Adapter-per-chain architecture
- src/adapters/ is the main boundary against external supermarket systems.
- There is one adapter family per chain: Cencosud/Jumbo/Santa Isabel, Unimarc, Tottus, and Lider.
- Adapters encapsulate site-specific scraping/API access, then translate results into the shared core schema so the rest of the system stays chain-agnostic.
5. Cencosud is the most complex subsystem
- The Cencosud area is split into specialized files: browser/session/cart/lists/session orchestration plus the chain adapter itself.
- This reflects the fact that Jumbo and Santa Isabel expose richer authenticated features: frequent purchases, saved lists, and cart operations.
- The architecture intentionally separates public catalog search from session-bound flows that must run against the user’s logged-in browser state.
6. Session handling and privacy boundary
- src/adapters/session.ts and the chain-specific session/browser helpers implement the “no credentials on server” model.
- For authenticated features, the server emits a browser snippet or can optionally bridge through Playwright; the actual authenticated state remains in the user’s browser profile.
- This is a major architectural boundary: public catalog requests can be server-side, but private account/cart operations are delegated to the user’s session.
7. HTTP and anti-bot-aware access
- src/http/client.ts centralizes outbound HTTP behavior.
- The client applies rate limits, retries/backoff, realistic user-agent behavior, and timeouts tuned per host type.
- This matters because some chains use public search APIs, while others rely on SSR pages or anti-bot-sensitive endpoints; the repo intentionally paces requests to behave like a human client.
8. Tools are the MCP surface area
- src/tools/ contains one MCP tool per file, such as search, product detail, offers, list building, cart access, store comparison, and branch discovery.
- The tools are thin orchestration layers: they parse inputs, call adapters/core services, and return normalized MCP responses.
- Long-running tools emit progress updates, and some comparison flows return partial results rather than blocking everything on a single slow chain.
9. Data flow for catalog and comparison
- A typical flow is: MCP tool → chain adapter → HTTP/browser/session boundary → raw chain response → core normalization/matching → tool response.
- search_products, get_product, get_offers, and compare_stores all follow this pattern, but differ in which adapter and which source data they use.
- compare_stores is especially important architecturally because it aggregates results from multiple adapters and must preserve pricing/unit-price consistency across chains.
10. Data flow for “smart shopping” features
- build_list and suggest_swaps sit on top of the core matching and opportunities logic.
- They combine user intent, frequent-purchase history, offer detection, and normalized unit-price comparisons to propose concrete product selections.
- These features depend heavily on the domain layer rather than any one supermarket integration.
11. Caching, limits, and resilience
- The core cache layer and the HTTP client work together to keep repeated lookups efficient and to reduce exposure to rate limits.
- The architecture favors graceful degradation: when one chain fails, the system can still return partial results or status per adapter.
- Environment variables tune timing and retry behavior, which is important because the repo interacts with heterogeneous external systems.
12. Testing strategy and fixtures
- tests/ contains both contract-style tests with recorded fixtures and opt-in live smoke tests.
- Fixtures capture real responses from each chain so the adapters can be validated without hitting live sites during normal CI.
- This test setup is part of the architecture: every adapter is isolated enough that a format change in one chain should not break the rest.
13. Operations, documentation, and change tracking
- .github/workflows/ci.yml and .github/workflows/smoke-live.yml indicate continuous validation plus scheduled live checks.
- The docs/ folder records endpoint plans and captured behavior from specific dates, which suggests the external integrations are expected to drift and need ongoing re-documentation.
- The repo is therefore a living integration layer, not a static library.
14. How to draw the architecture
- At the center, place the MCP server and tool registry.
- Surround it with a shared core domain layer.
- On the outside, draw one adapter boundary per supermarket chain, with a special authenticated-session path for Cencosud-related features.
- Add a shared HTTP client beneath the adapters, a browser/session bridge for private flows, and a separate test/fixture boundary that validates each chain integration independently.
Main entry points: server.ts MCP server · client.ts HTTP client · adapters Adapter tests · cencosud.ts Cencosud family
Components 34
MCP runtime
Node entrypoint, server setup, and prompt surface for stdio-based MCP execution.
- Entry point · Starts the Node.js MCP process and wires the server runtime.
src/index.ts - MCP server · Registers tools, prompts, and MCP-native messaging for stdio clients.
src/server.ts - Prompts · Prompt definitions surfaced to the client alongside tools.
src/prompts.ts
Core domain
Normalized product model and shared shopping algorithms.
- Types · Shared normalized product, store, cart, and pricing types.
src/core/types.ts - Normalize · Converts chain-specific responses into the shared product schema.
src/core/normalize.ts - Matching · Product matching, similarity, and comparison logic across chains.
src/core/matching.ts - Compare · Cross-store comparison and pricing consistency helpers.
src/core/compare.ts - List builder · Builds shopping lists from intent, history, offers, and normalized products.
src/core/listBuilder.ts - Opportunities · Finds bargains, swaps, and purchase opportunities from normalized data.
src/core/opportunities.ts - Cache · Shared lookup cache used to reduce repeated fetches and rate-limit pressure.
src/core/cache.ts
Chain adapters
Per-supermarket integration boundary plus shared HTTP and session plumbing.
- HTTP client · Central outbound HTTP layer with retries, pacing, headers, and timeouts.
src/http/client.ts - Session boundary · Shared session helpers for authenticated flows that keep credentials on the user side.
src/adapters/session.ts - Browser bridge · Optional bridge into a user browser profile for authenticated operations.
src/adapters/playwrightBridge.ts - Cencosud family · Jumbo and Santa Isabel integration with public catalog plus session-bound flows.
src/adapters/cencosud.ts - Cencosud session · Coordinates logged-in browser state and authenticated requests for Cencosud.
src/adapters/cencosudSession.ts - Cencosud cart · Cart read/write operations for authenticated Cencosud flows.
src/adapters/cencosudCart.ts - Cencosud lists · Frequent purchases and saved-list operations for authenticated Cencosud flows.
src/adapters/cencosudLists.ts - Unimarc · Adapter for Unimarc catalog and offers access.
src/adapters/unimarc.ts - Tottus · Adapter for Tottus catalog and product flows.
src/adapters/tottus.ts - Lider · Adapter for Lider catalog and offers access.
src/adapters/lider.ts
MCP tools
Thin orchestration layer exposed to the MCP client.
- Search products · Searches products through the appropriate chain adapter and returns normalized results.
src/tools/searchProducts.ts - Get product · Fetches product detail and normalizes chain-specific product data.
src/tools/getProduct.ts - Get offers · Retrieves chain offers and availability in a normalized form.
src/tools/getOffers.ts - Compare stores · Aggregates multiple adapters to compare pricing and unit-price consistency.
src/tools/compareStores.ts - Build list · Builds shopping lists using core matching and opportunity logic.
src/tools/buildList.ts - Suggest swaps · Suggests alternative products based on price, offers, and matching.
src/tools/suggestSwaps.ts - Cart access · Surfaces cart operations, including authenticated Cencosud actions when needed.
src/tools/cart.ts - Saved lists · Reads saved lists and frequent purchases for supported authenticated chains.
src/tools/getSavedLists.ts - Frequent purchases · Fetches frequently purchased items for session-bound shopping flows.
src/tools/getFrequentPurchases.ts - Discover branch · Finds store branches or locations relevant to a selected chain.
src/tools/discoverBranch.ts - Adapter status · Reports per-adapter health and partial availability for graceful degradation.
src/tools/adapterStatus.ts - Progress · Emits MCP progress notifications for longer operations.
src/tools/progress.ts
Tests & fixtures
Contract tests, live smoke checks, and recorded responses that validate each integration.
- Adapter tests · Chain-specific adapter tests validating normalization, parsing, and resilience.
tests/adapters - Fixtures · Captured HTTP, HTML, and JSON responses used by adapter tests.
tests/fixtures
Connections 39
- Entry point → MCP server: starts · Bootstraps the MCP server runtime.
- MCP server → Prompts: exposes · Registers prompt definitions with the MCP client.
- MCP server → Search products: registers · Surfaces search as an MCP tool.
- MCP server → Get product: registers · Surfaces product detail as an MCP tool.
- MCP server → Get offers: registers · Surfaces offers as an MCP tool.
- MCP server → Compare stores: registers · Surfaces store comparison as an MCP tool.
- MCP server → Build list: registers · Surfaces list building as an MCP tool.
- MCP server → Cart access: registers · Surfaces cart operations as an MCP tool.
- Search products → HTTP client: queries · Uses the shared HTTP layer for public catalog lookups.
- Search products → Normalize: normalizes · Converts raw chain data into the shared schema.
- Get product → Normalize: normalizes · Maps product detail into core types.
- Get offers → Compare: compares · Uses comparison helpers for pricing and unit-price consistency.
- Compare stores → Compare: aggregates · Combines results across adapters for store comparison.
- Build list → List builder: builds · Assembles shopping lists from domain logic.
- Suggest swaps → Opportunities: recommends · Relies on opportunities logic for alternative suggestions.
- Suggest swaps → Matching: matches · Uses similarity and substitution logic.
- Frequent purchases → Cencosud family: reads · Pulls frequent purchases from authenticated Cencosud flows.
- Cart access → Cencosud cart: delegates · Routes authenticated cart actions to the Cencosud subsystem.
- Saved lists → Cencosud lists: delegates · Routes saved-list access to the Cencosud subsystem.
- Discover branch → Unimarc: queries · Can resolve branch/location information from chain adapters.
- Adapter status → Adapter tests: reflects · Exposes adapter-level health and failure boundaries.
- Normalize → Types: produces · Creates the unified domain model used by all tools.
- Matching → Types: consumes · Operates over normalized product and pricing types.
- Compare → Matching: uses · Builds cross-store comparison on top of matching logic.
- List builder → Matching: uses · Finds candidate products and substitutes.
- Opportunities → Cache: uses · Caches repeated opportunity evaluations.
- HTTP client → Cache: leverages · Pairs request pacing with caching to reduce repeated lookups.
- Session boundary → Browser bridge: bridges · Optionally uses a browser profile to preserve user-side authentication.
- Cencosud family → Session boundary: depends on · Separates public catalog access from authenticated session flows.
- Cencosud family → HTTP client: fetches · Uses HTTP for catalog and API interactions when possible.
- Cencosud session → Session boundary: orchestrates · Coordinates the no-credentials-on-server session model.
- Cencosud cart → Cencosud session: uses · Requires authenticated session state for cart operations.
- Cencosud lists → Cencosud session: uses · Requires authenticated session state for saved lists.
- Unimarc → HTTP client: fetches · Uses shared HTTP behavior for Unimarc access.
- Tottus → HTTP client: fetches · Uses shared HTTP behavior for Tottus access.
- Lider → HTTP client: fetches · Uses shared HTTP behavior for Lider access.
- Adapter tests → Fixtures: validates against · Exercises adapters with recorded fixture data.
- Adapter tests → HTTP client: covers · Verifies HTTP behavior and retry/pacing logic.
- Adapter tests → Cencosud family: covers · Validates the most complex chain integration separately.