How thejandeera/kapruka-mcp works
1. Repository shape
- This repo is split into two major runtimes:
- a Python MCP server at the repo root (src/, cli.py)
- a Next.js/TypeScript client app in ayubowan/
- They are related but distinct: the Python side exposes Kapruka API capabilities as MCP tools, while the Next.js app provides the end-user shopping/chat experience.
2. Core backend purpose: MCP wrapper around Kapruka REST API
- The Python server is the integration boundary to the external Kapruka.com REST API.
- Its job is to translate API operations into MCP tools consumable by LLMs and MCP clients.
- The README makes clear the server supports both streamable HTTP and stdio transports, so transport is separated from the tool logic.
3. Backend layering
- src/server.py is the FastMCP entry point.
- src/tools/ contains one module per capability area:
- products.py
- categories.py
- orders.py
- delivery.py
- src/api/client.py is the shared async HTTP client layer and centralizes outbound REST calls plus error handling.
- src/config/settings.py holds environment-driven configuration, keeping API endpoint/key concerns out of business logic.
4. Backend cross-cutting concerns
- src/cache.py suggests response or lookup caching to reduce repeated API calls.
- src/order_rate_limit.py indicates order-related protections or throttling around sensitive operations.
- src/middleware.py implies request/response handling at the server boundary, likely for transport concerns or observability.
- src/activity_log.py suggests auditing or event recording for tool usage.
- src/well_known.py likely serves discovery metadata for clients.
5. Backend developer/runtime interface
- cli.py is the operator-facing entry point for local development and validation.
- It supports:
- running the MCP server
- stdio mode for inspector/debugging
- pinging the upstream Kapruka API
- listing registered tools
- tests/test_client.py covers the API client boundary, which is the most important integration seam.
6. Frontend application purpose
- ayubowan/ is a separate Next.js app that provides a shopping/chat UI.
- It appears to be an AI-assisted storefront, with the user interacting through a chat interface and product/cart components.
- The frontend is not just static UI; it includes agent logic and server routes, so it acts as a thin application layer over tool/agent capabilities.
7. Frontend UI composition
- components/ holds the visible experience:
- ChatInterface.tsx for conversational interaction
- ProductCard.tsx for catalog items
- CartDrawer.tsx for cart state and checkout preview
- MessageRenderer.tsx for rendering assistant/user messages
- Navbar.tsx for top-level navigation
- store/useStore.ts indicates client-side state management, likely for cart/session/UI state shared across components.
8. Frontend agent/orchestration boundary
- agents/orchestrator.ts, agents/shopper.ts, and agents/tools.ts show an internal agent layer inside the Next app.
- This layer likely turns user chat into structured shopping actions and tool calls.
- lib/mcp.ts is the bridge into the MCP world, so the frontend can talk to the backend server instead of embedding Kapruka API logic directly.
- This keeps the UI decoupled from the external REST API and centralizes backend tool access.
9. Frontend server routes
- app/api/chat/route.ts is the main application-facing backend endpoint for chat-driven interactions.
- app/api/proxy-image/route.ts suggests images are fetched through the app server, likely to work around remote image restrictions or CORS/hotlinking.
- app/api/test/route.ts is a small diagnostic route.
- app/page.tsx, layout.tsx, and globals.css define the app shell and presentation.
10. Deployment and packaging boundary
- deploy/ contains operational artifacts for production hosting:
- kapruka-mcp.service for systemd
- Caddyfile.snippet for reverse proxying
- sync-to-prod.sh for deployment sync
- That points to a self-hosted backend deployment behind a web proxy.
- server.json, pyproject.toml, and the two package.json/lockfile sets reinforce that the repo intentionally ships two independently deployable stacks.
11. Data flow at a high level
- User interacts with the Next.js UI.
- The UI/chat layer uses the agent/orchestrator logic and talks to MCP tools through lib/mcp.ts and the app API routes.
- The Python MCP server receives tool calls, uses src/api/client.py to call the external Kapruka REST API, and returns structured results.
- Some operations may flow back through frontend state management (useStore) for cart and display updates.
12. Architectural boundary summary
- The clearest separation is:
- presentation + conversational orchestration in ayubowan/
- API normalization + tool exposure in the Python MCP server
- external commerce data/source of truth in Kapruka’s REST API
- If you are drawing the diagram, the key boundaries are the transport boundary (Next.js routes / MCP transport), the tool boundary (MCP server), and the external service boundary (Kapruka API).
Main entry points: server.py MCP server · client.py API client · orchestrator.ts Orchestrator · orders.py Orders
Components 24
Python MCP server
Root-level Python runtime exposing Kapruka capabilities as MCP tools.
- CLI · Local command-line entrypoint for running, inspecting, and pinging the MCP server.
cli.py - MCP server · FastMCP entrypoint and transport boundary for exposed tools.
src/server.py - Middleware · Request/response handling around the server boundary.
src/middleware.py - Products · Product lookup and catalog tool surface.
src/tools/products.py - Categories · Category browsing and hierarchy tool surface.
src/tools/categories.py - Orders · Order creation and order lifecycle tool surface.
src/tools/orders.py - Delivery · Delivery and shipping-related tool surface.
src/tools/delivery.py - API client · Shared async HTTP client for Kapruka REST calls and error handling.
src/api/client.py - Settings · Environment-driven configuration for API and runtime settings.
src/config/settings.py - Cache · Shared caching layer for repeated lookups and responses.
src/cache.py - Rate limit · Order-specific throttling or protection for sensitive operations.
src/order_rate_limit.py - Activity log · Audit or event recording for tool usage and server activity.
src/activity_log.py - Discovery · Well-known discovery metadata for MCP clients.
src/well_known.py
Next.js app
Separate TypeScript runtime for chat-driven shopping experience.
- MCP bridge · Frontend-side bridge for talking to MCP tools.
ayubowan/lib/mcp.ts - Orchestrator · Main shopping/chat coordination layer inside the Next app.
ayubowan/agents/orchestrator.ts - Shopper agent · Agent logic for shopping-oriented reasoning and actions.
ayubowan/agents/shopper.ts - Agent tools · Helpers that map user intents to tool invocations.
ayubowan/agents/tools.ts - Chat API · Primary application route for chat-driven interactions.
ayubowan/app/api/chat/route.ts - Image proxy · Server-side image fetch route for remote image handling.
ayubowan/app/api/proxy-image/route.ts - Chat UI · Conversational interface for the shopping experience.
ayubowan/components/ChatInterface.tsx - Catalog UI · Visible product and cart presentation components.
ayubowan/components/ProductCard.tsx - Store · Shared client-side state for cart, session, and UI updates.
ayubowan/store/useStore.ts
Deployment
Packaging and operational artifacts for self-hosted deployment.
- Systemd service · Production service definition for running the MCP server.
deploy/kapruka-mcp.service - Caddy snippet · Reverse-proxy configuration snippet for deployment.
deploy/Caddyfile.snippet
Connections 25
- CLI → MCP server: run / inspect · Operator entrypoint launches and probes the server.
- MCP server → Middleware: wraps · Server boundary is mediated by request handling concerns.
- MCP server → Products: exposes · Registers product tools with MCP clients.
- MCP server → Categories: exposes · Registers category tools with MCP clients.
- MCP server → Orders: exposes · Registers order tools with MCP clients.
- MCP server → Delivery: exposes · Registers delivery tools with MCP clients.
- Products → API client: calls · Tool handlers delegate outbound REST work to the shared client.
- Categories → API client: calls · Tool handlers delegate outbound REST work to the shared client.
- Orders → API client: calls · Tool handlers delegate outbound REST work to the shared client.
- Delivery → API client: calls · Tool handlers delegate outbound REST work to the shared client.
- API client → Settings: reads · HTTP client uses configuration for endpoint and credentials.
- API client → Cache: uses · Client benefits from shared caching for repeated requests.
- Orders → Rate limit: guards · Order operations are protected by throttling or rate limits.
- MCP server → Activity log: records · Server activity and tool usage are audited.
- MCP server → Discovery: publishes · Discovery metadata is exposed alongside the server.
- Chat UI → Store: reads/writes · UI components use shared client state for cart and display updates.
- Chat UI → Orchestrator: drives · Chat interface hands user intent to the orchestration layer.
- Orchestrator → Shopper agent: coordinates · Main orchestrator delegates shopping reasoning to agent logic.
- Orchestrator → Agent tools: uses · Orchestrator uses tool adapters for structured actions.
- Agent tools → MCP bridge: invokes · Agent tooling routes through the MCP bridge.
- MCP bridge → MCP server: tool calls · Frontend reaches the Python MCP server through the bridge.
- Chat API → Orchestrator: serves · Application chat endpoint invokes orchestration.
- Image proxy → Catalog UI: supports · Image proxy backs remote asset rendering in the catalog UI.
- Systemd service → MCP server: runs · System service deploys the MCP server in production.
- Caddy snippet → Chat API: fronts · Reverse proxy can front application routes at deployment time.