How it24100500/ai-agent works
1. Overall shape
- This repo is centered on a Python MCP server that exposes the Kapruka.com REST API as MCP tools for LLM clients and other MCP consumers.
- The main production boundary is: MCP client → FastMCP server → internal tool modules → async HTTP client → Kapruka REST API.
2. Primary runtime entry points
- cli.py is the developer-facing entry point for running the server and utility commands.
- src/server.py is the actual server bootstrap for the MCP runtime.
- The server supports at least two transports: streamable HTTP and stdio for MCP Inspector / local tooling.
3. MCP tool layer
- src/tools/ contains the domain-facing tool groups:
- products.py
- orders.py
- categories.py
- delivery.py
- These modules are the main contract exposed to MCP clients and likely define the tool schemas, input validation, and tool-specific orchestration logic.
- This is the layer where the API is reshaped from Kapruka’s raw REST semantics into LLM-friendly operations.
4. API integration layer
- src/api/client.py is the outbound integration boundary.
- It wraps the Kapruka REST API with an async HTTP client and centralized error handling.
- The rest of the system should not talk directly to Kapruka; tools go through this client, which keeps external API concerns isolated.
5. Cross-cutting runtime concerns
- src/middleware.py likely hosts request/response concerns that apply across the server, such as logging, headers, authentication-related handling, or other request shaping.
- src/cache.py provides caching support to reduce repeated external API calls and stabilize tool performance.
- src/order_rate_limit.py indicates explicit throttling or protection around order-related actions, which is important because those are usually higher-risk or higher-cost operations.
6. Configuration boundary
- src/config/settings.py centralizes environment-based configuration.
- .env.example shows the system is configured primarily through environment variables, including Kapruka API URL and API key.
- This keeps deployment-specific values out of code and makes the server portable across environments.
7. Operational and observability support
- src/activity_log.py plus scripts/setup_activity_table.py suggest the server records tool or request activity in a persistent table, likely for auditability or usage tracking.
- That creates a second data path besides the main API proxy path: server activity → storage/logging backend.
- tests/test_client.py shows the HTTP client is a key unit boundary worthy of direct test coverage.
8. Well-known / metadata support
- src/well_known.py suggests the server exposes protocol or discovery metadata through a well-known endpoint or standardized integration surface.
- This is relevant for clients that need to discover server capabilities without hardcoding tool details.
9. Frontend boundary
- frontend/ is a separate React + TypeScript application.
- Based on the repo structure, it is a standalone UI, likely for browsing or demonstrating functionality, and is architecturally separate from the Python MCP runtime.
- It should be treated as an independent client-side subsystem rather than part of the server execution path.
10. Static content
- src/static/index.html and src/static/ indicate the Python service also serves some static HTML assets, likely for a landing page, docs, or a minimal web surface.
- This is distinct from the React frontend, which lives in its own package.
11. Deployment topology
- deploy/ contains production-oriented artifacts: a systemd service, a Caddy config snippet, and a sync-to-prod script.
- That implies the server is intended to run as a long-lived Linux service, usually behind a reverse proxy.
- server.json likely supports runtime/hosting configuration for the MCP/server environment.
12. Developer and validation tooling
- scripts/ includes helpers for API exploration, smoke testing, registry publishing, and activity-table setup.
- tests/ contains automated tests, while docs/ holds API notes and handover material.
- These support the repo’s main purpose: safely adapting an external commerce API into a stable MCP surface.
13. Key architectural flow to diagram
- A good diagram would show:
- MCP clients on the left
- FastMCP server / CLI entrypoint in the center
- Tool modules as the domain adapter layer
- Async Kapruka API client as the outbound integration boundary
- Kapruka REST API on the right
- Side paths for config/env, cache, rate limiting, and activity logging
- Separate boxes for frontend, deployment, and test/tooling as supporting subsystems
Main entry points: server.py MCP server · client.py API client · orders.py Orders · settings.py Settings
Components 19
MCP Runtime
Server entrypoints and protocol surface
- CLI · Developer command entry for running and managing the server
cli.py - MCP server · Bootstraps the FastMCP runtime and transport setup
src/server.py - Discovery · Well-known or discovery surface for clients
src/well_known.py - Static site · Served HTML assets for a minimal web surface
src/static/index.html
Tool Layer
Domain-facing MCP tools
- Products · Tool group for product browsing and lookup
src/tools/products.py - Orders · Tool group for order actions and orchestration
src/tools/orders.py - Categories · Tool group for category navigation and lookup
src/tools/categories.py - Delivery · Tool group for delivery-related operations
src/tools/delivery.py
Kapruka API
Outbound REST integration boundary
- API client · Central Kapruka REST API wrapper and error handling boundary
src/api/client.py - Kapruka REST · Upstream commerce API consumed by the server
Support
Cross-cutting runtime and persistence concerns
- Settings · Environment-based configuration for API and runtime behavior
src/config/settings.py - Middleware · Request and response shaping concerns
src/middleware.py - Cache · Caching layer for repeated API access and stability
src/cache.py - Rate limit · Throttling and protection around order actions
src/order_rate_limit.py - Activity log · Persistent activity tracking for tools or requests
src/activity_log.py
Frontend
Separate React client application
- React app · Standalone React + TypeScript frontend
frontend/src/App.tsx
Connections 22
- CLI → MCP server: starts · CLI launches the MCP server runtime
- MCP server → Discovery: exposes · Server publishes discovery metadata
- MCP server → Products: registers · Server binds product tools into MCP
- MCP server → Orders: registers · Server binds order tools into MCP
- MCP server → Categories: registers · Server binds category tools into MCP
- MCP server → Delivery: registers · Server binds delivery tools into MCP
- MCP server → Middleware: uses · Server applies shared request handling
- MCP server → Static site: serves · Server also serves static HTML assets
- Products → API client: calls · Tools delegate external reads and actions through the client
- Orders → API client: calls · Order operations go through the API client boundary
- Categories → API client: calls · Category lookups use the shared API client
- Delivery → API client: calls · Delivery operations use the shared API client
- API client → Kapruka REST: requests · Outbound REST calls reach the Kapruka API
- Settings → MCP server: configures · Environment settings shape server startup and behavior
- Settings → API client: configures · API base URL and credentials are injected here
- Cache → API client: wraps · Caching reduces repeated outbound calls
- Rate limit → Orders: guards · Order actions are protected by throttling
- Activity log → MCP server: records · Operational activity is recorded from the runtime
- React app → MCP server: consumes · Separate UI can consume the server as a client
- Deploy → MCP server: deploys · Production artifacts run and proxy the server
- Scripts → API client: exercises · Developer scripts probe the API integration boundary
- Tests → API client: tests · Unit tests focus on the HTTP client boundary