Integrate Cedar-OS with Mastra
Cedar-OS is an open-source agentic UI framework designed specifically for building the most ambitious AI-native applications. We built Cedar with Mastra in mind.
Should you use Cedar?
There are a few pillars we care about strongly that you can read more about here :
1. Developer experience
- Every single component is downloaded shadcn-style – You own all the code and can style it however you want
- Works out of the box – Just drop in our chat component, and it’ll work
- Fully extensible - Built on a Zustand store architecture that you can customize completely. Every single internal function can be overridden in one line.
2. Enabling truly AI-native applications
For the first time in history, products can come to life. We want to help you build something with life.
- Spells - Users can trigger AI from keyboard shortcuts, mouse events, text selection, and other components
- State Diff Management - Give users control over accepting/rejecting agent outputs
- Voice Integration - Let users control your app with their voice
Quick Start
Set up your project
Run Cedar’s CLI command:
npx cedar-os-cli plant-seed
If starting from scratch, select the Mastra starter template for a complete setup with both frontend and backend in a monorepo
If you already have a Mastra backend, use the blank frontend cedar repo option instead.
- This will give you the option to download components and download all dependencies for Cedar. We recommend at least downloading one of the chat components to get started.
Wrap your app with CedarCopilot
Wrap your application with the CedarCopilot provider to connect to your Mastra backend:
import { CedarCopilot } from 'cedar-os';
function App() {
return (
<CedarCopilot
llmProvider={{
provider: 'mastra',
baseURL: 'http://localhost:4111', // default dev port for Mastra
apiKey: process.env.NEXT_PUBLIC_MASTRA_API_KEY, // optional — only for backend auth
}}>
<YourApp />
</CedarCopilot>
);
}
Configure Mastra endpoints
Configure your Mastra backend to work with Cedar by following the Mastra Configuration Options .
Register API routes in your Mastra server (or NextJS serverless routes if in a monorepo):
import { registerApiRoute } from '@mastra/core/server';
// POST /chat
// The chat's non-streaming default endpoint
registerApiRoute('/chat', {
method: 'POST',
// …validate input w/ zod
handler: async (c) => {
/* your agent.generate() logic */
},
});
// POST /chat/stream (SSE)
// The chat's streaming default endpoint
registerApiRoute('/chat/stream', {
method: 'POST',
handler: async (c) => {
/* stream agent output in SSE format */
},
});
Add Cedar components
Drop Cedar components into your frontend – see Chat Overview .
Your backend and frontend are now linked! You’re ready to start building AI-native experiences with your Mastra agents.
More information
- Check out the detailed Mastra integration guide for more configuration options (or for manual installation instructions if something goes wrong)
- Explore Mastra-specific optimizations and features we’ve built
- Seamless event streaming - Automatic rendering of Mastra streamed eventsÂ
- Voice endpoint support - Built-in voice backend integrationÂ
- End-to-End type safety - Types for communicating between your app and Mastra backend
- Join our Discord! We’re excited to have you :)