@mastra/mcp-docs-server 0.13.4 → 0.13.5
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 +8 -8
- package/.docs/organized/changelogs/%40mastra%2Fagui.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +55 -55
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +11 -11
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +47 -47
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +42 -42
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +24 -24
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +24 -24
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +72 -72
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +31 -31
- package/.docs/organized/changelogs/%40mastra%2Ffastembed.md +7 -0
- package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Floggers.md +9 -9
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +21 -21
- 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 +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +77 -77
- package/.docs/organized/changelogs/%40mastra%2Frag.md +14 -14
- package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +6 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +54 -54
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +13 -13
- package/.docs/organized/changelogs/create-mastra.md +34 -34
- package/.docs/organized/changelogs/mastra.md +79 -79
- package/.docs/organized/code-examples/bird-checker-with-express.md +1 -1
- package/.docs/organized/code-examples/crypto-chatbot.md +9 -9
- package/.docs/organized/code-examples/fireworks-r1.md +1 -1
- package/.docs/organized/code-examples/memory-per-resource-example.md +1 -1
- package/.docs/organized/code-examples/memory-with-pg.md +1 -1
- package/.docs/organized/code-examples/memory-with-upstash.md +1 -1
- package/.docs/organized/code-examples/openapi-spec-writer.md +4 -4
- package/.docs/raw/agents/overview.mdx +16 -33
- package/.docs/raw/community/licensing.mdx +27 -19
- package/.docs/raw/deployment/cloud-providers/aws-lambda.mdx +279 -0
- package/.docs/raw/deployment/cloud-providers/digital-ocean.mdx +1 -1
- package/.docs/raw/deployment/server-deployment.mdx +56 -0
- package/.docs/raw/deployment/serverless-platforms/index.mdx +0 -1
- package/.docs/raw/frameworks/agentic-uis/ai-sdk.mdx +97 -0
- package/.docs/raw/frameworks/agentic-uis/assistant-ui.mdx +34 -0
- package/.docs/raw/memory/overview.mdx +2 -1
- package/.docs/raw/rag/retrieval.mdx +24 -5
- package/.docs/raw/reference/agents/generate.mdx +3 -2
- package/.docs/raw/reference/agents/stream.mdx +3 -2
- package/.docs/raw/reference/cli/dev.mdx +12 -0
- package/.docs/raw/reference/legacyWorkflows/createRun.mdx +0 -4
- package/.docs/raw/reference/memory/Memory.mdx +12 -6
- package/.docs/raw/reference/rag/rerankWithScorer.mdx +213 -0
- package/.docs/raw/reference/workflows/create-run.mdx +4 -4
- package/.docs/raw/reference/workflows/sendEvent.mdx +49 -0
- package/.docs/raw/{local-dev/mastra-dev.mdx → server-db/local-dev-playground.mdx} +10 -3
- package/.docs/raw/{client-js/overview.mdx → server-db/mastra-client.mdx} +16 -0
- package/.docs/raw/server-db/production-server.mdx +66 -0
- package/.docs/raw/tools-mcp/mcp-overview.mdx +4 -6
- package/.docs/raw/workflows/control-flow.mdx +34 -34
- package/.docs/raw/workflows/overview.mdx +1 -1
- package/.docs/raw/workflows/pausing-execution.mdx +74 -37
- package/LICENSE.md +11 -42
- package/package.json +6 -6
- package/.docs/raw/deployment/server.mdx +0 -116
- /package/.docs/raw/{deployment → server-db}/custom-api-routes.mdx +0 -0
- /package/.docs/raw/{deployment → server-db}/middleware.mdx +0 -0
- /package/.docs/raw/{storage/overview.mdx → server-db/storage.mdx} +0 -0
|
@@ -5,36 +5,39 @@ description: "Mastra License"
|
|
|
5
5
|
|
|
6
6
|
# License
|
|
7
7
|
|
|
8
|
-
##
|
|
8
|
+
## Apache License 2.0
|
|
9
9
|
|
|
10
|
-
Mastra is licensed under the
|
|
10
|
+
Mastra is licensed under the Apache License 2.0, a permissive open-source license that provides users with broad rights to use, modify, and distribute the software.
|
|
11
11
|
|
|
12
|
-
### What is
|
|
12
|
+
### What is Apache License 2.0?
|
|
13
13
|
|
|
14
|
-
The
|
|
14
|
+
The Apache License 2.0 is a permissive open-source license that grants users extensive rights to use, modify, and distribute the software. It allows:
|
|
15
15
|
|
|
16
|
-
- Free use for
|
|
16
|
+
- Free use for any purpose, including commercial use
|
|
17
17
|
- Viewing, modifying, and redistributing the source code
|
|
18
18
|
- Creating and distributing derivative works
|
|
19
|
-
- Commercial use
|
|
19
|
+
- Commercial use without restrictions
|
|
20
|
+
- Patent protection from contributors
|
|
20
21
|
|
|
21
|
-
The
|
|
22
|
+
The Apache License 2.0 is one of the most permissive and business-friendly open-source licenses available.
|
|
22
23
|
|
|
23
|
-
### Why We Chose
|
|
24
|
+
### Why We Chose Apache License 2.0
|
|
24
25
|
|
|
25
|
-
We selected the
|
|
26
|
+
We selected the Apache License 2.0 for several important reasons:
|
|
26
27
|
|
|
27
|
-
1. **
|
|
28
|
+
1. **True Open Source**: It's a recognized open-source license that aligns with open-source principles and community expectations.
|
|
28
29
|
|
|
29
|
-
2. **
|
|
30
|
+
2. **Business Friendly**: It allows for unrestricted commercial use and distribution, making it ideal for businesses of all sizes.
|
|
30
31
|
|
|
31
|
-
3. **
|
|
32
|
+
3. **Patent Protection**: It includes explicit patent protection for users, providing additional legal security.
|
|
32
33
|
|
|
33
|
-
4. **
|
|
34
|
+
4. **Community Focus**: It encourages community contributions and collaboration without restrictions.
|
|
35
|
+
|
|
36
|
+
5. **Widely Adopted**: It's one of the most popular and well-understood open-source licenses in the industry.
|
|
34
37
|
|
|
35
38
|
### Building Your Business with Mastra
|
|
36
39
|
|
|
37
|
-
|
|
40
|
+
The Apache License 2.0 provides maximum flexibility for building businesses with Mastra:
|
|
38
41
|
|
|
39
42
|
#### Allowed Business Models
|
|
40
43
|
|
|
@@ -43,6 +46,8 @@ Despite the licensing restrictions, there are numerous ways to build successful
|
|
|
43
46
|
- **Developing Custom Solutions**: Build bespoke AI solutions for clients using Mastra
|
|
44
47
|
- **Creating Add-ons and Extensions**: Develop and sell complementary tools that extend Mastra's functionality
|
|
45
48
|
- **Training and Education**: Offer courses and educational materials about using Mastra effectively
|
|
49
|
+
- **Hosted Services**: Offer Mastra as a hosted or managed service
|
|
50
|
+
- **SaaS Platforms**: Build SaaS platforms powered by Mastra
|
|
46
51
|
|
|
47
52
|
#### Examples of Compliant Usage
|
|
48
53
|
|
|
@@ -50,14 +55,17 @@ Despite the licensing restrictions, there are numerous ways to build successful
|
|
|
50
55
|
- A consulting firm offers implementation and customization services for Mastra
|
|
51
56
|
- A developer creates specialized agents and tools with Mastra and licenses them to other businesses
|
|
52
57
|
- A startup builds a vertical-specific solution (e.g., healthcare AI assistant) powered by Mastra
|
|
58
|
+
- A company offers Mastra as a hosted service to their customers
|
|
59
|
+
- A SaaS platform integrates Mastra as their AI backend
|
|
53
60
|
|
|
54
|
-
####
|
|
61
|
+
#### Compliance Requirements
|
|
55
62
|
|
|
56
|
-
The
|
|
63
|
+
The Apache License 2.0 has minimal requirements:
|
|
57
64
|
|
|
58
|
-
-
|
|
59
|
-
-
|
|
65
|
+
- **Attribution**: Maintain copyright notices and license information (including NOTICE file)
|
|
66
|
+
- **State Changes**: If you modify the software, state that you have made changes
|
|
67
|
+
- **Include License**: Include a copy of the Apache License 2.0 when distributing
|
|
60
68
|
|
|
61
69
|
### Questions About Licensing?
|
|
62
70
|
|
|
63
|
-
If you have specific questions about how the
|
|
71
|
+
If you have specific questions about how the Apache License 2.0 applies to your use case, please [contact us](https://discord.gg/BTYqqHKUrf) on Discord for clarification. We're committed to supporting all legitimate use cases while maintaining the open-source nature of the project.
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "AWS Lambda"
|
|
3
|
+
description: "Deploy your Mastra applications to AWS Lambda using Docker containers and the AWS Lambda Web Adapter."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import { Callout, Steps } from "nextra/components";
|
|
7
|
+
|
|
8
|
+
## AWS Lambda
|
|
9
|
+
|
|
10
|
+
Deploy your Mastra applications to AWS Lambda using Docker containers and the AWS Lambda Web Adapter.
|
|
11
|
+
This approach allows you to run your Mastra server as a containerized Lambda function with automatic scaling.
|
|
12
|
+
|
|
13
|
+
<Callout>
|
|
14
|
+
This guide assumes your Mastra application has been created using the default
|
|
15
|
+
`npx create-mastra@latest` command.
|
|
16
|
+
For more information on how to create a new Mastra application,
|
|
17
|
+
refer to our [getting started guide](/docs/getting-started/installation)
|
|
18
|
+
</Callout>
|
|
19
|
+
|
|
20
|
+
### Prerequisites
|
|
21
|
+
|
|
22
|
+
Before deploying to AWS Lambda, ensure you have:
|
|
23
|
+
|
|
24
|
+
- [AWS CLI](https://aws.amazon.com/cli/) installed and configured
|
|
25
|
+
- [Docker](https://www.docker.com/) installed and running
|
|
26
|
+
- An AWS account with appropriate permissions for Lambda, ECR, and IAM
|
|
27
|
+
- Your Mastra application configured with appropriate memory storage
|
|
28
|
+
|
|
29
|
+
### Memory Configuration
|
|
30
|
+
|
|
31
|
+
<Callout>
|
|
32
|
+
AWS Lambda uses an ephemeral file system,
|
|
33
|
+
meaning that any files written to the file system are short-lived and may be lost.
|
|
34
|
+
Avoid using a Mastra storage provider that uses the file system,
|
|
35
|
+
such as `LibSQLStore` with a file URL.
|
|
36
|
+
</Callout>
|
|
37
|
+
|
|
38
|
+
Lambda functions have limitations with file system storage. Configure your Mastra application to use either in-memory or external storage providers:
|
|
39
|
+
|
|
40
|
+
#### Option 1: In-Memory (Simplest)
|
|
41
|
+
|
|
42
|
+
```typescript filename="src/mastra/index.ts" copy showLineNumbers
|
|
43
|
+
import { LibSQLStore } from "@mastra/libsql";
|
|
44
|
+
|
|
45
|
+
const storage = new LibSQLStore({
|
|
46
|
+
url: ":memory:", // in-memory storage
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
#### Option 2: External Storage Providers
|
|
51
|
+
|
|
52
|
+
For persistent memory across Lambda invocations, use external storage providers like `LibSQLStore` with Turso or other storage providers like `PostgreStore`:
|
|
53
|
+
|
|
54
|
+
```typescript filename="src/mastra/index.ts" copy showLineNumbers
|
|
55
|
+
import { LibSQLStore } from "@mastra/libsql";
|
|
56
|
+
|
|
57
|
+
const storage = new LibSQLStore({
|
|
58
|
+
url: "libsql://your-database.turso.io", // External Turso database
|
|
59
|
+
authToken: process.env.TURSO_AUTH_TOKEN,
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
For more memory configuration options, see the [Memory documentation](/docs/memory/overview).
|
|
64
|
+
|
|
65
|
+
### Creating a Dockerfile
|
|
66
|
+
|
|
67
|
+
<Steps>
|
|
68
|
+
|
|
69
|
+
#### Create a Dockerfile in your project root
|
|
70
|
+
|
|
71
|
+
Create a `Dockerfile` in your Mastra project root directory:
|
|
72
|
+
|
|
73
|
+
```dockerfile filename="Dockerfile" copy showLineNumbers
|
|
74
|
+
FROM node:22-alpine
|
|
75
|
+
|
|
76
|
+
WORKDIR /app
|
|
77
|
+
COPY package*.json ./
|
|
78
|
+
RUN npm ci
|
|
79
|
+
COPY src ./src
|
|
80
|
+
RUN npx mastra build
|
|
81
|
+
RUN apk add --no-cache gcompat
|
|
82
|
+
|
|
83
|
+
COPY --from=public.ecr.aws/awsguru/aws-lambda-adapter:0.9.0 /lambda-adapter /opt/extensions/lambda-adapter
|
|
84
|
+
RUN addgroup -g 1001 -S nodejs && \
|
|
85
|
+
adduser -S mastra -u 1001 && \
|
|
86
|
+
chown -R mastra:nodejs /app
|
|
87
|
+
|
|
88
|
+
USER mastra
|
|
89
|
+
|
|
90
|
+
ENV PORT=8080
|
|
91
|
+
ENV NODE_ENV=production
|
|
92
|
+
ENV READINESS_CHECK_PATH="/api"
|
|
93
|
+
|
|
94
|
+
EXPOSE 8080
|
|
95
|
+
|
|
96
|
+
CMD ["node", "--import=./.mastra/output/instrumentation.mjs", ".mastra/output/index.mjs"]
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
</Steps>
|
|
100
|
+
|
|
101
|
+
### Building and Deploying
|
|
102
|
+
|
|
103
|
+
<Steps>
|
|
104
|
+
|
|
105
|
+
#### Set up environment variables
|
|
106
|
+
|
|
107
|
+
Set up your environment variables for the deployment process:
|
|
108
|
+
|
|
109
|
+
```bash copy
|
|
110
|
+
export PROJECT_NAME="your-mastra-app"
|
|
111
|
+
export AWS_REGION="us-east-1"
|
|
112
|
+
export AWS_ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text)
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
#### Build the Docker image
|
|
116
|
+
|
|
117
|
+
Build your Docker image locally:
|
|
118
|
+
|
|
119
|
+
```bash copy
|
|
120
|
+
docker build -t "$PROJECT_NAME" .
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
#### Create an ECR repository
|
|
124
|
+
|
|
125
|
+
Create an Amazon ECR repository to store your Docker image:
|
|
126
|
+
|
|
127
|
+
```bash copy
|
|
128
|
+
aws ecr create-repository --repository-name "$PROJECT_NAME" --region "$AWS_REGION"
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
#### Authenticate Docker with ECR
|
|
132
|
+
|
|
133
|
+
Log in to Amazon ECR:
|
|
134
|
+
|
|
135
|
+
```bash copy
|
|
136
|
+
aws ecr get-login-password --region "$AWS_REGION" | docker login --username AWS --password-stdin "$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com"
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
#### Tag and push the image
|
|
140
|
+
|
|
141
|
+
Tag your image with the ECR repository URI and push it:
|
|
142
|
+
|
|
143
|
+
```bash copy
|
|
144
|
+
docker tag "$PROJECT_NAME":latest "$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$PROJECT_NAME":latest
|
|
145
|
+
docker push "$AWS_ACCOUNT_ID.dkr.ecr.$AWS_REGION.amazonaws.com/$PROJECT_NAME":latest
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
#### Create the Lambda function
|
|
149
|
+
|
|
150
|
+
Create a Lambda function using the AWS Console:
|
|
151
|
+
|
|
152
|
+
1. Navigate to the [AWS Lambda Console](https://console.aws.amazon.com/lambda/)
|
|
153
|
+
2. Click **Create function**
|
|
154
|
+
3. Select **Container image**
|
|
155
|
+
4. Configure the function:
|
|
156
|
+
- **Function name**: Your function name (e.g., `mastra-app`)
|
|
157
|
+
- **Container image URI**: Click **Browse images** and select your ECR repository, then choose the `latest` tag
|
|
158
|
+
- **Architecture**: Select the architecture that matches your Docker build (typically `x86_64`)
|
|
159
|
+
|
|
160
|
+
#### Configure Function URL
|
|
161
|
+
|
|
162
|
+
Enable Function URL for external access:
|
|
163
|
+
|
|
164
|
+
1. In the Lambda function configuration, go to **Configuration** > **Function URL**
|
|
165
|
+
2. Click **Create function URL**
|
|
166
|
+
3. Set **Auth type** to **NONE** (for public access)
|
|
167
|
+
4. Configure **CORS** settings:
|
|
168
|
+
- **Allow-Origin**: `*` (restrict to your domain in production)
|
|
169
|
+
- **Allow-Headers**: `content-type`
|
|
170
|
+
- **Allow-Methods**: `*` (audit and restrict in production)
|
|
171
|
+
5. Click **Save**
|
|
172
|
+
|
|
173
|
+
#### Configure environment variables
|
|
174
|
+
|
|
175
|
+
Add your environment variables in the Lambda function configuration:
|
|
176
|
+
|
|
177
|
+
1. Go to **Configuration** > **Environment variables**
|
|
178
|
+
2. Add the required variables for your Mastra application:
|
|
179
|
+
- `OPENAI_API_KEY`: Your OpenAI API key (if using OpenAI)
|
|
180
|
+
- `ANTHROPIC_API_KEY`: Your Anthropic API key (if using Anthropic)
|
|
181
|
+
- `TURSO_AUTH_TOKEN`: Your Turso auth token (if using LibSQL with Turso)
|
|
182
|
+
- Other provider-specific API keys as needed
|
|
183
|
+
|
|
184
|
+
#### Adjust function settings
|
|
185
|
+
|
|
186
|
+
Configure the function's memory and timeout settings:
|
|
187
|
+
|
|
188
|
+
1. Go to **Configuration** > **General configuration**
|
|
189
|
+
2. Set the following recommended values:
|
|
190
|
+
- **Memory**: 512 MB (adjust based on your application needs)
|
|
191
|
+
- **Timeout**: 30 seconds (adjust based on your application needs)
|
|
192
|
+
- **Ephemeral storage**: 512 MB (optional, for temporary files)
|
|
193
|
+
|
|
194
|
+
</Steps>
|
|
195
|
+
|
|
196
|
+
### Testing your deployment
|
|
197
|
+
|
|
198
|
+
Once deployed, test your Lambda function:
|
|
199
|
+
|
|
200
|
+
1. Copy the **Function URL** from the Lambda console
|
|
201
|
+
2. Visit the URL in your browser to see your Mastra's server home screen
|
|
202
|
+
3. Test your agents and workflows using the generated API endpoints
|
|
203
|
+
|
|
204
|
+
For more information about available API endpoints, see the [Server documentation](/docs/deployment/server).
|
|
205
|
+
|
|
206
|
+
### Connecting your client
|
|
207
|
+
|
|
208
|
+
Update your client application to use the Lambda function URL:
|
|
209
|
+
|
|
210
|
+
```typescript filename="src/client.ts" copy showLineNumbers
|
|
211
|
+
import { MastraClient } from "@mastra/client-js";
|
|
212
|
+
|
|
213
|
+
const mastraClient = new MastraClient({
|
|
214
|
+
baseUrl: "https://your-function-url.lambda-url.us-east-1.on.aws",
|
|
215
|
+
});
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### Troubleshooting
|
|
219
|
+
|
|
220
|
+
#### Function timeout errors
|
|
221
|
+
|
|
222
|
+
If your Lambda function times out:
|
|
223
|
+
|
|
224
|
+
- Increase the timeout value in **Configuration** > **General configuration**
|
|
225
|
+
- Optimize your Mastra application for faster cold starts
|
|
226
|
+
- Consider using provisioned concurrency for consistent performance
|
|
227
|
+
|
|
228
|
+
#### Memory issues
|
|
229
|
+
|
|
230
|
+
If you encounter memory-related errors:
|
|
231
|
+
|
|
232
|
+
- Increase the memory allocation in **Configuration** > **General configuration**
|
|
233
|
+
- Monitor memory usage in CloudWatch Logs
|
|
234
|
+
- Optimize your application's memory usage
|
|
235
|
+
|
|
236
|
+
#### CORS issues
|
|
237
|
+
|
|
238
|
+
If you encounter CORS errors when accessing endpoints but not the home page:
|
|
239
|
+
|
|
240
|
+
- Verify CORS headers are properly set in your Mastra server configuration
|
|
241
|
+
- Check the Lambda Function URL CORS configuration
|
|
242
|
+
- Ensure your client is making requests to the correct URL
|
|
243
|
+
|
|
244
|
+
#### Container image issues
|
|
245
|
+
|
|
246
|
+
If the Lambda function fails to start:
|
|
247
|
+
|
|
248
|
+
- Verify the Docker image builds successfully locally
|
|
249
|
+
- Check that the `CMD` instruction in your Dockerfile is correct
|
|
250
|
+
- Review CloudWatch Logs for container startup errors
|
|
251
|
+
- Ensure the Lambda Web Adapter is properly installed in the container
|
|
252
|
+
|
|
253
|
+
### Production considerations
|
|
254
|
+
|
|
255
|
+
For production deployments:
|
|
256
|
+
|
|
257
|
+
#### Security
|
|
258
|
+
|
|
259
|
+
- Restrict CORS origins to your trusted domains
|
|
260
|
+
- Use AWS IAM roles for secure access to other AWS services
|
|
261
|
+
- Store sensitive environment variables in AWS Secrets Manager or Parameter Store
|
|
262
|
+
|
|
263
|
+
#### Monitoring
|
|
264
|
+
|
|
265
|
+
- Enable CloudWatch monitoring for your Lambda function
|
|
266
|
+
- Set up CloudWatch alarms for errors and performance metrics
|
|
267
|
+
- Use AWS X-Ray for distributed tracing
|
|
268
|
+
|
|
269
|
+
#### Scaling
|
|
270
|
+
|
|
271
|
+
- Configure provisioned concurrency for predictable performance
|
|
272
|
+
- Monitor concurrent executions and adjust limits as needed
|
|
273
|
+
- Consider using Application Load Balancer for more complex routing needs
|
|
274
|
+
|
|
275
|
+
## Next steps
|
|
276
|
+
|
|
277
|
+
- [Mastra Client SDK](/docs/client-js/overview)
|
|
278
|
+
- [AWS Lambda documentation](https://docs.aws.amazon.com/lambda/)
|
|
279
|
+
- [AWS Lambda Web Adapter](https://github.com/awslabs/aws-lambda-web-adapter)
|
|
@@ -100,7 +100,7 @@ The guide assumes your droplet runs Ubuntu 24+.
|
|
|
100
100
|
|
|
101
101
|
You can now connect to your Mastra server from your client application using a `MastraClient` from the `@mastra/client-js` package.
|
|
102
102
|
|
|
103
|
-
Refer to the [`MastraClient` documentation](
|
|
103
|
+
Refer to the [`MastraClient` documentation](/docs/server-db/mastra-client) for more information.
|
|
104
104
|
|
|
105
105
|
```typescript copy showLineNumbers
|
|
106
106
|
import { MastraClient } from "@mastra/client-js";
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Deploy A Mastra Server"
|
|
3
|
+
description: "Deploy a Mastra server with middleware and other options"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Deploy A Mastra Server
|
|
7
|
+
|
|
8
|
+
Mastra builds to a standard Node.js server, so you can deploy it to any platform that supports Node.js applications.
|
|
9
|
+
|
|
10
|
+
- Cloud VMs (AWS EC2, DigitalOcean Droplets, GCP Compute Engine)
|
|
11
|
+
- Container platforms (Docker, Kubernetes)
|
|
12
|
+
- Platform as a Service (Heroku, Railway)
|
|
13
|
+
- Self-hosted servers
|
|
14
|
+
|
|
15
|
+
See the [Cloud Providers](/docs/deployment/cloud-providers/) for more information.
|
|
16
|
+
|
|
17
|
+
### Building
|
|
18
|
+
|
|
19
|
+
Build the application:
|
|
20
|
+
|
|
21
|
+
```bash copy
|
|
22
|
+
# Build from current directory
|
|
23
|
+
mastra build
|
|
24
|
+
|
|
25
|
+
# Or specify a directory
|
|
26
|
+
mastra build --dir ./my-project
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
The build process:
|
|
30
|
+
|
|
31
|
+
1. Locates entry file (`src/mastra/index.ts` or `src/mastra/index.js`)
|
|
32
|
+
2. Creates `.mastra` output directory
|
|
33
|
+
3. Bundles code using Rollup with tree shaking and source maps
|
|
34
|
+
4. Generates [Hono](https://hono.dev) HTTP server
|
|
35
|
+
|
|
36
|
+
See [`mastra build`](/reference/cli/build) for all options.
|
|
37
|
+
|
|
38
|
+
### Running the Server
|
|
39
|
+
|
|
40
|
+
Start the HTTP server:
|
|
41
|
+
|
|
42
|
+
```bash copy
|
|
43
|
+
node .mastra/output/index.mjs
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Enable Telemetry for build output
|
|
47
|
+
|
|
48
|
+
Load instrumentation for the build output like so:
|
|
49
|
+
|
|
50
|
+
```bash copy
|
|
51
|
+
node --import=./.mastra/output/instrumentation.mjs .mastra/output/index.mjs
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Serverless Deployment
|
|
55
|
+
|
|
56
|
+
Mastra also supports serverless deployment on Cloudflare Workers, Vercel, and Netlify. See [Serverless Platforms](/docs/deployment/serverless-platforms/) for more information.
|
|
@@ -30,7 +30,6 @@ Before you begin, ensure you have:
|
|
|
30
30
|
|
|
31
31
|
Specifically, ensure you've removed it from both `src/mastra/index.ts` and `src/mastra/agents/weather-agent.ts`:
|
|
32
32
|
|
|
33
|
-
|
|
34
33
|
```diff filename="src/mastra/index.ts" showLineNumbers
|
|
35
34
|
export const mastra = new Mastra({
|
|
36
35
|
// ...
|
|
@@ -189,6 +189,103 @@ export default function Page() {
|
|
|
189
189
|
}
|
|
190
190
|
```
|
|
191
191
|
|
|
192
|
+
### With additional data / RuntimeContext
|
|
193
|
+
|
|
194
|
+
You can send additional data via the UI hooks that can be leveraged in Mastra as RuntimeContext using the `sendExtraMessageFields` option.
|
|
195
|
+
|
|
196
|
+
#### Frontend: Using sendExtraMessageFields
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
import { useChat } from '@ai-sdk/react';
|
|
200
|
+
|
|
201
|
+
export function ChatComponent() {
|
|
202
|
+
const { messages, input, handleInputChange, handleSubmit } = useChat({
|
|
203
|
+
api: '/api/chat',
|
|
204
|
+
sendExtraMessageFields: true, // Enable sending extra fields
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
const handleFormSubmit = (e: React.FormEvent) => {
|
|
208
|
+
e.preventDefault();
|
|
209
|
+
handleSubmit(e,{
|
|
210
|
+
// Add context data to the message
|
|
211
|
+
data: {
|
|
212
|
+
userId: 'user123',
|
|
213
|
+
preferences: { language: 'en', temperature: 'celsius' },
|
|
214
|
+
},
|
|
215
|
+
});
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
return (
|
|
219
|
+
<form onSubmit={handleFormSubmit}>
|
|
220
|
+
<input value={input} onChange={handleInputChange} />
|
|
221
|
+
</form>
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
#### Backend: Handling in API Route
|
|
227
|
+
|
|
228
|
+
```typescript filename="app/api/chat/route.ts" copy
|
|
229
|
+
import { mastra } from "@/src/mastra";
|
|
230
|
+
import { RuntimeContext } from "@mastra/core/runtime-context";
|
|
231
|
+
|
|
232
|
+
export async function POST(req: Request) {
|
|
233
|
+
const { messages, data } = await req.json();
|
|
234
|
+
const myAgent = mastra.getAgent("weatherAgent");
|
|
235
|
+
|
|
236
|
+
const runtimeContext = new RuntimeContext();
|
|
237
|
+
|
|
238
|
+
if (data) {
|
|
239
|
+
Object.entries(data).forEach(([key, value]) => {
|
|
240
|
+
runtimeContext.set(key, value);
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
const stream = await myAgent.stream(messages, { runtimeContext });
|
|
245
|
+
return stream.toDataStreamResponse();
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
#### Alternative: Server Middleware
|
|
250
|
+
|
|
251
|
+
You can also handle this at the server middleware level:
|
|
252
|
+
|
|
253
|
+
```typescript filename="src/mastra/index.ts" copy
|
|
254
|
+
import { Mastra } from "@mastra/core";
|
|
255
|
+
|
|
256
|
+
export const mastra = new Mastra({
|
|
257
|
+
agents: { weatherAgent },
|
|
258
|
+
server: {
|
|
259
|
+
middleware: [
|
|
260
|
+
async (c, next) => {
|
|
261
|
+
const runtimeContext = c.get("runtimeContext");
|
|
262
|
+
|
|
263
|
+
if (c.req.method === 'POST') {
|
|
264
|
+
try {
|
|
265
|
+
// Clone the request since reading the body can only be done once
|
|
266
|
+
const clonedReq = c.req.raw.clone();
|
|
267
|
+
const body = await clonedReq.json();
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
if (body?.data) {
|
|
271
|
+
Object.entries(body.data).forEach(([key, value]) => {
|
|
272
|
+
runtimeContext.set(key, value);
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
} catch {
|
|
276
|
+
// Continue without additional data
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
await next();
|
|
281
|
+
},
|
|
282
|
+
],
|
|
283
|
+
},
|
|
284
|
+
});
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
You can then access this data in your tools via the `runtimeContext` parameter. See the [Runtime Context documentation](/docs/agents/runtime-variables) for more details.
|
|
288
|
+
|
|
192
289
|
## Tool Calling
|
|
193
290
|
|
|
194
291
|
### AI SDK Tool Format
|
|
@@ -69,6 +69,40 @@ You now have a basic Mastra server project ready. You should have the following
|
|
|
69
69
|
Ensure that you have set the appropriate environment variables for your LLM provider in the `.env` file.
|
|
70
70
|
</Callout>
|
|
71
71
|
|
|
72
|
+
### Compatibility Fix
|
|
73
|
+
|
|
74
|
+
Currently, to ensure proper compatibility between Mastra and Assistant UI, you need to setup server middleware. Update your `/mastra/index.ts` file with the following configuration:
|
|
75
|
+
|
|
76
|
+
```typescript showLineNumbers copy filename="src/mastra/index.ts"
|
|
77
|
+
export const mastra = new Mastra({
|
|
78
|
+
//mastra server middleware
|
|
79
|
+
server:{
|
|
80
|
+
middleware: [{
|
|
81
|
+
path: '/api/agents/*/stream',
|
|
82
|
+
handler: async (c,next)=>{
|
|
83
|
+
|
|
84
|
+
const body = await c.req.json();
|
|
85
|
+
|
|
86
|
+
if ('state' in body && body.state == null) {
|
|
87
|
+
delete body.state;
|
|
88
|
+
delete body.tools;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
c.req.json = async() => body;
|
|
92
|
+
|
|
93
|
+
return next()
|
|
94
|
+
}
|
|
95
|
+
}]
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
This middleware ensures that when Assistant UI sends a request with `state: null` and `tools: {}` in the request body, we remove those properties to make the request work properly with Mastra.
|
|
101
|
+
|
|
102
|
+
<Callout type="info">
|
|
103
|
+
The `state: null` property can cause errors like `Cannot use 'in' operator to search for 'input' in null` in Mastra. Additionally, passing `tools: {}` overrides Mastra's built-in tools. Mastra only supports `clientTools` via the Mastra client SDK from the client side. For more information about client tools, see the [Client Tools documentation](/reference/client-js/agents#client-tools).
|
|
104
|
+
</Callout>
|
|
105
|
+
|
|
72
106
|
### Run the Mastra Server
|
|
73
107
|
|
|
74
108
|
Run the Mastra server using the following command:
|
|
@@ -96,7 +96,7 @@ const memory = new Memory({
|
|
|
96
96
|
});
|
|
97
97
|
```
|
|
98
98
|
|
|
99
|
-
By default, title generation uses the same model as your agent. For cost optimization, you can specify a
|
|
99
|
+
By default, title generation uses the same model and default instructions as your agent. For customization or cost optimization, you can specify a different model or provide custom instructions specifically for title generation:
|
|
100
100
|
|
|
101
101
|
```typescript {5-7}
|
|
102
102
|
const memory = new Memory({
|
|
@@ -104,6 +104,7 @@ const memory = new Memory({
|
|
|
104
104
|
threads: {
|
|
105
105
|
generateTitle: {
|
|
106
106
|
model: openai("gpt-4.1-nano"), // Use cheaper model for titles
|
|
107
|
+
instructions: "Generate a concise title for this conversation based on the first user message.",
|
|
107
108
|
},
|
|
108
109
|
},
|
|
109
110
|
},
|
|
@@ -456,7 +456,10 @@ Here's how to use re-ranking:
|
|
|
456
456
|
|
|
457
457
|
```ts showLineNumbers copy
|
|
458
458
|
import { openai } from "@ai-sdk/openai";
|
|
459
|
-
import {
|
|
459
|
+
import {
|
|
460
|
+
rerankWithScorer as rerank,
|
|
461
|
+
MastraAgentRelevanceScorer
|
|
462
|
+
} from "@mastra/rag";
|
|
460
463
|
|
|
461
464
|
// Get initial results from vector search
|
|
462
465
|
const initialResults = await pgVector.query({
|
|
@@ -465,19 +468,35 @@ const initialResults = await pgVector.query({
|
|
|
465
468
|
topK: 10,
|
|
466
469
|
});
|
|
467
470
|
|
|
471
|
+
// Create a relevance scorer
|
|
472
|
+
const relevanceProvider = new MastraAgentRelevanceScorer('relevance-scorer', openai("gpt-4o-mini"));
|
|
473
|
+
|
|
468
474
|
// Re-rank the results
|
|
469
|
-
const rerankedResults = await rerank(
|
|
470
|
-
initialResults,
|
|
475
|
+
const rerankedResults = await rerank({
|
|
476
|
+
results: initialResults,
|
|
471
477
|
query,
|
|
472
|
-
|
|
478
|
+
provider: relevanceProvider,
|
|
479
|
+
options: {
|
|
480
|
+
topK: 10,
|
|
481
|
+
},
|
|
473
482
|
);
|
|
474
483
|
```
|
|
475
484
|
|
|
476
485
|
> **Note:** For semantic scoring to work properly during re-ranking, each result must include the text content in its `metadata.text` field.
|
|
477
486
|
|
|
487
|
+
You can also use other relevance score providers like Cohere or ZeroEntropy:
|
|
488
|
+
|
|
489
|
+
```ts showLineNumbers copy
|
|
490
|
+
const relevanceProvider = new CohereRelevanceScorer('rerank-v3.5');
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
```ts showLineNumbers copy
|
|
494
|
+
const relevanceProvider = new ZeroEntropyRelevanceScorer('zerank-1');
|
|
495
|
+
```
|
|
496
|
+
|
|
478
497
|
The re-ranked results combine vector similarity with semantic understanding to improve retrieval quality.
|
|
479
498
|
|
|
480
|
-
For more details about re-ranking, see the [rerank()](/reference/rag/
|
|
499
|
+
For more details about re-ranking, see the [rerank()](/reference/rag/rerankWithScorer) method.
|
|
481
500
|
|
|
482
501
|
For an example of how to use the re-ranking method, see the [Re-ranking Results](../../examples/rag/rerank/rerank.mdx) example.
|
|
483
502
|
|
|
@@ -265,10 +265,11 @@ Configuration options for memory management:
|
|
|
265
265
|
parameters: [
|
|
266
266
|
{
|
|
267
267
|
name: "generateTitle",
|
|
268
|
-
type: "boolean | { model: LanguageModelV1 | ((ctx: RuntimeContext) => LanguageModelV1 | Promise<LanguageModelV1>) }",
|
|
268
|
+
type: "boolean | { model: LanguageModelV1 | ((ctx: RuntimeContext) => LanguageModelV1 | Promise<LanguageModelV1>), instructions: string | ((ctx: RuntimeContext) => string | Promise<string>) }",
|
|
269
269
|
isOptional: true,
|
|
270
270
|
description:
|
|
271
|
-
|
|
271
|
+
`Controls automatic thread title generation from the user's first message. Can be a boolean to enable/disable using the agent's model, or an object specifying a custom model and/or custom instructions for title generation (useful for cost optimization or title customization).
|
|
272
|
+
Example: { model: openai('gpt-4.1-nano'), instructions: 'Generate a concise title based on the initial user message.' }`,
|
|
272
273
|
},
|
|
273
274
|
],
|
|
274
275
|
},
|