@mastra/mcp-docs-server 0.13.32 → 0.13.33

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 (29) hide show
  1. package/.docs/organized/changelogs/%40internal%2Fchangeset-cli.md +2 -0
  2. package/.docs/organized/changelogs/%40internal%2Fexternal-types.md +2 -0
  3. package/.docs/organized/changelogs/%40internal%2Fstorage-test-utils.md +9 -9
  4. package/.docs/organized/changelogs/%40internal%2Ftypes-builder.md +2 -0
  5. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +15 -15
  6. package/.docs/organized/changelogs/%40mastra%2Fcore.md +5 -5
  7. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +17 -17
  8. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloudflare.md +17 -17
  9. package/.docs/organized/changelogs/%40mastra%2Fdeployer-netlify.md +17 -17
  10. package/.docs/organized/changelogs/%40mastra%2Fdeployer-vercel.md +17 -17
  11. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +21 -21
  12. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +15 -15
  13. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +27 -27
  14. package/.docs/organized/changelogs/%40mastra%2Freact.md +14 -0
  15. package/.docs/organized/changelogs/%40mastra%2Fserver.md +19 -19
  16. package/.docs/organized/changelogs/create-mastra.md +5 -5
  17. package/.docs/organized/changelogs/mastra.md +21 -21
  18. package/.docs/raw/deployment/cloud-providers/aws-lambda.mdx +1 -1
  19. package/.docs/raw/getting-started/project-structure.mdx +48 -45
  20. package/.docs/raw/getting-started/studio.mdx +158 -0
  21. package/.docs/raw/reference/workflows/step.mdx +1 -1
  22. package/.docs/raw/tools-mcp/overview.mdx +2 -2
  23. package/.docs/raw/workflows/agents-and-tools.mdx +131 -0
  24. package/.docs/raw/workflows/overview.mdx +15 -13
  25. package/CHANGELOG.md +14 -0
  26. package/package.json +5 -5
  27. package/.docs/organized/code-examples/agent.md +0 -1387
  28. package/.docs/raw/server-db/local-dev-playground.mdx +0 -233
  29. package/.docs/raw/workflows/using-with-agents-and-tools.mdx +0 -350
