@mastra/mcp-docs-server 1.1.25-alpha.1 → 1.1.25-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -97,22 +97,62 @@ export const mastra = new Mastra({
97
97
 
98
98
  ### Authorization (User Isolation)
99
99
 
100
- Authentication verifies who the user is. Authorization controls what they can access. Without authorization middleware, an authenticated user could access other users' threads by guessing IDs or manipulating the `resourceId` parameter.
100
+ Authentication verifies who the user is. Authorization controls what they can access. Without resource ID scoping, an authenticated user could access other users' threads by guessing IDs or manipulating the `resourceId` parameter.
101
101
 
102
- Mastra provides reserved context keys that, when set by middleware, take precedence over client-provided values. The server automatically enforces these keys across memory and agent endpoints:
102
+ The simplest way to scope memory and threads to the authenticated user is the `mapUserToResourceId` callback in the auth config:
103
103
 
104
104
  ```typescript
105
105
  import { Mastra } from '@mastra/core'
106
- import { MASTRA_RESOURCE_ID_KEY } from '@mastra/core/request-context'
107
- import { getAuthenticatedUser } from '@mastra/server/auth'
108
106
 
109
107
  export const mastra = new Mastra({
110
108
  server: {
111
109
  auth: {
112
110
  authenticateToken: async token => {
113
- // Your auth logic returns the user
114
- return verifyToken(token) // { id: 'user-123', ... }
111
+ return verifyToken(token) // { id: 'user-123', orgId: 'org-456', ... }
115
112
  },
113
+ mapUserToResourceId: user => user.id,
114
+ },
115
+ },
116
+ })
117
+ ```
118
+
119
+ After successful authentication, `mapUserToResourceId` is called with the authenticated user object. The returned value is set as `MASTRA_RESOURCE_ID_KEY` on the request context, which works across all server adapters (Hono, Express, Next.js, etc.).
120
+
121
+ The resource ID doesn't have to be `user.id`. Common patterns:
122
+
123
+ ```typescript
124
+ // Org-scoped
125
+ mapUserToResourceId: user => `${user.orgId}:${user.id}`
126
+
127
+ // From a JWT claim
128
+ mapUserToResourceId: user => user.tenantId
129
+
130
+ // Composite key
131
+ mapUserToResourceId: user => `${user.workspaceId}:${user.projectId}:${user.id}`
132
+ ```
133
+
134
+ With a resource ID set, the server automatically:
135
+
136
+ - **Filters thread listing** to only return threads owned by the user
137
+ - **Validates thread access** and returns 403 if accessing another user's thread
138
+ - **Forces thread creation** to use the authenticated user's ID
139
+ - **Validates message operations** including deletion, ensuring messages belong to owned threads
140
+
141
+ Even if a client passes `?resourceId=other-user-id`, the auth-set value takes precedence. Attempts to access threads or messages owned by other users will return a 403 error.
142
+
143
+ #### Advanced: Setting resource ID in middleware
144
+
145
+ For more complex scenarios (e.g., looking up the resource ID from a database), you can set `MASTRA_RESOURCE_ID_KEY` directly in middleware:
146
+
147
+ ```typescript
148
+ import { Mastra } from '@mastra/core'
149
+ import { MASTRA_RESOURCE_ID_KEY } from '@mastra/core/request-context'
150
+ import { getAuthenticatedUser } from '@mastra/server/auth'
151
+
152
+ export const mastra = new Mastra({
153
+ server: {
154
+ auth: {
155
+ authenticateToken: async token => verifyToken(token),
116
156
  },
117
157
  middleware: [
118
158
  {
@@ -134,10 +174,7 @@ export const mastra = new Mastra({
134
174
  return c.json({ error: 'Unauthorized' }, 401)
135
175
  }
136
176
 
137
- // Force all API operations to use this user's ID
138
- // This takes precedence over any client-provided resourceId
139
177
  requestContext.set(MASTRA_RESOURCE_ID_KEY, user.id)
140
-
141
178
  return next()
142
179
  },
143
180
  },
@@ -148,15 +185,6 @@ export const mastra = new Mastra({
148
185
 
149
186
  `server.middleware` runs before Mastra's per-route auth checks. When middleware needs the authenticated user, call `getAuthenticatedUser()` to resolve it from the configured auth provider without changing the default route auth flow.
150
187
 
151
- With this middleware, the server automatically:
152
-
153
- - **Filters thread listing** to only return threads owned by the user
154
- - **Validates thread access** and returns 403 if accessing another user's thread
155
- - **Forces thread creation** to use the authenticated user's ID
156
- - **Validates message operations** including deletion, ensuring messages belong to owned threads
157
-
158
- Even if a client passes `?resourceId=other-user-id`, the middleware-set value takes precedence. Attempts to access threads or messages owned by other users will return a 403 error.
159
-
160
188
  #### Using `MASTRA_THREAD_ID_KEY`
161
189
 
162
190
  You can also set `MASTRA_THREAD_ID_KEY` to override the client-provided thread ID:
@@ -234,7 +234,18 @@ export const weatherTool = createTool({
234
234
 
235
235
  ## Reserved keys
236
236
 
237
- Mastra reserves special context keys for security purposes. When set by middleware, these keys take precedence over client-provided values. The server automatically validates ownership and returns 403 errors when users attempt to access resources they don't own.
237
+ Mastra reserves special context keys for security purposes. When set, these keys take precedence over client-provided values. The server automatically validates ownership and returns 403 errors when users attempt to access resources they don't own.
238
+
239
+ The easiest way to set `MASTRA_RESOURCE_ID_KEY` is via the `mapUserToResourceId` callback in auth config:
240
+
241
+ ```typescript
242
+ auth: {
243
+ authenticateToken: async token => verifyToken(token),
244
+ mapUserToResourceId: user => user.id,
245
+ }
246
+ ```
247
+
248
+ You can also set these keys manually in middleware:
238
249
 
239
250
  ```typescript
240
251
  import { MASTRA_RESOURCE_ID_KEY, MASTRA_THREAD_ID_KEY } from '@mastra/core/request-context'
@@ -544,11 +544,14 @@ export const mastra = new Mastra({
544
544
  server: {
545
545
  auth: new MastraJwtAuth({
546
546
  secret: process.env.MASTRA_JWT_SECRET,
547
+ mapUserToResourceId: user => user.id,
547
548
  }),
548
549
  },
549
550
  })
550
551
  ```
551
552
 
553
+ The `mapUserToResourceId` callback maps the authenticated user to a resource ID for memory/thread scoping. When provided, it's called after successful authentication and the returned value is set on the request context as `MASTRA_RESOURCE_ID_KEY`. See [Authorization (User Isolation)](https://mastra.ai/docs/server/middleware) for details.
554
+
552
555
  ### server.bodySizeLimit
553
556
 
554
557
  **Type:** `number`\
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @mastra/mcp-docs-server
2
2
 
3
+ ## 1.1.25-alpha.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`8fad147`](https://github.com/mastra-ai/mastra/commit/8fad14759804179c8e080ce4d9dec6ef1a808b31), [`582644c`](https://github.com/mastra-ai/mastra/commit/582644c4a87f83b4f245a84d72b9e8590585012e), [`5d84914`](https://github.com/mastra-ai/mastra/commit/5d84914e0e520c642a40329b210b413fcd139898), [`fd2f314`](https://github.com/mastra-ai/mastra/commit/fd2f31473d3449b6b97e837ef8641264377f41a7), [`e80fead`](https://github.com/mastra-ai/mastra/commit/e80fead1412cc0d1b2f7d6a1ce5017d9e0098ff7), [`0287b64`](https://github.com/mastra-ai/mastra/commit/0287b644a5c3272755cf3112e71338106664103b)]:
8
+ - @mastra/core@1.25.0-alpha.1
9
+
3
10
  ## 1.1.25-alpha.0
4
11
 
5
12
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/mcp-docs-server",
3
- "version": "1.1.25-alpha.1",
3
+ "version": "1.1.25-alpha.3",
4
4
  "description": "MCP server for accessing Mastra.ai documentation, changelogs, and news.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -29,7 +29,7 @@
29
29
  "jsdom": "^26.1.0",
30
30
  "local-pkg": "^1.1.2",
31
31
  "zod": "^4.3.6",
32
- "@mastra/core": "1.24.2-alpha.0",
32
+ "@mastra/core": "1.25.0-alpha.1",
33
33
  "@mastra/mcp": "^1.4.2"
34
34
  },
35
35
  "devDependencies": {
@@ -47,8 +47,8 @@
47
47
  "typescript": "^5.9.3",
48
48
  "vitest": "4.0.18",
49
49
  "@internal/types-builder": "0.0.57",
50
- "@mastra/core": "1.24.2-alpha.0",
51
- "@internal/lint": "0.0.82"
50
+ "@internal/lint": "0.0.82",
51
+ "@mastra/core": "1.25.0-alpha.1"
52
52
  },
53
53
  "homepage": "https://mastra.ai",
54
54
  "repository": {