-
Notifications
You must be signed in to change notification settings - Fork 0
Add a self-hosted Mastra Studio example #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
717f27d
Add self-hosted Mastra Studio example
andrelandgraf 28280a0
Harden deployment defaults and SSE access
andrelandgraf 5c8520d
Fail deployment on missing Studio settings
andrelandgraf 409c86a
Clarify public authentication routes
andrelandgraf 4dec253
Polish Studio deployment workflow
andrelandgraf ab72e6e
Link Lakebase Postgres documentation
andrelandgraf dd77205
Address final review findings
andrelandgraf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| MASTRA_MODEL=neon/gpt-5-4-mini | ||
| MASTRA_STUDIO_TOKEN= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| pull_request: | ||
| push: | ||
| branches: | ||
| - main | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| persist-credentials: false | ||
| - uses: oven-sh/setup-bun@v2 | ||
| with: | ||
| bun-version: 1.3.14 | ||
| - run: bun install --frozen-lockfile | ||
| - run: bun run typecheck | ||
| - run: bun run test | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| node_modules | ||
| coverage | ||
| dist | ||
| out | ||
| *.log | ||
| *.tsbuildinfo | ||
|
|
||
| .env | ||
| .env.* | ||
| !.env.example | ||
| .neon | ||
|
|
||
| .DS_Store | ||
| .idea |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # Agent instructions | ||
|
|
||
| - Work directly on `main`; do not create branches or pull requests. | ||
| - Commit and push changes to `main` after verification. | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,110 @@ | ||
| # mastra-studio | ||
| Self-host Mastra Studio with Neon Functions, Postgres, Object Storage, and AI Gateway | ||
| # Mastra Studio on Neon | ||
|
|
||
| Self-host [Mastra Studio](https://mastra.ai/docs/getting-started/studio) with Neon. | ||
|
|
||
| - [Neon Functions](https://neon.com/docs/compute/functions/overview) serves the Mastra API and proxies the Studio SPA. | ||
| - [Neon Object Storage](https://neon.com/docs/storage/overview) holds the static Studio assets. | ||
| - [Neon AI Gateway](https://neon.com/docs/ai-gateway/overview) runs the example assistant. | ||
| - [Lakebase Postgres on Neon](https://neon.com/docs/introduction/neon-and-lakebase) stores memory, logs, traces, and metrics. | ||
| - [Mastra SimpleAuth](https://mastra.ai/docs/server/auth/simple-auth) protects Studio and all non-auth Mastra API routes. | ||
|
|
||
|  | ||
|
|
||
| ## Architecture | ||
|
|
||
| ```text | ||
| Browser ──▶ Neon Function ──▶ Object Storage (Studio assets) | ||
| ├────▶ AI Gateway (model calls) | ||
| └────▶ Lakebase Postgres | ||
| ├─ public schema (memory) | ||
| └─ mastra_observability schema (logs, traces, metrics) | ||
| ``` | ||
|
|
||
| The Studio bucket is public-read because it contains only static Studio assets. The Function keeps protected API routes behind authentication. | ||
|
|
||
| ## Deploy | ||
|
|
||
| Prerequisites: | ||
|
|
||
| - [Bun](https://bun.sh/) | ||
| - [Neon CLI](https://neon.com/docs/reference/neon-cli) | ||
| - A Neon project on the [Launch or Scale plan](https://neon.com/docs/ai-gateway/overview#pricing), in AWS US East (Ohio) (`aws-us-east-2`) | ||
|
|
||
| Install dependencies and create the two deployment settings: | ||
|
|
||
| ```bash | ||
| bun install | ||
| cp .env.example .env.deploy | ||
| ``` | ||
|
|
||
| Keep the two custom settings in `.env.deploy`; `neon deploy` writes Neon-generated service credentials to `.env.local`. Set `MASTRA_STUDIO_TOKEN` to a random value, for example from `openssl rand -hex 32`. | ||
|
|
||
| Load the settings, then link the checkout to the target Neon project and branch: | ||
|
|
||
| ```bash | ||
| set -a | ||
| source .env.deploy | ||
| set +a | ||
| neon link | ||
| neon checkout main | ||
| ``` | ||
|
|
||
| Provision Postgres, Object Storage, Functions, and AI Gateway: | ||
|
|
||
| ```bash | ||
| neon deploy --env .env.deploy | ||
| ``` | ||
|
|
||
| Upload the installed Mastra Studio build: | ||
|
|
||
| ```bash | ||
| bun run studio:upload | ||
| ``` | ||
|
|
||
| Run `studio:upload` again after changing the `mastra` package version; the assets come from the installed package. | ||
|
|
||
| Open the Function URL printed by `neon deploy`, then sign in with: | ||
|
|
||
| ```text | ||
| Email: any value (SimpleAuth ignores it) | ||
| Password: the MASTRA_STUDIO_TOKEN value | ||
| ``` | ||
|
|
||
| ## Local development | ||
|
|
||
| ```bash | ||
| set -a | ||
| source .env.deploy | ||
| set +a | ||
| neon dev | ||
| ``` | ||
|
|
||
| Studio runs at `http://localhost:8787`. | ||
|
|
||
| ## Included example | ||
|
|
||
| The Studio exposes: | ||
|
|
||
| - one memory-enabled assistant | ||
| - `calculate`, `get-current-time`, and `get-database-time` tools | ||
| - persisted logs, full trace trees, and automatic model/agent metrics | ||
|
|
||
| ## Verify | ||
|
|
||
| ```bash | ||
| bun run typecheck | ||
| bun run test | ||
| curl http://localhost:8787/health | ||
| ``` | ||
|
|
||
| Unauthenticated requests to protected `/api/*` routes and `/refresh-events` return `401`. | ||
| Mastra authenticates the routes it registers. Custom routes must check `auth.getCurrentUser` explicitly, as `/refresh-events` does. | ||
|
|
||
| ## Production boundaries | ||
|
|
||
| - SimpleAuth is a shared-token example, not multi-user authentication. | ||
| - Each open Studio tab holds an SSE Function invocation. Neon Functions default to [100 concurrent invocations per account](https://neon.com/docs/compute/functions/reference/runtime-limits#concurrency). | ||
| - Observability uses a separate schema in the application database, not a separate database. Each live Function isolate can open up to five Postgres connections. | ||
| - Traces can include prompts and model output. Configure redaction and retention for your data policy; this example does not add a retention job. | ||
| - Functions, Object Storage, and AI Gateway are [beta services not yet recommended for production workloads](https://neon.com/docs/get-started/backend-beta). | ||
| - The Mastra packages are pinned alpha releases because the observability APIs used here are not yet stable. |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.