Tutorial: Add Chat to Your App
This tutorial walks you through building a chat-over-data application with MooseStack: an LLM-powered chat UI backed by ClickHouse, with MCP tools for querying your data, and a Next.js frontend where you can build custom dashboards or use a query builder.
By the end of this guide you'll have
Chat UI with MCP-backed data access
A resizable chat panel in your Next.js app, powered by Claude, that queries your ClickHouse data through MCP tools.
MooseStack backend with MCP server
A MooseStack service exposing query_clickhouse and get_data_catalog tools, with bearer token authentication.
Type-safe query layer (optional)
A defineQueryModel-based metrics layer that projects consistent metric definitions to chat, MCP, APIs, and dashboards.
Query builder APIs (optional)
Deterministic REST endpoints powered by buildQuery — no LLM in the loop, same metric definitions as chat and MCP.
Production deployment
Backend deployed on Fiveonefour, frontend on Vercel, with production data loaded and authenticated.
Everything is code: your data models, query layer, MCP tools, and chat configuration all live in your repo, go through PR review, and deploy through your normal CI/CD pipeline. With MooseStack, you iterate locally against a real ClickHouse instance, then deploy to Fiveonefour when you're ready to ship.
Sample data
If you don't have your own data yet, you can use the Amazon Customer Reviews dataset (150M+ rows, no auth required) to follow along.
Want Python Examples?
You'll work through:
- Project and Dev Harness Setup to initialize your MooseStack project, configure authentication, connect your dev harness, and verify the chat UI runs locally.
- Model and Load Data to define your data models and populate ClickHouse.
- Test Basic Chat to verify the chat can query your data and customize the system prompt.
- Query Layer (optional) to add type-safe metrics that stay consistent across every surface.
- Query Builder (optional) to create deterministic REST API endpoints from your query model.
- Deploy to Production to ship your backend to Fiveonefour and frontend to Vercel.
AI-assisted Development
We recommend using an AI copilot to accelerate development. However, you can complete every step manually if you prefer. Any AI-enabled editor (Claude Code, Cursor, Codex, Opencode, GitHub Copilot, Windsurf, etc.) will work. Editors that support MCPs can make this workflow even faster.
Project and Dev Harness Setup
Get your project initialized and running locally.
Model and Load Your Data
Define your data models in MooseStack and get data into ClickHouse.
Test Basic Chat with Data Access
Verify that your chat can query your data through the MCP tools.
Query Layer (Optional)
Right now, the chat generates SQL on the fly. That works for exploration, but the moment the same metric lives in chat, an API, a dashboard, and an MCP tool, you have multiple SQL definitions that can drift.
Example: chat generates SUM(amount) for revenue. The dashboard uses sumIf(amount, status = 'completed'). One is wrong. A query layer prevents this by giving every surface the same definition.
It solves two problems:
- Consistency: one metric definition, same answer everywhere. No re-implementation per surface.
- Safe changes: update a metric once, every consumer stays in sync. The type system catches breaking changes at compile time.

See the query layer docs and Define once, project everywhere for more detail. The steps below walk you through implementing it.
Dashboard and Query Builder (Optional)
Your chat app works — now add visual components. This section covers slotting in dashboard charts powered by your query model, and building a composable query builder for flexible data exploration.
A query builder gives users a point-and-click interface to explore data — select metrics, pick dimensions, apply filters — without writing SQL or relying on an LLM. Because it reads directly from your query model's metadata, any metric or dimension you add to your defineQueryModel automatically appears as an option in the UI. One definition, every surface.
See the query builder docs and the financial demo APIs for working examples.
Deploy to Production
Ship your backend to Fiveonefour and your frontend to Vercel. Both platforms deploy from GitHub, so pushing to your repo triggers builds automatically.