Skip to content

Commit f79daa2

Browse files
YujohnNattrassYJMastra Code (anthropic/claude-opus-4-8)
authored
feat(template-agent-builder): make WorkOS auth and EE license optional in dev (#18171)
## Summary The Agent Builder template could not start unless WorkOS auth credentials and a `MASTRA_EE_LICENSE` were both set, which made it hard to try the template locally. This change makes both optional for local development so the template boots out of the box. - **Auth is now optional.** WorkOS AuthKit + RBAC follow the same env-gated pattern already used for the Composio, Slack, and Browserbase integrations: they are only enabled when the WorkOS variables are present. With them unset, the template runs without authentication. - **The redundant startup license check is removed.** The license is still enforced by `@mastra/editor` for production use (with a development bypass), so the template's own fail-fast guard was redundant and blocked local dev. Development no longer requires a license. ## Changes - `src/mastra/auth.ts`: `initWorkOS` returns `null` when the WorkOS env vars are not all set, instead of throwing. - `src/mastra/index.ts`: `auth`/`rbac` are spread into the server config only when WorkOS is configured; removed the `requireEnterpriseLicense()` startup call. - `src/mastra/env.ts`: removed the now-unused `requireEnterpriseLicense` and `requiredEnv` helpers. - `.env.example`: WorkOS moved to an optional section; license documented as required for production only. - `README.md`: WorkOS listed under optional integrations; license framed as production-only with a dev note. ## Test plan - Copy the template out of the monorepo, `pnpm install`, set only `OPENAI_API_KEY`, run `mastra dev` — it boots with no auth and no license. - Add `WORKOS_API_KEY`, `WORKOS_CLIENT_ID`, `WORKOS_COOKIE_PASSWORD` and restart — auth + RBAC are enabled. ## Note This PR is based on the playground request-context fix branch so its diff is scoped to the template only. Rebase onto `main` once that PR merges. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## ELI5 (Explain Like I'm 5) This PR makes it possible to run the Agent Builder template on your computer without needing to set up special authentication or buy an enterprise license first. Instead of requiring all the setup details before you can even start the app, it now checks if you have them and skips authentication if you don't, letting you test and develop locally with just the OpenAI API key. ## Changes Summary ### Core Functionality Changes **Authentication made optional for local development:** - `src/mastra/auth.ts`: The `initWorkOS` function now returns `null` when WorkOS environment variables (`WORKOS_API_KEY`, `WORKOS_CLIENT_ID`, `WORKOS_COOKIE_PASSWORD`) are missing, instead of throwing an error. When variables are present, it initializes WorkOS auth and RBAC as before. - `src/mastra/index.ts`: The Mastra server configuration now conditionally includes `auth` and `rbac` only when WorkOS is properly configured. Removed the unconditional `requireEnterpriseLicense()` startup-time check. - `src/mastra/env.ts`: Removed the `requiredEnv` and `requireEnterpriseLicense` helper functions that are no longer needed with the optional authentication pattern. ### Configuration & Documentation Updates **Updated environment variable documentation:** - `.env.example`: Clarified that `OPENAI_API_KEY` powers builder-created agents and that `MASTRA_EE_LICENSE` is required only for production (development runs without it). Expanded WorkOS section to explain that AuthKit + RBAC are only enabled when all required WorkOS variables are set. - `README.md`: Updated to reflect that WorkOS AuthKit authentication/RBAC is optional, adjusted license prerequisites for production vs. development, and documented that the template runs without authentication when WorkOS values are unset. ### Model & Dependency Updates **Model configuration:** - `src/mastra/index.ts`: Updated the builder model allowlist to use the `gpt-5.4-*` family with `gpt-5.4-nano` as the default model. Removed redundant builder features configuration block. **New dependencies:** - `package.json`: Added `@mastra/stagehand: "latest"` and `zod: "^4.3.6"` as direct dependencies (zod was previously relied upon as a peer of `@mastra/core`). <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: YJ <yj@example.com> Co-authored-by: Mastra Code (anthropic/claude-opus-4-8) <noreply@mastra.ai>
1 parent b04369d commit f79daa2

6 files changed

Lines changed: 33 additions & 54 deletions

File tree

templates/template-agent-builder/.env.example

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
# Required
2-
# Agent Builder is an Enterprise feature. Use a valid license key (at least 32 characters).
3-
MASTRA_EE_LICENSE=
2+
# OPENAI_API_KEY powers builder-created agents that use the default OpenAI model.
43
OPENAI_API_KEY=
54

6-
# Required: WorkOS AuthKit + RBAC
5+
# Required for production: Agent Builder is an Enterprise feature.
6+
# Use a valid license key (at least 32 characters). Development runs without one.
7+
MASTRA_EE_LICENSE=
8+
9+
# Optional: WorkOS AuthKit + RBAC
10+
# Enables authentication and RBAC only when all three values are set.
711
# WORKOS_COOKIE_PASSWORD must be at least 32 characters.
812
WORKOS_API_KEY=
913
WORKOS_CLIENT_ID=

templates/template-agent-builder/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ A minimal [Mastra](https://mastra.ai) Agent Builder template with safe defaults.
55
## Features
66

77
- Agent Builder enabled by default
8-
- WorkOS AuthKit authentication and WorkOS-backed RBAC permissions
8+
- Optional WorkOS AuthKit authentication and WorkOS-backed RBAC permissions
99
- Local filesystem workspace at `.mastra/workspace`
1010
- No starter agents, tools, or workflows
1111
- Observational memory enabled for builder-created agents
@@ -15,8 +15,7 @@ A minimal [Mastra](https://mastra.ai) Agent Builder template with safe defaults.
1515

1616
- Node.js 22.13 or newer
1717
- An OpenAI API key
18-
- A valid `MASTRA_EE_LICENSE` for Agent Builder
19-
- WorkOS AuthKit credentials for authentication/RBAC
18+
- A valid `MASTRA_EE_LICENSE` for running Agent Builder in production
2019

2120
## Quickstart
2221

@@ -28,10 +27,10 @@ A minimal [Mastra](https://mastra.ai) Agent Builder template with safe defaults.
2827

2928
2. **Configure environment variables**
3029
Copy `.env.example` to `.env`, then set:
31-
- `MASTRA_EE_LICENSE` — required; the template fails fast if it is missing or shorter than 32 characters.
30+
- `MASTRA_EE_LICENSE` — required to run Agent Builder in production. Development environments run without one.
3231
- `OPENAI_API_KEY` — required for builder-created agents that use the default OpenAI model.
33-
- `WORKOS_API_KEY`, `WORKOS_CLIENT_ID`, and `WORKOS_COOKIE_PASSWORD` — required for AuthKit login and RBAC. The cookie password must be at least 32 characters.
34-
- `WORKOS_REDIRECT_URI` — defaults to `http://localhost:4111/api/auth/callback`.
32+
33+
Authentication is optional. See [Optional integrations](#optional-integrations) for WorkOS and other providers.
3534

3635
3. **Start Mastra**
3736

@@ -46,6 +45,7 @@ A minimal [Mastra](https://mastra.ai) Agent Builder template with safe defaults.
4645

4746
The template does not register optional integrations with empty credentials. They appear only after you set their required environment variables:
4847

48+
- **WorkOS AuthKit (auth + RBAC)**: set `WORKOS_API_KEY`, `WORKOS_CLIENT_ID`, and `WORKOS_COOKIE_PASSWORD` (the cookie password must be at least 32 characters). `WORKOS_REDIRECT_URI` is optional and defaults to `http://localhost:4111/api/auth/callback`. When these are unset, the template runs without authentication.
4949
- **Composio**: set `COMPOSIO_API_KEY`.
5050
- **Slack**: set `SLACK_APP_CONFIG_TOKEN` and `SLACK_APP_CONFIG_REFRESH_TOKEN`. `SLACK_BASE_URL` is optional.
5151
- **Browserbase + Stagehand**: set both `BROWSERBASE_API_KEY` and `BROWSERBASE_PROJECT_ID`.

templates/template-agent-builder/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
"@mastra/libsql": "latest",
1717
"@mastra/observability": "latest",
1818
"@mastra/slack": "latest",
19-
"@mastra/stagehand": "latest"
19+
"@mastra/stagehand": "latest",
20+
"zod": "^4.3.6"
2021
},
2122
"devDependencies": {
2223
"@types/node": "latest",

templates/template-agent-builder/src/mastra/auth.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { MastraAuthWorkos, MastraRBACWorkos } from '@mastra/auth-workos';
22

3-
import { requiredEnv } from './env';
3+
import { hasEnv } from './env';
44

55
export async function initWorkOS() {
6-
requiredEnv('WORKOS_API_KEY');
7-
requiredEnv('WORKOS_CLIENT_ID');
8-
requiredEnv('WORKOS_COOKIE_PASSWORD');
6+
if (!hasEnv('WORKOS_API_KEY') || !hasEnv('WORKOS_CLIENT_ID') || !hasEnv('WORKOS_COOKIE_PASSWORD')) {
7+
return null;
8+
}
99

1010
const mastraAuth = new MastraAuthWorkos({
1111
redirectUri: process.env.WORKOS_REDIRECT_URI || 'http://localhost:4111/api/auth/callback',
Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,3 @@
11
export const getEnv = (name: string) => process.env[name]?.trim();
22

33
export const hasEnv = (name: string) => Boolean(getEnv(name));
4-
5-
export const requiredEnv = (name: string) => {
6-
const value = getEnv(name);
7-
8-
if (!value) {
9-
throw new Error(`Missing required environment variable: ${name}. Add it to .env before starting.`);
10-
}
11-
12-
return value;
13-
};
14-
15-
export const requireEnterpriseLicense = () => {
16-
const license = requiredEnv('MASTRA_EE_LICENSE');
17-
18-
if (license.length < 32) {
19-
throw new Error(
20-
'Agent Builder requires a valid MASTRA_EE_LICENSE with at least 32 characters. Add it to .env before starting.',
21-
);
22-
}
23-
24-
return license;
25-
};

templates/template-agent-builder/src/mastra/index.ts

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,9 @@ import { SlackProvider } from '@mastra/slack';
88
import { StagehandBrowser } from '@mastra/stagehand';
99

1010
import { initWorkOS } from './auth';
11-
import { getEnv, hasEnv, requireEnterpriseLicense } from './env';
11+
import { getEnv, hasEnv } from './env';
1212
import { workspace } from './workspace';
1313

14-
requireEnterpriseLicense();
1514
const workos = await initWorkOS();
1615

1716
const storage = new LibSQLStore({
@@ -50,18 +49,6 @@ const editor = new MastraEditor({
5049
: {}),
5150
builder: {
5251
enabled: true,
53-
features: {
54-
agent: {
55-
tools: true,
56-
agents: true,
57-
workflows: true,
58-
favorites: true,
59-
skills: true,
60-
model: true,
61-
browser: hasBrowserbase,
62-
avatarUpload: true,
63-
},
64-
},
6552
configuration: {
6653
agent: {
6754
workspace: { type: 'id', workspaceId: workspace.id },
@@ -72,10 +59,15 @@ const editor = new MastraEditor({
7259
},
7360
},
7461
models: {
75-
allowed: [{ provider: 'openai' }, { provider: 'anthropic', modelId: 'claude-sonnet-4-6' }],
62+
allowed: [
63+
{ provider: 'openai', modelId: 'gpt-5.4-nano' },
64+
{ provider: 'openai', modelId: 'gpt-5.4-mini' },
65+
{ provider: 'openai', modelId: 'gpt-5.4' },
66+
{ provider: 'openai', modelId: 'gpt-5.4-pro' },
67+
],
7668
default: {
7769
provider: 'openai',
78-
modelId: 'gpt-5',
70+
modelId: 'gpt-5.4-nano',
7971
},
8072
},
8173
...(hasBrowserbase
@@ -103,8 +95,12 @@ export const mastra = new Mastra({
10395
sourcemap: true,
10496
},
10597
server: {
106-
auth: workos.mastraAuth,
107-
rbac: workos.rbacProvider,
98+
...(workos
99+
? {
100+
auth: workos.mastraAuth,
101+
rbac: workos.rbacProvider,
102+
}
103+
: {}),
108104
build: {
109105
swaggerUI: true,
110106
},

0 commit comments

Comments
 (0)