Overview
Digcrate is a Next.js application with a Convex real-time backend. The browser communicates with serverless API routes on Vercel, which in turn talk to Convex (database), Anthropic (AI), and MCP tool servers (music data).Tech stack
Project structure
The agentic loop
Every user message goes through a multi-turn tool-use loop implemented insrc/lib/agentic-loop.ts.
- The browser sends a
POSTto/api/chatwith the message, session history, model choice, and API key. - The route handler builds the tool list from
crate-cliMCP servers and callsagenticLoop(). - The loop calls the Anthropic (or OpenRouter) API with the message and available tools.
- If the model returns
tool_useblocks, the loop executes each tool call against the appropriate MCP server. - Tool results are fed back to the model as
tool_resultblocks. Steps 3–5 repeat up to 25 turns. - Each turn emits Server-Sent Events to the browser:
thinking,tool_start,tool_end,answer_token, and finallydone. - The browser’s chat panel renders tokens as they arrive and parses OpenUI components from the final answer.
useOpenRouter flag on AgenticLoopOptions selects the path.
Key data flows
Authentication
/api/webhooks/clerk. The Convex users table stores the Clerk user ID, email, encrypted API keys, and Stripe customer ID.