How kct-git/ecom-mcp works
1. What this repo is
- This is a Python MCP server that wraps the Kapruka.com REST API and exposes Kapruka capabilities as LLM-friendly tools for MCP clients.
- The core architectural boundary is between MCP/tool requests on one side and the external Kapruka API on the other.
2. Primary request flow
- An MCP client connects to the server, invokes a tool, and the request is routed into a domain-specific module under src/tools/.
- Tool code calls a shared async API client in src/api/client.py, which talks to the Kapruka REST service and returns normalized results or errors back through the MCP layer.
3. Server/runtime entry points
- cli.py is the developer-facing entry point for starting the server and running utility commands like pinging the upstream API or listing registered tools.
- src/server.py is the main server bootstrap for the MCP runtime.
- The server supports both streamable HTTP and stdio transport, which matters because it can run as a network service or as a local subprocess for MCP Inspector/testing.
4. Tooling boundary
- src/tools/ is split by domain: products, orders, delivery, and categories.
- Each module represents a tool group, so the architecture is organized around business capability rather than a single generic API wrapper.
- This is the main place where domain-specific parameter mapping and response shaping happen.
5. API integration layer
- src/api/client.py is the shared integration point to Kapruka.
- It centralizes outbound HTTP behavior, error handling, and likely request composition, so the rest of the codebase does not need to know Kapruka-specific transport details.
- tests/test_client.py indicates this layer is important enough to have direct unit coverage.
6. Configuration and secrets
- src/config/settings.py provides environment-based configuration.
- .env.example shows the external dependencies that define the runtime boundary: Kapruka API base URL, API key, and related server settings.
- This keeps the server deployable across environments without code changes.
7. Cross-cutting concerns
- src/middleware.py, src/cache.py, src/order_rate_limit.py, and src/activity_log.py are supporting subsystems that sit around the tool/API flow.
- They suggest the server adds operational safeguards such as caching, order-specific throttling, and activity tracking/audit logging.
- These are important diagram boundaries because they affect requests across multiple tool groups, not just one module.
8. Discovery and static surface
- src/well_known.py and src/static/index.html imply the server also serves lightweight discovery or landing content alongside MCP functionality.
- This is not the core business logic, but it is part of the external interface surface that clients or operators may hit.
9. Operational/deployment layer
- The deploy/ directory contains a Caddyfile.snippet, a systemd service file, and a production sync script.
- That indicates the server is designed to run behind a reverse proxy and as a managed service in production, rather than only as a local dev process.
10. Maintenance and support scripts
- scripts/ contains operational helpers for API exploration, smoke testing, registry publishing, and activity-table setup.
- These scripts support onboarding, verification, and deployment workflows; they are not part of the runtime request path but are relevant to how the system is operated.
11. Documentation and handoff artifacts
- docs/ contains design briefs and handoff notes, which suggests the repo has evolved through explicit API/product iterations.
- For architecture purposes, treat these as context for behavior and evolution, not runtime dependencies.
12. Overall structure to diagram
- The diagram should show: MCP client → server/transport → tool modules → shared API client → Kapruka REST API, with configuration, middleware/caching/rate limiting/activity logging, and deployment/runtime wrappers as surrounding layers.
Main entry points: server.py Server · client.py API client · middleware.py Middleware · settings.py Settings
Components 20
External systems
Clients and upstream service outside this repository.
- MCP client · Any MCP host or inspector invoking tools over stdio or HTTP.
- Kapruka API · External Kapruka.com service consumed by the server.
Runtime entrypoints
Server bootstrap and developer-facing commands.
Domain tools
Business-capability tool modules exposed through MCP.
- Products · Tools for product-related lookup and shaping.
src/tools/products.py - Orders · Tools for order-related workflows and actions.
src/tools/orders.py - Delivery · Tools for delivery-related capabilities.
src/tools/delivery.py - Categories · Tools for category discovery and navigation.
src/tools/categories.py
Integration layer
Shared API client and operational safeguards around outbound requests.
- Middleware · Request-layer hooks that wrap tool execution and server behavior.
src/middleware.py - Cache · Shared caching layer for repeated or expensive lookups.
src/cache.py - Rate limit · Order-specific throttling and request protection.
src/order_rate_limit.py - Activity log · Operational logging or tracking of activity across requests.
src/activity_log.py - API client · Shared async HTTP client and error handling for Kapruka REST calls.
src/api/client.py
Support surface
Configuration and lightweight auxiliary server surfaces.
- Settings · Environment-driven configuration used across the runtime.
src/config/settings.py - Well-known · Lightweight discovery or metadata endpoint surface.
src/well_known.py - Landing page · Simple static index served alongside the MCP runtime.
src/static/index.html
Operations
Deployment and maintenance helpers.
- Caddy snippet · Reverse-proxy configuration fragment for production hosting.
deploy/Caddyfile.snippet - Systemd unit · Managed service definition for production runtime.
deploy/kapruka-mcp.service - Sync script · Production deployment synchronization script.
deploy/sync-to-prod.sh - Ops scripts · Support scripts for exploration, smoke tests, registry publishing, and setup.
scripts/explore_api.py
Connections 23
- MCP client → Server: tool calls · Clients invoke MCP tools through the server transport.
- CLI → Server: start · CLI launches or manages the MCP server runtime.
- Server → Middleware: wraps · The server applies cross-cutting request handling.
- Middleware → Cache: uses · Request processing can consult shared caching.
- Middleware → Rate limit: guards · Order flows are protected by throttling.
- Middleware → Activity log: records · Operational activity is tracked during request handling.
- Server → Well-known: serves · The runtime exposes discovery metadata.
- Server → Landing page: serves · The runtime can serve a lightweight landing page.
- Server → Products: registers · Product tools are exposed through the MCP server.
- Server → Orders: registers · Order tools are exposed through the MCP server.
- Server → Delivery: registers · Delivery tools are exposed through the MCP server.
- Server → Categories: registers · Category tools are exposed through the MCP server.
- Products → API client: calls · Product tools fetch data through the shared API client.
- Orders → API client: calls · Order tools fetch and mutate via the shared API client.
- Delivery → API client: calls · Delivery tools retrieve upstream data through the shared client.
- Categories → API client: calls · Category tools query Kapruka through the shared client.
- API client → Kapruka API: HTTP · Shared async client talks to the Kapruka REST service.
- Settings → Server: configures · Runtime settings shape transport and server behavior.
- Settings → API client: configures · API base URL, keys, and related client settings.
- Caddy snippet → Server: fronts · Reverse proxy configuration routes traffic to the server.
- Systemd unit → Server: runs · System service manages the production process.
- Sync script → Systemd unit: deploys · Sync script supports production rollout of service assets.
- Ops scripts → API client: exercise · Maintenance scripts probe and smoke test the API layer.