@mastra/mcp-docs-server 1.2.4-alpha.6 → 1.2.4-alpha.8
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.
|
@@ -2,22 +2,55 @@
|
|
|
2
2
|
|
|
3
3
|
# Mastra.getAgentById()
|
|
4
4
|
|
|
5
|
-
The `.getAgentById()` method
|
|
5
|
+
The `.getAgentById()` method retrieves a registered agent by its `id`. It first searches registered agents by `agent.id`. If no agent matches, it falls back to [`Mastra.getAgent()`](https://mastra.ai/reference/core/getAgent) and treats the provided value as the agent registry key.
|
|
6
|
+
|
|
7
|
+
Use `mastra.getAgentById(id)` to retrieve the code-defined agent. Use `await mastra.getAgentById(id, version)` to retrieve a versioned agent.
|
|
6
8
|
|
|
7
9
|
## Usage example
|
|
8
10
|
|
|
11
|
+
The following example registers an agent, retrieves it by ID, and uses the returned agent.
|
|
12
|
+
|
|
9
13
|
```typescript
|
|
10
|
-
mastra
|
|
14
|
+
import { Agent } from '@mastra/core/agent'
|
|
15
|
+
import { Mastra } from '@mastra/core/mastra'
|
|
16
|
+
|
|
17
|
+
const supportAgent = new Agent({
|
|
18
|
+
id: 'support-agent-id',
|
|
19
|
+
name: 'Support Agent',
|
|
20
|
+
instructions: 'Answer support questions clearly and concisely.',
|
|
21
|
+
model: 'openai/gpt-5.5',
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
export const mastra = new Mastra({
|
|
25
|
+
agents: {
|
|
26
|
+
supportAgent,
|
|
27
|
+
},
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
const agent = mastra.getAgentById('support-agent-id')
|
|
31
|
+
|
|
32
|
+
const response = await agent.generate('How can I reset my password?')
|
|
11
33
|
```
|
|
12
34
|
|
|
13
35
|
## Parameters
|
|
14
36
|
|
|
15
|
-
**id** (`string`): The ID of the agent to retrieve.
|
|
37
|
+
**id** (`string`): The ID of the agent to retrieve. Mastra first searches registered agents by \`agent.id\`. If none match, it uses this value as the agent registry key and calls \`getAgent()\`.
|
|
38
|
+
|
|
39
|
+
**version** (`{ versionId: string } | { status?: 'draft' | 'published' }`): Optional version selector for retrieving a versioned agent. When provided, the method returns a promise.
|
|
40
|
+
|
|
41
|
+
**version.versionId** (`string`): The ID of a specific agent version to retrieve.
|
|
42
|
+
|
|
43
|
+
**version.status** (`'draft' | 'published'`): Select the latest agent version with this publication status.
|
|
16
44
|
|
|
17
45
|
## Returns
|
|
18
46
|
|
|
19
|
-
**agent** (`
|
|
47
|
+
**agent** (`TAgents[TAgentName]`): The agent instance with the specified ID when \`version\` is omitted.
|
|
48
|
+
|
|
49
|
+
**agent** (`Promise<TAgents[TAgentName]>`): A promise that resolves to the versioned agent instance when \`version\` is provided.
|
|
50
|
+
|
|
51
|
+
Throws a `MastraError` when no agent is found by ID or registry key.
|
|
20
52
|
|
|
21
53
|
## Related
|
|
22
54
|
|
|
55
|
+
- [Mastra.getAgent()](https://mastra.ai/reference/core/getAgent)
|
|
23
56
|
- [Agents overview](https://mastra.ai/docs/agents/overview)
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
**Added in:** `@mastra/core@1.4.0`
|
|
6
6
|
|
|
7
|
-
Lists individual item results for a specific experiment with pagination.
|
|
7
|
+
Lists individual item results for a specific experiment with optional filters and pagination. Filters are applied at the storage layer.
|
|
8
8
|
|
|
9
9
|
## Usage example
|
|
10
10
|
|
|
@@ -23,6 +23,18 @@ const { results, pagination } = await dataset.listExperimentResults({
|
|
|
23
23
|
perPage: 50,
|
|
24
24
|
})
|
|
25
25
|
|
|
26
|
+
// Restrict to results that still need review
|
|
27
|
+
const { results: pending } = await dataset.listExperimentResults({
|
|
28
|
+
experimentId: 'exp-id',
|
|
29
|
+
status: 'needs-review',
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
// Restrict to results tied to a specific trace
|
|
33
|
+
const { results: byTrace } = await dataset.listExperimentResults({
|
|
34
|
+
experimentId: 'exp-id',
|
|
35
|
+
traceId: 'trace-abc',
|
|
36
|
+
})
|
|
37
|
+
|
|
26
38
|
for (const result of results) {
|
|
27
39
|
console.log(`Item ${result.itemId}: ${result.error ? 'FAILED' : 'OK'}`)
|
|
28
40
|
}
|
|
@@ -32,6 +44,12 @@ for (const result of results) {
|
|
|
32
44
|
|
|
33
45
|
**experimentId** (`string`): ID of the experiment to list results for.
|
|
34
46
|
|
|
47
|
+
**traceId** (`string`): Restrict results to those linked to this trace ID.
|
|
48
|
+
|
|
49
|
+
**status** (`'needs-review' | 'reviewed' | 'complete'`): Restrict results to this per-result review status.
|
|
50
|
+
|
|
51
|
+
**filters** (`ExperimentTenancyFilters`): Multi-tenant scoping filters (\`organizationId\`, \`projectId\`). Forwarded to the storage layer.
|
|
52
|
+
|
|
35
53
|
**page** (`number`): Page number. Defaults to \`0\`.
|
|
36
54
|
|
|
37
55
|
**perPage** (`number`): Number of results per page. Defaults to \`20\`.
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
**Added in:** `@mastra/core@1.4.0`
|
|
6
6
|
|
|
7
|
-
Lists
|
|
7
|
+
Lists experiments (runs) for this dataset with optional filters and pagination. Filters are applied at the storage layer, so results are always scoped to the current dataset.
|
|
8
8
|
|
|
9
9
|
## Usage example
|
|
10
10
|
|
|
@@ -17,8 +17,17 @@ const mastra = new Mastra({
|
|
|
17
17
|
|
|
18
18
|
const dataset = await mastra.datasets.get({ id: 'dataset-id' })
|
|
19
19
|
|
|
20
|
+
// Basic pagination
|
|
20
21
|
const { experiments, pagination } = await dataset.listExperiments({ page: 0, perPage: 10 })
|
|
21
22
|
|
|
23
|
+
// Filter to a specific agent version — useful for baseline vs variant comparisons
|
|
24
|
+
const { experiments: v2Runs } = await dataset.listExperiments({
|
|
25
|
+
targetType: 'agent',
|
|
26
|
+
targetId: 'my-agent',
|
|
27
|
+
agentVersion: 'v2',
|
|
28
|
+
status: 'completed',
|
|
29
|
+
})
|
|
30
|
+
|
|
22
31
|
for (const exp of experiments) {
|
|
23
32
|
console.log(`${exp.id}: ${exp.status} (${exp.succeededCount}/${exp.totalItems})`)
|
|
24
33
|
}
|
|
@@ -26,6 +35,16 @@ for (const exp of experiments) {
|
|
|
26
35
|
|
|
27
36
|
## Parameters
|
|
28
37
|
|
|
38
|
+
**targetType** (`'agent' | 'workflow' | 'scorer' | 'processor'`): Restrict results to experiments run against this target type.
|
|
39
|
+
|
|
40
|
+
**targetId** (`string`): Restrict results to experiments run against this target ID.
|
|
41
|
+
|
|
42
|
+
**agentVersion** (`string`): Restrict results to experiments recorded against this agent version. Useful for distinguishing baseline from variant runs.
|
|
43
|
+
|
|
44
|
+
**status** (`'pending' | 'running' | 'completed' | 'failed'`): Restrict results to experiments in this status.
|
|
45
|
+
|
|
46
|
+
**filters** (`ExperimentTenancyFilters`): Multi-tenant scoping filters (\`organizationId\`, \`projectId\`). Forwarded to the storage layer.
|
|
47
|
+
|
|
29
48
|
**page** (`number`): Page number. Defaults to \`0\`.
|
|
30
49
|
|
|
31
50
|
**perPage** (`number`): Number of experiments per page. Defaults to \`20\`.
|
|
@@ -55,7 +55,13 @@ export const tool = createTool({
|
|
|
55
55
|
|
|
56
56
|
**requestContextSchema** (`StandardJSONSchemaV1`): A Standard JSON Schema for validating request context values. When provided, the context is validated before execute() runs, returning an error object if validation fails.
|
|
57
57
|
|
|
58
|
-
**
|
|
58
|
+
**providerOptions** (`Record<string, Record<string, unknown>>`): Provider-specific options passed to the model when this tool is used. Keys are provider names, such as \`anthropic\` or \`openai\`, and values are provider-specific configuration objects.
|
|
59
|
+
|
|
60
|
+
**inputExamples** (`Array<{ input: Record<string, unknown> }>`): Examples of valid tool inputs that supported model providers can use as input examples.
|
|
61
|
+
|
|
62
|
+
**background** (`ToolBackgroundConfig`): Background task configuration for this tool. When enabled, the tool can execute in the background while the agent conversation continues.
|
|
63
|
+
|
|
64
|
+
**execute** (`function`): The function that contains the tool's logic. Ordinary custom tools usually provide \`execute\`, but the type allows omission for tool definitions that are executed or adapted elsewhere. It receives two parameters: the validated input data based on inputSchema (first parameter) and an execution context object (second parameter) containing \`requestContext\`, \`abortSignal\`, and other execution metadata.
|
|
59
65
|
|
|
60
66
|
**execute.input** (`z.infer<TInput>`): The validated input data based on inputSchema
|
|
61
67
|
|
|
@@ -63,8 +69,6 @@ export const tool = createTool({
|
|
|
63
69
|
|
|
64
70
|
**execute.context.requestContext** (`RequestContext`): Request Context for accessing shared state and dependencies
|
|
65
71
|
|
|
66
|
-
**execute.context.tracingContext** (`TracingContext`): Tracing context for creating child spans and adding metadata
|
|
67
|
-
|
|
68
72
|
**execute.context.abortSignal** (`AbortSignal`): Signal for aborting the tool execution
|
|
69
73
|
|
|
70
74
|
**execute.context.agent** (`AgentToolExecutionContext`): Agent-specific context, available when the tool is executed by an agent.
|
|
@@ -75,13 +79,15 @@ export const tool = createTool({
|
|
|
75
79
|
|
|
76
80
|
**execute.context.observe** (`ToolObserve`): Observability helpers for recording child spans and structured logs from inside a tool's execute function. Always provided — when no tracing context is active, \`span\` runs the function directly and \`log\` is a no-op.
|
|
77
81
|
|
|
78
|
-
**onInputStart** (`function`): Optional callback invoked when the tool call input streaming begins.
|
|
82
|
+
**onInputStart** (`function`): Optional callback invoked when the tool call input streaming begins. Signature: \`(options: ToolCallOptions) => void | PromiseLike\<void>\`.
|
|
83
|
+
|
|
84
|
+
**onInputDelta** (`function`): Optional callback invoked for each incremental chunk of input text as it streams in. Signature: \`({ inputTextDelta, ...options }: { inputTextDelta: string } & ToolCallOptions) => void | PromiseLike\<void>\`.
|
|
79
85
|
|
|
80
|
-
**
|
|
86
|
+
**onInputAvailable** (`function`): Optional callback invoked when the complete tool input is available and parsed. Signature: \`({ input, ...options }: { input: TSchemaIn } & ToolCallOptions) => void | PromiseLike\<void>\`.
|
|
81
87
|
|
|
82
|
-
**
|
|
88
|
+
**onOutput** (`function`): Optional callback invoked after the tool has successfully executed and returned output. Signature: \`({ output, toolName, ...options }: { output: TSchemaOut; toolName: string } & Omit\<ToolCallOptions, 'messages'>) => void | PromiseLike\<void>\`.
|
|
83
89
|
|
|
84
|
-
|
|
90
|
+
Runtime-populated fields such as `mastra` and `mcpMetadata` appear in source types but are set by Mastra or MCP adapters. You do not need to configure them for ordinary `createTool()` usage.
|
|
85
91
|
|
|
86
92
|
## Returns
|
|
87
93
|
|
|
@@ -310,8 +316,9 @@ export const weatherTool = createTool({
|
|
|
310
316
|
},
|
|
311
317
|
},
|
|
312
318
|
execute: async inputData => {
|
|
313
|
-
|
|
314
|
-
|
|
319
|
+
return {
|
|
320
|
+
weather: `Current weather for ${inputData.location}: sunny`,
|
|
321
|
+
}
|
|
315
322
|
},
|
|
316
323
|
})
|
|
317
324
|
```
|
|
@@ -320,7 +327,44 @@ export const weatherTool = createTool({
|
|
|
320
327
|
|
|
321
328
|
Tools support lifecycle hooks that allow you to monitor and react to different stages of tool execution. These hooks are particularly useful for logging, analytics, validation, and real-time updates during streaming.
|
|
322
329
|
|
|
323
|
-
|
|
330
|
+
The following example demonstrates a tool with all lifecycle hooks configured:
|
|
331
|
+
|
|
332
|
+
```typescript
|
|
333
|
+
import { createTool } from '@mastra/core/tools'
|
|
334
|
+
import { z } from 'zod'
|
|
335
|
+
|
|
336
|
+
export const weatherTool = createTool({
|
|
337
|
+
id: 'get-weather',
|
|
338
|
+
description: 'Get weather for a city',
|
|
339
|
+
inputSchema: z.object({
|
|
340
|
+
city: z.string(),
|
|
341
|
+
}),
|
|
342
|
+
outputSchema: z.object({
|
|
343
|
+
city: z.string(),
|
|
344
|
+
forecast: z.string(),
|
|
345
|
+
}),
|
|
346
|
+
execute: async ({ city }) => {
|
|
347
|
+
return {
|
|
348
|
+
city,
|
|
349
|
+
forecast: 'sunny',
|
|
350
|
+
}
|
|
351
|
+
},
|
|
352
|
+
onInputStart: ({ toolCallId }) => {
|
|
353
|
+
console.log(`Tool call ${toolCallId} input started`)
|
|
354
|
+
},
|
|
355
|
+
onInputDelta: ({ inputTextDelta, toolCallId }) => {
|
|
356
|
+
console.log(`Tool call ${toolCallId} received input chunk: ${inputTextDelta}`)
|
|
357
|
+
},
|
|
358
|
+
onInputAvailable: ({ input, toolCallId }) => {
|
|
359
|
+
console.log(`Tool call ${toolCallId} received city: ${input.city}`)
|
|
360
|
+
},
|
|
361
|
+
onOutput: ({ output, toolCallId, toolName }) => {
|
|
362
|
+
console.log(`Tool ${toolName} call ${toolCallId} returned forecast: ${output.forecast}`)
|
|
363
|
+
},
|
|
364
|
+
})
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
### Available hooks
|
|
324
368
|
|
|
325
369
|
#### `onInputStart`
|
|
326
370
|
|
|
@@ -389,7 +433,7 @@ export const tool = createTool({
|
|
|
389
433
|
})
|
|
390
434
|
```
|
|
391
435
|
|
|
392
|
-
### Hook
|
|
436
|
+
### Hook execution order
|
|
393
437
|
|
|
394
438
|
For a typical streaming tool call, the hooks are invoked in this order:
|
|
395
439
|
|
|
@@ -399,19 +443,14 @@ For a typical streaming tool call, the hooks are invoked in this order:
|
|
|
399
443
|
4. Tool's **execute** function runs
|
|
400
444
|
5. **onOutput**: Tool has completed successfully
|
|
401
445
|
|
|
402
|
-
### Hook
|
|
403
|
-
|
|
404
|
-
All hooks receive a parameter object with these common properties:
|
|
405
|
-
|
|
406
|
-
- `toolCallId` (string): Unique identifier for this specific tool call
|
|
407
|
-
- `abortSignal` (AbortSignal): Signal for detecting if the operation should be cancelled
|
|
446
|
+
### Hook parameters
|
|
408
447
|
|
|
409
|
-
|
|
448
|
+
Hook callbacks receive these source-backed parameter shapes:
|
|
410
449
|
|
|
411
|
-
- `onInputStart
|
|
412
|
-
- `onInputDelta
|
|
413
|
-
- `onInputAvailable
|
|
414
|
-
- `onOutput
|
|
450
|
+
- `onInputStart`: Receives `ToolCallOptions`, including fields such as `toolCallId`, `messages`, and `abortSignal`.
|
|
451
|
+
- `onInputDelta`: Receives `{ inputTextDelta: string } & ToolCallOptions`.
|
|
452
|
+
- `onInputAvailable`: Receives `{ input: TSchemaIn } & ToolCallOptions`, where `input` is typed from `inputSchema`.
|
|
453
|
+
- `onOutput`: Receives `{ output: TSchemaOut; toolName: string } & Omit<ToolCallOptions, 'messages'>`, where `output` is typed from `outputSchema`. This hook does not receive `messages`.
|
|
415
454
|
|
|
416
455
|
### Error handling
|
|
417
456
|
|
|
@@ -430,7 +469,7 @@ mcp: {
|
|
|
430
469
|
}
|
|
431
470
|
```
|
|
432
471
|
|
|
433
|
-
### `ToolAnnotations`
|
|
472
|
+
### `ToolAnnotations` properties
|
|
434
473
|
|
|
435
474
|
**title** (`string`): A human-readable title for the tool. Used for display purposes in UI components.
|
|
436
475
|
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @mastra/mcp-docs-server
|
|
2
2
|
|
|
3
|
+
## 1.2.4-alpha.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`6a61846`](https://github.com/mastra-ai/mastra/commit/6a61846eeda29fb714549b70f1bee2bf6b141c44)]:
|
|
8
|
+
- @mastra/core@1.49.0-alpha.4
|
|
9
|
+
|
|
3
10
|
## 1.2.4-alpha.6
|
|
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.2.4-alpha.
|
|
3
|
+
"version": "1.2.4-alpha.8",
|
|
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.49.0-alpha.
|
|
31
|
+
"@mastra/core": "1.49.0-alpha.4",
|
|
32
32
|
"@mastra/mcp": "^1.13.0-alpha.1"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"vitest": "4.1.8",
|
|
48
48
|
"@internal/lint": "0.0.110",
|
|
49
49
|
"@internal/types-builder": "0.0.85",
|
|
50
|
-
"@mastra/core": "1.49.0-alpha.
|
|
50
|
+
"@mastra/core": "1.49.0-alpha.4"
|
|
51
51
|
},
|
|
52
52
|
"homepage": "https://mastra.ai",
|
|
53
53
|
"repository": {
|