An agentic AI chatbot that lets retail staff query live order,
inventory, and customer data using natural language โ with an
enterprise-grade pattern to ensure customer PII never reaches the AI
model.
RoleFull Stack Architect & Developer
PlatformAWS EC2 ยท Nginx ยท GitHub Actions
DomainRetail Operations
TypeAI / MCP Agentic POC
The Problem
Retail staff spending 20+ minutes per shift hunting through dashboards
for basic answers
The retail client's operations team needed answers like "what's the
stock level for SKU-4821?" and "how many orders are pending dispatch
in the North region?" โ all requiring separate dashboard logins and
SQL knowledge.
Critical Constraint: Customer PII (names,
addresses, phone numbers, email) must never be sent to the OpenAI
API. GDPR and internal data policy required all external AI calls to
operate on anonymised identifiers only.
Architecture
MCP Server as the intelligent data access layer
1
React Chat UIClean streaming chat interface with SSE for real-time response
streaming. Responses stream token by token.
2
FastAPI Orchestration LayerReceives user messages, manages conversation history, calls AI
with tools available, and routes tool results through the
agentic loop until a final answer is reached.
3
MCP Server (Tool Definitions)Exposes typed tools: get_order_by_id, get_stock_level,
list_pending_dispatch. Each tool returns only fields needed โ
never full customer records.
4
ID-Based Lazy Loading (PII Protection)AI model is given only numeric IDs. Full PII is assembled
server-side and presented to the user โ never sent to OpenAI.
This is the enterprise data boundary pattern.
5
PostgreSQL Retail DatabaseNormalised retail schema. MCP tools use parameterised queries
exclusively โ no dynamic SQL construction.
Key Challenges
Engineering the PII boundary correctly
๐
Preventing PII leakage through the agentic loopEarly versions allowed the model to request full customer
objects. Fixed by strict tool schema design โ no tool returns
name, email, phone, or address fields.
๐
Agentic loop not terminatingGPT-4o-mini occasionally called tools in circles. Fixed with a
maximum tool call depth of 8 and loop-detection checking
repeated (tool, argument) pairs.
โก
SSE streaming dropped by NginxNginx buffered the SSE stream, causing burst responses instead
of streaming. Fixed with X-Accel-Buffering: no and
proxy_buffering off on the /stream endpoint.
Outcomes
Staff got answers in seconds, not dashboards
~8s
Average query response time
0
PII records sent to OpenAI
92%
Query accuracy in testing
CI/CD
Auto-deploy via GitHub Actions
Result: Client approved Phase 2 โ expanding tool
coverage to supplier and logistics data.