@mastra/mcp-docs-server 0.13.26 → 0.13.27-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/%40internal%2Fstorage-test-utils.md +9 -9
- package/.docs/organized/changelogs/%40internal%2Ftypes-builder.md +2 -0
- package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +13 -13
- package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +11 -0
- package/.docs/organized/changelogs/%40mastra%2Fastra.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fchroma.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +23 -23
- package/.docs/organized/changelogs/%40mastra%2Fcloud.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +61 -61
- package/.docs/organized/changelogs/%40mastra%2Fcouchbase.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +24 -24
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +20 -20
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +22 -22
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +45 -45
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Fevals.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Flance.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +16 -16
- package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fmcp.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fopensearch.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fpinecone.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +65 -65
- package/.docs/organized/changelogs/%40mastra%2Fqdrant.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Frag.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Freact.md +18 -0
- package/.docs/organized/changelogs/%40mastra%2Fs3vectors.md +12 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +27 -27
- package/.docs/organized/changelogs/%40mastra%2Fturbopuffer.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fvectorize.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fvoice-azure.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fvoice-cloudflare.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fvoice-deepgram.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fvoice-elevenlabs.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fvoice-gladia.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google-gemini-live.md +9 -0
- package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fvoice-murf.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai-realtime.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fvoice-openai.md +10 -10
- package/.docs/organized/changelogs/%40mastra%2Fvoice-playai.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fvoice-sarvam.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fvoice-speechify.md +10 -10
- package/.docs/organized/changelogs/create-mastra.md +47 -47
- package/.docs/organized/changelogs/mastra.md +63 -63
- package/.docs/organized/code-examples/agent.md +19 -14
- package/.docs/organized/code-examples/heads-up-game.md +5 -5
- package/.docs/raw/agents/agent-memory.mdx +86 -125
- package/.docs/raw/agents/input-processors.mdx +3 -3
- package/.docs/raw/agents/output-processors.mdx +4 -4
- package/.docs/raw/agents/overview.mdx +11 -52
- package/.docs/raw/agents/using-tools-and-mcp.mdx +34 -29
- package/.docs/raw/deployment/serverless-platforms/vercel-deployer.mdx +18 -0
- package/.docs/raw/frameworks/agentic-uis/ai-sdk.mdx +4 -8
- package/.docs/raw/getting-started/installation.mdx +2 -3
- package/.docs/raw/getting-started/model-providers.mdx +28 -123
- package/.docs/raw/memory/semantic-recall.mdx +1 -1
- package/.docs/raw/reference/agents/agent.mdx +1 -1
- package/.docs/raw/reference/agents/generate.mdx +255 -218
- package/.docs/raw/reference/agents/generateLegacy.mdx +528 -0
- package/.docs/raw/reference/agents/getDefaultStreamOptions.mdx +3 -4
- package/.docs/raw/reference/agents/migration-guide.mdx +291 -0
- package/.docs/raw/reference/client-js/agents.mdx +14 -8
- package/.docs/raw/reference/deployer/vercel.mdx +26 -0
- package/.docs/raw/reference/streaming/ChunkType.mdx +4 -4
- package/.docs/raw/reference/streaming/agents/MastraModelOutput.mdx +13 -13
- package/.docs/raw/reference/streaming/agents/stream.mdx +351 -178
- package/.docs/raw/reference/streaming/agents/streamLegacy.mdx +515 -0
- package/.docs/raw/reference/{rag → vectors}/astra.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/chroma.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/couchbase.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/lance.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/libsql.mdx +2 -4
- package/.docs/raw/reference/{rag → vectors}/mongodb.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/opensearch.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/pg.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/pinecone.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/qdrant.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/s3vectors.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/turbopuffer.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/upstash.mdx +2 -2
- package/.docs/raw/reference/{rag → vectors}/vectorize.mdx +2 -2
- package/.docs/raw/streaming/events.mdx +4 -4
- package/.docs/raw/streaming/overview.mdx +9 -11
- package/.docs/raw/streaming/tool-streaming.mdx +3 -3
- package/.docs/raw/streaming/workflow-streaming.mdx +3 -3
- package/CHANGELOG.md +8 -0
- package/package.json +4 -4
- package/.docs/organized/code-examples/agent-network.md +0 -322
- package/.docs/raw/getting-started/model-capability.mdx +0 -11
- package/.docs/raw/reference/agents/generateVNext.mdx +0 -557
- package/.docs/raw/reference/agents/getDefaultVNextStreamOptions.mdx +0 -67
- package/.docs/raw/reference/streaming/agents/streamVNext.mdx +0 -673
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: "Agent Overview |
|
|
2
|
+
title: "Agent Overview | Agents | Mastra Docs"
|
|
3
3
|
description: Overview of agents in Mastra, detailing their capabilities and how they interact with tools, workflows, and external systems.
|
|
4
4
|
---
|
|
5
5
|
|
|
@@ -76,9 +76,9 @@ Instructions can be provided in multiple formats for greater flexibility:
|
|
|
76
76
|
instructions: "You are a helpful assistant."
|
|
77
77
|
|
|
78
78
|
// System message object
|
|
79
|
-
instructions: {
|
|
80
|
-
role: "system",
|
|
81
|
-
content: "You are an expert programmer."
|
|
79
|
+
instructions: {
|
|
80
|
+
role: "system",
|
|
81
|
+
content: "You are an expert programmer."
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
// Array of strings
|
|
@@ -112,10 +112,9 @@ Provider-specific options allow you to leverage unique features of different LLM
|
|
|
112
112
|
|
|
113
113
|
> See [Agent](../../reference/agents/agent.mdx) for more information.
|
|
114
114
|
|
|
115
|
-
|
|
116
115
|
### Registering an agent
|
|
117
116
|
|
|
118
|
-
Register your agent in the Mastra instance:
|
|
117
|
+
Register your agent in the Mastra instance to make it available throughout your application. Once registered, it can be called from workflows, tools, or other agents, and has access to shared resources such as memory, logging, and observability features:
|
|
119
118
|
|
|
120
119
|
```typescript showLineNumbers filename="src/mastra/index.ts" copy
|
|
121
120
|
import { Mastra } from "@mastra/core/mastra";
|
|
@@ -145,7 +144,7 @@ Use `.generate()` to get a response from an agent. Pass a single string for simp
|
|
|
145
144
|
|
|
146
145
|
### Generating text
|
|
147
146
|
|
|
148
|
-
Call `.generate()` with an array of message objects
|
|
147
|
+
Call `.generate()` with an array of message objects containing `role` and `content`. The `role` defines the speaker for each message. Typical roles are `user` for human input, `assistant` for agent responses, and `system` for instructions. This structure helps the LLM maintain conversation flow and generate contextually appropriate responses.
|
|
149
148
|
|
|
150
149
|
```typescript showLineNumbers copy
|
|
151
150
|
const response = await testAgent.generate([
|
|
@@ -158,49 +157,9 @@ const response = await testAgent.generate([
|
|
|
158
157
|
console.log(response.text);
|
|
159
158
|
```
|
|
160
159
|
|
|
161
|
-
## Streaming responses
|
|
162
|
-
|
|
163
|
-
Use `.stream()` for real-time responses. Pass a single string for simple prompts, an array of strings when providing multiple pieces of context, or an array of message objects with `role` and `content` for precise control over roles and conversational flows.
|
|
164
|
-
|
|
165
|
-
> See [.stream()](../../reference/agents/stream.mdx) for more information.
|
|
166
|
-
|
|
167
|
-
### Streaming text
|
|
168
|
-
|
|
169
|
-
Use `.stream()` with an array of message objects that include `role` and `content`:
|
|
170
|
-
|
|
171
|
-
```typescript showLineNumbers copy
|
|
172
|
-
const stream = await testAgent.stream([
|
|
173
|
-
{ role: "user", content: "Help me organize my day" },
|
|
174
|
-
{ role: "user", content: "My day starts at 9am and finishes at 5.30pm" },
|
|
175
|
-
{ role: "user", content: "I take lunch between 12:30 and 13:30" },
|
|
176
|
-
{ role: "user", content: "I have meetings Monday to Friday between 10:30 and 11:30" }
|
|
177
|
-
]);
|
|
178
|
-
|
|
179
|
-
for await (const chunk of stream.textStream) {
|
|
180
|
-
process.stdout.write(chunk);
|
|
181
|
-
}
|
|
182
|
-
```
|
|
183
|
-
|
|
184
|
-
### Completion using `onFinish()`
|
|
185
|
-
|
|
186
|
-
When streaming responses, the `onFinish()` callback runs after the LLM finishes generating its response and all tool executions are complete.
|
|
187
|
-
It provides the final `text`, execution `steps`, `finishReason`, token `usage` statistics, and other metadata useful for monitoring or logging.
|
|
188
|
-
|
|
189
|
-
```typescript showLineNumbers copy
|
|
190
|
-
const stream = await testAgent.stream("Help me organize my day", {
|
|
191
|
-
onFinish: ({ steps, text, finishReason, usage }) => {
|
|
192
|
-
console.log({ steps, text, finishReason, usage });
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
for await (const chunk of stream.textStream) {
|
|
197
|
-
process.stdout.write(chunk);
|
|
198
|
-
}
|
|
199
|
-
```
|
|
200
|
-
|
|
201
160
|
## Structured output
|
|
202
161
|
|
|
203
|
-
Agents can return structured, type-safe data by defining the expected output
|
|
162
|
+
Agents can return structured, type-safe data by defining the expected output using either [Zod](https://zod.dev/) or [JSON Schema](https://json-schema.org/). We recommend Zod for better TypeScript support and developer experience. The parsed result is available on `response.object`, allowing you to work directly with validated and typed data.
|
|
204
163
|
|
|
205
164
|
### Using Zod
|
|
206
165
|
|
|
@@ -233,7 +192,7 @@ console.log(response.object);
|
|
|
233
192
|
|
|
234
193
|
#### Agents with tools
|
|
235
194
|
|
|
236
|
-
To generate structured output with agents that use tools, use the `
|
|
195
|
+
To generate structured output with agents that use tools, use the `output` property:
|
|
237
196
|
|
|
238
197
|
```typescript {6} showLineNumbers copy
|
|
239
198
|
import { z } from "zod";
|
|
@@ -241,7 +200,7 @@ import { z } from "zod";
|
|
|
241
200
|
const response = await testAgent.generate(
|
|
242
201
|
// ...
|
|
243
202
|
{
|
|
244
|
-
|
|
203
|
+
output: z.object({
|
|
245
204
|
summary: z.string(),
|
|
246
205
|
keywords: z.array(z.string())
|
|
247
206
|
})
|
|
@@ -251,7 +210,7 @@ const response = await testAgent.generate(
|
|
|
251
210
|
console.log(response.object);
|
|
252
211
|
```
|
|
253
212
|
|
|
254
|
-
##
|
|
213
|
+
## Working with images
|
|
255
214
|
|
|
256
215
|
Agents can analyze and describe images by processing both the visual content and any text within them. To enable image analysis, pass an object with `type: 'image'` and the image URL in the `content` array. You can combine image content with text prompts to guide the agent's analysis.
|
|
257
216
|
|
|
@@ -284,7 +243,7 @@ For a detailed guide to creating and configuring tools, see the [Tools Overview]
|
|
|
284
243
|
|
|
285
244
|
### Using `maxSteps`
|
|
286
245
|
|
|
287
|
-
The `maxSteps` parameter controls the maximum number of sequential LLM calls an agent can make
|
|
246
|
+
The `maxSteps` parameter controls the maximum number of sequential LLM calls an agent can make. Each step includes generating a response, executing any tool calls, and processing the result. Limiting steps helps prevent infinite loops, reduce latency, and control token usage for agents that use tools. The default is 1, but can be increased:
|
|
288
247
|
|
|
289
248
|
```typescript showLineNumbers copy
|
|
290
249
|
const response = await testAgent.generate("Help me organize my day", {
|
|
@@ -1,63 +1,68 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: "
|
|
2
|
+
title: "Tools and MCP | Agents | Mastra Docs"
|
|
3
3
|
description: Learn how to create tools, add them to Mastra agents, and integrate tools from MCP servers.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
#
|
|
6
|
+
# Tools and MCP
|
|
7
7
|
|
|
8
|
-
Tools are typed functions that can be executed by agents or workflows
|
|
8
|
+
Tools are typed functions that can be executed by agents or workflows to help them carry out specific tasks like sending a message, querying a database, or calling an external API. Each tool defines its expected inputs, contains the logic to perform its operation, and may delegate execution to an MCP client for accessing external systems. They give agents a structured way to move beyond language generation and enable deterministic outcomes through well-defined interfaces.
|
|
9
9
|
|
|
10
10
|
Mastra supports two patterns for providing tools to agents:
|
|
11
|
+
|
|
11
12
|
- **Direct assignment**: Static tools available at initialization
|
|
12
|
-
- **Function-based**: Dynamic tools resolved based on runtime context
|
|
13
|
+
- **Function-based**: Dynamic tools resolved based on runtime context
|
|
13
14
|
|
|
14
|
-
## Creating
|
|
15
|
+
## Creating a tool
|
|
15
16
|
|
|
16
|
-
|
|
17
|
+
This example shows how to create a simple tool that asynchronously fetches data from a weather API:
|
|
17
18
|
|
|
18
|
-
```typescript filename="src/mastra/tools/
|
|
19
|
+
```typescript filename="src/mastra/tools/weather-tool.ts" showLineNumbers copy
|
|
19
20
|
import { createTool } from "@mastra/core/tools";
|
|
20
21
|
import { z } from "zod";
|
|
21
22
|
|
|
22
|
-
export const
|
|
23
|
-
id: "
|
|
23
|
+
export const weatherTool = createTool({
|
|
24
|
+
id: "weather-tool",
|
|
25
|
+
description: "Fetches the current weather information for a given city",
|
|
24
26
|
inputSchema: z.object({
|
|
25
27
|
city: z.string(),
|
|
26
28
|
}),
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
execute: async ({ context }) => {
|
|
30
|
+
const { city } = context;
|
|
31
|
+
const response = await fetch(`https://weather.service?city=${city}`);
|
|
32
|
+
|
|
33
|
+
const { temperature, conditions } = await response.json();
|
|
34
|
+
|
|
35
|
+
return { temperature, conditions };
|
|
32
36
|
},
|
|
33
37
|
});
|
|
34
38
|
```
|
|
35
39
|
|
|
36
|
-
For details on creating and designing tools, see the [Tools Overview](
|
|
40
|
+
For details on creating and designing tools, see the [Tools Overview](../tools-mcp/overview.mdx).
|
|
37
41
|
|
|
38
|
-
## Adding
|
|
42
|
+
## Adding tools to an agent
|
|
39
43
|
|
|
40
44
|
To make a tool available to an agent, add it to the `tools` property in the agent's configuration.
|
|
41
45
|
|
|
42
|
-
```typescript filename="src/mastra/agents/
|
|
46
|
+
```typescript {3,12} filename="src/mastra/agents/weather-agent.ts" showLineNumbers copy
|
|
43
47
|
import { Agent } from "@mastra/core/agent";
|
|
44
48
|
import { openai } from "@ai-sdk/openai";
|
|
45
|
-
import {
|
|
49
|
+
import { weatherTool } from "../tools/weather-tool";
|
|
46
50
|
|
|
47
51
|
export const weatherAgent = new Agent({
|
|
48
52
|
name: "Weather Agent",
|
|
49
|
-
instructions:
|
|
50
|
-
|
|
53
|
+
instructions: `
|
|
54
|
+
You are a helpful assistant that provides weather information.
|
|
55
|
+
When asked about the weather, use the weatherTool to fetch the data.`,
|
|
51
56
|
model: openai("gpt-4o-mini"),
|
|
52
57
|
tools: {
|
|
53
|
-
|
|
58
|
+
weatherTool,
|
|
54
59
|
},
|
|
55
60
|
});
|
|
56
61
|
```
|
|
57
62
|
|
|
58
63
|
When you call the agent, it can now decide to use the configured tool based on its instructions and the user's prompt.
|
|
59
64
|
|
|
60
|
-
## Adding MCP
|
|
65
|
+
## Adding MCP tools to an agent
|
|
61
66
|
|
|
62
67
|
[Model Context Protocol (MCP)](https://modelcontextprotocol.io/introduction) provides a standardized way for AI models to discover and interact with external tools and resources. You can connect your Mastra agent to MCP servers to use tools provided by third parties.
|
|
63
68
|
|
|
@@ -71,7 +76,7 @@ First, install the Mastra MCP package:
|
|
|
71
76
|
npm install @mastra/mcp@latest
|
|
72
77
|
```
|
|
73
78
|
|
|
74
|
-
### Using MCP
|
|
79
|
+
### Using MCP tools
|
|
75
80
|
|
|
76
81
|
Because there are so many MCP server registries to choose from, we've created an [MCP Registry Registry](https://mastra.ai/mcp-registry-registry) to help you find MCP servers.
|
|
77
82
|
|
|
@@ -121,7 +126,7 @@ import { openai } from "@ai-sdk/openai";
|
|
|
121
126
|
|
|
122
127
|
const myAgent = new Agent({
|
|
123
128
|
name: "My Agent",
|
|
124
|
-
description: "An agent that can use tools from an http MCP server",
|
|
129
|
+
description: "An agent that can use tools from an http MCP server",
|
|
125
130
|
instructions: "You can use remote calculation tools.",
|
|
126
131
|
model: openai("gpt-4o-mini"),
|
|
127
132
|
tools: async () => {
|
|
@@ -148,7 +153,7 @@ export const mcpServer = new MCPServer({
|
|
|
148
153
|
|
|
149
154
|
For more details on configuring `MCPClient` and the difference between static and dynamic MCP server configurations, see the [MCP Overview](/docs/tools-mcp/mcp-overview).
|
|
150
155
|
|
|
151
|
-
## Accessing MCP
|
|
156
|
+
## Accessing MCP resources
|
|
152
157
|
|
|
153
158
|
In addition to tools, MCP servers can also expose resources - data or content that can be retrieved and used in your application.
|
|
154
159
|
|
|
@@ -169,11 +174,11 @@ if (resources.filesystem) {
|
|
|
169
174
|
|
|
170
175
|
Each resource has a URI, name, description, and MIME type. The `getResources()` method handles errors gracefully - if a server fails or doesn't support resources, it will be omitted from the results.
|
|
171
176
|
|
|
172
|
-
## Accessing MCP
|
|
177
|
+
## Accessing MCP prompts
|
|
173
178
|
|
|
174
179
|
MCP servers can also expose prompts, which represent structured message templates or conversational context for agents.
|
|
175
180
|
|
|
176
|
-
### Listing
|
|
181
|
+
### Listing prompts
|
|
177
182
|
|
|
178
183
|
```typescript filename="src/mastra/prompts.ts"
|
|
179
184
|
import { mcp } from "./mcp";
|
|
@@ -192,7 +197,7 @@ if (prompts.weather) {
|
|
|
192
197
|
|
|
193
198
|
Each prompt has a name, description, and (optional) version.
|
|
194
199
|
|
|
195
|
-
### Retrieving a
|
|
200
|
+
### Retrieving a prompt and its messages
|
|
196
201
|
|
|
197
202
|
```typescript filename="src/mastra/prompts.ts"
|
|
198
203
|
const { prompt, messages } = await mcp.prompts.get({ serverName: "weather", name: "current" });
|
|
@@ -200,7 +205,7 @@ console.log(prompt); // { name: "current", version: "v1", ... }
|
|
|
200
205
|
console.log(messages); // [ { role: "assistant", content: { type: "text", text: "..." } }, ... ]
|
|
201
206
|
```
|
|
202
207
|
|
|
203
|
-
## Exposing
|
|
208
|
+
## Exposing agents as tools via `MCPServer`
|
|
204
209
|
|
|
205
210
|
In addition to using tools from MCP servers, your Mastra Agents themselves can be exposed as tools to any MCP-compatible client using Mastra's `MCPServer`.
|
|
206
211
|
|
|
@@ -29,6 +29,24 @@ export const mastra = new Mastra({
|
|
|
29
29
|
|
|
30
30
|
> See the [VercelDeployer](/reference/deployer/vercel) API reference for all available configuration options.
|
|
31
31
|
|
|
32
|
+
### Optional overrides
|
|
33
|
+
|
|
34
|
+
The Vercel deployer can write a few high‑value settings into the Vercel Output API function config (`.vc-config.json`):
|
|
35
|
+
|
|
36
|
+
- `maxDuration?: number` — Function execution timeout (seconds)
|
|
37
|
+
- `memory?: number` — Function memory allocation (MB)
|
|
38
|
+
- `regions?: string[]` — Regions (e.g. `['sfo1','iad1']`)
|
|
39
|
+
|
|
40
|
+
Example:
|
|
41
|
+
|
|
42
|
+
```ts filename="src/mastra/index.ts" showLineNumbers copy
|
|
43
|
+
deployer: new VercelDeployer({
|
|
44
|
+
maxDuration: 600,
|
|
45
|
+
memory: 1536,
|
|
46
|
+
regions: ["sfo1", "iad1"],
|
|
47
|
+
})
|
|
48
|
+
```
|
|
49
|
+
|
|
32
50
|
## Continuous integration
|
|
33
51
|
|
|
34
52
|
After connecting your Mastra project’s Git repository to Vercel, update the project settings. In the Vercel dashboard, go to **Settings** > **Build and Deployment**, and under **Framework settings**, set the following:
|
|
@@ -384,13 +384,13 @@ This guide covers Mastra-specific considerations when migrating from AI SDK v4 t
|
|
|
384
384
|
|
|
385
385
|
> Please add any feedback or bug reports to the [AI SDK v5 mega issue in Github.](https://github.com/mastra-ai/mastra/issues/5470)
|
|
386
386
|
|
|
387
|
-
###
|
|
387
|
+
### Stream Support
|
|
388
388
|
|
|
389
|
-
Mastra's experimental `
|
|
389
|
+
Mastra's experimental `stream` method now includes native AI SDK v5 support through the `format` parameter. This provides seamless integration with AI SDK v5's streaming interfaces without requiring compatibility wrappers.
|
|
390
390
|
|
|
391
391
|
```typescript
|
|
392
|
-
// Use
|
|
393
|
-
const stream = await agent.
|
|
392
|
+
// Use stream with AI SDK v5 format
|
|
393
|
+
const stream = await agent.stream(messages, {
|
|
394
394
|
format: 'aisdk' // Enable AI SDK v5 compatibility
|
|
395
395
|
});
|
|
396
396
|
|
|
@@ -483,10 +483,6 @@ const { error, status, sendMessage, messages, regenerate, stop } =
|
|
|
483
483
|
});
|
|
484
484
|
```
|
|
485
485
|
|
|
486
|
-
<Callout type="info">
|
|
487
|
-
**Note**: The `streamVNext` method with format support is experimental and may change as we refine the feature based on feedback. See the [Agent Streaming documentation](/docs/agents/streaming) for more details about streamVNext.
|
|
488
|
-
</Callout>
|
|
489
|
-
|
|
490
486
|
### Type Inference for Tools
|
|
491
487
|
|
|
492
488
|
When using tools with TypeScript in AI SDK v5, Mastra provides type inference helpers to ensure type safety for your tool inputs and outputs.
|
|
@@ -405,10 +405,9 @@ Install the latest version to the `@ai-sdk/openai` package:
|
|
|
405
405
|
</Tab>
|
|
406
406
|
</Tabs>
|
|
407
407
|
|
|
408
|
-
Update the `planActivities` step in `src/mastra/workflows/weather-workflow.ts` as
|
|
408
|
+
Update the `planActivities` step in `src/mastra/workflows/weather-workflow.ts` as follows:
|
|
409
409
|
```ts filename="src/mastra/workflows/weather-workflow.ts" showLineNumbers{150} copy
|
|
410
|
-
const response = await agent.stream([
|
|
411
|
-
const response = await agent.streamVNext([ // [!code ++]
|
|
410
|
+
const response = await agent.stream([
|
|
412
411
|
{
|
|
413
412
|
role: 'user',
|
|
414
413
|
content: prompt,
|
|
@@ -7,150 +7,55 @@ import { Callout } from "nextra/components"
|
|
|
7
7
|
|
|
8
8
|
# Model Providers
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
Mastra's unified model router gives you access to 541+ models from 38 providers with a single API. Switch between models and providers without changing your code. Automatic environment variable detection handles authentication, while TypeScript provides full autocomplete for every model.
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
## Quick Start
|
|
13
|
+
|
|
14
|
+
Simply use the `provider/model` string pattern:
|
|
15
|
+
|
|
16
|
+
```typescript showLineNumbers copy filename="src/mastra/agents/weather-agent.ts"
|
|
17
|
+
import { Agent } from "@mastra/core";
|
|
15
18
|
|
|
16
19
|
const agent = new Agent({
|
|
17
20
|
name: "WeatherAgent",
|
|
18
|
-
instructions: "
|
|
19
|
-
model: openai
|
|
21
|
+
instructions: "You are a helpful weather assistant",
|
|
22
|
+
model: "openai/gpt-4o"
|
|
20
23
|
});
|
|
21
24
|
|
|
22
25
|
const result = await agent.generate("What is the weather like?");
|
|
23
26
|
```
|
|
24
27
|
|
|
25
|
-
##
|
|
26
|
-
|
|
27
|
-
Model providers from the AI SDK can be grouped into three main categories:
|
|
28
|
-
|
|
29
|
-
- [Official providers maintained by the AI SDK team](/docs/getting-started/model-providers#official-providers)
|
|
30
|
-
- [OpenAI-compatible providers](/docs/getting-started/model-providers#openai-compatible-providers)
|
|
31
|
-
- [Community providers](/docs/getting-started/model-providers#community-providers)
|
|
32
|
-
|
|
33
|
-
> You can find a list of all available model providers in the [AI SDK documentation](https://ai-sdk.dev/providers/ai-sdk-providers).
|
|
28
|
+
## Browse Providers
|
|
34
29
|
|
|
35
30
|
<Callout>
|
|
36
|
-
|
|
37
|
-
The default model provider selected during the installation process is installed in the project.
|
|
38
|
-
|
|
39
|
-
If you want to use a different model provider, you need to install it in your project as well.
|
|
31
|
+
**[→ View all 38 providers and 7 gateways](../../models)**
|
|
40
32
|
</Callout>
|
|
41
33
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
### Official providers
|
|
45
|
-
|
|
46
|
-
Official model providers are maintained by the AI SDK team.
|
|
47
|
-
Their packages are usually prefixed with `@ai-sdk/`, e.g. `@ai-sdk/anthropic`, `@ai-sdk/openai`, etc.
|
|
48
|
-
|
|
49
|
-
```typescript showLineNumbers copy {1,7} filename="src/mastra/agents/weather-agent.ts"
|
|
50
|
-
import { openai } from "@ai-sdk/openai";
|
|
51
|
-
import { Agent } from "@mastra/core/agent";
|
|
52
|
-
|
|
53
|
-
const agent = new Agent({
|
|
54
|
-
name: "WeatherAgent",
|
|
55
|
-
instructions: "Instructions for the agent...",
|
|
56
|
-
model: openai("gpt-4-turbo"),
|
|
57
|
-
});
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
Additional configuration may be done by importing a helper function from the AI SDK provider.
|
|
61
|
-
Here's an example using the OpenAI provider:
|
|
62
|
-
|
|
63
|
-
```typescript showLineNumbers copy filename="src/mastra/agents/weather-agent.ts" {1,4-8,13}
|
|
64
|
-
import { createOpenAI } from "@ai-sdk/openai";
|
|
65
|
-
import { Agent } from "@mastra/core/agent";
|
|
66
|
-
|
|
67
|
-
const openai = createOpenAI({
|
|
68
|
-
baseUrl: "<your-custom-base-url>",
|
|
69
|
-
apiKey: "<your-custom-api-key>",
|
|
70
|
-
...otherOptions,
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
const agent = new Agent({
|
|
74
|
-
name: "WeatherAgent",
|
|
75
|
-
instructions: "Instructions for the agent...",
|
|
76
|
-
model: openai("<model-name>"),
|
|
77
|
-
});
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
### OpenAI-compatible providers
|
|
34
|
+
## Configuration
|
|
81
35
|
|
|
82
|
-
|
|
36
|
+
Models automatically detect API keys from environment variables.
|
|
83
37
|
|
|
84
|
-
|
|
38
|
+
## AI SDK Compatibility
|
|
85
39
|
|
|
86
|
-
|
|
87
|
-
import { createOpenAICompatible } from "@ai-sdk/openai-compatible";
|
|
88
|
-
import { Agent } from "@mastra/core/agent";
|
|
40
|
+
While Mastra provides built-in support for 541+ models, you can also use [Vercel AI SDK](https://sdk.vercel.ai/providers/ai-sdk-providers) model providers for additional flexibility:
|
|
89
41
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
apiKey: "<api-key>",
|
|
94
|
-
headers: {},
|
|
95
|
-
queryParams: {},
|
|
96
|
-
fetch: async (url, options) => {
|
|
97
|
-
// custom fetch logic
|
|
98
|
-
return fetch(url, options);
|
|
99
|
-
},
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
const agent = new Agent({
|
|
103
|
-
name: "WeatherAgent",
|
|
104
|
-
instructions: "Instructions for the agent...",
|
|
105
|
-
model: openaiCompatible("<model-name>"),
|
|
106
|
-
});
|
|
107
|
-
```
|
|
108
|
-
|
|
109
|
-
For more information on the OpenAI-compatible provider, please refer to the [AI SDK documentation](https://ai-sdk.dev/providers/openai-compatible-providers).
|
|
110
|
-
|
|
111
|
-
### Community providers
|
|
112
|
-
|
|
113
|
-
The AI SDK provides a [Language Model Specification](https://github.com/vercel/ai/tree/main/packages/provider/src/language-model/v1).
|
|
114
|
-
Following this specification, you can create your own model provider compatible with the AI SDK.
|
|
115
|
-
|
|
116
|
-
Some community providers have implemented this specification and are compatible with the AI SDK.
|
|
117
|
-
We will look at one such provider, the Ollama provider available in the [`ollama-ai-provider-v2`](https://github.com/nordwestt/ollama-ai-provider-v2) package.
|
|
118
|
-
|
|
119
|
-
Here's an example:
|
|
120
|
-
|
|
121
|
-
```typescript showLineNumbers copy filename="src/mastra/agents/weather-agent.ts" {1,7}
|
|
122
|
-
import { ollama } from "ollama-ai-provider-v2";
|
|
123
|
-
import { Agent } from "@mastra/core/agent";
|
|
124
|
-
|
|
125
|
-
const agent = new Agent({
|
|
126
|
-
name: "WeatherAgent",
|
|
127
|
-
instructions: "Instructions for the agent...",
|
|
128
|
-
model: ollama("llama3.2:latest"),
|
|
129
|
-
});
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
You can also configure the Ollama provider like so:
|
|
133
|
-
|
|
134
|
-
```typescript showLineNumbers copy filename="src/mastra/agents/weather-agent.ts" {1,4-7,12}
|
|
135
|
-
import { createOllama } from "ollama-ai-provider-v2";
|
|
136
|
-
import { Agent } from "@mastra/core/agent";
|
|
137
|
-
|
|
138
|
-
const ollama = createOllama({
|
|
139
|
-
baseUrl: "<your-custom-base-url>",
|
|
140
|
-
...otherOptions,
|
|
141
|
-
});
|
|
42
|
+
```typescript
|
|
43
|
+
import { openai } from "@ai-sdk/openai";
|
|
44
|
+
import { Agent } from "@mastra/core";
|
|
142
45
|
|
|
143
46
|
const agent = new Agent({
|
|
144
|
-
name: "
|
|
145
|
-
|
|
146
|
-
model: ollama("llama3.2:latest"),
|
|
47
|
+
name: "AISDKAgent",
|
|
48
|
+
model: openai("gpt-4-turbo") // AI SDK model provider
|
|
147
49
|
});
|
|
148
50
|
```
|
|
149
51
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
<Callout>
|
|
153
|
-
While this example shows how to use the Ollama provider, other providers like `openrouter`, `azure`, etc. may also be used.
|
|
52
|
+
<Callout type="info">
|
|
53
|
+
**Recommendation**: Use Mastra's built-in model router (`"provider/model"` strings) for simplicity. Use AI SDK providers only when you need specific features not available in the built-in providers.
|
|
154
54
|
</Callout>
|
|
155
55
|
|
|
156
|
-
|
|
56
|
+
## Learn More
|
|
57
|
+
|
|
58
|
+
- [📚 Browse All Model Providers](../../models) - Complete list with examples
|
|
59
|
+
- [🚀 Agent Documentation](/reference/agents/agent) - Using models with agents
|
|
60
|
+
- [⚙️ Environment Variables](/docs/deployment/environment-variables) - Configuration guide
|
|
61
|
+
- [🔧 Tool Configuration](/docs/tools/overview) - Adding tools to agents
|
|
@@ -170,7 +170,7 @@ const agent = new Agent({
|
|
|
170
170
|
});
|
|
171
171
|
```
|
|
172
172
|
|
|
173
|
-
For detailed information about index configuration options and performance tuning, see the [PgVector configuration guide](/reference/
|
|
173
|
+
For detailed information about index configuration options and performance tuning, see the [PgVector configuration guide](/reference/vectors/pg#index-configuration-guide).
|
|
174
174
|
|
|
175
175
|
### Disabling
|
|
176
176
|
|
|
@@ -162,7 +162,7 @@ export const agent = new Agent({
|
|
|
162
162
|
description: "Default options used when calling `stream()`.",
|
|
163
163
|
},
|
|
164
164
|
{
|
|
165
|
-
name: "
|
|
165
|
+
name: "defaultStreamOptions",
|
|
166
166
|
type: "AgentExecutionOptions | ({ runtimeContext: RuntimeContext }) => AgentExecutionOptions | Promise<AgentExecutionOptions>",
|
|
167
167
|
isOptional: true,
|
|
168
168
|
description: "Default options used when calling `stream()` in vNext mode.",
|