@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.
Files changed (159) hide show
  1. package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +12 -12
  2. package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +24 -24
  3. package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +45 -45
  4. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +83 -83
  5. package/.docs/organized/changelogs/%40mastra%2Fcloudflare-d1.md +39 -39
  6. package/.docs/organized/changelogs/%40mastra%2Fcloudflare.md +39 -39
  7. package/.docs/organized/changelogs/%40mastra%2Fconvex.md +38 -0
  8. package/.docs/organized/changelogs/%40mastra%2Fcore.md +174 -174
  9. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +17 -17
  10. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +27 -27
  11. package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +39 -39
  12. package/.docs/organized/changelogs/%40mastra%2Ffastembed.md +6 -0
  13. package/.docs/organized/changelogs/%40mastra%2Flance.md +39 -39
  14. package/.docs/organized/changelogs/%40mastra%2Flibsql.md +45 -45
  15. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +15 -15
  16. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +13 -13
  17. package/.docs/organized/changelogs/%40mastra%2Fmongodb.md +39 -39
  18. package/.docs/organized/changelogs/%40mastra%2Fmssql.md +39 -39
  19. package/.docs/organized/changelogs/%40mastra%2Fpg.md +45 -45
  20. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +75 -75
  21. package/.docs/organized/changelogs/%40mastra%2Freact.md +40 -0
  22. package/.docs/organized/changelogs/%40mastra%2Fschema-compat.md +6 -0
  23. package/.docs/organized/changelogs/%40mastra%2Fserver.md +29 -29
  24. package/.docs/organized/changelogs/%40mastra%2Fupstash.md +39 -39
  25. package/.docs/organized/changelogs/create-mastra.md +29 -29
  26. package/.docs/organized/changelogs/mastra.md +35 -35
  27. package/.docs/organized/code-examples/quick-start.md +0 -4
  28. package/.docs/organized/code-examples/stock-price-tool.md +21 -2
  29. package/.docs/raw/agents/agent-approval.mdx +136 -2
  30. package/.docs/raw/agents/agent-memory.mdx +4 -4
  31. package/.docs/raw/agents/guardrails.mdx +1 -1
  32. package/.docs/raw/agents/networks.mdx +1 -1
  33. package/.docs/raw/agents/overview.mdx +2 -2
  34. package/.docs/raw/agents/using-tools.mdx +1 -1
  35. package/.docs/raw/course/01-first-agent/07-creating-your-agent.md +1 -2
  36. package/.docs/raw/course/01-first-agent/12-connecting-tool-to-agent.md +1 -1
  37. package/.docs/raw/course/01-first-agent/16-adding-memory-to-agent.md +1 -2
  38. package/.docs/raw/course/02-agent-tools-mcp/05-updating-your-agent.md +1 -1
  39. package/.docs/raw/course/02-agent-tools-mcp/10-updating-agent-instructions-zapier.md +1 -1
  40. package/.docs/raw/course/02-agent-tools-mcp/16-updating-agent-instructions-github.md +1 -1
  41. package/.docs/raw/course/02-agent-tools-mcp/21-updating-agent-instructions-hackernews.md +1 -1
  42. package/.docs/raw/course/02-agent-tools-mcp/27-updating-agent-instructions-filesystem.md +1 -1
  43. package/.docs/raw/course/02-agent-tools-mcp/31-enhancing-memory-configuration.md +2 -2
  44. package/.docs/raw/course/03-agent-memory/04-creating-basic-memory-agent.md +1 -2
  45. package/.docs/raw/course/03-agent-memory/08-configuring-conversation-history.md +1 -2
  46. package/.docs/raw/course/03-agent-memory/16-configuring-semantic-recall.md +3 -4
  47. package/.docs/raw/course/03-agent-memory/21-configuring-working-memory.md +2 -3
  48. package/.docs/raw/course/03-agent-memory/22-custom-working-memory-templates.md +2 -3
  49. package/.docs/raw/course/03-agent-memory/25-combining-memory-features.md +1 -2
  50. package/.docs/raw/course/03-agent-memory/27-creating-learning-assistant.md +2 -3
  51. package/.docs/raw/course/04-workflows/11-creating-an-ai-agent.md +2 -3
  52. package/.docs/raw/deployment/cloud-providers.mdx +20 -0
  53. package/.docs/raw/deployment/{building-mastra.mdx → mastra-server.mdx} +2 -2
  54. package/.docs/raw/deployment/monorepo.mdx +23 -44
  55. package/.docs/raw/deployment/overview.mdx +28 -53
  56. package/.docs/raw/deployment/web-framework.mdx +12 -14
  57. package/.docs/raw/getting-started/start.mdx +10 -1
  58. package/.docs/raw/getting-started/studio.mdx +1 -1
  59. package/.docs/raw/guides/build-your-ui/ai-sdk-ui.mdx +1021 -67
  60. package/.docs/raw/{deployment/cloud-providers → guides/deployment}/aws-lambda.mdx +3 -6
  61. package/.docs/raw/{deployment/cloud-providers → guides/deployment}/azure-app-services.mdx +4 -6
  62. package/.docs/raw/{deployment/cloud-providers → guides/deployment}/cloudflare-deployer.mdx +4 -0
  63. package/.docs/raw/{deployment/cloud-providers → guides/deployment}/digital-ocean.mdx +3 -6
  64. package/.docs/raw/guides/deployment/index.mdx +32 -0
  65. package/.docs/raw/{deployment/cloud-providers → guides/deployment}/netlify-deployer.mdx +4 -0
  66. package/.docs/raw/{deployment/cloud-providers → guides/deployment}/vercel-deployer.mdx +4 -0
  67. package/.docs/raw/guides/getting-started/express.mdx +71 -152
  68. package/.docs/raw/guides/getting-started/hono.mdx +227 -0
  69. package/.docs/raw/guides/getting-started/next-js.mdx +173 -63
  70. package/.docs/raw/guides/getting-started/vite-react.mdx +307 -137
  71. package/.docs/raw/guides/guide/research-assistant.mdx +4 -4
  72. package/.docs/raw/guides/migrations/upgrade-to-v1/client.mdx +17 -0
  73. package/.docs/raw/guides/migrations/upgrade-to-v1/overview.mdx +6 -0
  74. package/.docs/raw/index.mdx +1 -1
  75. package/.docs/raw/{deployment/mastra-cloud → mastra-cloud}/dashboard.mdx +2 -6
  76. package/.docs/raw/{deployment/mastra-cloud → mastra-cloud}/observability.mdx +1 -5
  77. package/.docs/raw/{deployment/mastra-cloud → mastra-cloud}/overview.mdx +2 -6
  78. package/.docs/raw/{deployment/mastra-cloud → mastra-cloud}/setting-up.mdx +3 -6
  79. package/.docs/raw/memory/overview.mdx +1 -1
  80. package/.docs/raw/memory/storage/memory-with-libsql.mdx +1 -1
  81. package/.docs/raw/memory/storage/memory-with-mongodb.mdx +1 -1
  82. package/.docs/raw/memory/storage/memory-with-pg.mdx +1 -1
  83. package/.docs/raw/memory/storage/memory-with-upstash.mdx +1 -1
  84. package/.docs/raw/{server-db/storage.mdx → memory/storage/overview.mdx} +2 -2
  85. package/.docs/raw/observability/logging.mdx +1 -1
  86. package/.docs/raw/observability/tracing/exporters/cloud.mdx +1 -1
  87. package/.docs/raw/observability/tracing/exporters/default.mdx +1 -1
  88. package/.docs/raw/rag/chunking-and-embedding.mdx +12 -25
  89. package/.docs/raw/rag/graph-rag.mdx +220 -0
  90. package/.docs/raw/rag/overview.mdx +1 -2
  91. package/.docs/raw/rag/retrieval.mdx +13 -29
  92. package/.docs/raw/rag/vector-databases.mdx +7 -3
  93. package/.docs/raw/reference/agents/getDefaultGenerateOptions.mdx +1 -1
  94. package/.docs/raw/reference/agents/getDefaultOptions.mdx +1 -1
  95. package/.docs/raw/reference/agents/getDefaultStreamOptions.mdx +1 -1
  96. package/.docs/raw/reference/agents/getInstructions.mdx +1 -1
  97. package/.docs/raw/reference/agents/getLLM.mdx +1 -1
  98. package/.docs/raw/reference/agents/getMemory.mdx +1 -1
  99. package/.docs/raw/reference/agents/getModel.mdx +1 -1
  100. package/.docs/raw/reference/agents/listScorers.mdx +1 -1
  101. package/.docs/raw/reference/ai-sdk/chat-route.mdx +1 -1
  102. package/.docs/raw/reference/ai-sdk/handle-chat-stream.mdx +1 -1
  103. package/.docs/raw/reference/ai-sdk/handle-network-stream.mdx +1 -1
  104. package/.docs/raw/reference/ai-sdk/handle-workflow-stream.mdx +1 -1
  105. package/.docs/raw/reference/ai-sdk/network-route.mdx +1 -1
  106. package/.docs/raw/reference/ai-sdk/to-ai-sdk-v4-messages.mdx +127 -0
  107. package/.docs/raw/reference/ai-sdk/to-ai-sdk-v5-messages.mdx +107 -0
  108. package/.docs/raw/reference/ai-sdk/workflow-route.mdx +1 -1
  109. package/.docs/raw/reference/auth/auth0.mdx +1 -1
  110. package/.docs/raw/reference/auth/clerk.mdx +1 -1
  111. package/.docs/raw/reference/auth/firebase.mdx +1 -1
  112. package/.docs/raw/reference/auth/jwt.mdx +1 -1
  113. package/.docs/raw/reference/auth/supabase.mdx +1 -1
  114. package/.docs/raw/reference/auth/workos.mdx +1 -1
  115. package/.docs/raw/reference/cli/mastra.mdx +1 -1
  116. package/.docs/raw/reference/client-js/mastra-client.mdx +1 -1
  117. package/.docs/raw/reference/client-js/workflows.mdx +20 -0
  118. package/.docs/raw/reference/core/getServer.mdx +2 -2
  119. package/.docs/raw/reference/core/getStorage.mdx +1 -1
  120. package/.docs/raw/reference/core/getStoredAgentById.mdx +1 -1
  121. package/.docs/raw/reference/core/listStoredAgents.mdx +1 -1
  122. package/.docs/raw/reference/core/setStorage.mdx +1 -1
  123. package/.docs/raw/reference/logging/pino-logger.mdx +1 -1
  124. package/.docs/raw/reference/rag/database-config.mdx +1 -1
  125. package/.docs/raw/reference/server/create-route.mdx +1 -1
  126. package/.docs/raw/reference/server/express-adapter.mdx +4 -4
  127. package/.docs/raw/reference/server/hono-adapter.mdx +4 -4
  128. package/.docs/raw/reference/server/mastra-server.mdx +2 -2
  129. package/.docs/raw/reference/server/routes.mdx +28 -1
  130. package/.docs/raw/reference/streaming/agents/stream.mdx +22 -0
  131. package/.docs/raw/reference/streaming/workflows/stream.mdx +33 -20
  132. package/.docs/raw/reference/tools/create-tool.mdx +23 -1
  133. package/.docs/raw/reference/tools/graph-rag-tool.mdx +3 -3
  134. package/.docs/raw/reference/tools/vector-query-tool.mdx +3 -3
  135. package/.docs/raw/reference/workflows/run-methods/startAsync.mdx +143 -0
  136. package/.docs/raw/reference/workflows/workflow-methods/create-run.mdx +35 -0
  137. package/.docs/raw/reference/workflows/workflow.mdx +14 -0
  138. package/.docs/raw/{auth → server/auth}/auth0.mdx +1 -1
  139. package/.docs/raw/{auth → server/auth}/clerk.mdx +1 -1
  140. package/.docs/raw/{auth → server/auth}/firebase.mdx +1 -1
  141. package/.docs/raw/{auth → server/auth}/index.mdx +6 -6
  142. package/.docs/raw/{auth → server/auth}/jwt.mdx +1 -1
  143. package/.docs/raw/{auth → server/auth}/supabase.mdx +1 -1
  144. package/.docs/raw/{auth → server/auth}/workos.mdx +1 -1
  145. package/.docs/raw/{server-db → server}/custom-adapters.mdx +3 -3
  146. package/.docs/raw/{server-db → server}/custom-api-routes.mdx +1 -1
  147. package/.docs/raw/{server-db → server}/mastra-client.mdx +2 -2
  148. package/.docs/raw/{server-db → server}/mastra-server.mdx +5 -5
  149. package/.docs/raw/{server-db → server}/middleware.mdx +2 -2
  150. package/.docs/raw/{server-db → server}/request-context.mdx +3 -3
  151. package/.docs/raw/{server-db → server}/server-adapters.mdx +6 -6
  152. package/.docs/raw/tools-mcp/overview.mdx +2 -2
  153. package/.docs/raw/workflows/error-handling.mdx +162 -1
  154. package/.docs/raw/workflows/overview.mdx +2 -2
  155. package/CHANGELOG.md +14 -0
  156. package/package.json +3 -3
  157. package/.docs/organized/changelogs/%40internal%2Fai-sdk-v4.md +0 -1
  158. package/.docs/raw/deployment/cloud-providers/index.mdx +0 -55
  159. /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
