@mastra/mcp-docs-server 0.13.12-alpha.2 → 0.13.12-alpha.4

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 (27) hide show
  1. package/.docs/organized/changelogs/%40mastra%2Fclickhouse.md +24 -24
  2. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +34 -34
  3. package/.docs/organized/changelogs/%40mastra%2Fcore.md +29 -29
  4. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +44 -44
  5. package/.docs/organized/changelogs/%40mastra%2Ffirecrawl.md +23 -23
  6. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +33 -33
  7. package/.docs/organized/changelogs/%40mastra%2Fmcp.md +24 -24
  8. package/.docs/organized/changelogs/%40mastra%2Fmemory.md +27 -27
  9. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +38 -38
  10. package/.docs/organized/changelogs/%40mastra%2Frag.md +23 -23
  11. package/.docs/organized/changelogs/%40mastra%2Fserver.md +34 -34
  12. package/.docs/organized/changelogs/%40mastra%2Fvoice-google.md +24 -24
  13. package/.docs/organized/changelogs/create-mastra.md +9 -9
  14. package/.docs/organized/changelogs/mastra.md +42 -42
  15. package/.docs/organized/code-examples/agent.md +75 -11
  16. package/.docs/raw/deployment/server-deployment.mdx +57 -27
  17. package/.docs/raw/deployment/serverless-platforms/cloudflare-deployer.mdx +4 -7
  18. package/.docs/raw/frameworks/servers/express.mdx +135 -143
  19. package/.docs/raw/reference/agents/agent.mdx +1 -1
  20. package/.docs/raw/reference/agents/getDefaultVNextStreamOptions.mdx +1 -1
  21. package/.docs/raw/reference/agents/streamVNext.mdx +1 -1
  22. package/.docs/raw/reference/deployer/cloudflare.mdx +20 -131
  23. package/.docs/raw/reference/memory/Memory.mdx +1 -1
  24. package/.docs/raw/reference/voice/google-gemini-live.mdx +629 -0
  25. package/.docs/raw/voice/overview.mdx +21 -33
  26. package/.docs/raw/workflows/suspend-and-resume.mdx +2 -2
  27. package/package.json +4 -4
@@ -3,7 +3,7 @@ title: "Getting started with Mastra and Express | Mastra Guides"
3
3
  description: A step-by-step guide to integrating Mastra with an Express backend.
4
4
  ---
5
5
 
6
- import { Callout, Steps, Tabs, FileTree } from "nextra/components";
6
+ import { Callout } from "nextra/components";
7
7
 
8
8
  # Integrate Mastra in your Express project
9
9
 
@@ -13,153 +13,148 @@ Mastra integrates with Express, making it easy to:
13
13
  - Maintain full control over your server logic and routing
14
14
  - Scale your backend independently of your frontend
15
15
 
16
- Use this guide to scaffold and integrate Mastra with your Express project.
16
+ Express can invoke Mastra directly so you don't need to run a Mastra server alongside your Express server.
17
17
 
18
- <Callout type="warning">
19
- This setup is compatible with the following package versions:
20
- - `express`: 4.x
21
- - `@types/express`: 4.x
18
+ 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.
22
19
 
23
- Type compatibility in 5.x can be inconsistent while `express` and `@types/express` evolve toward alignment.
20
+ ## Prerequisites
24
21
 
25
- </Callout>
22
+ - An existing Express app set up with TypeScript
23
+ - Node.js `v20.0` or higher
24
+ - An API key from a supported [Model Provider](/docs/getting-started/model-providers)
25
+
26
+ ## Adding Mastra
26
27
 
27
- <Steps>
28
- ## Install Mastra
29
-
30
- Install the required Mastra packages:
31
-
32
- <Tabs items={["npm", "yarn", "pnpm", "bun"]}>
33
- <Tabs.Tab>
34
- ```bash copy
35
- npm install mastra@latest @mastra/core@latest @mastra/libsql@latest
36
- ```
37
- </Tabs.Tab>
38
- <Tabs.Tab>
39
- ```bash copy
40
- yarn add mastra@latest @mastra/core@latest @mastra/libsql@latest
41
- ```
42
- </Tabs.Tab>
43
- <Tabs.Tab>
44
- ```bash copy
45
- pnpm add mastra@latest @mastra/core@latest @mastra/libsql@latest
46
- ```
47
- </Tabs.Tab>
48
- <Tabs.Tab>
49
- ```bash copy
50
- bun add mastra@latest @mastra/core@latest @mastra/libsql@latest
51
- ```
52
- </Tabs.Tab>
53
- </Tabs>
54
-
55
- ## Integrate Mastra
56
-
57
- To integrate Mastra in your project, you have two options:
58
-
59
- ### 1. Use the One-Liner
60
-
61
- Run the following command to quickly scaffold the default Weather agent with sensible defaults:
28
+ 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](/docs/getting-started/model-providers).
62
29
 
