@mastra/mcp-docs-server 1.0.0-beta.11 → 1.0.0-beta.13
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%2Fagent-builder.md +12 -12
- package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +24 -24
- package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +45 -45
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +83 -83
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Fconvex.md +38 -0
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +174 -174
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +27 -27
- package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Ffastembed.md +6 -0
- package/.docs/organized/changelogs/%40mastra%2Flance.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Flibsql.md +45 -45
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +15 -15
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +13 -13
- package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Fmssql.md +39 -39
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +45 -45
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +75 -75
- package/.docs/organized/changelogs/%40mastra%2Freact.md +40 -0
- package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +6 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +29 -29
- package/.docs/organized/changelogs/%40mastra%2Fupstash.md +39 -39
- package/.docs/organized/changelogs/create-mastra.md +29 -29
- package/.docs/organized/changelogs/mastra.md +35 -35
- package/.docs/organized/code-examples/quick-start.md +0 -4
- package/.docs/organized/code-examples/stock-price-tool.md +21 -2
- package/.docs/raw/agents/agent-approval.mdx +136 -2
- package/.docs/raw/agents/agent-memory.mdx +4 -4
- package/.docs/raw/agents/guardrails.mdx +1 -1
- package/.docs/raw/agents/networks.mdx +1 -1
- package/.docs/raw/agents/overview.mdx +2 -2
- package/.docs/raw/agents/using-tools.mdx +1 -1
- package/.docs/raw/course/01-first-agent/07-creating-your-agent.md +1 -2
- package/.docs/raw/course/01-first-agent/12-connecting-tool-to-agent.md +1 -1
- package/.docs/raw/course/01-first-agent/16-adding-memory-to-agent.md +1 -2
- package/.docs/raw/course/02-agent-tools-mcp/05-updating-your-agent.md +1 -1
- package/.docs/raw/course/02-agent-tools-mcp/10-updating-agent-instructions-zapier.md +1 -1
- package/.docs/raw/course/02-agent-tools-mcp/16-updating-agent-instructions-github.md +1 -1
- package/.docs/raw/course/02-agent-tools-mcp/21-updating-agent-instructions-hackernews.md +1 -1
- package/.docs/raw/course/02-agent-tools-mcp/27-updating-agent-instructions-filesystem.md +1 -1
- package/.docs/raw/course/02-agent-tools-mcp/31-enhancing-memory-configuration.md +2 -2
- package/.docs/raw/course/03-agent-memory/04-creating-basic-memory-agent.md +1 -2
- package/.docs/raw/course/03-agent-memory/08-configuring-conversation-history.md +1 -2
- package/.docs/raw/course/03-agent-memory/16-configuring-semantic-recall.md +3 -4
- package/.docs/raw/course/03-agent-memory/21-configuring-working-memory.md +2 -3
- package/.docs/raw/course/03-agent-memory/22-custom-working-memory-templates.md +2 -3
- package/.docs/raw/course/03-agent-memory/25-combining-memory-features.md +1 -2
- package/.docs/raw/course/03-agent-memory/27-creating-learning-assistant.md +2 -3
- package/.docs/raw/course/04-workflows/11-creating-an-ai-agent.md +2 -3
- package/.docs/raw/deployment/cloud-providers.mdx +20 -0
- package/.docs/raw/deployment/{building-mastra.mdx → mastra-server.mdx} +2 -2
- package/.docs/raw/deployment/monorepo.mdx +23 -44
- package/.docs/raw/deployment/overview.mdx +28 -53
- package/.docs/raw/deployment/web-framework.mdx +12 -14
- package/.docs/raw/getting-started/start.mdx +10 -1
- package/.docs/raw/getting-started/studio.mdx +1 -1
- package/.docs/raw/guides/build-your-ui/ai-sdk-ui.mdx +1021 -67
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/aws-lambda.mdx +3 -6
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/azure-app-services.mdx +4 -6
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/cloudflare-deployer.mdx +4 -0
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/digital-ocean.mdx +3 -6
- package/.docs/raw/guides/deployment/index.mdx +32 -0
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/netlify-deployer.mdx +4 -0
- package/.docs/raw/{deployment/cloud-providers → guides/deployment}/vercel-deployer.mdx +4 -0
- package/.docs/raw/guides/getting-started/express.mdx +71 -152
- package/.docs/raw/guides/getting-started/hono.mdx +227 -0
- package/.docs/raw/guides/getting-started/next-js.mdx +173 -63
- package/.docs/raw/guides/getting-started/vite-react.mdx +307 -137
- package/.docs/raw/guides/guide/research-assistant.mdx +4 -4
- package/.docs/raw/guides/migrations/upgrade-to-v1/client.mdx +17 -0
- package/.docs/raw/guides/migrations/upgrade-to-v1/overview.mdx +6 -0
- package/.docs/raw/index.mdx +1 -1
- package/.docs/raw/{deployment/mastra-cloud → mastra-cloud}/dashboard.mdx +2 -6
- package/.docs/raw/{deployment/mastra-cloud → mastra-cloud}/observability.mdx +1 -5
- package/.docs/raw/{deployment/mastra-cloud → mastra-cloud}/overview.mdx +2 -6
- package/.docs/raw/{deployment/mastra-cloud → mastra-cloud}/setting-up.mdx +3 -6
- package/.docs/raw/memory/overview.mdx +1 -1
- package/.docs/raw/memory/storage/memory-with-libsql.mdx +1 -1
- package/.docs/raw/memory/storage/memory-with-mongodb.mdx +1 -1
- package/.docs/raw/memory/storage/memory-with-pg.mdx +1 -1
- package/.docs/raw/memory/storage/memory-with-upstash.mdx +1 -1
- package/.docs/raw/{server-db/storage.mdx → memory/storage/overview.mdx} +2 -2
- package/.docs/raw/observability/logging.mdx +1 -1
- package/.docs/raw/observability/tracing/exporters/cloud.mdx +1 -1
- package/.docs/raw/observability/tracing/exporters/default.mdx +1 -1
- package/.docs/raw/rag/chunking-and-embedding.mdx +12 -25
- package/.docs/raw/rag/graph-rag.mdx +220 -0
- package/.docs/raw/rag/overview.mdx +1 -2
- package/.docs/raw/rag/retrieval.mdx +13 -29
- package/.docs/raw/rag/vector-databases.mdx +7 -3
- package/.docs/raw/reference/agents/getDefaultGenerateOptions.mdx +1 -1
- package/.docs/raw/reference/agents/getDefaultOptions.mdx +1 -1
- package/.docs/raw/reference/agents/getDefaultStreamOptions.mdx +1 -1
- package/.docs/raw/reference/agents/getInstructions.mdx +1 -1
- package/.docs/raw/reference/agents/getLLM.mdx +1 -1
- package/.docs/raw/reference/agents/getMemory.mdx +1 -1
- package/.docs/raw/reference/agents/getModel.mdx +1 -1
- package/.docs/raw/reference/agents/listScorers.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/chat-route.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/handle-chat-stream.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/handle-network-stream.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/handle-workflow-stream.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/network-route.mdx +1 -1
- package/.docs/raw/reference/ai-sdk/to-ai-sdk-v4-messages.mdx +127 -0
- package/.docs/raw/reference/ai-sdk/to-ai-sdk-v5-messages.mdx +107 -0
- package/.docs/raw/reference/ai-sdk/workflow-route.mdx +1 -1
- package/.docs/raw/reference/auth/auth0.mdx +1 -1
- package/.docs/raw/reference/auth/clerk.mdx +1 -1
- package/.docs/raw/reference/auth/firebase.mdx +1 -1
- package/.docs/raw/reference/auth/jwt.mdx +1 -1
- package/.docs/raw/reference/auth/supabase.mdx +1 -1
- package/.docs/raw/reference/auth/workos.mdx +1 -1
- package/.docs/raw/reference/cli/mastra.mdx +1 -1
- package/.docs/raw/reference/client-js/mastra-client.mdx +1 -1
- package/.docs/raw/reference/client-js/workflows.mdx +20 -0
- package/.docs/raw/reference/core/getServer.mdx +2 -2
- package/.docs/raw/reference/core/getStorage.mdx +1 -1
- package/.docs/raw/reference/core/getStoredAgentById.mdx +1 -1
- package/.docs/raw/reference/core/listStoredAgents.mdx +1 -1
- package/.docs/raw/reference/core/setStorage.mdx +1 -1
- package/.docs/raw/reference/logging/pino-logger.mdx +1 -1
- package/.docs/raw/reference/rag/database-config.mdx +1 -1
- package/.docs/raw/reference/server/create-route.mdx +1 -1
- package/.docs/raw/reference/server/express-adapter.mdx +4 -4
- package/.docs/raw/reference/server/hono-adapter.mdx +4 -4
- package/.docs/raw/reference/server/mastra-server.mdx +2 -2
- package/.docs/raw/reference/server/routes.mdx +28 -1
- package/.docs/raw/reference/streaming/agents/stream.mdx +22 -0
- package/.docs/raw/reference/streaming/workflows/stream.mdx +33 -20
- package/.docs/raw/reference/tools/create-tool.mdx +23 -1
- package/.docs/raw/reference/tools/graph-rag-tool.mdx +3 -3
- package/.docs/raw/reference/tools/vector-query-tool.mdx +3 -3
- package/.docs/raw/reference/workflows/run-methods/startAsync.mdx +143 -0
- package/.docs/raw/reference/workflows/workflow-methods/create-run.mdx +35 -0
- package/.docs/raw/reference/workflows/workflow.mdx +14 -0
- package/.docs/raw/{auth → server/auth}/auth0.mdx +1 -1
- package/.docs/raw/{auth → server/auth}/clerk.mdx +1 -1
- package/.docs/raw/{auth → server/auth}/firebase.mdx +1 -1
- package/.docs/raw/{auth → server/auth}/index.mdx +6 -6
- package/.docs/raw/{auth → server/auth}/jwt.mdx +1 -1
- package/.docs/raw/{auth → server/auth}/supabase.mdx +1 -1
- package/.docs/raw/{auth → server/auth}/workos.mdx +1 -1
- package/.docs/raw/{server-db → server}/custom-adapters.mdx +3 -3
- package/.docs/raw/{server-db → server}/custom-api-routes.mdx +1 -1
- package/.docs/raw/{server-db → server}/mastra-client.mdx +2 -2
- package/.docs/raw/{server-db → server}/mastra-server.mdx +5 -5
- package/.docs/raw/{server-db → server}/middleware.mdx +2 -2
- package/.docs/raw/{server-db → server}/request-context.mdx +3 -3
- package/.docs/raw/{server-db → server}/server-adapters.mdx +6 -6
- package/.docs/raw/tools-mcp/overview.mdx +2 -2
- package/.docs/raw/workflows/error-handling.mdx +162 -1
- package/.docs/raw/workflows/overview.mdx +2 -2
- package/CHANGELOG.md +14 -0
- package/package.json +3 -3
- package/.docs/organized/changelogs/%40internal%2Fai-sdk-v4.md +0 -1
- package/.docs/raw/deployment/cloud-providers/index.mdx +0 -55
- /package/.docs/raw/{deployment/cloud-providers → guides/deployment}/amazon-ec2.mdx +0 -0
|
@@ -29,11 +29,8 @@ Before deploying to AWS Lambda, ensure you have:
|
|
|
29
29
|
|
|
30
30
|
## Memory Configuration
|
|
31
31
|
|
|
32
|
-
:::
|
|
33
|
-
AWS Lambda uses an ephemeral file system,
|
|
34
|
-
meaning that any files written to the file system are short-lived and may be lost.
|
|
35
|
-
Avoid using a Mastra storage provider that uses the file system,
|
|
36
|
-
such as `LibSQLStore` with a file URL.
|
|
32
|
+
:::warning
|
|
33
|
+
AWS Lambda uses an ephemeral file system, meaning that any files written to the file system are short-lived and may be lost. Remove any usage of [LibSQLStore](/docs/v1/memory/storage/overview) with file URLs from your Mastra configuration. Use in-memory storage (`:memory:`) or external storage providers like Turso, PostgreSQL, or Upstash.
|
|
37
34
|
:::
|
|
38
35
|
|
|
39
36
|
Lambda functions have limitations with file system storage. Configure your Mastra application to use either in-memory or external storage providers:
|
|
@@ -216,7 +213,7 @@ Once deployed, test your Lambda function:
|
|
|
216
213
|
2. Visit the URL in your browser to see your Mastra's server home screen
|
|
217
214
|
3. Test your agents and workflows using the generated API endpoints
|
|
218
215
|
|
|
219
|
-
For more information about available API endpoints, see the [Server documentation](/docs/v1/deployment/
|
|
216
|
+
For more information about available API endpoints, see the [Server documentation](/docs/v1/deployment/mastra-server).
|
|
220
217
|
|
|
221
218
|
## Connecting your client
|
|
222
219
|
|
|
@@ -17,6 +17,10 @@ For more information on how to create a new Mastra application,
|
|
|
17
17
|
refer to our [getting started guide](/guides/v1/getting-started/quickstart)
|
|
18
18
|
:::
|
|
19
19
|
|
|
20
|
+
:::warning
|
|
21
|
+
Azure App Services uses an ephemeral filesystem for some pricing tiers. Remove any usage of [LibSQLStore](/docs/v1/memory/storage/overview) with file URLs from your Mastra configuration. Use in-memory storage (`:memory:`) or external storage providers like Turso, PostgreSQL, or Upstash.
|
|
22
|
+
:::
|
|
23
|
+
|
|
20
24
|
## Prerequisites
|
|
21
25
|
|
|
22
26
|
- An [Azure account](https://azure.microsoft.com/) with an active subscription
|
|
@@ -151,12 +155,6 @@ const mastraClient = new MastraClient({
|
|
|
151
155
|
});
|
|
152
156
|
```
|
|
153
157
|
|
|
154
|
-
:::note
|
|
155
|
-
Azure App Services uses an ephemeral file system for some pricing tiers.
|
|
156
|
-
For production applications, avoid using Mastra storage providers that rely on the local file system,
|
|
157
|
-
such as `LibSQLStore` with a file URL. Consider using cloud-based storage solutions instead.
|
|
158
|
-
:::
|
|
159
|
-
|
|
160
158
|
## Next steps
|
|
161
159
|
|
|
162
160
|
- [Mastra Client SDK](/reference/v1/client-js/mastra-client)
|
|
@@ -7,6 +7,10 @@ description: "Learn how to deploy a Mastra application to Cloudflare using the M
|
|
|
7
7
|
|
|
8
8
|
The `CloudflareDeployer` class handles deployment of standalone Mastra applications to Cloudflare Workers. It manages configuration, deployment, and extends the base [Deployer](/reference/v1/deployer/) class with Cloudflare specific functionality.
|
|
9
9
|
|
|
10
|
+
:::warning
|
|
11
|
+
Cloudflare Workers do not support filesystem access. Remove any usage of [LibSQLStore](/docs/v1/memory/storage/overview) with file URLs from your Mastra configuration. Use in-memory storage (`:memory:`) or external storage providers like Turso, PostgreSQL, or Upstash.
|
|
12
|
+
:::
|
|
13
|
+
|
|
10
14
|
## Installation
|
|
11
15
|
|
|
12
16
|
```bash copy
|
|
@@ -97,11 +97,8 @@ Deployment
|
|
|
97
97
|
|
|
98
98
|
You can now access your deployed application at the URL provided by Digital Ocean.
|
|
99
99
|
|
|
100
|
-
:::
|
|
101
|
-
The Digital Ocean App Platform uses an ephemeral file system,
|
|
102
|
-
meaning that any files written to the file system are short-lived and may be lost.
|
|
103
|
-
Avoid using a Mastra storage provider that uses the file system,
|
|
104
|
-
such as `LibSQLStore` with a file URL.
|
|
100
|
+
:::warning
|
|
101
|
+
The Digital Ocean App Platform uses an ephemeral file system, meaning that any files written to the file system are short-lived and may be lost. Remove any usage of [LibSQLStore](/docs/v1/memory/storage/overview) with file URLs from your Mastra configuration. Use in-memory storage (`:memory:`) or external storage providers like Turso, PostgreSQL, or Upstash.
|
|
105
102
|
:::
|
|
106
103
|
|
|
107
104
|
</TabItem>
|
|
@@ -220,7 +217,7 @@ Your Mastra application will run on port 4111 by default. Ensure your reverse pr
|
|
|
220
217
|
|
|
221
218
|
You can now connect to your Mastra server from your client application using a `MastraClient` from the `@mastra/client-js` package.
|
|
222
219
|
|
|
223
|
-
Refer to the [`MastraClient` documentation](/docs/v1/server
|
|
220
|
+
Refer to the [`MastraClient` documentation](/docs/v1/server/mastra-client) for more information.
|
|
224
221
|
|
|
225
222
|
```typescript copy showLineNumbers
|
|
226
223
|
import { MastraClient } from "@mastra/client-js";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Cloud Providers | Deployment"
|
|
3
|
+
description: "Deploy your Mastra applications to popular cloud providers."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Cloud Providers
|
|
7
|
+
|
|
8
|
+
Standalone Mastra applications can be deployed to popular cloud providers, see one of the following guides for more information:
|
|
9
|
+
|
|
10
|
+
- [Amazon EC2](/guides/v1/deployment/amazon-ec2)
|
|
11
|
+
- [AWS Lambda](/guides/v1/deployment/aws-lambda)
|
|
12
|
+
- [Azure App Services](/guides/v1/deployment/azure-app-services)
|
|
13
|
+
- [Cloudflare](/guides/v1/deployment/cloudflare-deployer)
|
|
14
|
+
- [Digital Ocean](/guides/v1/deployment/digital-ocean)
|
|
15
|
+
- [Netlify](/guides/v1/deployment/netlify-deployer)
|
|
16
|
+
- [Vercel](/guides/v1/deployment/vercel-deployer)
|
|
17
|
+
|
|
18
|
+
For self-hosted Node.js server deployment, see the [Creating A Mastra Server](/docs/v1/deployment/mastra-server) guide.
|
|
19
|
+
|
|
20
|
+
## Prerequisites
|
|
21
|
+
|
|
22
|
+
Before deploying to a cloud provider, ensure you have:
|
|
23
|
+
|
|
24
|
+
- A [Mastra application](/guides/v1/getting-started/quickstart)
|
|
25
|
+
- Node.js `v22.13.0` or later
|
|
26
|
+
- A GitHub repository for your application (required for most CI/CD setups)
|
|
27
|
+
- Domain name management access (for SSL and HTTPS)
|
|
28
|
+
- Basic familiarity with server setup (e.g. Nginx, environment variables)
|
|
29
|
+
|
|
30
|
+
:::warning
|
|
31
|
+
`LibSQLStore` writes to the local filesystem, which is not supported in cloud environments that use ephemeral file systems. If you're deploying to platforms like AWS Lambda, Netlify, Azure App Services, or Digital Ocean App Platform, you must remove all usage of [LibSQLStore](/docs/v1/memory/storage/overview) with file URLs. Use in-memory storage (`:memory:`) or external storage providers like Turso, PostgreSQL, or Upstash.
|
|
32
|
+
:::
|
|
@@ -7,6 +7,10 @@ description: "Learn how to deploy a Mastra application to Netlify using the Mast
|
|
|
7
7
|
|
|
8
8
|
The `NetlifyDeployer` class handles deployment of standalone Mastra applications to Netlify. It manages configuration, deployment, and extends the base [Deployer](/reference/v1/deployer/) class with Netlify specific functionality.
|
|
9
9
|
|
|
10
|
+
:::warning
|
|
11
|
+
Netlify Functions use an ephemeral filesystem. Remove any usage of [LibSQLStore](/docs/v1/memory/storage/overview) with file URLs from your Mastra configuration. Use in-memory storage (`:memory:`) or external storage providers like Turso, PostgreSQL, or Upstash.
|
|
12
|
+
:::
|
|
13
|
+
|
|
10
14
|
## Installation
|
|
11
15
|
|
|
12
16
|
```bash copy
|
|
@@ -7,6 +7,10 @@ description: "Learn how to deploy a Mastra application to Vercel using the Mastr
|
|
|
7
7
|
|
|
8
8
|
The `VercelDeployer` class handles deployment of standalone Mastra applications to Vercel. It manages configuration, deployment, and extends the base [Deployer](/reference/v1/deployer/) class with Vercel specific functionality.
|
|
9
9
|
|
|
10
|
+
:::warning
|
|
11
|
+
Vercel Functions use an ephemeral filesystem. Remove any usage of [LibSQLStore](/docs/v1/memory/storage/overview) with file URLs from your Mastra configuration. Use in-memory storage (`:memory:`) or external storage providers like Turso, PostgreSQL, or Upstash.
|
|
12
|
+
:::
|
|
13
|
+
|
|
10
14
|
## Installation
|
|
11
15
|
|
|
12
16
|
```bash copy
|
|
@@ -1,209 +1,128 @@
|
|
|
1
1
|
---
|
|
2
|
-
title: "
|
|
3
|
-
description:
|
|
2
|
+
title: "Express | Frameworks"
|
|
3
|
+
description: "Get started with Mastra and Express"
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
import Tabs from "@theme/Tabs";
|
|
7
|
+
import TabItem from "@theme/TabItem";
|
|
7
8
|
|
|
8
|
-
Mastra
|
|
9
|
+
# Integrate Mastra in your Express project
|
|
9
10
|
|
|
10
|
-
-
|
|
11
|
-
- Maintain full control over your server logic and routing
|
|
12
|
-
- Scale your backend independently of your frontend
|
|
11
|
+
In this guide, you'll build a tool-calling AI agent using Mastra and Express. Using the [Express server adapter](/reference/v1/server/express-adapter), you can expose your agents as HTTP endpoints without writing the routing yourself or running a separate Mastra server.
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
## Before you begin
|
|
15
14
|
|
|
16
|
-
|
|
15
|
+
- You'll need an API key from a supported [model provider](/models/v1). If you don't have a preference, use [OpenAI](/models/v1/providers/openai).
|
|
16
|
+
- Install Node.js `v22.13.0` or later
|
|
17
17
|
|
|
18
|
-
##
|
|
18
|
+
## Create a new Express app (optional)
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
- Node.js `v22.13.0` or later
|
|
22
|
-
- An API key from a supported [Model Provider](/models/v1)
|
|
20
|
+
If you already have an Express app, skip to the next step.
|
|
23
21
|
|
|
24
|
-
|
|
22
|
+
Clone this [boilerplate repository](https://github.com/mastra-ai/express-ts-boilerplate) and install dependencies:
|
|
25
23
|
|
|
26
|
-
|
|
24
|
+
<Tabs>
|
|
25
|
+
<TabItem value="https" label="HTTPS">
|
|
27
26
|
|
|
28
27
|
```bash copy
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
If not existent yet, create an `.env` file and add your OpenAI API key:
|
|
33
|
-
|
|
34
|
-
```bash title=".env" copy
|
|
35
|
-
OPENAI_API_KEY=<your-api-key>
|
|
28
|
+
git clone https://github.com/mastra-ai/express-ts-boilerplate.git
|
|
29
|
+
cd express-ts-boilerplate
|
|
30
|
+
npm install
|
|
36
31
|
```
|
|
37
32
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
Each LLM provider uses a different env var. See [Model Providers](/models/v1/providers/) for more information.
|
|
41
|
-
|
|
42
|
-
:::
|
|
43
|
-
|
|
44
|
-
Create a Mastra configuration file at `src/mastra/index.ts`:
|
|
45
|
-
|
|
46
|
-
```ts title="src/mastra/index.ts" copy
|
|
47
|
-
import { Mastra } from "@mastra/core";
|
|
33
|
+
</TabItem>
|
|
34
|
+
<TabItem value="ssh" label="SSH">
|
|
48
35
|
|
|
49
|
-
|
|
36
|
+
```bash copy
|
|
37
|
+
git clone git@github.com:mastra-ai/express-ts-boilerplate.git
|
|
38
|
+
cd express-ts-boilerplate
|
|
39
|
+
npm install
|
|
50
40
|
```
|
|
51
41
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
```ts title="src/mastra/tools/weather-tool.ts" copy
|
|
55
|
-
import { createTool } from "@mastra/core/tools";
|
|
56
|
-
import { z } from "zod";
|
|
57
|
-
|
|
58
|
-
export const weatherTool = createTool({
|
|
59
|
-
id: "get-weather",
|
|
60
|
-
description: "Get current weather for a location",
|
|
61
|
-
inputSchema: z.object({
|
|
62
|
-
location: z.string().describe("City name"),
|
|
63
|
-
}),
|
|
64
|
-
outputSchema: z.object({
|
|
65
|
-
output: z.string(),
|
|
66
|
-
}),
|
|
67
|
-
execute: async () => {
|
|
68
|
-
return {
|
|
69
|
-
output: "The weather is sunny",
|
|
70
|
-
};
|
|
71
|
-
},
|
|
72
|
-
});
|
|
73
|
-
```
|
|
42
|
+
</TabItem>
|
|
43
|
+
</Tabs>
|
|
74
44
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
```ts title="src/mastra/agents/weather-agent.ts" copy
|
|
78
|
-
import { Agent } from "@mastra/core/agent";
|
|
79
|
-
import { weatherTool } from "../tools/weather-tool";
|
|
80
|
-
|
|
81
|
-
export const weatherAgent = new Agent({
|
|
82
|
-
id: "weather-agent",
|
|
83
|
-
name: "Weather Agent",
|
|
84
|
-
instructions: `
|
|
85
|
-
You are a helpful weather assistant that provides accurate weather information.
|
|
86
|
-
|
|
87
|
-
Your primary function is to help users get weather details for specific locations. When responding:
|
|
88
|
-
- Always ask for a location if none is provided
|
|
89
|
-
- If the location name isn't in English, please translate it
|
|
90
|
-
- If giving a location with multiple parts (e.g. "New York, NY"), use the most relevant part (e.g. "New York")
|
|
91
|
-
- Include relevant details like humidity, wind conditions, and precipitation
|
|
92
|
-
- Keep responses concise but informative
|
|
93
|
-
|
|
94
|
-
Use the weatherTool to fetch current weather data.
|
|
95
|
-
`,
|
|
96
|
-
model: "openai/gpt-5.1",
|
|
97
|
-
tools: { weatherTool },
|
|
98
|
-
});
|
|
99
|
-
```
|
|
45
|
+
## Initialize Mastra
|
|
100
46
|
|
|
101
|
-
|
|
47
|
+
Inside your Express project directory, run [`mastra init`](/reference/v1/cli/mastra#mastra-init).
|
|
102
48
|
|
|
103
|
-
|
|
104
|
-
import { Mastra } from "@mastra/core";
|
|
105
|
-
import { weatherAgent } from "./agents/weather-agent";
|
|
49
|
+
When prompted, choose a provider (e.g. OpenAI) and enter your key:
|
|
106
50
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
});
|
|
51
|
+
```bash copy
|
|
52
|
+
npx mastra@beta init
|
|
110
53
|
```
|
|
111
54
|
|
|
112
|
-
|
|
55
|
+
This creates a `src/mastra` folder with an example weather agent and the following files:
|
|
113
56
|
|
|
114
|
-
|
|
57
|
+
- `index.ts` - Mastra config, including memory
|
|
58
|
+
- `tools/weather-tool.ts` - a tool to fetch weather for a given location
|
|
59
|
+
- `agents/weather-agent.ts`- a weather agent with a prompt that uses the tool
|
|
115
60
|
|
|
116
|
-
|
|
61
|
+
You'll pass the `src/mastra/index.ts` file to the Express server adapter later.
|
|
117
62
|
|
|
118
|
-
|
|
63
|
+
## Add server adapter
|
|
119
64
|
|
|
120
|
-
|
|
121
|
-
import express, { Request, Response } from "express";
|
|
65
|
+
Install the Express server adapter package:
|
|
122
66
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
app.get("/", (req: Request, res: Response) => {
|
|
127
|
-
res.send("Hello, world!");
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
app.listen(port, () => {
|
|
131
|
-
console.log(`Server is running at http://localhost:${port}`);
|
|
132
|
-
});
|
|
67
|
+
```bash copy
|
|
68
|
+
npm install @mastra/express@beta
|
|
133
69
|
```
|
|
134
70
|
|
|
135
|
-
|
|
71
|
+
Open the Express entry file at `src/index.ts` and add the required import and initialization code:
|
|
136
72
|
|
|
137
|
-
```
|
|
138
|
-
import express, { Request, Response } from "express";
|
|
73
|
+
```typescript copy {2-3,11-12} title="src/index.ts"
|
|
74
|
+
import express, { type Request, type Response } from "express";
|
|
75
|
+
import { MastraServer } from "@mastra/express";
|
|
139
76
|
import { mastra } from "./mastra";
|
|
140
77
|
|
|
141
78
|
const app = express();
|
|
142
|
-
const
|
|
143
|
-
|
|
144
|
-
app.get("/", (req: Request, res: Response) => {
|
|
145
|
-
res.send("Hello, world!");
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
app.get("/api/weather", async (req: Request, res: Response) => {
|
|
149
|
-
const { city } = req.query as { city?: string };
|
|
79
|
+
const PORT = process.env.PORT || 3000;
|
|
150
80
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
81
|
+
// Middleware
|
|
82
|
+
app.use(express.json());
|
|
154
83
|
|
|
155
|
-
|
|
84
|
+
const server = new MastraServer({ app, mastra });
|
|
85
|
+
await server.init();
|
|
156
86
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
} catch (error) {
|
|
161
|
-
console.error("Agent error:", error);
|
|
162
|
-
res.status(500).send("An error occurred while processing your request");
|
|
163
|
-
}
|
|
87
|
+
// Routes
|
|
88
|
+
app.get("/", (_req: Request, res: Response) => {
|
|
89
|
+
res.json({ message: "Hello, World!" });
|
|
164
90
|
});
|
|
165
91
|
|
|
166
|
-
|
|
167
|
-
|
|
92
|
+
// Start server
|
|
93
|
+
app.listen(PORT, () => {
|
|
94
|
+
console.log(`Server is running on http://localhost:${PORT}`);
|
|
168
95
|
});
|
|
169
96
|
```
|
|
170
97
|
|
|
171
|
-
|
|
98
|
+
The `MastraServer` is initialized with the existing Express `app` and the root `mastra` instance. Calling `init()` registers the Mastra middleware and exposes all available Mastra endpoints.
|
|
172
99
|
|
|
173
|
-
|
|
100
|
+
## Test your agent
|
|
174
101
|
|
|
175
|
-
|
|
102
|
+
By default, Mastra's endpoints are added under the `/api` subpath and use your agent/workflow IDs. The default `weather-agent` created by `mastra init` is available at `/api/agents/weather-agent`.
|
|
176
103
|
|
|
177
|
-
|
|
104
|
+
Start your Express server:
|
|
178
105
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
```
|
|
182
|
-
http://localhost:3456/api/weather?city=London
|
|
106
|
+
```bash copy
|
|
107
|
+
npm run start
|
|
183
108
|
```
|
|
184
109
|
|
|
185
|
-
|
|
110
|
+
In a separate terminal window, use `curl` to ask the weather agent:
|
|
186
111
|
|
|
187
|
-
```
|
|
188
|
-
|
|
112
|
+
```bash copy
|
|
113
|
+
curl -X POST http://localhost:3000/api/agents/weather-agent/generate -H "Content-Type: application/json" -d "{\"messages\":[{\"role\":\"user\",\"content\":\"What is the weather like in Seoul?\"}]}"
|
|
189
114
|
```
|
|
190
115
|
|
|
191
|
-
##
|
|
116
|
+
## Next steps
|
|
192
117
|
|
|
193
|
-
|
|
118
|
+
Congratulations on building your Mastra agent with Express! 🎉
|
|
194
119
|
|
|
195
|
-
|
|
120
|
+
From here, you can extend the project with your own tools and logic:
|
|
196
121
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
"mastra:dev": "mastra dev"
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
```
|
|
122
|
+
- Learn more about [agents](/docs/v1/agents/overview)
|
|
123
|
+
- Give your agent its own [tools](/docs/v1/agents/using-tools)
|
|
124
|
+
- Add human-like [memory](/docs/v1/agents/agent-memory) to your agent
|
|
204
125
|
|
|
205
|
-
|
|
126
|
+
When you're ready, read more about how Mastra integrates with Express:
|
|
206
127
|
|
|
207
|
-
|
|
208
|
-
npm run mastra:dev
|
|
209
|
-
```
|
|
128
|
+
- [Server Adapters](/docs/v1/server/server-adapters)
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "Hono | Frameworks"
|
|
3
|
+
description: "Get started with Mastra and Hono"
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
import Tabs from "@theme/Tabs";
|
|
7
|
+
import TabItem from "@theme/TabItem";
|
|
8
|
+
|
|
9
|
+
# Integrate Mastra in your Hono project
|
|
10
|
+
|
|
11
|
+
In this guide, you'll build a tool-calling AI agent using Mastra and Hono. Using the [Hono server adapter](/reference/v1/server/hono-adapter), you can expose your agents as HTTP endpoints without writing the routing yourself or running a separate Mastra server.
|
|
12
|
+
|
|
13
|
+
## Before you begin
|
|
14
|
+
|
|
15
|
+
- You'll need an API key from a supported [model provider](/models/v1). If you don't have a preference, use [OpenAI](/models/v1/providers/openai).
|
|
16
|
+
- Install Node.js `v22.13.0` or later
|
|
17
|
+
|
|
18
|
+
## Create a new Hono app (optional)
|
|
19
|
+
|
|
20
|
+
If you already have a Hono app, skip to the next step.
|
|
21
|
+
|
|
22
|
+
Run the following command to [create a new Hono app](https://hono.dev/docs/getting-started/basic):
|
|
23
|
+
|
|
24
|
+
<Tabs groupId="pm">
|
|
25
|
+
<TabItem value="npm" label="npm">
|
|
26
|
+
|
|
27
|
+
```bash copy
|
|
28
|
+
npm create hono@latest mastra-hono -- --template nodejs --install --pm npm
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
</TabItem>
|
|
32
|
+
<TabItem value="pnpm" label="pnpm">
|
|
33
|
+
|
|
34
|
+
```bash copy
|
|
35
|
+
pnpm create hono@latest mastra-hono --template nodejs --install --pm pnpm
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
</TabItem>
|
|
39
|
+
<TabItem value="yarn" label="yarn">
|
|
40
|
+
|
|
41
|
+
```bash copy
|
|
42
|
+
yarn create hono@latest mastra-hono --template nodejs --install --pm yarn
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
</TabItem>
|
|
46
|
+
<TabItem value="bun" label="bun">
|
|
47
|
+
|
|
48
|
+
```bash copy
|
|
49
|
+
bun create hono@latest mastra-hono --template nodejs --install --pm bun
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
</TabItem>
|
|
53
|
+
</Tabs>
|
|
54
|
+
|
|
55
|
+
This creates a project called `mastra-hono`, but you can replace it with any name you want.
|
|
56
|
+
|
|
57
|
+
## Initialize Mastra
|
|
58
|
+
|
|
59
|
+
Inside your Hono project directory, run [`mastra init`](/reference/v1/cli/mastra#mastra-init).
|
|
60
|
+
|
|
61
|
+
When prompted, choose a provider (e.g. OpenAI) and enter your key:
|
|
62
|
+
|
|
63
|
+
<Tabs groupId="pm">
|
|
64
|
+
<TabItem value="npm" label="npm">
|
|
65
|
+
|
|
66
|
+
```bash copy
|
|
67
|
+
cd mastra-hono
|
|
68
|
+
npx mastra@beta init
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
</TabItem>
|
|
72
|
+
<TabItem value="pnpm" label="pnpm">
|
|
73
|
+
|
|
74
|
+
```bash copy
|
|
75
|
+
cd mastra-hono
|
|
76
|
+
pnpm dlx mastra@beta init
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
</TabItem>
|
|
80
|
+
<TabItem value="yarn" label="yarn">
|
|
81
|
+
|
|
82
|
+
```bash copy
|
|
83
|
+
cd mastra-hono
|
|
84
|
+
yarn dlx mastra@beta init
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
</TabItem>
|
|
88
|
+
<TabItem value="bun" label="bun">
|
|
89
|
+
|
|
90
|
+
```bash copy
|
|
91
|
+
cd mastra-hono
|
|
92
|
+
bunx mastra@beta init
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
</TabItem>
|
|
96
|
+
</Tabs>
|
|
97
|
+
|
|
98
|
+
This creates a `src/mastra` folder with an example weather agent and the following files:
|
|
99
|
+
|
|
100
|
+
- `index.ts` - Mastra config, including memory
|
|
101
|
+
- `tools/weather-tool.ts` - a tool to fetch weather for a given location
|
|
102
|
+
- `agents/weather-agent.ts`- a weather agent with a prompt that uses the tool
|
|
103
|
+
|
|
104
|
+
You'll pass the `src/mastra/index.ts` file to the Hono server adapter later.
|
|
105
|
+
|
|
106
|
+
## Add server adapter
|
|
107
|
+
|
|
108
|
+
Install the Hono server adapter package:
|
|
109
|
+
|
|
110
|
+
<Tabs groupId="pm">
|
|
111
|
+
<TabItem value="npm" label="npm">
|
|
112
|
+
|
|
113
|
+
```bash copy
|
|
114
|
+
npm install @mastra/hono@beta
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
</TabItem>
|
|
118
|
+
<TabItem value="pnpm" label="pnpm">
|
|
119
|
+
|
|
120
|
+
```bash copy
|
|
121
|
+
pnpm add @mastra/hono@beta
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
</TabItem>
|
|
125
|
+
<TabItem value="yarn" label="yarn">
|
|
126
|
+
|
|
127
|
+
```bash copy
|
|
128
|
+
yarn add @mastra/hono@beta
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
</TabItem>
|
|
132
|
+
<TabItem value="bun" label="bun">
|
|
133
|
+
|
|
134
|
+
```bash copy
|
|
135
|
+
bun add @mastra/hono@beta
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
</TabItem>
|
|
139
|
+
</Tabs>
|
|
140
|
+
|
|
141
|
+
Open the Hono entry file at `src/index.ts` and add the required import and initialization code:
|
|
142
|
+
|
|
143
|
+
```typescript copy title="src/index.ts" {3-8,10-11,13}
|
|
144
|
+
import { serve } from '@hono/node-server'
|
|
145
|
+
import { Hono } from 'hono'
|
|
146
|
+
import {
|
|
147
|
+
type HonoBindings,
|
|
148
|
+
type HonoVariables,
|
|
149
|
+
MastraServer
|
|
150
|
+
} from '@mastra/hono';
|
|
151
|
+
import { mastra } from './mastra/index.js';
|
|
152
|
+
|
|
153
|
+
const app = new Hono<{ Bindings: HonoBindings; Variables: HonoVariables }>();
|
|
154
|
+
const server = new MastraServer({ app, mastra });
|
|
155
|
+
|
|
156
|
+
await server.init();
|
|
157
|
+
|
|
158
|
+
app.get('/', (c) => {
|
|
159
|
+
return c.text('Hello Hono!')
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
serve({
|
|
163
|
+
fetch: app.fetch,
|
|
164
|
+
port: 3000
|
|
165
|
+
}, (info) => {
|
|
166
|
+
console.log(`Server is running on http://localhost:${info.port}`)
|
|
167
|
+
})
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
The `MastraServer` is initialized with the existing Hono `app` and the root `mastra` instance. Calling `init()` registers the Mastra middleware and exposes all available Mastra endpoints.
|
|
171
|
+
|
|
172
|
+
## Test your agent
|
|
173
|
+
|
|
174
|
+
By default, Mastra's endpoints are added under the `/api` subpath and use your agent/workflow IDs. The default `weather-agent` created by `mastra init` is available at `/api/agents/weather-agent`.
|
|
175
|
+
|
|
176
|
+
Start your Hono server:
|
|
177
|
+
|
|
178
|
+
<Tabs groupId="pm">
|
|
179
|
+
<TabItem value="npm" label="npm">
|
|
180
|
+
|
|
181
|
+
```bash copy
|
|
182
|
+
npm run dev
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
</TabItem>
|
|
186
|
+
<TabItem value="pnpm" label="pnpm">
|
|
187
|
+
|
|
188
|
+
```bash copy
|
|
189
|
+
pnpm run dev
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
</TabItem>
|
|
193
|
+
<TabItem value="yarn" label="yarn">
|
|
194
|
+
|
|
195
|
+
```bash copy
|
|
196
|
+
yarn run dev
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
</TabItem>
|
|
200
|
+
<TabItem value="bun" label="bun">
|
|
201
|
+
|
|
202
|
+
```bash copy
|
|
203
|
+
bun run dev
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
</TabItem>
|
|
207
|
+
</Tabs>
|
|
208
|
+
|
|
209
|
+
In a separate terminal window, use `curl` to ask the weather agent:
|
|
210
|
+
|
|
211
|
+
```bash copy
|
|
212
|
+
curl -X POST http://localhost:3000/api/agents/weather-agent/generate -H "Content-Type: application/json" -d "{\"messages\":[{\"role\":\"user\",\"content\":\"What is the weather like in Seoul?\"}]}"
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
## Next steps
|
|
216
|
+
|
|
217
|
+
Congratulations on building your Mastra agent with Hono! 🎉
|
|
218
|
+
|
|
219
|
+
From here, you can extend the project with your own tools and logic:
|
|
220
|
+
|
|
221
|
+
- Learn more about [agents](/docs/v1/agents/overview)
|
|
222
|
+
- Give your agent its own [tools](/docs/v1/agents/using-tools)
|
|
223
|
+
- Add human-like [memory](/docs/v1/agents/agent-memory) to your agent
|
|
224
|
+
|
|
225
|
+
When you're ready, read more about how Mastra integrates with Hono:
|
|
226
|
+
|
|
227
|
+
- [Server Adapters](/docs/v1/server/server-adapters)
|