@mastra/mcp-docs-server 0.0.1 → 0.0.2-alpha.0
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.
- package/.docs/organized/changelogs/%40mastra%2Fastra.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +27 -27
- package/.docs/organized/changelogs/%40mastra%2Fcomposio.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +24 -24
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +37 -37
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +37 -37
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +37 -37
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +36 -36
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +29 -29
- package/.docs/organized/changelogs/%40mastra%2Fgithub.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +26 -0
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +29 -29
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +34 -34
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Frag.md +27 -27
- package/.docs/organized/changelogs/%40mastra%2Fragie.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fspeech-azure.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fspeech-deepgram.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fspeech-elevenlabs.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fspeech-google.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fspeech-ibm.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fspeech-murf.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fspeech-openai.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fspeech-playai.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fspeech-replicate.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fspeech-speechify.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fstabilityai.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +24 -0
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +26 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +25 -25
- package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +25 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +25 -25
- package/.docs/organized/changelogs/create-mastra.md +16 -16
- package/.docs/organized/changelogs/mastra.md +52 -52
- package/.docs/organized/code-examples/agent.md +8 -3
- package/.docs/organized/code-examples/ai-sdk-useChat.md +1 -0
- package/.docs/organized/code-examples/weather-agent.md +1 -0
- package/.docs/raw/deployment/client.mdx +120 -0
- package/.docs/raw/deployment/server.mdx +1 -1
- package/.docs/raw/evals/00-overview.mdx +58 -75
- package/.docs/raw/evals/01-textual-evals.mdx +53 -0
- package/.docs/raw/evals/02-custom-eval.mdx +6 -170
- package/.docs/raw/evals/03-running-in-ci.mdx +78 -0
- package/.docs/raw/getting-started/installation.mdx +24 -13
- package/.docs/raw/getting-started/mcp-docs-server.mdx +138 -0
- package/.docs/raw/index.mdx +2 -2
- package/.docs/raw/local-dev/add-to-existing-project.mdx +48 -0
- package/.docs/raw/local-dev/creating-a-new-project.mdx +54 -0
- package/.docs/raw/local-dev/mastra-dev.mdx +78 -35
- package/.docs/raw/reference/agents/createTool.mdx +128 -89
- package/.docs/raw/reference/agents/stream.mdx +19 -18
- package/.docs/raw/reference/cli/dev.mdx +58 -21
- package/.docs/raw/storage/overview.mdx +331 -0
- package/package.json +2 -2
- package/.docs/raw/evals/01-supported-evals.mdx +0 -31
- package/.docs/raw/local-dev/creating-projects.mdx +0 -74
- package/.docs/raw/reference/client-js/index.mdx +0 -127
- /package/.docs/raw/{local-dev/integrations.mdx → integrations/index.mdx} +0 -0
|
@@ -1,65 +1,108 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: "Inspecting Agents with `mastra dev` | Mastra Local Dev Docs"
|
|
3
|
-
description: Documentation for the
|
|
3
|
+
description: Documentation for the Mastra local development environment for Mastra applications.
|
|
4
4
|
---
|
|
5
|
+
import YouTube from "../../../components/youtube";
|
|
5
6
|
|
|
6
|
-
#
|
|
7
|
+
# Local Development Environment
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
Mastra provides a local development environment where you can test your agents, workflows, and tools while developing locally.
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
<YouTube id="spGlcTEjuXY" />
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
## Launch Development Server
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
You can launch the Mastra development environment using the Mastra CLI by running:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
mastra dev
|
|
19
|
+
```
|
|
19
20
|
|
|
20
21
|
By default, the server runs at http://localhost:4111, but you can change the port with the `--port` flag.
|
|
21
22
|
|
|
22
|
-
##
|
|
23
|
+
## Dev Playground
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
`mastra dev` serves a playground UI for interacting with your agents, workflows, and tools. The playground provides dedicated interfaces for testing each component of your Mastra application during development.
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
npm install @mastra/client-js
|
|
28
|
-
```
|
|
27
|
+
### Agent Playground
|
|
29
28
|
|
|
30
|
-
|
|
29
|
+
The Agent playground provides an interactive chat interface where you can test and debug your agents during development. Key features include:
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
- **Chat Interface**: Directly interact with your agents to test their responses and behavior.
|
|
32
|
+
- **Prompt CMS**: Experiment with different system instructions for your agent:
|
|
33
|
+
- A/B test different prompt versions.
|
|
34
|
+
- Track performance metrics for each variant.
|
|
35
|
+
- Select and deploy the most effective prompt version.
|
|
36
|
+
- **Agent Traces**: View detailed execution traces to understand how your agent processes requests, including:
|
|
37
|
+
- Prompt construction.
|
|
38
|
+
- Tool usage.
|
|
39
|
+
- Decision-making steps.
|
|
40
|
+
- Response generation.
|
|
41
|
+
- **Agent Evals**: When you've set up [Agent evaluation metrics](/docs/evals/00-overview), you can:
|
|
42
|
+
- Run evaluations directly from the playground.
|
|
43
|
+
- View evaluation results and metrics.
|
|
44
|
+
- Compare agent performance across different test cases.
|
|
34
45
|
|
|
35
|
-
|
|
36
|
-
baseUrl: "http://localhost:4111",
|
|
37
|
-
});
|
|
46
|
+
### Workflow Playground
|
|
38
47
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
48
|
+
The Workflow playground helps you visualize and test your workflow implementations:
|
|
49
|
+
|
|
50
|
+
- **Workflow Visualization**: Workflow graph visualization.
|
|
51
|
+
|
|
52
|
+
- **Run Workflows**:
|
|
53
|
+
- Trigger test workflow runs with custom input data.
|
|
54
|
+
- Debug workflow logic and conditions.
|
|
55
|
+
- Simulate different execution paths.
|
|
56
|
+
- View detailed execution logs for each step.
|
|
45
57
|
|
|
46
|
-
|
|
58
|
+
- **Workflow Traces**: Examine detailed execution traces that show:
|
|
59
|
+
- Step-by-step workflow progression.
|
|
60
|
+
- State transitions and data flow.
|
|
61
|
+
- Tool invocations and their results.
|
|
62
|
+
- Decision points and branching logic.
|
|
63
|
+
- Error handling and recovery paths.
|
|
47
64
|
|
|
48
|
-
|
|
65
|
+
### Tools Playground
|
|
49
66
|
|
|
50
|
-
|
|
67
|
+
The Tools playground allows you to test your custom tools in isolation:
|
|
51
68
|
|
|
52
|
-
|
|
69
|
+
- Test individual tools without running a full agent or workflow.
|
|
70
|
+
- Input test data and view tool responses.
|
|
71
|
+
- Debug tool implementation and error handling.
|
|
72
|
+
- Verify tool input/output schemas.
|
|
73
|
+
- Monitor tool performance and execution time.
|
|
74
|
+
|
|
75
|
+
## REST API Endpoints
|
|
76
|
+
|
|
77
|
+
`mastra dev` also spins up REST API routes for your agents and workflows via the local [Mastra Server](/docs/deployment/server). This allows you to test your API endpoints before deployment. See [Mastra Dev reference](http://localhost:3000/docs/reference/cli/dev#routes) for more details about all endpoints.
|
|
78
|
+
|
|
79
|
+
You can then leverage the [Mastra Client](/docs/deployment/client) SDK to interact with your served REST API routes seamlessly.
|
|
53
80
|
|
|
54
81
|
## OpenAPI Specification
|
|
55
82
|
|
|
56
|
-
`mastra dev` provides an OpenAPI spec at:
|
|
83
|
+
`mastra dev` provides an OpenAPI spec at http://localhost:4111/openapi.json
|
|
84
|
+
|
|
85
|
+
## Local Dev Architecture
|
|
86
|
+
|
|
87
|
+
The local development server is designed to run without any external dependencies or containerization. This is achieved through:
|
|
88
|
+
|
|
89
|
+
- **Dev Server**: Uses [Hono](https://hono.dev) as the underlying framework to power the [Mastra Server](/docs/deployment/server).
|
|
90
|
+
|
|
91
|
+
- **In-Memory Storage**: Uses [LibSQL](https://libsql.org/) memory adapters for:
|
|
92
|
+
- Agent memory management.
|
|
93
|
+
- Trace storage.
|
|
94
|
+
- Evals storage.
|
|
95
|
+
- Workflow snapshots.
|
|
96
|
+
|
|
97
|
+
- **Vector Storage**: Uses [FastEmbed](https://github.com/qdrant/fastembed) for:
|
|
98
|
+
- Default embedding generation.
|
|
99
|
+
- Vector storage and retrieval.
|
|
100
|
+
- Semantic search capabilities.
|
|
57
101
|
|
|
58
|
-
-
|
|
102
|
+
This architecture allows you to start developing immediately without setting up databases or vector stores, while still maintaining production-like behavior in your local environment.
|
|
59
103
|
|
|
60
104
|
## Summary
|
|
61
105
|
|
|
62
106
|
`mastra dev` makes it easy to develop, debug, and iterate on your AI logic in a self-contained environment before deploying to production.
|
|
63
107
|
|
|
64
|
-
- [Mastra Dev reference](../reference/cli/dev.mdx)
|
|
65
|
-
- [Client SDK documentation](/docs/reference/client-js)
|
|
108
|
+
- [Mastra Dev reference](../reference/cli/dev.mdx)
|
|
@@ -5,140 +5,162 @@ description: Documentation for the createTool function in Mastra, which creates
|
|
|
5
5
|
|
|
6
6
|
# `createTool()`
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
The `createTool()` function creates typed tools that can be executed by agents or workflows. Tools have built-in schema validation, execution context, and integration with the Mastra ecosystem.
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
## Overview
|
|
11
|
+
|
|
12
|
+
Tools are a fundamental building block in Mastra that allow agents to interact with external systems, perform computations, and access data. Each tool has:
|
|
13
|
+
|
|
14
|
+
- A unique identifier
|
|
15
|
+
- A description that helps the AI understand when and how to use the tool
|
|
16
|
+
- Optional input and output schemas for validation
|
|
17
|
+
- An execution function that implements the tool's logic
|
|
18
|
+
|
|
19
|
+
## Example Usage
|
|
20
|
+
|
|
21
|
+
```ts filename="src/tools/stock-tools.ts" showLineNumbers copy
|
|
22
|
+
import { createTool } from "@mastra/core/tools";
|
|
12
23
|
import { z } from "zod";
|
|
13
24
|
|
|
25
|
+
// Helper function to fetch stock data
|
|
14
26
|
const getStockPrice = async (symbol: string) => {
|
|
15
|
-
const
|
|
16
|
-
`https://mastra-stock-data.vercel.app/api/stock-data?symbol=${symbol}
|
|
17
|
-
)
|
|
27
|
+
const response = await fetch(
|
|
28
|
+
`https://mastra-stock-data.vercel.app/api/stock-data?symbol=${symbol}`
|
|
29
|
+
);
|
|
30
|
+
const data = await response.json();
|
|
18
31
|
return data.prices["4. close"];
|
|
19
32
|
};
|
|
20
33
|
|
|
21
|
-
|
|
22
|
-
|
|
34
|
+
// Create a tool to get stock prices
|
|
35
|
+
export const stockPriceTool = createTool({
|
|
36
|
+
id: "getStockPrice",
|
|
37
|
+
description: "Fetches the current stock price for a given ticker symbol",
|
|
23
38
|
inputSchema: z.object({
|
|
39
|
+
symbol: z.string().describe("The stock ticker symbol (e.g., AAPL, MSFT)")
|
|
40
|
+
}),
|
|
41
|
+
outputSchema: z.object({
|
|
24
42
|
symbol: z.string(),
|
|
43
|
+
price: z.number(),
|
|
44
|
+
currency: z.string(),
|
|
45
|
+
timestamp: z.string()
|
|
25
46
|
}),
|
|
26
|
-
description: `Fetches the last day's closing stock price for a given symbol`,
|
|
27
47
|
execute: async ({ context }) => {
|
|
28
|
-
|
|
48
|
+
const price = await getStockPrice(context.symbol);
|
|
49
|
+
|
|
29
50
|
return {
|
|
30
51
|
symbol: context.symbol,
|
|
31
|
-
|
|
52
|
+
price: parseFloat(price),
|
|
53
|
+
currency: "USD",
|
|
54
|
+
timestamp: new Date().toISOString()
|
|
32
55
|
};
|
|
33
|
-
}
|
|
56
|
+
}
|
|
34
57
|
});
|
|
35
58
|
|
|
36
|
-
|
|
37
|
-
|
|
59
|
+
// Create a tool that uses the thread context
|
|
60
|
+
export const threadInfoTool = createTool({
|
|
61
|
+
id: "getThreadInfo",
|
|
62
|
+
description: "Returns information about the current conversation thread",
|
|
38
63
|
inputSchema: z.object({
|
|
39
|
-
includeResource: z.boolean().optional()
|
|
64
|
+
includeResource: z.boolean().optional().default(false)
|
|
40
65
|
}),
|
|
41
|
-
description: `Gets information about the current conversation thread`,
|
|
42
66
|
execute: async ({ context, threadId, resourceId }) => {
|
|
43
|
-
console.log("Current thread:", threadId);
|
|
44
|
-
console.log("Current resource:", resourceId);
|
|
45
|
-
|
|
46
67
|
return {
|
|
47
68
|
threadId,
|
|
48
69
|
resourceId: context.includeResource ? resourceId : undefined,
|
|
70
|
+
timestamp: new Date().toISOString()
|
|
49
71
|
};
|
|
50
|
-
}
|
|
72
|
+
}
|
|
51
73
|
});
|
|
52
74
|
```
|
|
53
75
|
|
|
54
|
-
## API
|
|
76
|
+
## API Reference
|
|
55
77
|
|
|
56
78
|
### Parameters
|
|
57
79
|
|
|
80
|
+
`createTool()` accepts a single object with the following properties:
|
|
81
|
+
|
|
58
82
|
<PropertiesTable
|
|
59
83
|
content={[
|
|
60
84
|
{
|
|
61
|
-
name: "
|
|
85
|
+
name: "id",
|
|
62
86
|
type: "string",
|
|
63
87
|
required: true,
|
|
64
|
-
description:
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
name: "schema",
|
|
68
|
-
type: "ZodSchema",
|
|
69
|
-
required: true,
|
|
70
|
-
description: "Zod schema for validating inputs",
|
|
88
|
+
description: "Unique identifier for the tool. This should be descriptive of the tool's function."
|
|
71
89
|
},
|
|
72
90
|
{
|
|
73
91
|
name: "description",
|
|
74
92
|
type: "string",
|
|
75
93
|
required: true,
|
|
76
|
-
description: "
|
|
94
|
+
description: "Detailed description of what the tool does, when it should be used, and what inputs it requires. This helps the AI understand how to use the tool effectively."
|
|
77
95
|
},
|
|
78
96
|
{
|
|
79
|
-
name: "
|
|
80
|
-
type: "(
|
|
81
|
-
required:
|
|
82
|
-
description: "Async function that
|
|
97
|
+
name: "execute",
|
|
98
|
+
type: "(context: ToolExecutionContext, options?: any) => Promise<any>",
|
|
99
|
+
required: false,
|
|
100
|
+
description: "Async function that implements the tool's logic. Receives the execution context and optional configuration.",
|
|
83
101
|
properties: [
|
|
84
102
|
{
|
|
85
|
-
type: "
|
|
103
|
+
type: "ToolExecutionContext",
|
|
86
104
|
parameters: [
|
|
87
105
|
{
|
|
88
|
-
name: "
|
|
106
|
+
name: "context",
|
|
89
107
|
type: "object",
|
|
90
|
-
description: "The validated input data
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
name: "integrationsRegistry",
|
|
94
|
-
type: "function",
|
|
95
|
-
description: "Function to get connected integrations",
|
|
108
|
+
description: "The validated input data that matches the inputSchema"
|
|
96
109
|
},
|
|
97
110
|
{
|
|
98
|
-
name: "
|
|
111
|
+
name: "threadId",
|
|
99
112
|
type: "string",
|
|
100
113
|
isOptional: true,
|
|
101
|
-
description: "
|
|
114
|
+
description: "Identifier for the conversation thread, if available"
|
|
102
115
|
},
|
|
103
116
|
{
|
|
104
|
-
name: "
|
|
117
|
+
name: "resourceId",
|
|
105
118
|
type: "string",
|
|
106
119
|
isOptional: true,
|
|
107
|
-
description:
|
|
108
|
-
"Identifier for the conversation thread. Allows for maintaining context across multiple interactions.",
|
|
120
|
+
description: "Identifier for the user or resource interacting with the tool"
|
|
109
121
|
},
|
|
110
122
|
{
|
|
111
|
-
name: "
|
|
112
|
-
type: "
|
|
123
|
+
name: "mastra",
|
|
124
|
+
type: "Mastra",
|
|
113
125
|
isOptional: true,
|
|
114
|
-
description:
|
|
115
|
-
"Identifier for the user or resource interacting with the tool.",
|
|
126
|
+
description: "Reference to the Mastra instance, if available"
|
|
116
127
|
},
|
|
128
|
+
]
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
type: "ToolOptions",
|
|
132
|
+
parameters: [
|
|
117
133
|
{
|
|
118
|
-
name: "
|
|
119
|
-
type: "
|
|
120
|
-
description: "
|
|
134
|
+
name: "toolCallId",
|
|
135
|
+
type: "string",
|
|
136
|
+
description: "The ID of the tool call. You can use it e.g. when sending tool-call related information with stream data."
|
|
121
137
|
},
|
|
122
138
|
{
|
|
123
|
-
name: "
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
description: "Mastra engine instance",
|
|
139
|
+
name: "messages",
|
|
140
|
+
type: "CoreMessage[]",
|
|
141
|
+
description: "Messages that were sent to the language model to initiate the response that contained the tool call. The messages do not include the system prompt nor the assistant response that contained the tool call."
|
|
127
142
|
},
|
|
128
143
|
{
|
|
129
|
-
name: "
|
|
130
|
-
type: "
|
|
131
|
-
|
|
144
|
+
name: "abortSignal",
|
|
145
|
+
type: "AbortSignal",
|
|
146
|
+
isOptional: true,
|
|
147
|
+
description: "An optional abort signal that indicates that the overall operation should be aborted."
|
|
132
148
|
},
|
|
133
|
-
]
|
|
134
|
-
}
|
|
135
|
-
]
|
|
149
|
+
]
|
|
150
|
+
}
|
|
151
|
+
]
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
name: "inputSchema",
|
|
155
|
+
type: "ZodSchema",
|
|
156
|
+
required: false,
|
|
157
|
+
description: "Zod schema that defines and validates the tool's input parameters. If not provided, the tool will accept any input."
|
|
136
158
|
},
|
|
137
159
|
{
|
|
138
160
|
name: "outputSchema",
|
|
139
161
|
type: "ZodSchema",
|
|
140
|
-
|
|
141
|
-
description: "Zod schema
|
|
162
|
+
required: false,
|
|
163
|
+
description: "Zod schema that defines and validates the tool's output. Helps ensure the tool returns data in the expected format."
|
|
142
164
|
},
|
|
143
165
|
]}
|
|
144
166
|
/>
|
|
@@ -148,43 +170,60 @@ export const threadInfo = createTool({
|
|
|
148
170
|
<PropertiesTable
|
|
149
171
|
content={[
|
|
150
172
|
{
|
|
151
|
-
name: "
|
|
152
|
-
type: "
|
|
153
|
-
description:
|
|
154
|
-
"The tool API object that includes the schema, label, description, and executor function.",
|
|
173
|
+
name: "Tool",
|
|
174
|
+
type: "Tool<TSchemaIn, TSchemaOut>",
|
|
175
|
+
description: "A Tool instance that can be used with agents, workflows, or directly executed.",
|
|
155
176
|
properties: [
|
|
156
177
|
{
|
|
157
|
-
type: "
|
|
178
|
+
type: "Tool",
|
|
158
179
|
parameters: [
|
|
159
180
|
{
|
|
160
|
-
name: "
|
|
161
|
-
type: "ZodSchema<IN>",
|
|
162
|
-
description: "Zod schema for validating inputs.",
|
|
163
|
-
},
|
|
164
|
-
{
|
|
165
|
-
name: "label",
|
|
181
|
+
name: "id",
|
|
166
182
|
type: "string",
|
|
167
|
-
description: "
|
|
183
|
+
description: "The tool's unique identifier"
|
|
168
184
|
},
|
|
169
185
|
{
|
|
170
186
|
name: "description",
|
|
171
187
|
type: "string",
|
|
172
|
-
description: "Description of the tool's functionality
|
|
188
|
+
description: "Description of the tool's functionality"
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
name: "inputSchema",
|
|
192
|
+
type: "ZodSchema | undefined",
|
|
193
|
+
description: "Schema for validating inputs"
|
|
173
194
|
},
|
|
174
195
|
{
|
|
175
196
|
name: "outputSchema",
|
|
176
|
-
type: "ZodSchema
|
|
177
|
-
|
|
178
|
-
description: "Zod schema for validating outputs.",
|
|
197
|
+
type: "ZodSchema | undefined",
|
|
198
|
+
description: "Schema for validating outputs"
|
|
179
199
|
},
|
|
180
200
|
{
|
|
181
201
|
name: "execute",
|
|
182
|
-
type: "
|
|
183
|
-
description: "
|
|
184
|
-
}
|
|
185
|
-
]
|
|
186
|
-
}
|
|
187
|
-
]
|
|
188
|
-
}
|
|
202
|
+
type: "Function",
|
|
203
|
+
description: "The tool's execution function"
|
|
204
|
+
}
|
|
205
|
+
]
|
|
206
|
+
}
|
|
207
|
+
]
|
|
208
|
+
}
|
|
189
209
|
]}
|
|
190
210
|
/>
|
|
211
|
+
|
|
212
|
+
## Type Safety
|
|
213
|
+
|
|
214
|
+
The `createTool()` function provides full type safety through TypeScript generics:
|
|
215
|
+
|
|
216
|
+
- Input types are inferred from the `inputSchema`
|
|
217
|
+
- Output types are inferred from the `outputSchema`
|
|
218
|
+
- The execution context is properly typed based on the input schema
|
|
219
|
+
|
|
220
|
+
This ensures that your tools are type-safe throughout your application.
|
|
221
|
+
|
|
222
|
+
## Best Practices
|
|
223
|
+
|
|
224
|
+
1. **Descriptive IDs**: Use clear, action-oriented IDs like `getWeatherForecast` or `searchDatabase`
|
|
225
|
+
2. **Detailed Descriptions**: Provide comprehensive descriptions that explain when and how to use the tool
|
|
226
|
+
3. **Input Validation**: Use Zod schemas to validate inputs and provide helpful error messages
|
|
227
|
+
4. **Error Handling**: Implement proper error handling in your execute function
|
|
228
|
+
5. **Idempotency**: When possible, make your tools idempotent (same input always produces same output)
|
|
229
|
+
6. **Performance**: Keep tools lightweight and fast to execute
|
|
@@ -238,12 +238,6 @@ Settings for telemetry collection during streaming:
|
|
|
238
238
|
|
|
239
239
|
<PropertiesTable
|
|
240
240
|
content={[
|
|
241
|
-
{
|
|
242
|
-
name: "functionId",
|
|
243
|
-
type: "string",
|
|
244
|
-
isOptional: true,
|
|
245
|
-
description: "Identifier for this function. Used to group telemetry data by function.",
|
|
246
|
-
},
|
|
247
241
|
{
|
|
248
242
|
name: "isEnabled",
|
|
249
243
|
type: "boolean",
|
|
@@ -251,12 +245,6 @@ Settings for telemetry collection during streaming:
|
|
|
251
245
|
defaultValue: "false",
|
|
252
246
|
description: "Enable or disable telemetry. Disabled by default while experimental.",
|
|
253
247
|
},
|
|
254
|
-
{
|
|
255
|
-
name: "metadata",
|
|
256
|
-
type: "Record<string, AttributeValue>",
|
|
257
|
-
isOptional: true,
|
|
258
|
-
description: "Additional information to include in the telemetry data. AttributeValue can be string, number, boolean, array of these types, or null.",
|
|
259
|
-
},
|
|
260
248
|
{
|
|
261
249
|
name: "recordInputs",
|
|
262
250
|
type: "boolean",
|
|
@@ -271,6 +259,18 @@ Settings for telemetry collection during streaming:
|
|
|
271
259
|
defaultValue: "true",
|
|
272
260
|
description: "Enable or disable output recording. You might want to disable this to avoid recording sensitive information, reduce data transfers, or increase performance.",
|
|
273
261
|
},
|
|
262
|
+
{
|
|
263
|
+
name: "functionId",
|
|
264
|
+
type: "string",
|
|
265
|
+
isOptional: true,
|
|
266
|
+
description: "Identifier for this function. Used to group telemetry data by function.",
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
name: "metadata",
|
|
270
|
+
type: "Record<string, AttributeValue>",
|
|
271
|
+
isOptional: true,
|
|
272
|
+
description: "Additional information to include in the telemetry data. AttributeValue can be string, number, boolean, array of these types, or null.",
|
|
273
|
+
},
|
|
274
274
|
{
|
|
275
275
|
name: "tracer",
|
|
276
276
|
type: "Tracer",
|
|
@@ -289,10 +289,10 @@ The return value of the `stream()` method depends on the options provided, speci
|
|
|
289
289
|
<PropertiesTable
|
|
290
290
|
content={[
|
|
291
291
|
{
|
|
292
|
-
name: "
|
|
293
|
-
type: "
|
|
292
|
+
name: "textStream",
|
|
293
|
+
type: "AsyncIterable<string>",
|
|
294
294
|
isOptional: true,
|
|
295
|
-
description: "
|
|
295
|
+
description: "Stream of text chunks. Present when output is 'text' (no schema provided) or when using `experimental_output`.",
|
|
296
296
|
},
|
|
297
297
|
{
|
|
298
298
|
name: "objectStream",
|
|
@@ -307,10 +307,10 @@ The return value of the `stream()` method depends on the options provided, speci
|
|
|
307
307
|
description: "Stream of structured data. Present only when using `experimental_output` option.",
|
|
308
308
|
},
|
|
309
309
|
{
|
|
310
|
-
name: "
|
|
311
|
-
type: "
|
|
310
|
+
name: "object",
|
|
311
|
+
type: "Promise<object>",
|
|
312
312
|
isOptional: true,
|
|
313
|
-
description: "
|
|
313
|
+
description: "Promise that resolves to the final structured output. Present when using either `output` or `experimental_output` options.",
|
|
314
314
|
}
|
|
315
315
|
]}
|
|
316
316
|
/>
|
|
@@ -359,3 +359,4 @@ console.log("Final structured result:", result);
|
|
|
359
359
|
```
|
|
360
360
|
|
|
361
361
|
The key difference between Agent's `stream()` and LLM's `stream()` is that Agents maintain conversation context through `threadId`, can access tools, and integrate with the agent's memory system.
|
|
362
|
+
|
|
@@ -5,7 +5,7 @@ description: Documentation for the mastra dev command, which starts a developmen
|
|
|
5
5
|
|
|
6
6
|
# `mastra dev` Reference
|
|
7
7
|
|
|
8
|
-
The `mastra dev` command starts a development server that exposes REST
|
|
8
|
+
The `mastra dev` command starts a development server that exposes REST routes for your agents, tools, and workflows,
|
|
9
9
|
|
|
10
10
|
## Parameters
|
|
11
11
|
|
|
@@ -37,39 +37,81 @@ The `mastra dev` command starts a development server that exposes REST endpoints
|
|
|
37
37
|
|
|
38
38
|
## Routes
|
|
39
39
|
|
|
40
|
-
Starting the server with `mastra dev` exposes a set of REST
|
|
40
|
+
Starting the server with `mastra dev` exposes a set of REST routes by default:
|
|
41
|
+
|
|
42
|
+
### System Routes
|
|
43
|
+
- **GET `/api`**: Get API status.
|
|
41
44
|
|
|
42
45
|
### Agent Routes
|
|
43
46
|
|
|
44
47
|
Agents are expected to be exported from `src/mastra/agents`.
|
|
45
48
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
49
|
+
- **GET `/api/agents`**: Lists the registered agents found in your Mastra folder.
|
|
50
|
+
- **GET `/api/agents/:agentId`**: Get agent by ID.
|
|
51
|
+
- **GET `/api/agents/:agentId/evals/ci`**: Get CI evals by agent ID.
|
|
52
|
+
- **GET `/api/agents/:agentId/evals/live`**: Get live evals by agent ID.
|
|
53
|
+
- **POST `/api/agents/:agentId/generate`**: Sends a text-based prompt to the specified agent, returning the agent's response.
|
|
54
|
+
- **POST `/api/agents/:agentId/stream`**: Stream a response from an agent.
|
|
55
|
+
- **POST `/api/agents/:agentId/instructions`**: Update an agent's instructions.
|
|
56
|
+
- **POST `/api/agents/:agentId/instructions/enhance`**: Generate an improved system prompt from instructions.
|
|
57
|
+
- **GET `/api/agents/:agentId/speakers`**: Get available speakers for an agent.
|
|
58
|
+
- **POST `/api/agents/:agentId/speak`**: Convert text to speech using the agent's voice provider.
|
|
59
|
+
- **POST `/api/agents/:agentId/listen`**: Convert speech to text using the agent's voice provider.
|
|
60
|
+
- **POST `/api/agents/:agentId/tools/:toolId/execute`**: Execute a tool through an agent.
|
|
50
61
|
|
|
51
62
|
### Tool Routes
|
|
52
63
|
|
|
53
64
|
Tools are expected to be exported from `src/mastra/tools` (or the configured tools directory).
|
|
54
65
|
|
|
55
|
-
|
|
56
|
-
|
|
66
|
+
- **GET `/api/tools`**: Get all tools.
|
|
67
|
+
- **GET `/api/tools/:toolId`**: Get tool by ID.
|
|
68
|
+
- **POST `/api/tools/:toolId/execute`**: Invokes a specific tool by name, passing input data in the request body.
|
|
57
69
|
|
|
58
70
|
### Workflow Routes
|
|
59
71
|
|
|
60
72
|
Workflows are expected to be exported from `src/mastra/workflows` (or the configured workflows directory).
|
|
61
73
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
74
|
+
- **GET `/api/workflows`**: Get all workflows.
|
|
75
|
+
- **GET `/api/workflows/:workflowId`**: Get workflow by ID.
|
|
76
|
+
- **POST `/api/workflows/:workflowName/start`**: Starts the specified workflow.
|
|
77
|
+
- **POST `/api/workflows/:workflowName/:instanceId/event`**: Sends an event or trigger signal to an existing workflow instance.
|
|
78
|
+
- **GET `/api/workflows/:workflowName/:instanceId/status`**: Returns status info for a running workflow instance.
|
|
79
|
+
- **POST `/api/workflows/:workflowId/resume`**: Resume a suspended workflow step.
|
|
80
|
+
- **POST `/api/workflows/:workflowId/resumeAsync`**: Resume a suspended workflow step asynchronously.
|
|
81
|
+
- **POST `/api/workflows/:workflowId/createRun`**: Create a new workflow run.
|
|
82
|
+
- **POST `/api/workflows/:workflowId/startAsync`**: Execute/Start a workflow asynchronously.
|
|
83
|
+
- **GET `/api/workflows/:workflowId/watch`**: Watch workflow transitions in real-time.
|
|
84
|
+
|
|
85
|
+
### Memory Routes
|
|
86
|
+
- **GET `/api/memory/status`**: Get memory status.
|
|
87
|
+
- **GET `/api/memory/threads`**: Get all threads.
|
|
88
|
+
- **GET `/api/memory/threads/:threadId`**: Get thread by ID.
|
|
89
|
+
- **GET `/api/memory/threads/:threadId/messages`**: Get messages for a thread.
|
|
90
|
+
- **POST `/api/memory/threads`**: Create a new thread.
|
|
91
|
+
- **PATCH `/api/memory/threads/:threadId`**: Update a thread.
|
|
92
|
+
- **DELETE `/api/memory/threads/:threadId`**: Delete a thread.
|
|
93
|
+
- **POST `/api/memory/save-messages`**: Save messages.
|
|
94
|
+
|
|
95
|
+
### Telemetry Routes
|
|
96
|
+
- **GET `/api/telemetry`**: Get all traces.
|
|
97
|
+
|
|
98
|
+
### Log Routes
|
|
99
|
+
- **GET `/api/logs`**: Get all logs.
|
|
100
|
+
- **GET `/api/logs/transports`**: List of all log transports.
|
|
101
|
+
- **GET `/api/logs/:runId`**: Get logs by run ID.
|
|
102
|
+
|
|
103
|
+
### Vector Routes
|
|
104
|
+
- **POST `/api/vector/:vectorName/upsert`**: Upsert vectors into an index.
|
|
105
|
+
- **POST `/api/vector/:vectorName/create-index`**: Create a new vector index.
|
|
106
|
+
- **POST `/api/vector/:vectorName/query`**: Query vectors from an index.
|
|
107
|
+
- **GET `/api/vector/:vectorName/indexes`**: List all indexes for a vector store.
|
|
108
|
+
- **GET `/api/vector/:vectorName/indexes/:indexName`**: Get details about a specific index.
|
|
109
|
+
- **DELETE `/api/vector/:vectorName/indexes/:indexName`**: Delete a specific index.
|
|
68
110
|
|
|
69
111
|
### OpenAPI Specification
|
|
70
112
|
|
|
71
|
-
|
|
72
|
-
|
|
113
|
+
- **GET `/openapi.json`**: Returns an auto-generated OpenAPI specification for your project's routes.
|
|
114
|
+
- **GET `/swagger-ui`**: Access Swagger UI for API documentation.
|
|
73
115
|
|
|
74
116
|
## Additional Notes
|
|
75
117
|
|
|
@@ -90,8 +132,3 @@ curl -X POST http://localhost:4111/api/agents/myAgent/generate \
|
|
|
90
132
|
]
|
|
91
133
|
}'
|
|
92
134
|
```
|
|
93
|
-
|
|
94
|
-
## Related Docs
|
|
95
|
-
|
|
96
|
-
- [REST Endpoints Overview](../../local-dev/mastra-dev.mdx) – More detailed usage of the dev server and agent endpoints.
|
|
97
|
-
- [mastra deploy](../../deployment/deployment.mdx) – Deploy your project to Vercel or Cloudflare.
|