@mastra/mcp-docs-server 1.1.49-alpha.1 → 1.1.49-alpha.2

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.
@@ -0,0 +1,429 @@
1
+ # Session class
2
+
3
+ > **Alpha:** The `Harness` feature is in alpha stage and subject to breaking changes in minor versions until it graduates from its alpha status.
4
+
5
+ A `Session` owns all the state tied to a single conversation. The [`Harness`](https://mastra.ai/reference/harness/harness-class) is the shared host — agents, storage, config, the thread lock, and the event bus — while the `Session` holds everything that is per-conversation: identity, the active thread binding and reads, mode and model selection, run and abort state, the live agent stream, tool suspensions, follow-ups, approvals, permission grants, token usage, and the display-state snapshot.
6
+
7
+ Access the session through `harness.session`.
8
+
9
+ For a conceptual introduction, see the [Harness overview](https://mastra.ai/docs/harness/overview).
10
+
11
+ ## Usage example
12
+
13
+ ```typescript
14
+ // Read per-conversation state through harness.session
15
+ const modeId = harness.session.mode.get()
16
+ const modelId = harness.session.model.get()
17
+ const threadId = harness.session.thread.getId()
18
+ const grants = harness.session.getGrants()
19
+
20
+ // Render from the coalesced display-state snapshot
21
+ harness.subscribe(event => {
22
+ if (event.type === 'display_state_changed') {
23
+ render(harness.session.displayState.get())
24
+ }
25
+ })
26
+ ```
27
+
28
+ ## Properties
29
+
30
+ The session is organized into sub-objects, each owning one domain of per-conversation state.
31
+
32
+ **identity** (`SessionIdentity`): Resource identity for the conversation. See identity methods below.
33
+
34
+ **thread** (`SessionThread`): Active thread binding and thread/message reads. See thread methods below.
35
+
36
+ **mode** (`SessionMode`): Active mode selection. See mode methods below.
37
+
38
+ **model** (`SessionModel`): Active model selection, including per-mode persistence. See model methods below.
39
+
40
+ **run** (`SessionRun`): Run and trace identity plus abort state for the in-flight run. See run methods below.
41
+
42
+ **stream** (`SessionStream`): The live subscription to the agent thread stream. See stream methods below.
43
+
44
+ **suspensions** (`SessionSuspensions`): Parked interactive tool calls awaiting a resume. See suspensions methods below.
45
+
46
+ **followUps** (`SessionFollowUps`): Queue of messages submitted while a run is in progress. See follow-up methods below.
47
+
48
+ **approval** (`SessionApproval`): The pending tool-approval gate. See approval methods below.
49
+
50
+ **displayState** (`SessionDisplayState`): The canonical HarnessDisplayState snapshot a UI renders from. See display-state methods below.
51
+
52
+ **state** (`SessionState<TState>`): The schema-validated, session-owned Harness state. See state methods below.
53
+
54
+ ## Methods
55
+
56
+ ### Permissions
57
+
58
+ Session-scoped grants auto-approve tools without prompting. Grants are ephemeral — they reset when the session restarts and are never persisted.
59
+
60
+ #### `grantCategory(category)`
61
+
62
+ Grant a tool category for the current session. Tools in this category are auto-approved.
63
+
64
+ ```typescript
65
+ harness.session.grantCategory('edit')
66
+ ```
67
+
68
+ #### `grantTool(toolName)`
69
+
70
+ Grant a specific tool for the current session.
71
+
72
+ ```typescript
73
+ harness.session.grantTool('mastra_workspace_execute_command')
74
+ ```
75
+
76
+ #### `getGrants()`
77
+
78
+ Return the currently granted categories and tools.
79
+
80
+ ```typescript
81
+ const grants = harness.session.getGrants()
82
+ // { categories: string[], tools: string[] }
83
+ ```
84
+
85
+ ### Tool approvals
86
+
87
+ #### `respondToToolApproval({ decision, requestContext? })`
88
+
89
+ Respond to a pending tool approval request, raised by a `tool_approval_required` event. Pass `always_allow_category` to also grant the tool's whole category for the rest of the session.
90
+
91
+ ```typescript
92
+ harness.session.respondToToolApproval({ decision: 'approve' })
93
+ harness.session.respondToToolApproval({ decision: 'decline' })
94
+ harness.session.respondToToolApproval({ decision: 'always_allow_category' })
95
+ ```
96
+
97
+ ### Run control
98
+
99
+ #### `getCurrentRunId()`
100
+
101
+ Return the run ID of the in-flight run, or `null` when idle. Prefers the live stream's active run, falling back to the last stored run ID.
102
+
103
+ ```typescript
104
+ const runId = harness.session.getCurrentRunId()
105
+ ```
106
+
107
+ #### `abortRun()`
108
+
109
+ Abort the in-flight run: aborts the live stream, requests abort on the run, and clears parked tool suspensions.
110
+
111
+ ```typescript
112
+ harness.session.abortRun()
113
+ ```
114
+
115
+ ### Token usage
116
+
117
+ #### `getTokenUsage()`
118
+
119
+ Return a copy of the running token-usage tally for the active thread.
120
+
121
+ ```typescript
122
+ const usage = harness.session.getTokenUsage()
123
+ // { promptTokens, completionTokens, totalTokens, ... }
124
+ ```
125
+
126
+ ## Identity
127
+
128
+ `session.identity` owns the resource ID for the conversation.
129
+
130
+ ### `session.identity.getResourceId()`
131
+
132
+ Return the current resource ID.
133
+
134
+ ```typescript
135
+ const resourceId = harness.session.identity.getResourceId()
136
+ ```
137
+
138
+ ### `session.identity.getDefaultResourceId()`
139
+
140
+ Return the resource ID the session was created with.
141
+
142
+ ```typescript
143
+ const defaultResourceId = harness.session.identity.getDefaultResourceId()
144
+ ```
145
+
146
+ To change the resource ID, use [`harness.setResourceId()`](https://mastra.ai/reference/harness/harness-class), which also tears down the active thread.
147
+
148
+ ## Thread
149
+
150
+ `session.thread` owns the active thread binding plus thread and message reads. Thread lifecycle (create, switch, clone, delete, rename) lives on the [`Harness`](https://mastra.ai/reference/harness/harness-class) because it coordinates the shared thread lock and event bus.
151
+
152
+ ### `session.thread.getId()`
153
+
154
+ Return the active thread ID, or `null` when no thread is bound.
155
+
156
+ ```typescript
157
+ const threadId = harness.session.thread.getId()
158
+ ```
159
+
160
+ ### `session.thread.list(options?)`
161
+
162
+ List threads from storage. By default only threads for the current resource are returned, and transient forked subagent threads are hidden.
163
+
164
+ ```typescript
165
+ const threads = await harness.session.thread.list()
166
+ const allThreads = await harness.session.thread.list({ allResources: true })
167
+ const everything = await harness.session.thread.list({ includeForkedSubagents: true })
168
+ ```
169
+
170
+ ### `session.thread.getById({ threadId })`
171
+
172
+ Return a single thread by ID, or `null` if it doesn't exist.
173
+
174
+ ```typescript
175
+ const thread = await harness.session.thread.getById({ threadId: 'thread-abc123' })
176
+ ```
177
+
178
+ ### `session.thread.listActiveMessages(options?)`
179
+
180
+ Retrieve messages for the active thread. Returns an empty array when no thread is bound.
181
+
182
+ ```typescript
183
+ const messages = await harness.session.thread.listActiveMessages({ limit: 50 })
184
+ ```
185
+
186
+ ### `session.thread.listMessages({ threadId, limit? })`
187
+
188
+ Retrieve messages for a specific thread.
189
+
190
+ ```typescript
191
+ const messages = await harness.session.thread.listMessages({ threadId: 'thread-abc123' })
192
+ ```
193
+
194
+ ### `session.thread.firstUserMessage({ threadId })`
195
+
196
+ Retrieve the first user message for a thread, or `null` if none.
197
+
198
+ ```typescript
199
+ const firstMsg = await harness.session.thread.firstUserMessage({ threadId: 'thread-abc123' })
200
+ ```
201
+
202
+ ### `session.thread.firstUserMessages({ threadIds })`
203
+
204
+ Retrieve the first user message for many threads at once, returned as a map.
205
+
206
+ ```typescript
207
+ const firstByThread = await harness.session.thread.firstUserMessages({
208
+ threadIds: ['thread-a', 'thread-b'],
209
+ })
210
+ ```
211
+
212
+ ### `session.thread.getSetting({ key })` / `setSetting({ key, value })` / `deleteSetting({ key })`
213
+
214
+ Read, write, and remove per-thread settings stored on the active thread's metadata.
215
+
216
+ ```typescript
217
+ await harness.session.thread.setSetting({ key: 'omThreshold', value: 0.8 })
218
+ const value = await harness.session.thread.getSetting({ key: 'omThreshold' })
219
+ await harness.session.thread.deleteSetting({ key: 'omThreshold' })
220
+ ```
221
+
222
+ ## Mode
223
+
224
+ `session.mode` owns the active mode selection. Switching modes is performed on the [`Harness`](https://mastra.ai/reference/harness/harness-class) because it emits events and rebinds the stream.
225
+
226
+ ### `session.mode.get()`
227
+
228
+ Return the active mode ID.
229
+
230
+ ```typescript
231
+ const modeId = harness.session.mode.get()
232
+ ```
233
+
234
+ ### `session.mode.resolve()`
235
+
236
+ Return the full `HarnessMode` object for the active mode, resolved against the harness's configured modes.
237
+
238
+ ```typescript
239
+ const mode = harness.session.mode.resolve()
240
+ ```
241
+
242
+ ## Model
243
+
244
+ `session.model` owns the active model selection, including per-mode model memory. Switching models is performed on the [`Harness`](https://mastra.ai/reference/harness/harness-class).
245
+
246
+ ### `session.model.get()`
247
+
248
+ Return the active model ID.
249
+
250
+ ```typescript
251
+ const modelId = harness.session.model.get()
252
+ ```
253
+
254
+ ### `session.model.hasSelection()`
255
+
256
+ Check whether a model is currently selected.
257
+
258
+ ```typescript
259
+ if (harness.session.model.hasSelection()) {
260
+ // Ready to send messages
261
+ }
262
+ ```
263
+
264
+ ## Run
265
+
266
+ `session.run` owns run and trace identity plus abort state for the in-flight run.
267
+
268
+ ### `session.run.getRunId()` / `getTraceId()`
269
+
270
+ Return the stored run ID and trace ID for the current run, or `null` when idle.
271
+
272
+ ```typescript
273
+ const runId = harness.session.run.getRunId()
274
+ const traceId = harness.session.run.getTraceId()
275
+ ```
276
+
277
+ ### `session.run.isRunning()`
278
+
279
+ Return whether a run is currently in progress.
280
+
281
+ ```typescript
282
+ if (harness.session.run.isRunning()) {
283
+ // A run is active
284
+ }
285
+ ```
286
+
287
+ ## Stream
288
+
289
+ `session.stream` owns the live subscription to the agent thread stream and its dedup key.
290
+
291
+ ### `session.stream.activeRunId()`
292
+
293
+ Return the run ID active on the live stream, or `null` when no stream is open.
294
+
295
+ ```typescript
296
+ const runId = harness.session.stream.activeRunId()
297
+ ```
298
+
299
+ ### `session.stream.isActive()`
300
+
301
+ Return whether the stream currently has an active run.
302
+
303
+ ```typescript
304
+ if (harness.session.stream.isActive()) {
305
+ // The current thread's stream is producing output
306
+ }
307
+ ```
308
+
309
+ ## Suspensions
310
+
311
+ `session.suspensions` owns parked interactive tool calls (such as `ask_user` and `request_access`) awaiting a resume.
312
+
313
+ ### `session.suspensions.hasPending()`
314
+
315
+ Return whether any tool is currently suspended.
316
+
317
+ ```typescript
318
+ if (harness.session.suspensions.hasPending()) {
319
+ // At least one interactive tool is waiting for a response
320
+ }
321
+ ```
322
+
323
+ ### `session.suspensions.has({ toolCallId })`
324
+
325
+ Return whether a specific tool call is suspended.
326
+
327
+ ```typescript
328
+ const waiting = harness.session.suspensions.has({ toolCallId: event.toolCallId })
329
+ ```
330
+
331
+ Resume a suspended tool with [`harness.respondToToolSuspension()`](https://mastra.ai/reference/harness/harness-class).
332
+
333
+ ## Follow-ups
334
+
335
+ `session.followUps` owns the FIFO queue of messages submitted while a run is in progress.
336
+
337
+ ### `session.followUps.count()`
338
+
339
+ Return the number of queued follow-ups.
340
+
341
+ ```typescript
342
+ const queued = harness.session.followUps.count()
343
+ ```
344
+
345
+ ### `session.followUps.isEmpty()`
346
+
347
+ Return whether the follow-up queue is empty.
348
+
349
+ ```typescript
350
+ if (!harness.session.followUps.isEmpty()) {
351
+ // Messages are waiting to be processed
352
+ }
353
+ ```
354
+
355
+ ## Approval
356
+
357
+ `session.approval` owns the pending tool-approval gate.
358
+
359
+ ### `session.approval.isArmed()`
360
+
361
+ Return whether a tool is currently awaiting an approval decision.
362
+
363
+ ```typescript
364
+ if (harness.session.approval.isArmed()) {
365
+ // Show the approval prompt
366
+ }
367
+ ```
368
+
369
+ Respond with [`session.respondToToolApproval()`](#respondtotoolapproval-decision-requestcontext-).
370
+
371
+ ## Display state
372
+
373
+ `session.displayState` owns the canonical `HarnessDisplayState` snapshot a UI renders from, and the reducer that keeps it in sync with every harness event.
374
+
375
+ ### `session.displayState.get()`
376
+
377
+ Return the current `HarnessDisplayState` snapshot for UI rendering.
378
+
379
+ ```typescript
380
+ const displayState = harness.session.displayState.get()
381
+ ```
382
+
383
+ ### `session.displayState.restoreTasks(tasks)`
384
+
385
+ Restore the task portion of the snapshot after a UI replays persisted task tool history. This is a pure update of the snapshot and does not emit an event, so re-render explicitly after calling it.
386
+
387
+ ```typescript
388
+ harness.session.displayState.restoreTasks(replayedTasks)
389
+ ```
390
+
391
+ After every event the harness emits `display_state_changed`, so high-frequency events such as `message_update`, `tool_update`, and `tool_input_delta` are coalesced into the next snapshot. Subscribe with [`harness.subscribe()`](https://mastra.ai/reference/harness/harness-class) and read the latest snapshot from `session.displayState.get()`.
392
+
393
+ ## State
394
+
395
+ `session.state` owns the schema-validated Harness state for the conversation. It holds the current snapshot, validates updates against the `stateSchema` passed to the Harness, serializes concurrent writes, and emits a `state_changed` event on every change.
396
+
397
+ ### `session.state.get()`
398
+
399
+ Return a readonly copy of the current state snapshot.
400
+
401
+ ```typescript
402
+ const state = harness.session.state.get()
403
+ ```
404
+
405
+ ### `session.state.set(updates)`
406
+
407
+ Merge a partial update into the state. Updates are queued so concurrent calls apply in order, validated against the schema, and emit `state_changed` with the changed keys.
408
+
409
+ ```typescript
410
+ await harness.session.state.set({ yolo: true })
411
+ ```
412
+
413
+ ### `session.state.update(updater)`
414
+
415
+ Run an updater against the current snapshot and apply its result atomically within the write queue. Use this for read-modify-write changes that must see the latest state. The updater returns `updates` to merge, optional `events` to emit, and a `result` value that `update()` resolves to.
416
+
417
+ ```typescript
418
+ const added = await harness.session.state.update(current => ({
419
+ updates: { count: (current.count ?? 0) + 1 },
420
+ result: (current.count ?? 0) + 1,
421
+ }))
422
+ ```
423
+
424
+ ## Related
425
+
426
+ - [Harness class](https://mastra.ai/reference/harness/harness-class)
427
+ - [Harness overview](https://mastra.ai/docs/harness/overview)
428
+ - [Threads and state](https://mastra.ai/docs/harness/threads-and-state)
429
+ - [Tool approvals](https://mastra.ai/docs/harness/tool-approvals)
@@ -159,6 +159,7 @@ The Reference section provides documentation of Mastra's API, including paramete
159
159
  - [.update()](https://mastra.ai/reference/datasets/update)
160
160
  - [.updateItem()](https://mastra.ai/reference/datasets/updateItem)
161
161
  - [Harness Class](https://mastra.ai/reference/harness/harness-class)
162
+ - [Session Class](https://mastra.ai/reference/harness/session)
162
163
  - [API Reference](https://mastra.ai/reference/mastra-platform/api)
163
164
  - [Cloned Thread Utilities](https://mastra.ai/reference/memory/clone-utilities)
164
165
  - [Memory Class](https://mastra.ai/reference/memory/memory-class)
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @mastra/mcp-docs-server
2
2
 
3
+ ## 1.1.49-alpha.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`339c57c`](https://github.com/mastra-ai/mastra/commit/339c57c5b2c6dbe75a125e138228e0556528976f), [`1dd4117`](https://github.com/mastra-ai/mastra/commit/1dd4117dcbd8e031ede9f0489436bfbc6f0315b8), [`2b11d1f`](https://github.com/mastra-ai/mastra/commit/2b11d1f6ac7024c5dd2b2dd12a48a956ac9d63bd), [`49af8df`](https://github.com/mastra-ai/mastra/commit/49af8df589c4ff71a5015a4553b377b32704b691), [`30ce559`](https://github.com/mastra-ai/mastra/commit/30ce55902ecf819b8ab8697398dd68b108228063), [`c241b92`](https://github.com/mastra-ai/mastra/commit/c241b929dc8c8d6a7b7219c99ed13ac1f3124a77), [`7d6ff70`](https://github.com/mastra-ai/mastra/commit/7d6ff708727297a0526ca0e26e93eeb5bbaaa187)]:
8
+ - @mastra/core@1.44.0-alpha.2
9
+
3
10
  ## 1.1.49-alpha.1
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.49-alpha.1",
3
+ "version": "1.1.49-alpha.2",
4
4
  "description": "MCP server for accessing Mastra.ai documentation, changelogs, and news.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -28,7 +28,7 @@
28
28
  "jsdom": "^26.1.0",
29
29
  "local-pkg": "^1.1.2",
30
30
  "zod": "^4.4.3",
31
- "@mastra/core": "1.44.0-alpha.1",
31
+ "@mastra/core": "1.44.0-alpha.2",
32
32
  "@mastra/mcp": "^1.10.1-alpha.0"
33
33
  },
34
34
  "devDependencies": {
@@ -45,9 +45,9 @@
45
45
  "tsx": "^4.22.4",
46
46
  "typescript": "^6.0.3",
47
47
  "vitest": "4.1.8",
48
- "@internal/lint": "0.0.105",
49
48
  "@internal/types-builder": "0.0.80",
50
- "@mastra/core": "1.44.0-alpha.1"
49
+ "@internal/lint": "0.0.105",
50
+ "@mastra/core": "1.44.0-alpha.2"
51
51
  },
52
52
  "homepage": "https://mastra.ai",
53
53
  "repository": {