- :::note
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/building-mastra).
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
- :::note
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-db/mastra-client) for more information.
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: "Integrate Mastra in your Express project | Frameworks"
3
- description: A step-by-step guide to integrating Mastra with an Express backend.
2
+ title: "Express | Frameworks"
3
+ description: "Get started with Mastra and Express"
4
4
  ---
5
5
 
6
- # Integrate Mastra in your Express project
6
+ import Tabs from "@theme/Tabs";
7
+ import TabItem from "@theme/TabItem";
7
8
 
8
- Mastra integrates with Express, making it easy to:
9
+ # Integrate Mastra in your Express project
9
10
 
10
- - Build flexible APIs to serve AI-powered features
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
- Express can invoke Mastra directly so you don't need to run a Mastra server alongside your Express server.
13
+ ## Before you begin
15
14
 
16
- In this guide you'll learn how to install the necessary Mastra dependencies, create an example agent, and invoke Mastra from an Express API route.
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
- ## Prerequisites
18
+ ## Create a new Express app (optional)
19
19
 
20
- - An existing Express app set up with TypeScript
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
- ## Adding Mastra
22
+ Clone this [boilerplate repository](https://github.com/mastra-ai/express-ts-boilerplate) and install dependencies:
25
23
 
26
- First, install the necessary Mastra dependencies to run an Agent. This guide uses OpenAI as its model but you can use any supported [model provider](/models/v1).
24
+ <Tabs>
25
+ <TabItem value="https" label="HTTPS">
27
26
 
28
27
  ```bash copy
29
- npm install mastra@beta @mastra/core@beta @mastra/libsql@beta zod@^3.0.0
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
- :::note
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
- export const mastra = new Mastra({});
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
- Create a `weatherTool` that the `weatherAgent` will use at `src/mastra/tools/weather-tool.ts`. It returns a placeholder value inside the `execute()` function (you'd put your API calls in here).
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
- Add a `weatherAgent` at `src/mastra/agents/weather-agent.ts`:
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
- Lastly, add the `weatherAgent` to `src/mastra/index.ts`:
47
+ Inside your Express project directory, run [`mastra init`](/reference/v1/cli/mastra#mastra-init).
102
48
 
103
- ```ts title="src/mastra/index.ts" copy {2, 5}
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
- export const mastra = new Mastra({
108
- agents: { weatherAgent },
109
- });
51
+ ```bash copy
52
+ npx mastra@beta init
110
53
  ```
111
54
 
112
- Now you're done with setting up the Mastra boilerplate code and are ready to integrate it into your Express routes.
55
+ This creates a `src/mastra` folder with an example weather agent and the following files:
113
56
 
114
- ## Using Mastra with Express
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
- Create an `/api/weather` endpoint that expects a `city` query parameter. The `city` parameter will be passed to the `weatherAgent` when asking it through a prompt.
61
+ You'll pass the `src/mastra/index.ts` file to the Express server adapter later.
117
62
 
118
- You might have a file like this in your existing project:
63
+ ## Add server adapter
119
64
 
120
- ```ts title="src/server.ts" copy
121
- import express, { Request, Response } from "express";
65
+ Install the Express server adapter package:
122
66
 
123
- const app = express();
124
- const port = 3456;
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
- Adding the `/api/weather` endpoint looks like this:
71
+ Open the Express entry file at `src/index.ts` and add the required import and initialization code:
136
72
 
137
- ```ts title="src/server.ts" copy {2, 11-27}
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 port = 3456;
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
- if (!city) {
152
- return res.status(400).send("Missing 'city' query parameter");
153
- }
81
+ // Middleware
82
+ app.use(express.json());
154
83
 
155
- const agent = mastra.getAgent("weatherAgent");
84
+ const server = new MastraServer({ app, mastra });
85
+ await server.init();
156
86
 
157
- try {
158
- const result = await agent.generate(`What's the weather like in ${city}?`);
159
- res.send(result.text);
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
- app.listen(port, () => {
167
- console.log(`Server is running at http://localhost:${port}`);
92
+ // Start server
93
+ app.listen(PORT, () => {
94
+ console.log(`Server is running on http://localhost:${PORT}`);
168
95
  });
169
96
  ```
170
97
 
171
- By importing the `src/mastra/index.ts` file you can use methods like [`.getAgent()`](/reference/v1/core/getAgent) to get programmatic access. With [`.generate()`](/reference/v1/agents/generate) you then can interact with the respective agent.
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
- :::note
100
+ ## Test your agent
174
101
 
175
- Read the [Agent reference docs](/reference/v1/agents/agent) to learn more.
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
- Start your Express server and visit the `/api/weather` endpoint. For example:
180
-
181
- ```
182
- http://localhost:3456/api/weather?city=London
106
+ ```bash copy
107
+ npm run start
183
108
  ```
184
109
 
185
- You should get a response back similar to this:
110
+ In a separate terminal window, use `curl` to ask the weather agent:
186
111
 
187
- ```
188
- The weather in London is currently sunny. If you need more details like humidity, wind conditions, or precipitation, just let me know!
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
- ## Running the Agent Server
116
+ ## Next steps
192
117
 
193
- In production it's not necessary to run Mastra alongside your Express server. But for development Mastra offers a [Local Development Environment](/docs/v1/getting-started/studio) which you can use to improve and debug your agent.
118
+ Congratulations on building your Mastra agent with Express! 🎉
194
119
 
195
- Add a script to your `package.json`:
120
+ From here, you can extend the project with your own tools and logic:
196
121
 
197
- ```json title="package.json" copy
198
- {
199
- "scripts": {
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
- Start the Mastra dev server:
126
+ When you're ready, read more about how Mastra integrates with Express:
206
127
 
207
- ```bash copy
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)