63
30
  ```bash copy
64
- npx mastra@latest init --default
31
+ npm install mastra@latest @mastra/core@latest @mastra/libsql@latest zod@^3.0.0 @ai-sdk/openai@^1.0.0
65
32
  ```
66
33
 
67
- > See [mastra init](/reference/cli/init) for more information.
68
-
69
- ### 2. Use the Interactive CLI
70
-
71
- If you prefer to customize the setup, run the `init` command and choose from the options when prompted:
34
+ If not existent yet, create an `.env` file and add your OpenAI API key:
72
35
 
73
- ```bash copy
74
- npx mastra@latest init
36
+ ```bash filename=".env" copy
37
+ OPENAI_API_KEY=<your-api-key>
75
38
  ```
76
39
 
77
- Add the `dev` and `build` scripts to `package.json`:
40
+ <Callout>
41
+ Each LLM provider uses a different env var. See [Model Capabilities](/docs/getting-started/model-capability) for more information.
42
+ </Callout>
78
43
 
79
- ```json filename="package.json"
80
- {
81
- "scripts": {
82
- ...
83
- "dev": "mastra dev",
84
- "build": "mastra build"
85
- }
86
- }
87
- ```
44
+ Create a Mastra configuration file at `src/mastra/index.ts`:
88
45
 
89
- > If your project already uses `dev` and `build` scripts, we recommend using: `dev:mastra` and `build:mastra`.
46
+ ```ts filename="src/mastra/index.ts" copy
47
+ import { Mastra } from '@mastra/core/mastra';
90
48
 
91
- ## Initialize TypeScript
49
+ export const mastra = new Mastra({});
50
+ ```
92
51
 
93
- Create a `tsconfig.json` file in your project root with the following configuration:
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 filename="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
+ ```
94
74
 
95
- ```json filename="tsconfig.json" copy
96
- {
97
- "compilerOptions": {
98
- "target": "ES2022",
99
- "module": "ES2022",
100
- "moduleResolution": "bundler",
101
- "esModuleInterop": true,
102
- "forceConsistentCasingInFileNames": true,
103
- "strict": true,
104
- "skipLibCheck": true,
105
- "outDir": "dist"
106
- },
107
- "include": ["src/**/*"],
108
- "exclude": ["node_modules", "dist", ".mastra"]
109
- }
75
+ Add a `weatherAgent` at `src/mastra/agents/weather-agent.ts`:
76
+
77
+ ```ts filename="src/mastra/agents/weather-agent.ts" copy
78
+ import { openai } from "@ai-sdk/openai";
79
+ import { Agent } from "@mastra/core/agent";
80
+ import { weatherTool } from "../tools/weather-tool";
81
+
82
+ export const weatherAgent = new 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-4o-mini'),
97
+ tools: { weatherTool }
98
+ });
110
99
  ```
111
100
 
112
- > This TypeScript configuration is optimized for Mastra projects, using modern module resolution and strict type checking.
101
+ Lastly, add the `weatherAgent` to `src/mastra/index.ts`:
113
102
 
114
- ## Set Up API Key
103
+ ```ts filename="src/mastra/index.ts" copy {2, 5}
104
+ import { Mastra } from '@mastra/core/mastra';
105
+ import { weatherAgent } from './agents/weather-agent';
106
+
107
+ export const mastra = new Mastra({
108
+ agents: { weatherAgent },
109
+ });
115
110
 
116
- ```bash filename=".env" copy
117
- OPENAI_API_KEY=<your-api-key>
118
111
  ```
119
112
 
120
- > Each llm provider uses a different env var. See [Model Capabilities](/docs/getting-started/model-capability) for more information.
113
+ Now you're done with setting up the Mastra boilerplate code and are ready to integrate it into your Express routes.
121
114
 
122
- ## Start the Mastra Dev Server
115
+ ## Using Mastra with Express
123
116
 
124
- Start the Mastra dev server to expose your agents as REST endpoints:
117
+ 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.
125
118
 
126
- <Tabs items={["npm", "CLI"]}>
127
- <Tabs.Tab>
128
- ```bash copy
129
- npm run dev
130
- ```
131
- </Tabs.Tab>
132
- <Tabs.Tab>
133
- ```bash copy
134
- mastra dev
135
- ```
136
- </Tabs.Tab>
137
- </Tabs>
119
+ You might have a file like this in your existing project:
138
120
 