@@ -1,233 +0,0 @@
1
- ---
2
- title: "Inspecting agents and workflows with mastra dev | Mastra Local Dev Docs"
3
- description: Documentation for the Mastra local development environment for Mastra applications.
4
- ---
5
-
6
- import YouTube from "@/components/youtube";
7
- import { VideoPlayer } from "@/components/video-player"
8
- import { Tabs, Tab } from "@/components/tabs";
9
-
10
- # Playground
11
-
12
- Mastra provides a local development environment where you can test your agents, workflows, and tools during development.
13
-
14
- Start the local development server by running:
15
-
16
- <Tabs items={["npm", "yarn", "pnpm", "bun", "Mastra CLI"]}>
17
- <Tab>
18
- ```bash copy
19
- npm run dev
20
- ```
21
- </Tab>
22
- <Tab>
23
- ```bash copy
24
- yarn run dev
25
- ```
26
- </Tab>
27
- <Tab>
28
- ```bash copy
29
- pnpm run dev
30
- ```
31
- </Tab>
32
- <Tab>
33
- ```bash copy
34
- bun run dev
35
- ```
36
- </Tab>
37
- <Tab>
38
- ```bash copy
39
- mastra dev
40
- ```
41
- </Tab>
42
- </Tabs>
43
-
44
- The local development server provides access to the following interfaces:
45
-
46
- - Playground: [http://localhost:4111/](http://localhost:4111/)
47
- - Mastra API: [http://localhost:4111/api](http://localhost:4111/api)
48
- - OpenAPI Spec: [http://localhost:4111/openapi.json](http://localhost:4111/openapi.json)
49
- - Swagger UI – API explorer: [http://localhost:4111/swagger-ui](http://localhost:4111/swagger-ui)
50
-
51
- ## Local Development Playground
52
-
53
- The Playground lets you interact with your agents, workflows, and tools. It provides dedicated interfaces for testing each component of your Mastra application during development and is available at: [http://localhost:4111/](http://localhost:4111/).
54
-
55
- <YouTube id="spGlcTEjuXY" startTime={126}/>
56
-
57
- ### Agents
58
-
59
- Quickly test and debug your agents during development using the interactive chat interface in the Agent Playground.
60
-
61
- <VideoPlayer
62
- src="https://res.cloudinary.com/mastra-assets/video/upload/v1751406022/local-dev-agents-playground_100_m3begx.mp4"
63
- />
64
-
65
- Key features:
66
-
67
- - **Chat Interface**: Talk to your agent and see how it responds in real time.
68
- - **Model Settings**: Tweak settings like temperature and top-p to see how they affect output.
69
- - **Agent Endpoints**: See the available REST API routes your agent exposes and how to use them.
70
- - **Agent Traces**: Step through what the agent did behind the scenes, tool calls, decisions, and more.
71
- - **Agent Evals**: Run tests against your agent and see how well it performs.
72
-
73
- ### Workflows
74
-
75
- Validate workflows by supplying defined inputs and visualizing each step within the Workflow Playground.
76
-
77
- <VideoPlayer
78
- src="https://res.cloudinary.com/mastra-assets/video/upload/v1751406027/local-dev-workflows-playground_100_rbc466.mp4"
79
- />
80
-
81
- Key features:
82
-
83
- - **Workflow Visualization**: See your workflow as a visual graph so you can follow the steps and branches at a glance.
84
- - **Step Inputs & Outputs**: Check the data going into and coming out of each step to see how everything flows.
85
- - **Run Workflows**: Test your workflow with real inputs to validate the logic and debug any issues.
86
- - **Execution JSON**: Get the full picture of a run as raw JSON—inputs, outputs, errors, and results included.
87
- - **Workflow Traces**: Dig into a detailed breakdown of each step, including data flow, tool calls, and any errors along the way.
88
-
89
- ### Tools
90
-
91
- Quickly test and debug custom tools in isolation using the Tools Playground, without running a full agent or workflow.
92
-
93
- <VideoPlayer
94
- src="https://res.cloudinary.com/mastra-assets/video/upload/v1751406316/local-dev-agents-tools_100_fe1jdt.mp4"
95
- />
96
-
97
- Key features:
98
-
99
- - **Test Tools in Isolation**: Try out individual tools on their own without running a full agent or workflow.
100
- - **Input & Responses**: Send sample inputs to see how the tool responds.
101
- - **Tool Usage**: Find out which agents rely on this tool and how they’re using it.
102
-
103
-
104
- ### MCP Servers
105
-
106
- Explore connection details, tool usage, and IDE configuration for local MCP server development.
107
-
108
- ![MCP Servers Playground](/image/local-dev/local-dev-mcp-server-playground.jpg)
109
-
110
- Key features:
111
-
112
- - **Connection Details**: Access the endpoints and config needed to wire up your MCP environment.
113
- - **Available Tools**: See all tools currently published, including their names, versions, and which agents use them.
114
- - **IDE Configuration**: Grab ready-to-use config you can drop into your local setup for testing and publishing tools.
115
-
116
-
117
- ## REST API Endpoints
118
-
119
- The local development server exposes a set of REST API routes via the [Mastra Server](/docs/deployment/server-deployment), allowing you to test and interact with your agents and workflows before deployment.
120
-
121
- For a full overview of available API routes, including agents, tools, and workflows, visit [http://localhost:4111/swagger-ui](http://localhost:4111/swagger-ui) during `mastra dev`.
122
-
123
- ## OpenAPI Specification
124
-
125
- The local development server includes an OpenAPI specification available at: [http://localhost:4111/openapi.json](http://localhost:4111/openapi.json).
126
-
127
- To include OpenAPI documentation in your production server, enable it in the Mastra instance:
128
-
129
- ```typescript {6} filename="src/mastra/index.ts" copy
130
- import { Mastra } from "@mastra/core/mastra";
131
-
132
- export const mastra = new Mastra({
133
- server: {
134
- build: {
135
- openAPIDocs: true
136
- }
137
- },
138
- });
139
- ```
140
-
141
- ## Swagger UI
142
-
143
- The local development server includes an interactive Swagger UI - API explorer available at: [http://localhost:4111/swagger-ui](http://localhost:4111/swagger-ui).
144
-
145
- To include Swagger UI in your production server, enable it in the Mastra instance:
146
-
147
- ```typescript {6} filename="src/mastra/index.ts" copy
148
- import { Mastra } from "@mastra/core/mastra";
149
-
150
- export const mastra = new Mastra({
151
- server: {
152
- build: {
153
- swaggerUI: true
154
- },
155
- },
156
- });
157
- ```
158
-
159
- ## Architecture
160
-
161
- The local development server runs fully self-contained without external dependencies or containers. It leverages:
162
-
163
- - **Dev Server** powered by [Hono](https://hono.dev) for the core [Mastra Server](/docs/deployment/server).
164
- - **In-Memory Storage** via [LibSQL](https://libsql.org/) adapters for agent memory, traces, evals, and workflow snapshots.
165
- - **Vector Storage** using [FastEmbed](https://github.com/qdrant/fastembed) for embeddings, vector search, and semantic retrieval.
166
-
167
- This setup lets you start developing immediately with production-like behavior, no database or vector store setup required.
168
-
169
- ## Configuration
170
-
171
- By default, the server runs on port `4111`. You can customize the `host` and `port` through the Mastra server configuration.
172
-
173
- ```typescript {5,6} filename="src/mastra/index.ts" copy
174
- import { Mastra } from "@mastra/core/mastra";
175
-
176
- export const mastra = new Mastra({
177
- server: {
178
- port: 8080,
179
- host: "0.0.0.0",
180
- },
181
- });
182
- ```
183
-
184
- ### Local HTTPS
185
-
186
- Mastra provides a way to use a local HTTPS server for `mastra dev` (through [expo/devcert](https://github.com/expo/devcert)). When you use the `--https` flag, a private key and certificate will be created and used for your project. By default, certificates are issued for `localhost` unless you defined another `host` value.
187
-
188
- ```bash
189
- mastra dev --https
190
- ```
191
-
192
- You can provide your own key and cert file by specifying the `server.https` option in the Mastra server configuration.
193
-
194
- ```typescript {2,6-9} filename="src/mastra/index.ts" copy
195
- import { Mastra } from "@mastra/core/mastra";
196
- import fs from 'node:fs'
197
-
198
- export const mastra = new Mastra({
199
- server: {
200
- https: {
201
- key: fs.readFileSync('path/to/key.pem'),
202
- cert: fs.readFileSync('path/to/cert.pem')
203
- }
204
- },
205
- });
206
- ```
207
-
208
- When you provide both `--https` and `server.https` the latter will take precedence.
209
-
210
- ## Bundler options
211
-
212
- Use `transpilePackages` to compile TypeScript packages or libraries. Use `externals` to exclude dependencies resolved at runtime, and `sourcemap` to emit readable stack traces.
213
-
214
- ```typescript filename="src/mastra/index.ts" copy
215
- import { Mastra } from "@mastra/core/mastra";
216
-
217
- export const mastra = new Mastra({
218
- bundler: {
219
- transpilePackages: ["utils"],
220
- externals: ["ui"],
221
- sourcemap: true
222
- }
223
- });
224
- ```
225
-
226
- > See [Mastra Class](../../reference/core/mastra-class.mdx) for more configuration options.
227
-
228
-
229
- ## Next steps
230
-
231
- - [Mastra Cloud](/docs/mastra-cloud/overview)
232
- - [Deployment Overview](/docs/deployment/overview)
233
- - [Mastra Client SDK](/docs/client-js/overview)
@@ -1,350 +0,0 @@
1
- ---
2
- title: "Using Workflows with Agents and Tools | Workflows | Mastra Docs"
3
- description: "Steps in Mastra workflows provide a structured way to manage operations by defining inputs, outputs, and execution logic."
4
- ---
5
-
6
- # Agents and Tools
7
-
8
- Workflow steps are composable and typically run logic directly within the `execute` function. However, there are cases where calling an agent or tool is more appropriate. This pattern is especially useful when:
9
-
10
- - Generating natural language responses from user input using an LLM.
11
- - Abstracting complex or reusable logic into a dedicated tool.
12
- - Interacting with third-party APIs in a structured or reusable way.
13
-
14
- Workflows can use Mastra agents or tools directly as steps, for example: `createStep(testAgent)` or `createStep(testTool)`.
15
-
16
- ## Using agents in workflows
17
-
18
- To include an agent in a workflow, define it in the usual way, then either add it directly to the workflow using `createStep(testAgent)` or, invoke it from within a step's `execute` function using `.generate()`.
19
-
20
- ### Example agent
21
-
22
- This agent uses OpenAI to generate a fact about a city, country, and timezone.
23
-
24
- ```typescript filename="src/mastra/agents/test-agent.ts" showLineNumbers copy
25
- import { openai } from "@ai-sdk/openai";
26
- import { Agent } from "@mastra/core/agent";
27
-
28
- export const testAgent = new Agent({
29
- name: "test-agent",
30
- description: "Create facts for a country based on the city",
31
- instructions: `Return an interesting fact about the country based on the city provided`,
32
- model: openai("gpt-4o")
33
- });
34
- ```
35
-
36
- ### Adding an agent as a step
37
-
38
- In this example, `step1` uses the `testAgent` to generate an interesting fact about the country based on a given city.
39
-
40
- The `.map` method transforms the workflow input into a `prompt` string compatible with the `testAgent`.
41
-
42
- The step is composed into the workflow using `.then()`, allowing it to receive the mapped input and return the agent's structured output. The workflow is finalized with `.commit()`.
43
-
44
-
45
- ![Agent as step](/image/workflows/workflows-agent-tools-agent-step.jpg)
46
-
47
-
48
- ```typescript {3} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
49
- import { testAgent } from "../agents/test-agent";
50
-
51
- const step1 = createStep(testAgent);
52
-
53
- export const testWorkflow = createWorkflow({
54
- id: "test-workflow",
55
- description: 'Test workflow',
56
- inputSchema: z.object({
57
- input: z.string()
58
- }),
59
- outputSchema: z.object({
60
- output: z.string()
61
- })
62
- })
63
- .map(({ inputData }) => {
64
- const { input } = inputData;
65
- return {
66
- prompt: `Provide facts about the city: ${input}`
67
- };
68
- })
69
- .then(step1)
70
- .commit();
71
- ```
72
-
73
- ### Calling an agent with `.generate()`
74
-
75
- In this example, the `step1` builds a prompt using the provided `input` and passes it to the `testAgent`, which returns a plain-text response containing facts about the city and its country.
76
-
77
- The step is added to the workflow using the sequential `.then()` method, allowing it to receive input from the workflow and return structured output. The workflow is finalized with `.commit()`.
78
-
79
- ```typescript {1,18, 29} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
80
- import { testAgent } from "../agents/test-agent";
81
-
82
- const step1 = createStep({
83
- id: "step-1",
84
- description: "Create facts for a country based on the city",
85
- inputSchema: z.object({
86
- input: z.string()
87
- }),
88
- outputSchema: z.object({
89
- output: z.string()
90
- }),
91
-
92
- execute: async ({ inputData }) => {
93
- const { input } = inputData;
94
-
95
- const prompt = `Provide facts about the city: ${input}`
96
-
97
- const { text } = await testAgent.generate([
98
- { role: "user", content: prompt }
99
- ]);
100
-
101
- return {
102
- output: text
103
- };
104
- }
105
- });
106
-
107
- export const testWorkflow = createWorkflow({...})
108
- .then(step1)
109
- .commit();
110
- ```
111
-
112
- ## Using tools in workflows
113
-
114
- To use a tool within a workflow, define it in the usual way, then either add it directly to the workflow using `createStep(testTool)` or, invoke it from within a step's `execute` function using `.execute()`.
115
-
116
- ### Example tool
117
-
118
- The example below uses the Open Meteo API to retrieve geolocation details for a city, returning its name, country, and timezone.
119
-
120
- ```typescript filename="src/mastra/tools/test-tool.ts" showLineNumbers copy
121
- import { createTool } from "@mastra/core";
122
- import { z } from "zod";
123
-
124
- export const testTool = createTool({
125
- id: "test-tool",
126
- description: "Gets country for a city",
127
- inputSchema: z.object({
128
- input: z.string()
129
- }),
130
- outputSchema: z.object({
131
- country_name: z.string()
132
- }),
133
- execute: async ({ context }) => {
134
- const { input } = context;
135
- const geocodingResponse = await fetch(`https://geocoding-api.open-meteo.com/v1/search?name=${input}`);
136
- const geocodingData = await geocodingResponse.json();
137
-
138
- const { country } = geocodingData.results[0];
139
-
140
- return {
141
- country_name: country
142
- };
143
- }
144
- });
145
- ```
146
-
147
- ### Adding a tool as a step
148
-
149
- In this example, `step1` uses the `testTool`, which performs a geocoding lookup using the provided `city` and returns the resolved `country`.
150
-
151
- The step is added to the workflow using the sequential `.then()` method, allowing it to receive input from the workflow and return structured output. The workflow is finalized with `.commit()`.
152
-
153
- ![Tool as step](/image/workflows/workflows-agent-tools-tool-step.jpg)
154
-
155
- ```typescript {1,3,6} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
156
- import { testTool } from "../tools/test-tool";
157
-
158
- const step1 = createStep(testTool);
159
-
160
- export const testWorkflow = createWorkflow({...})
161
- .then(step1)
162
- .commit();
163
- ```
164
-
165
- ### Calling a tool with `.execute()`
166
-
167
- In this example, `step1` directly invokes `testTool` using its `.execute()` method. The tool performs a geocoding lookup with the provided `city` and returns the corresponding `country`.
168
-
169
- The result is returned as structured output from the step. The step is composed into the workflow using `.then()`, enabling it to process workflow input and produce typed output. The workflow is finalized with `.commit()`
170
-
171
- ```typescript {3,20,32} filename="src/mastra/workflows/test-workflow.ts" showLineNumbers copy
172
- import { RuntimeContext } from "@mastra/core/di";
173
-
174
- import { testTool } from "../tools/test-tool";
175
-
176
- const runtimeContext = new RuntimeContext();
177
-
178
- const step1 = createStep({
179
- id: "step-1",
180
- description: "Gets country for a city",
181
- inputSchema: z.object({
182
- input: z.string()
183
- }),
184
- outputSchema: z.object({
185
- output: z.string()
186
- }),
187
-
188
- execute: async ({ inputData }) => {
189
- const { input } = inputData;
190
-
191
- const { country_name } = await testTool.execute({
192
- context: { input },
193
- runtimeContext
194
- });
195
-
196
- return {
197
- output: country_name
198
- };
199
- }
200
- });
201
-
202
- export const testWorkflow = createWorkflow({...})
203
- .then(step1)
204
- .commit();
205
- ```
206
-
207
- ## Using workflows as tools
208
-
209
- In this example the `cityStringWorkflow` workflow has been added to the main Mastra instance.
210
-
211
-
212
- ```typescript {7} filename="src/mastra/index.ts" showLineNumbers copy
213
- import { Mastra } from "@mastra/core/mastra";
214
-
215
- import { testWorkflow, cityStringWorkflow } from "./workflows/test-workflow";
216
-
217
- export const mastra = new Mastra({
218
- ...
219
- workflows: { testWorkflow, cityStringWorkflow },
220
- });
221
- ```
222
-
223
- Once a workflow has been registered it can be referenced using `getWorkflow` from withing a tool.
224
-
225
- ```typescript {10,17-27} filename="src/mastra/tools/test-tool.ts" showLineNumbers copy
226
- export const cityCoordinatesTool = createTool({
227
- id: "city-tool",
228
- description: "Convert city details",
229
- inputSchema: z.object({
230
- city: z.string()
231
- }),
232
- outputSchema: z.object({
233
- outcome: z.string()
234
- }),
235
- execute: async ({ context, mastra }) => {
236
- const { city } = context;
237
- const geocodingResponse = await fetch(`https://geocoding-api.open-meteo.com/v1/search?name=${city}`);
238
- const geocodingData = await geocodingResponse.json();
239
-
240
- const { name, country, timezone } = geocodingData.results[0];
241
-
242
- const workflow = mastra?.getWorkflow("cityStringWorkflow");
243
-
244
- const run = await workflow?.createRunAsync();
245
-
246
- const { result } = await run?.start({
247
- inputData: {
248
- city_name: name,
249
- country_name: country,
250
- country_timezone: timezone
251
- }
252
- });
253
-
254
- return {
255
- outcome: result.outcome
256
- };
257
- }
258
- });
259
- ```
260
-
261
- ## Using workflows in agents
262
-
263
- You can also use Workflows in Agents. This agent is able to choose between using the test tool or the test workflow.
264
-
265
- ```typescript
266
- import { openai } from "@ai-sdk/openai";
267
- import { Agent } from "@mastra/core/agent";
268
- import { testTool } from "../tools/test-tool";
269
- import { testWorkflow } from "../workflows/test-workflow";
270
-
271
- export const testAgent = new Agent({
272
- name: "test-agent",
273
- description: "Create facts for a country based on the city",
274
- instructions: `Return an interesting fact about the country based on the city provided`,
275
- model: openai("gpt-4o"),
276
- workflows: {
277
- test_workflow: testWorkflow
278
- },
279
- tools: {
280
- test_tool: testTool
281
- },
282
- });
283
- ```
284
-
285
-
286
- ## Exposing workflows with `MCPServer`
287
-
288
- You can convert your workflows into tools by passing them into an instance of a Mastra `MCPServer`. This allows any MCP-compatible client to access your workflow.
289
-
290
- The workflow description becomes the tool description and the input schema becomes the tool's input schema.
291
-
292
- When you provide workflows to the server, each workflow is automatically exposed as a callable tool for example:
293
-
294
- - `run_testWorkflow`.
295
-
296
- ```typescript filename="src/test-mcp-server.ts" showLineNumbers copy
297
- import { MCPServer } from "@mastra/mcp";
298
-
299
- import { testAgent } from "./mastra/agents/test-agent";
300
- import { testTool } from "./mastra/tools/test-tool";
301
- import { testWorkflow } from "./mastra/workflows/test-workflow";
302
-
303
- async function startServer() {
304
- const server = new MCPServer({
305
- name: "test-mcp-server",
306
- version: "1.0.0",
307
- workflows: {
308
- testWorkflow
309
- }
310
- });
311
-
312
- await server.startStdio();
313
- console.log("MCPServer started on stdio");
314
- }
315
-
316
- startServer().catch(console.error);
317
- ```
318
-
319
- To verify that your workflow is available on the server, you can connect with an MCPClient.
320
-
321
- ```typescript filename="src/test-mcp-client.ts" showLineNumbers copy
322
- import { MCPClient } from "@mastra/mcp";
323
-
324
- async function main() {
325
- const mcp = new MCPClient({
326
- servers: {
327
- local: {
328
- command: "npx",
329
- args: ["tsx", "src/test-mcp-server.ts"]
330
- }
331
- }
332
- });
333
-
334
- const tools = await mcp.getTools();
335
- console.log(tools);
336
- }
337
-
338
- main().catch(console.error);
339
- ```
340
-
341
- Run the client script to see your workflow tool.
342
-
343
- ```bash
344
- npx tsx src/test-mcp-client.ts
345
- ```
346
-
347
- ## More resources
348
-
349
- - [MCPServer reference documentation](/reference/tools/mcp-server).
350
- - [MCPClient reference documentation](/reference/tools/mcp-client).