Commit b7dff0a
authored
feat(core): add setStudio method for runtime studio configuration (#18111)
## Summary
Adds `setStudio()` method to Mastra class, mirroring the existing
`setServer()` method. This enables runtime configuration of studio
auth/RBAC separately from server config.
## Why This Is Needed
Platform deploy wrappers need to implement **dual auth**:
- **Studio requests** (via `*.studio.mastra.cloud`): Use platform auth
(`MastraAuthStudio`)
- **Server requests** (via `*.server.mastra.cloud`): Open API access (no
auth or user-configured auth)
The dual auth flow:
1. Edge router sets `x-mastra-client-type: studio` header based on
domain
2. `@mastra/server`'s `getEffectiveAuthConfig()` routes to `studio.auth`
for studio requests
3. **Wrapper calls `setStudio()` to inject platform auth for studio
requests**
Without `setStudio()`, wrappers can only modify `server.auth` which
applies to **all** requests, breaking the dual auth contract.
## Changes
- Added `setStudio(studio: StudioConfig): void` method to `Mastra` class
- Follows same pattern as `setServer()`
## Usage
```typescript
// In platform deploy wrapper
mastra.setStudio({
auth: new MastraAuthStudio(),
rbac: new MastraRBACStudio({ roleMapping: { admin: ['*'] } }),
});
```
## Related
- Complements PR #17722 (dual auth system documentation)
- Enables unified runtime deploys in mastra-ai/platform
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## ELI5
This PR lets Mastra configure “Studio” login/security separately from
your API server’s login/security. So the admin dashboard (Studio) can
use one auth/RBAC setup while the server API uses another—without mixing
them up.
## Summary
This PR adds a new `setStudio(studio: StudioConfig): void` method to the
`Mastra` class (`packages/core/src/mastra/index.ts`) to configure Studio
authentication and RBAC at runtime, independently from server
configuration.
### What changed
- **New API:** `public setStudio(studio: StudioConfig): void`
- The method stores the provided Studio configuration on the instance’s
private `#studio` field, mirroring the existing `setServer()` pattern.
- **Dual-auth support (opt-in):**
- **Studio requests** (`*.studio.mastra.cloud`) can use Studio-specific
auth (e.g., `MastraAuthStudio`) and Studio-specific RBAC.
- **Server requests** (`*.server.mastra.cloud`) can continue using
server auth (or open API access) without being affected by Studio
settings.
- An edge router sets `x-mastra-client-type: studio` so the server-side
routing logic can apply `studio.auth` for Studio-marked requests.
### Tests & documentation
- Added a `setStudio` test suite verifying:
- a new `Mastra` instance starts with `getStudio()` unset,
- `setStudio()` sets/replaces the Studio config,
- updates can be “merged” by passing an object derived from
`...mastra.getStudio()` while changing nested fields (e.g., updating
`auth` while preserving `rbac`).
- Added a changeset documenting the new `setStudio()` feature and
providing an example usage.
### Example
```ts
mastra.setStudio({
auth: new MastraAuthStudio(),
rbac: new MastraRBACStudio({ roleMapping: { admin: ['*'] } }),
});
```
<!-- end of auto-generated comment: release notes by coderabbit.ai -->1 parent b91d921 commit b7dff0a
3 files changed
Lines changed: 73 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
964 | 964 | | |
965 | 965 | | |
966 | 966 | | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
967 | 989 | | |
968 | 990 | | |
969 | 991 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
0 commit comments