139
- > Once running, your agents are available locally. See [Local Development Environment](/docs/server-db/local-dev-playground) for more information.
121
+ ```ts filename="src/server.ts" copy
122
+ import express, { Request, Response } from 'express';
140
123
 
141
- ## Example Express App
124
+ const app = express();
125
+ const port = 3456;
142
126
 
143
- This example creates an `/api/weather` endpoint that expects a `city` query parameter.
127
+ app.get('/', (req: Request, res: Response) => {
128
+ res.send('Hello, world!');
129
+ });
144
130
 
145
- ```typescript filename="src/server.ts" showLineNumbers copy
146
- import "dotenv/config";
147
- import express, { Request, Response } from "express";
131
+ app.listen(port, () => {
132
+ console.log(`Server is running at http://localhost:${port}`);
133
+ });
134
+ ```
135
+
136
+ Adding the `/api/weather` endpoint looks like this:
148
137
 
149
- import { mastra } from "./mastra";
138
+ ```ts filename="src/server.ts" copy {2, 11-27}
139
+ import express, { Request, Response } from 'express';
140
+ import { mastra } from "./mastra"
150
141
 
151
142
  const app = express();
152
- const port = process.env.PORT ?? 3000;
143
+ const port = 3456;
144
+
145
+ app.get('/', (req: Request, res: Response) => {
146
+ res.send('Hello, world!');
147
+ });
153
148
 
