Natural-language Q&A over gateway MongoDB data using Claude AI.
- On startup, every
.jsfile inmodels/is loaded and its Mongoose schema is parsed into a plain-text summary. POST /askaccepts a plain-English question.- Claude call 1 (Query Generator) receives the schema summary and the question, and returns a raw JSON
{ collection, query }— either an aggregation pipeline or a find filter. - The query is executed against MongoDB using the native driver (read-only).
- Claude call 2 (Answer Formatter) converts the raw results into a concise 2-3 sentence human-readable answer.
npm install
cp .env.example .env # or edit .env directlyEdit .env:
MONGO_URI=mongodb://localhost:27017/gateway
ANTHROPIC_API_KEY=sk-ant-...
PORT=3000
Drop any Mongoose model file into models/. The server reads all .js files at startup and extracts collection names and field types automatically — no hardcoding required.
npm start # production
npm run dev # node --watch (auto-restarts on file changes)// Request
{ "question": "Which intent is failing the most this week?" }
// Response
{ "answer": "The most failing intent this week is 'placeOrder' with 1,243 failures." }{ "status": "ok" }| Situation | HTTP status |
|---|---|
| Missing/empty question | 400 |
| Claude returns invalid JSON | 400 (with raw_response) |
| MongoDB query fails | 500 |
| Claude formatter fails | 500 |