154
149
  app.get("/api/weather", async (req: Request, res: Response) => {
155
150
  const { city } = req.query as { city?: string };
156
-
151
+
157
152
  if (!city) {
158
153
  return res.status(400).send("Missing 'city' query parameter");
159
154
  }
160
-
155
+
161
156
  const agent = mastra.getAgent("weatherAgent");
162
-
157
+
163
158
  try {
164
159
  const result = await agent.generate(`What's the weather like in ${city}?`);
165
160
  res.send(result.text);
@@ -170,47 +165,44 @@ app.get("/api/weather", async (req: Request, res: Response) => {
170
165
  });
171
166
 
172
167
  app.listen(port, () => {
173
- console.log(`Server listening on port ${port}`);
168
+ console.log(`Server is running at http://localhost:${port}`);
174
169
  });
175
170
  ```
176
171
 
177
- With the Mastra dev server running, start your Express app separately. For example:
172
+ By importing the `src/mastra/index.ts` file you can use methods like [`.getAgent()`](/reference/agents/getAgent) to get programmatic access. With [`.generate()`](/reference/agents/generate) you then can interact with the respective agent.
173
+
174
+ <Callout>
175
+ Read the [Agent reference docs](/reference/agents/agent) to learn more.
176
+ </Callout>
177
+
178
+ Start your Express server and visit the `/api/weather` endpoint. For example:
178
179
 
179
- ```bash copy
180
- npx tsx --watch src/server.ts --watch-dir src
181
180
  ```
181
+ http://localhost:3456/api/weather?city=London
182
+ ```
183
+
184
+ You should get a response back similar to this:
182
185
 
183
- You can now make a request to the endpoint using one of the following:
184
-
185
- <Tabs items={["http", "curl"]}>
186
- <Tabs.Tab>
187
- ```bash copy
188
- http://localhost:3000/api/weather?city=London
189
- ```
190
- </Tabs.Tab>
191
- <Tabs.Tab>
192
- ```bash copy
193
- curl "http://localhost:3000/api/weather?city=London"
194
- ```
195
- </Tabs.Tab>
196
- </Tabs>
197
-
198
- You should see output similar to the below:
199
-
200
- ```plaintext
201
- The current weather in London is as follows:
202
-
203
- - **Temperature:** 12.9°C (Feels like 9.7°C)
204
- - **Humidity:** 63%
205
- - **Wind Speed:** 14.7 km/h
206
- - **Wind Gusts:** 32.4 km/h
207
- - **Conditions:** Overcast
208
-
209
- Let me know if you need more information!
210
186
  ```
187
+ The weather in London is currently sunny. If you need more details like humidity, wind conditions, or precipitation, just let me know!
188
+ ```
189
+
190
+ ## Running the Agent Server
211
191
 
212
- </Steps>
192
+ In production it's not necessary to run Mastra alongside your Express server. But for development Mastra offers a [Local Development Environment](/docs/server-db/local-dev-playground) which you can use to improve and debug your agent.
213
193
 
214
- ## Next Steps
194
+ Add a script to your `package.json`:
215
195
 
216
- - [Mastra Client SDK](/docs/deployment/client)
196
+ ```json filename="package.json" copy
197
+ {
198
+ "scripts": {
199
+ "mastra:dev": "mastra dev"
200
+ },
201
+ }
202
+ ```
203
+
204
+ Start the Mastra playground:
205
+
206
+ ```bash copy
207
+ npm run mastra:dev
208
+ ```
@@ -80,7 +80,7 @@ export const agent = new Agent({
80
80
  },
81
81
  {
82
82
  name: "defaultVNextStreamOptions",
83
- type: "AgentVNextStreamOptions | ({ runtimeContext: RuntimeContext }) => AgentVNextStreamOptions | Promise<AgentVNextStreamOptions>",
83
+ type: "AgentExecutionOptions | ({ runtimeContext: RuntimeContext }) => AgentExecutionOptions | Promise<AgentExecutionOptions>",
84
84
  isOptional: true,
85
85
  description: "Default options used when calling `stream()` in vNext mode.",
86
86
  },
@@ -33,7 +33,7 @@ await agent.getDefaultVNextStreamOptions();
33
33
  content={[
34
34
  {
35
35
  name: "defaultOptions",
36
- type: "AgentVNextStreamOptions<Output, StructuredOutput> | Promise<AgentVNextStreamOptions<Output, StructuredOutput>>",
36
+ type: "AgentExecutionOptions<Output, StructuredOutput> | Promise<AgentExecutionOptions<Output, StructuredOutput>>",
37
37
  description: "The default vNext streaming options configured for the agent, either as a direct object or a promise that resolves to the options.",
38
38
  },
39
39
  ]}
@@ -30,7 +30,7 @@ await agent.streamVNext("message for agent");
30
30
  },
31
31
  {
32
32
  name: "options",
33
- type: "AgentVNextStreamOptions<Output, StructuredOutput>",
33
+ type: "AgentExecutionOptions<Output, StructuredOutput>",
34
34
  isOptional: true,
35
35
  description: "Optional configuration for the streaming process.",
36
36
  },
@@ -16,49 +16,40 @@ import { CloudflareDeployer } from "@mastra/deployer-cloudflare";
16
16
  export const mastra = new Mastra({
17
17
  // ...
18
18
  deployer: new CloudflareDeployer({
19
- scope: "your-account-id",
20
- projectName: "your-project-name",
19
+ projectName: "hello-mastra",
21
20
  routes: [
22
21
  {
23
22
  pattern: "example.com/*",
24
23
  zone_name: "example.com",
25
- custom_domain: true,
26
- },
24
+ custom_domain: true
25
+ }
27
26
  ],
28
- workerNamespace: "your-namespace",
29
- auth: {
30
- apiToken: "your-api-token",
31
- apiEmail: "your-email",
27
+ workerNamespace: "my-namespace",
28
+ env: {
29
+ NODE_ENV: "production",
30
+ API_KEY: "<api-key>"
32
31
  },
33
32
  d1Databases: [
34
33
  {
35
- binding: "binding-name",
36
- database_name: "database-name",
37
- database_id: "database-id",
38
- },
34
+ binding: "DB",
35
+ database_name: "my-database",
36
+ database_id: "d1-database-id",
37
+ preview_database_id: "your-preview-database-id"
38
+ }
39
39
  ],
40
40
  kvNamespaces: [
41
41
  {
42
- binding: "binding-name",
43
- id: "namespace-id",
44
- },
45
- ],
46
- }),
42
+ binding: "CACHE",
43
+ id: "kv-namespace-id"
44
+ }
45
+ ]
47
46
  });
48
47
  ```
49
48
 
50
49
  ## Parameters
51
50
 
52
- ### Constructor Parameters
53
-
54
51
  <PropertiesTable
55
52
  content={[
56
- {
57
- name: "scope",
58
- type: "string",
59
- description: "Your Cloudflare account ID.",
60
- isOptional: false,
61
- },
62
53
  {
63
54
  name: "projectName",
64
55
  type: "string",
@@ -69,7 +60,7 @@ export const mastra = new Mastra({
69
60
  {
70
61
  name: "routes",
71
62
  type: "CFRoute[]",
72
- description: "Array of route configurations for your worker.",
63
+ description: "Array of route configurations for your worker. Each route requires: pattern (string), zone_name (string), custom_domain (boolean, optional).",
73
64
  isOptional: true,
74
65
  },
75
66
  {
@@ -81,122 +72,20 @@ export const mastra = new Mastra({
81
72
  {
82
73
  name: "env",
83
74
  type: "Record<string, any>",
84
- description:
85
- "Environment variables to be included in the worker configuration.",
75
+ description: "Environment variables to be included in the worker configuration.",
86
76
  isOptional: true,
87
77
  },
88
- {
89
- name: "auth",
90
- type: "object",
91
- description: "Cloudflare authentication details.",
92
- isOptional: false,
93
- },
94
78
  {
95
79
  name: "d1Databases",
96
80
  type: "D1DatabaseBinding[]",
97
- description: "Array of D1 database bindings for your worker.",
81
+ description: "Array of D1 database bindings. Each binding requires: binding (string), database_name (string), database_id (string), preview_database_id (string, optional).",
98
82
  isOptional: true,
99
83
  },
100
84
  {
101
85
  name: "kvNamespaces",
102
86
  type: "KVNamespaceBinding[]",
103
- description: "Array of KV namespace bindings for your worker.",
104
- isOptional: true,
105
- },
106
- ]}
107
- />
108
-
109
- ### auth Object
110
-
111
- <PropertiesTable
112
- content={[
113
- {
114
- name: "apiToken",
115
- type: "string",
116
- description: "Your Cloudflare API token.",
117
- isOptional: false,
118
- },
119
- {
120
- name: "apiEmail",
121
- type: "string",
122
- description: "Your Cloudflare account email.",
123
- isOptional: true,
124
- },
125
- ]}
126
- />
127
-
128
- ### CFRoute Object
129
-
130
- <PropertiesTable
131
- content={[
132
- {
133
- name: "pattern",
134
- type: "string",
135
- description: "URL pattern to match (e.g., 'example.com/*').",
136
- isOptional: false,
137
- },
138
- {
139
- name: "zone_name",
140
- type: "string",
141
- description: "Domain zone name.",
142
- isOptional: false,
143
- },
144
- {
145
- name: "custom_domain",
146
- type: "boolean",
147
- description: "Whether to use a custom domain.",
87
+ description: "Array of KV namespace bindings. Each binding requires: binding (string), id (string).",
148
88
  isOptional: true,
149
- defaultValue: "false",
150
- },
151
- ]}
152
- />
153
-
154
- ### D1DatabaseBinding Object
155
-
156
- <PropertiesTable
157
- content={[
158
- {
159
- name: "binding",
160
- type: "string",
161
- description: "Name used in Worker code (e.g., `env.testdb`).",
162
- isOptional: false,
163
- },
164
- {
165
- name: "database_name",
166
- type: "string",
167
- description: "Human-readable name (for dashboard).",
168
- isOptional: false,
169
- },
170
- {
171
- name: "database_id",
172
- type: "string",
173
- description: "Cloudflare D1 database ID.",
174
- isOptional: false,
175
- },
176
- {
177
- name: "preview_database_id",
178
- type: "string",
179
- description: "For preview deployments.",
180
- isOptional: true,
181
- },
182
- ]}
183
- />
184
-
185
- ### KVNamespaceBinding Object
186
-
187
- <PropertiesTable
188
- content={[
189
- {
190
- name: "binding",
191
- type: "string",
192
- description: "Name used in Worker code (e.g., `env.test_namespace`).",
193
- isOptional: false,
194
- },
195
- {
196
- name: "id",
197
- type: "string",
198
- description: "Cloudflare KV namespace ID.",
199
- isOptional: false,
200
89
  },
201
90
  ]}
202
91
  />
@@ -291,7 +291,7 @@ Mastra supports many embedding models through the [Vercel AI SDK](https://sdk.ve
291
291
  },
292
292
  {
293
293
  name: "threads",
294
- type: "{ generateTitle?: boolean | { model: LanguageModelV1 | ((ctx: RuntimeContext) => LanguageModelV1 | Promise<LanguageModelV1>), instructions?: string | ((ctx: RuntimeContext) => string | Promise<string>) } }",
294
+ type: "{ generateTitle?: boolean | { model: MastraLanguageModel | ((ctx: RuntimeContext) => MastraLanguageModel | Promise<MastraLanguageModel>), instructions?: string | ((ctx: RuntimeContext) => string | Promise<string>) } }",
295
295
  description:
296
296
  "Settings related to memory thread creation. `generateTitle` 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 or custom instructions for title generation (useful for cost optimization or title customization). Example: { generateTitle: { model: openai('gpt-4.1-nano'), instructions: 'Concise title based on the initial user message.' } }",
297
297
  isOptional: true,