@mastra/mcp-docs-server 0.13.19-alpha.0 → 0.13.19-alpha.2

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 (81) hide show
  1. package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +9 -0
  2. package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +21 -21
  3. package/.docs/organized/changelogs/%40mastra%2Fcloud.md +10 -10
  4. package/.docs/organized/changelogs/%40mastra%2Fcore.md +31 -31
  5. package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +16 -0
  6. package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +19 -19
  7. package/.docs/organized/changelogs/%40mastra%2Fdynamodb.md +11 -11
  8. package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +18 -18
  9. package/.docs/organized/changelogs/%40mastra%2Fmcp-registry-registry.md +10 -10
  10. package/.docs/organized/changelogs/%40mastra%2Fmcp.md +10 -10
  11. package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +13 -13
  12. package/.docs/organized/changelogs/%40mastra%2Fserver.md +19 -19
  13. package/.docs/organized/changelogs/create-mastra.md +7 -7
  14. package/.docs/organized/changelogs/mastra.md +14 -14
  15. package/.docs/organized/code-examples/ai-sdk-useChat.md +1 -1
  16. package/.docs/organized/code-examples/workflow-with-suspend-resume.md +1 -0
  17. package/.docs/raw/agents/dynamic-agents.mdx +5 -5
  18. package/.docs/raw/agents/runtime-context.mdx +103 -0
  19. package/.docs/raw/auth/jwt.mdx +2 -2
  20. package/.docs/raw/auth/supabase.mdx +128 -0
  21. package/.docs/raw/deployment/overview.mdx +7 -7
  22. package/.docs/raw/frameworks/agentic-uis/ai-sdk.mdx +1 -1
  23. package/.docs/raw/getting-started/mcp-docs-server.mdx +52 -48
  24. package/.docs/raw/memory/overview.mdx +2 -2
  25. package/.docs/raw/reference/agents/getDefaultGenerateOptions.mdx +1 -1
  26. package/.docs/raw/reference/agents/getDefaultStreamOptions.mdx +1 -1
  27. package/.docs/raw/reference/agents/getDefaultVNextStreamOptions.mdx +1 -1
  28. package/.docs/raw/reference/agents/getInstructions.mdx +1 -1
  29. package/.docs/raw/reference/agents/getLLM.mdx +1 -1
  30. package/.docs/raw/reference/agents/getMemory.mdx +1 -1
  31. package/.docs/raw/reference/agents/getModel.mdx +1 -1
  32. package/.docs/raw/reference/agents/getScorers.mdx +1 -1
  33. package/.docs/raw/reference/agents/streamVNext.mdx +120 -29
  34. package/.docs/raw/reference/auth/jwt.mdx +2 -3
  35. package/.docs/raw/reference/auth/supabase.mdx +62 -0
  36. package/.docs/raw/reference/{agents → core}/getAgent.mdx +1 -2
  37. package/.docs/raw/reference/core/getAgentById.mdx +43 -0
  38. package/.docs/raw/reference/core/getAgents.mdx +35 -0
  39. package/.docs/raw/reference/core/getDeployer.mdx +35 -0
  40. package/.docs/raw/reference/core/getLogger.mdx +35 -0
  41. package/.docs/raw/reference/core/getLogs.mdx +92 -0
  42. package/.docs/raw/reference/core/getLogsByRunId.mdx +84 -0
  43. package/.docs/raw/reference/core/getMCPServer.mdx +49 -0
  44. package/.docs/raw/reference/core/getMCPServers.mdx +35 -0
  45. package/.docs/raw/reference/core/getMemory.mdx +35 -0
  46. package/.docs/raw/reference/core/getServer.mdx +35 -0
  47. package/.docs/raw/reference/core/getStorage.mdx +35 -0
  48. package/.docs/raw/reference/core/getTelemetry.mdx +35 -0
  49. package/.docs/raw/reference/core/getVector.mdx +43 -0
  50. package/.docs/raw/reference/core/getVectors.mdx +35 -0
  51. package/.docs/raw/reference/core/getWorkflow.mdx +49 -0
  52. package/.docs/raw/reference/core/getWorkflows.mdx +44 -0
  53. package/.docs/raw/reference/core/mastra-class.mdx +14 -178
  54. package/.docs/raw/reference/core/setLogger.mdx +47 -0
  55. package/.docs/raw/reference/core/setStorage.mdx +39 -0
  56. package/.docs/raw/reference/core/setTelemetry.mdx +35 -0
  57. package/.docs/raw/reference/tools/create-tool.mdx +1 -1
  58. package/.docs/raw/reference/tools/graph-rag-tool.mdx +2 -2
  59. package/.docs/raw/reference/tools/vector-query-tool.mdx +2 -2
  60. package/.docs/raw/tools-mcp/runtime-context.mdx +63 -0
  61. package/.docs/raw/workflows/control-flow.mdx +2 -2
  62. package/.docs/raw/workflows/overview.mdx +8 -8
  63. package/.docs/raw/workflows/suspend-and-resume.mdx +4 -4
  64. package/CHANGELOG.md +17 -0
  65. package/package.json +5 -5
  66. package/.docs/raw/agents/runtime-variables.mdx +0 -116
  67. package/.docs/raw/reference/workflows/execute.mdx +0 -131
  68. package/.docs/raw/tools-mcp/dynamic-context.mdx +0 -131
  69. /package/.docs/raw/reference/workflows/{branch.mdx → workflow-methods/branch.mdx} +0 -0
  70. /package/.docs/raw/reference/workflows/{commit.mdx → workflow-methods/commit.mdx} +0 -0
  71. /package/.docs/raw/reference/workflows/{create-run.mdx → workflow-methods/create-run.mdx} +0 -0
  72. /package/.docs/raw/reference/workflows/{dountil.mdx → workflow-methods/dountil.mdx} +0 -0
  73. /package/.docs/raw/reference/workflows/{dowhile.mdx → workflow-methods/dowhile.mdx} +0 -0
  74. /package/.docs/raw/reference/workflows/{foreach.mdx → workflow-methods/foreach.mdx} +0 -0
  75. /package/.docs/raw/reference/workflows/{map.mdx → workflow-methods/map.mdx} +0 -0
  76. /package/.docs/raw/reference/workflows/{parallel.mdx → workflow-methods/parallel.mdx} +0 -0
  77. /package/.docs/raw/reference/workflows/{sendEvent.mdx → workflow-methods/sendEvent.mdx} +0 -0
  78. /package/.docs/raw/reference/workflows/{sleep.mdx → workflow-methods/sleep.mdx} +0 -0
  79. /package/.docs/raw/reference/workflows/{sleepUntil.mdx → workflow-methods/sleepUntil.mdx} +0 -0
  80. /package/.docs/raw/reference/workflows/{then.mdx → workflow-methods/then.mdx} +0 -0
  81. /package/.docs/raw/reference/workflows/{waitForEvent.mdx → workflow-methods/waitForEvent.mdx} +0 -0
@@ -93,5 +93,5 @@ The `createTool()` function returns a `Tool` object.
93
93
 
94
94
  - [Tools Overview](/docs/tools-mcp/overview.mdx)
95
95
  - [Using Tools with Agents](/docs/agents/using-tools-and-mcp.mdx)
96
- - [Dynamic Tool Context](/docs/tools-mcp/dynamic-context.mdx)
96
+ - [Tool Runtime Context](/docs/tools-mcp/runtime-context.mdx)
97
97
  - [Advanced Tool Usage](/docs/tools-mcp/advanced-usage.mdx)
@@ -253,8 +253,8 @@ const response = await agent.generate(
253
253
 
254
254
  For more information on runtime context, please see:
255
255
 
256
- - [Runtime Variables](../../docs/agents/runtime-variables.mdx)
257
- - [Dynamic Context](../../docs/tools-mcp/dynamic-context.mdx)
256
+ - [Agent Runtime Context](../../docs/agents/runtime-context.mdx)
257
+ - [Tool Runtime Context](../../docs/tools-mcp/runtime-context.mdx)
258
258
 
259
259
  ## Related
260
260
 
@@ -558,8 +558,8 @@ const response = await agent.generate(
558
558
 
559
559
  For more information on runtime context, please see:
560
560
 
561
- - [Runtime Variables](../../docs/agents/runtime-variables.mdx)
562
- - [Dynamic Context](../../docs/tools-mcp/dynamic-context.mdx)
561
+ - [Agent Runtime Context](../../docs/agents/runtime-context.mdx)
562
+ - [Tool Runtime Context](../../docs/tools-mcp/runtime-context.mdx)
563
563
 
564
564
  ## Usage Without a Mastra Server
565
565
 
@@ -0,0 +1,63 @@
1
+ ---
2
+ title: "Runtime context | Tools & MCP | Mastra Docs"
3
+ description: Learn how to use Mastra's RuntimeContext to provide dynamic, request-specific configuration to tools.
4
+ ---
5
+
6
+ import { Callout } from "nextra/components";
7
+
8
+ # Tool Runtime Context
9
+
10
+ Mastra provides `RuntimeContext`, a dependency injection system that lets you configure tools with runtime variables. If you find yourself creating multiple tools that perform similar tasks, runtime context allows you to consolidate them into a single, more flexible tool.
11
+
12
+ ## Overview
13
+
14
+ The dependency injection system allows you to:
15
+
16
+ 1. Pass runtime configuration variables to tools through a type-safe `runtimeContext`.
17
+ 2. Access these variables within tool execution context.
18
+ 3. Modify tool behavior without changing the underlying code.
19
+ 4. Share configuration across multiple tools within the same agent.
20
+
21
+ <Callout>
22
+ **Note:** `RuntimeContext` is primarily used for passing data *into* tool
23
+ executions. It's distinct from agent memory, which handles conversation
24
+ history and state persistence across multiple calls.
25
+ </Callout>
26
+
27
+
28
+ ## Accessing `runtimeContext` in tools
29
+
30
+ Tools can access the same `runtimeContext` used by their parent agent, allowing them to adjust behavior based on runtime configuration. In this example, the `temperature-unit` is retrieved within the tool’s `execute` function to ensure consistent formatting with the agent’s instructions.
31
+
32
+ ```typescript {14-15} filename="src/mastra/tools/test-weather-tool" showLineNumbers copy
33
+ import { createTool } from "@mastra/core/tools";
34
+ import { z } from "zod";
35
+
36
+ type WeatherRuntimeContext = {
37
+ "temperature-unit": "celsius" | "fahrenheit";
38
+ };
39
+
40
+ export const testWeatherTool = createTool({
41
+ id: "getWeather",
42
+ description: "Get the current weather for a location",
43
+ inputSchema: z.object({
44
+ location: z.string().describe("The location to get weather for")
45
+ }),
46
+ execute: async ({ context, runtimeContext }) => {
47
+ const temperatureUnit = runtimeContext.get("temperature-unit") as WeatherRuntimeContext["temperature-unit"];
48
+
49
+ const weather = await fetchWeather(context.location, temperatureUnit);
50
+
51
+ return { result: weather };
52
+ }
53
+ });
54
+
55
+ async function fetchWeather(location: string, temperatureUnit: WeatherRuntimeContext["temperature-unit"]) {
56
+ // ...
57
+ }
58
+ ```
59
+
60
+
61
+ ## Related
62
+
63
+ [Agent Runtime Context](../agents/runtime-context.mdx)
@@ -53,7 +53,7 @@ export const testWorkflow = createWorkflow({...})
53
53
 
54
54
  This executes `step1` and `step2` concurrently, then continues to `step3` after both complete.
55
55
 
56
- > See [Parallel Execution with Steps](/examples/workflows/parallel-steps) for more information.
56
+ > See [Parallel Execution with Steps](../../examples/workflows/parallel-steps.mdx) for more information.
57
57
 
58
58
  > 📹 Watch: How to run steps in parallel and optimize your Mastra workflow → [YouTube (3 minutes)](https://youtu.be/pTSOSWbreE0)
59
59
 
@@ -80,7 +80,7 @@ export const testWorkflow = createWorkflow({...})
80
80
 
81
81
  Branch conditions are evaluated sequentially, but steps with matching conditions are executed in parallel.
82
82
 
83
- > See [Workflow with Conditional Branching](/examples/workflows/conditional-branching) for more information.
83
+ > See [Workflow with Conditional Branching](../../examples/workflows/conditional-branching.mdx) for more information.
84
84
 
85
85
  ## Looping steps
86
86
 
@@ -46,7 +46,7 @@ Steps are the building blocks of workflows. Create a step using `createStep`:
46
46
  const step1 = createStep({...});
47
47
  ```
48
48
 
49
- > See [createStep](/reference/workflows/step) for more information.
49
+ > See [createStep](../../reference/workflows/step.mdx) for more information.
50
50
 
51
51
  ### Create workflow
52
52
 
@@ -72,7 +72,7 @@ export const testWorkflow = createWorkflow({
72
72
  .commit();
73
73
  ```
74
74
 
75
- > See [workflow](/reference/workflows/workflow) for more information.
75
+ > See [workflow](../../reference/workflows/workflow.mdx) for more information.
76
76
 
77
77
  #### Composing steps
78
78
 
@@ -100,7 +100,7 @@ export const testWorkflow = createWorkflow({
100
100
  .commit();
101
101
  ```
102
102
 
103
- > Steps can be composed using a number of different methods. See [Control Flow](/docs/workflows/control-flow) for more information.
103
+ > Steps can be composed using a number of different methods. See [Control Flow](./control-flow.mdx) for more information.
104
104
 
105
105
  #### Cloning steps
106
106
 
@@ -163,7 +163,7 @@ There are two ways to run and test workflows.
163
163
 
164
164
  With the Mastra Dev Server running you can run the workflow from the Mastra Playground by visiting [http://localhost:4111/workflows](http://localhost:4111/workflows) in your browser.
165
165
 
166
- > For more information, see the [Local Dev Playground](/docs/server-db/local-dev-playground) documentation.
166
+ > For more information, see the [Local Dev Playground](../server-db/local-dev-playground.mdx) documentation.
167
167
 
168
168
  ### Command line
169
169
 
@@ -188,7 +188,7 @@ if (result.status === 'success') {
188
188
  console.log(result.result.output);
189
189
  }
190
190
  ```
191
- > see [createRunAsync](../../reference/workflows/create-run.mdx) and [start](../../reference/workflows/run-methods/start.mdx) for more information.
191
+ > see [createRunAsync](../../reference/workflows/run.mdx) and [start](../../reference/workflows/run-methods/start.mdx) for more information.
192
192
 
193
193
  To trigger this workflow, run the following:
194
194
 
@@ -286,7 +286,7 @@ for await (const chunk of result.stream) {
286
286
  }
287
287
  ```
288
288
 
289
- > See [stream](/reference/workflows/run-methods/stream) and [messages](/reference/workflows/run-methods/stream#messages) for more information.
289
+ > See [stream](../../reference/workflows/run-methods/stream.mdx) for more information.
290
290
 
291
291
  ## Watch Workflow
292
292
 
@@ -308,7 +308,7 @@ const result = await run.start({
308
308
  });
309
309
  ```
310
310
 
311
- > See [watch](/reference/workflows/run-methods/watch) for more information.
311
+ > See [watch](../../reference/workflows/run-methods/watch.mdx) for more information.
312
312
 
313
313
  ## Related
314
314
 
@@ -321,5 +321,5 @@ const result = await run.start({
321
321
 
322
322
  ## Workflows (Legacy)
323
323
 
324
- For legacy workflow documentation, see [Workflows (Legacy)](/docs/workflows-legacy/overview).
324
+ For legacy workflow documentation, see [Workflows (Legacy)](../workflows-legacy/overview.mdx).
325
325
 
@@ -60,7 +60,7 @@ export const testWorkflow = createWorkflow({
60
60
  .commit();
61
61
  ```
62
62
 
63
- > For more details, check out the [Suspend workflow example](/examples/workflows/human-in-the-loop#suspend-workflow).
63
+ > For more details, check out the [Suspend workflow example](../../examples/workflows/human-in-the-loop.mdx#suspend-workflow).
64
64
 
65
65
  ### Identifying suspended steps
66
66
 
@@ -89,8 +89,6 @@ if (result.status === "suspended") {
89
89
  }
90
90
  ```
91
91
 
92
- > See [Run Workflow Results](/docs/workflows/overview#run-workflow-results) for more details.
93
-
94
92
  In this case, the logic resumes the first step listed in the `suspended` array. A `step` can also be defined using it's `id`, for example: 'step-1'.
95
93
 
96
94
  ```json
@@ -111,6 +109,8 @@ In this case, the logic resumes the first step listed in the `suspended` array.
111
109
  }
112
110
  ```
113
111
 
112
+ > See [Run Workflow Results](./overview.mdx#run-workflow-results) for more details.
113
+
114
114
  ## Providing user feedback with suspend
115
115
 
116
116
  When a workflow is suspended, feedback can be surfaced to the user through the `suspendSchema`. Include a reason in the `suspend` payload to explain why the workflow paused.
@@ -168,7 +168,7 @@ In this case, the reason provided explains that the user must confirm to continu
168
168
  }
169
169
  ```
170
170
 
171
- > See [Run Workflow Results](/docs/workflows/overview#run-workflow-results) for more details.
171
+ > See [Run Workflow Results](./overview.mdx#run-workflow-results) for more details.
172
172
 
173
173
  ## Resuming a workflow with `resume()`
174
174
 
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @mastra/mcp-docs-server
2
2
 
3
+ ## 0.13.19-alpha.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`827d876`](https://github.com/mastra-ai/mastra/commit/827d8766f36a900afcaf64a040f7ba76249009b3), [`7eaf1d1`](https://github.com/mastra-ai/mastra/commit/7eaf1d1cec7e828d7a98efc2a748ac395bbdba3b), [`f3427cd`](https://github.com/mastra-ai/mastra/commit/f3427cdaf9eecd63360dfc897a4acbf5f4143a4e), [`05f13b8`](https://github.com/mastra-ai/mastra/commit/05f13b8fb269ccfc4de98e9db58dbe16eae55a5e)]:
8
+ - @mastra/core@0.16.1-alpha.2
9
+
10
+ ## 0.13.19-alpha.1
11
+
12
+ ### Patch Changes
13
+
14
+ - dependencies updates: ([#7527](https://github.com/mastra-ai/mastra/pull/7527))
15
+ - Updated dependency [`@modelcontextprotocol/sdk@^1.17.5` ↗︎](https://www.npmjs.com/package/@modelcontextprotocol/sdk/v/1.17.5) (from `^1.17.3`, in `dependencies`)
16
+ - Updated dependencies [[`0f7b8c0`](https://github.com/mastra-ai/mastra/commit/0f7b8c0c22d2a677a0f71c35ad1bc2d60b063d39), [`47b6dc9`](https://github.com/mastra-ai/mastra/commit/47b6dc94f4976d4f3d3882e8f19eb365bbc5976c), [`565d65f`](https://github.com/mastra-ai/mastra/commit/565d65fc16314a99f081975ec92f2636dff0c86d), [`4da3d68`](https://github.com/mastra-ai/mastra/commit/4da3d68a778e5c4d5a17351ef223289fe2f45a45), [`0b0bbb2`](https://github.com/mastra-ai/mastra/commit/0b0bbb24f4198ead69792e92b68a350f52b45cf3), [`d951f41`](https://github.com/mastra-ai/mastra/commit/d951f41771e4e5da8da4b9f870949f9509e38756), [`8049e2e`](https://github.com/mastra-ai/mastra/commit/8049e2e8cce80a00353c64894c62b695ac34e35e)]:
17
+ - @mastra/mcp@0.12.0-alpha.1
18
+ - @mastra/core@0.16.1-alpha.1
19
+
3
20
  ## 0.13.19-alpha.0
4
21
 
5
22
  ### Patch Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mastra/mcp-docs-server",
3
- "version": "0.13.19-alpha.0",
3
+ "version": "0.13.19-alpha.2",
4
4
  "description": "MCP server for accessing Mastra.ai documentation, changelogs, and news.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -25,7 +25,7 @@
25
25
  "author": "",
26
26
  "license": "Apache-2.0",
27
27
  "dependencies": {
28
- "@modelcontextprotocol/sdk": "^1.17.3",
28
+ "@modelcontextprotocol/sdk": "^1.17.5",
29
29
  "date-fns": "^4.1.0",
30
30
  "exit-hook": "^4.0.0",
31
31
  "jsdom": "^26.1.0",
@@ -33,8 +33,8 @@
33
33
  "uuid": "^11.1.0",
34
34
  "zod": "^3.25.76",
35
35
  "zod-to-json-schema": "^3.24.6",
36
- "@mastra/core": "0.16.1-alpha.0",
37
- "@mastra/mcp": "^0.12.0-alpha.0"
36
+ "@mastra/mcp": "^0.12.0-alpha.1",
37
+ "@mastra/core": "0.16.1-alpha.2"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@hono/node-server": "^1.17.1",
@@ -50,7 +50,7 @@
50
50
  "typescript": "^5.8.3",
51
51
  "vitest": "^3.2.4",
52
52
  "@internal/lint": "0.0.36",
53
- "@mastra/core": "0.16.1-alpha.0"
53
+ "@mastra/core": "0.16.1-alpha.2"
54
54
  },
55
55
  "homepage": "https://mastra.ai",
56
56
  "repository": {
@@ -1,116 +0,0 @@
1
- ---
2
- title: "Runtime context | Agents | Mastra Docs"
3
- description: Learn how to use Mastra's dependency injection system to provide runtime configuration to agents and tools.
4
- ---
5
-
6
- # Agent Runtime Context
7
-
8
- Mastra provides runtime context, which is a system based on dependency injection that enables you to configure your agents and tools with runtime variables. If you find yourself creating several different agents that do very similar things, runtime context allows you to combine them into one agent.
9
-
10
- ## Overview
11
-
12
- The dependency injection system allows you to:
13
-
14
- 1. Pass runtime configuration variables to agents through a type-safe runtimeContext
15
- 2. Access these variables within tool execution contexts
16
- 3. Modify agent behavior without changing the underlying code
17
- 4. Share configuration across multiple tools within the same agent
18
-
19
- ## Basic Usage
20
-
21
- ```typescript
22
- const agent = mastra.getAgent("weatherAgent");
23
-
24
- // Define your runtimeContext's type structure
25
- type WeatherRuntimeContext = {
26
- "temperature-scale": "celsius" | "fahrenheit";
27
- };
28
-
29
- const runtimeContext = new RuntimeContext<WeatherRuntimeContext>();
30
- runtimeContext.set("temperature-scale", "celsius");
31
-
32
- const response = await agent.generate("What's the weather like today?", {
33
- runtimeContext,
34
- });
35
-
36
- console.log(response.text);
37
- ```
38
-
39
- ## Using with REST API
40
-
41
- Here's how to dynamically set temperature units based on a user's location using the Cloudflare `CF-IPCountry` header:
42
-
43
- ```typescript filename="src/index.ts"
44
- import { Mastra } from "@mastra/core";
45
- import { RuntimeContext } from "@mastra/core/di";
46
- import { agent as weatherAgent } from "./agents/weather";
47
-
48
- // Define RuntimeContext type with clear, descriptive types
49
- type WeatherRuntimeContext = {
50
- "temperature-scale": "celsius" | "fahrenheit";
51
- };
52
-
53
- export const mastra = new Mastra({
54
- agents: {
55
- weather: weatherAgent,
56
- },
57
- server: {
58
- middleware: [
59
- async (c, next) => {
60
- const country = c.req.header("CF-IPCountry");
61
- const runtimeContext = c.get<WeatherRuntimeContext>("runtimeContext");
62
-
63
- // Set temperature scale based on country
64
- runtimeContext.set(
65
- "temperature-scale",
66
- country === "US" ? "fahrenheit" : "celsius",
67
- );
68
-
69
- await next(); // Don't forget to call next()
70
- },
71
- ],
72
- },
73
- });
74
- ```
75
-
76
- ## Creating Tools with Variables
77
-
78
- Tools can access runtimeContext variables and must conform to the agent's runtimeContext type:
79
-
80
- ```typescript
81
- import { createTool } from "@mastra/core/tools";
82
- import { z } from "zod";
83
-
84
- export const weatherTool = createTool({
85
- id: "getWeather",
86
- description: "Get the current weather for a location",
87
- inputSchema: z.object({
88
- location: z.string().describe("The location to get weather for"),
89
- }),
90
- execute: async ({ context, runtimeContext }) => {
91
- // Type-safe access to runtimeContext variables
92
- const temperatureUnit = runtimeContext.get("temperature-scale");
93
-
94
- const weather = await fetchWeather(context.location, {
95
- temperatureUnit,
96
- });
97
-
98
- return { result: weather };
99
- },
100
- });
101
-
102
- async function fetchWeather(
103
- location: string,
104
- { temperatureUnit }: { temperatureUnit: "celsius" | "fahrenheit" },
105
- ): Promise<WeatherResponse> {
106
- // Implementation of weather API call
107
- const response = await weatherApi.fetch(location, temperatureUnit);
108
-
109
- return {
110
- location,
111
- temperature: "72°F",
112
- conditions: "Sunny",
113
- unit: temperatureUnit,
114
- };
115
- }
116
- ```
@@ -1,131 +0,0 @@
1
- ---
2
- title: "Reference: Workflow.execute() | Workflows | Mastra Docs"
3
- description: Documentation for the `Workflow.execute()` method in workflows, which executes a workflow directly and returns the output.
4
- ---
5
-
6
- # Workflow.execute()
7
-
8
- The `.execute()` method executes a workflow directly and returns the output, allowing you to run a workflow without creating a separate run instance.
9
-
10
- ## Usage example
11
-
12
- ```typescript showLineNumbers copy
13
- await workflow.execute({
14
- inputData: {
15
- value: "hello world"
16
- }
17
- });
18
- ```
19
-
20
- ## Parameters
21
-
22
- <PropertiesTable
23
- content={[
24
- {
25
- name: "inputData",
26
- type: "z.infer<TInput>",
27
- description: "Input data that matches the workflow's input schema",
28
- isOptional: false,
29
- },
30
- {
31
- name: "resumeData",
32
- type: "any",
33
- description: "Data for resuming a suspended workflow",
34
- isOptional: true,
35
- },
36
- {
37
- name: "suspend",
38
- type: "(suspendPayload: any) => Promise<any>",
39
- description: "Function to suspend workflow execution",
40
- isOptional: false,
41
- },
42
- {
43
- name: "resume",
44
- type: "object",
45
- description: "Configuration for resuming workflow execution",
46
- isOptional: true,
47
- properties: [
48
- {
49
- name: "steps",
50
- type: "string[]",
51
- description: "Steps to resume",
52
- isOptional: false,
53
- },
54
- {
55
- name: "resumePayload",
56
- type: "any",
57
- description: "Payload data for resuming",
58
- isOptional: false,
59
- },
60
- {
61
- name: "runId",
62
- type: "string",
63
- description: "ID of the run to resume",
64
- isOptional: true,
65
- },
66
- ],
67
- },
68
- {
69
- name: "emitter",
70
- type: "object",
71
- description: "Event emitter object for workflow events",
72
- isOptional: false,
73
- properties: [
74
- {
75
- name: "emit",
76
- type: "(event: string, data: any) => void",
77
- description: "Function to emit events",
78
- isOptional: false,
79
- },
80
- ],
81
- },
82
- {
83
- name: "mastra",
84
- type: "Mastra",
85
- description: "Mastra instance",
86
- isOptional: false,
87
- },
88
- {
89
- name: "runtimeContext",
90
- type: "RuntimeContext",
91
- description: "Runtime context data to use during workflow execution",
92
- isOptional: true,
93
- },
94
- {
95
- name: "abort",
96
- type: "() => any",
97
- description: "Function to abort workflow execution",
98
- isOptional: false,
99
- },
100
- {
101
- name: "abortSignal",
102
- type: "AbortSignal",
103
- description: "Abort signal for workflow execution",
104
- isOptional: false,
105
- },
106
- {
107
- name: "runCount",
108
- type: "number",
109
- description: "Number of times the workflow has been run",
110
- isOptional: true,
111
- },
112
- ]}
113
- />
114
-
115
- ## Returns
116
-
117
- <PropertiesTable
118
- content={[
119
- {
120
- name: "result",
121
- type: "Promise<z.infer<TOutput>>",
122
- description: "A promise that resolves to the output of the executed workflow",
123
- },
124
- ]}
125
- />
126
-
127
- ## Related
128
-
129
- - [Workflow.createRunAsync()](./create-run.mdx) - Alternative method for creating workflow runs
130
- - [WorkflowRun.start()](./run-methods/start.mdx) - Starting workflow execution
131
- - [Workflows overview](../../docs/workflows/overview.mdx#run-workflow)
@@ -1,131 +0,0 @@
1
- ---
2
- title: "Dynamic Tool Context | Tools & MCP | Mastra Docs"
3
- description: Learn how to use Mastra's RuntimeContext to provide dynamic, request-specific configuration to tools.
4
- ---
5
-
6
- import { Callout } from "nextra/components";
7
-
8
- # Dynamic Tool Context
9
-
10
- Mastra provides `RuntimeContext`, a system based on dependency injection, that allows you to pass dynamic, request-specific configuration to your tools during execution. This is useful when a tool's behavior needs to change based on user identity, request headers, or other runtime factors, without altering the tool's core code.
11
-
12
- <Callout>
13
- **Note:** `RuntimeContext` is primarily used for passing data *into* tool
14
- executions. It's distinct from agent memory, which handles conversation
15
- history and state persistence across multiple calls.
16
- </Callout>
17
-
18
- ## Basic Usage
19
-
20
- To use `RuntimeContext`, first define a type structure for your dynamic configuration. Then, create an instance of `RuntimeContext` typed with your definition and set the desired values. Finally, include the `runtimeContext` instance in the options object when calling `agent.generate()` or `agent.stream()`.
21
-
22
- ```typescript
23
- import { RuntimeContext } from "@mastra/core/di";
24
- // Assume 'agent' is an already defined Mastra Agent instance
25
-
26
- // Define the context type
27
- type WeatherRuntimeContext = {
28
- "temperature-scale": "celsius" | "fahrenheit";
29
- };
30
-
31
- // Instantiate RuntimeContext and set values
32
- const runtimeContext = new RuntimeContext<WeatherRuntimeContext>();
33
- runtimeContext.set("temperature-scale", "celsius");
34
-
35
- // Pass to agent call
36
- const response = await agent.generate("What's the weather like today?", {
37
- runtimeContext, // Pass the context here
38
- });
39
-
40
- console.log(response.text);
41
- ```
42
-
43
- ## Accessing Context in Tools
44
-
45
- Tools receive the `runtimeContext` as part of the second argument to their `execute` function. You can then use the `.get()` method to retrieve values.
46
-
47
- ```typescript filename="src/mastra/tools/weather-tool.ts"
48
- import { createTool } from "@mastra/core/tools";
49
- import { z } from "zod";
50
- // Assume WeatherRuntimeContext is defined as above and accessible here
51
-
52
- // Dummy fetch function
53
- async function fetchWeather(
54
- location: string,
55
- options: { temperatureUnit: "celsius" | "fahrenheit" },
56
- ): Promise<any> {
57
- console.log(`Fetching weather for ${location} in ${options.temperatureUnit}`);
58
- // Replace with actual API call
59
- return { temperature: options.temperatureUnit === "celsius" ? 20 : 68 };
60
- }
61
-
62
- export const weatherTool = createTool({
63
- id: "getWeather",
64
- description: "Get the current weather for a location",
65
- inputSchema: z.object({
66
- location: z.string().describe("The location to get weather for"),
67
- }),
68
- // The tool's execute function receives runtimeContext
69
- execute: async ({ context, runtimeContext }) => {
70
- // Type-safe access to runtimeContext variables
71
- const temperatureUnit = runtimeContext.get("temperature-scale");
72
-
73
- // Use the context value in the tool logic
74
- const weather = await fetchWeather(context.location, {
75
- temperatureUnit,
76
- });
77
-
78
- return {
79
- result: `The temperature is ${weather.temperature}°${temperatureUnit === "celsius" ? "C" : "F"}`,
80
- };
81
- },
82
- });
83
- ```
84
-
85
- When the agent uses `weatherTool`, the `temperature-scale` value set in the `runtimeContext` during the `agent.generate()` call will be available inside the tool's `execute` function.
86
-
87
- ## Using with Server Middleware
88
-
89
- In server environments (like Express or Next.js), you can use middleware to automatically populate `RuntimeContext` based on incoming request data, such as headers or user sessions.
90
-
91
- Here's an example using Mastra's built-in server middleware support (which uses Hono internally) to set the temperature scale based on the Cloudflare `CF-IPCountry` header:
92
-
93
- ```typescript filename="src/mastra/index.ts"
94
- import { Mastra } from "@mastra/core";
95
- import { RuntimeContext } from "@mastra/core/di";
96
- import { weatherAgent } from "./agents/weather"; // Assume agent is defined elsewhere
97
-
98
- // Define RuntimeContext type
99
- type WeatherRuntimeContext = {
100
- "temperature-scale": "celsius" | "fahrenheit";
101
- };
102
-
103
- export const mastra = new Mastra({
104
- agents: {
105
- weather: weatherAgent,
106
- },
107
- server: {
108
- middleware: [
109
- async (c, next) => {
110
- // Get the RuntimeContext instance
111
- const runtimeContext =
112
- c.get<RuntimeContext<WeatherRuntimeContext>>("runtimeContext");
113
-
114
- // Get country code from request header
115
- const country = c.req.header("CF-IPCountry");
116
-
117
- // Set temperature scale based on country
118
- runtimeContext.set(
119
- "temperature-scale",
120
- country === "US" ? "fahrenheit" : "celsius",
121
- );
122
-
123
- // Continue request processing
124
- await next();
125
- },
126
- ],
127
- },
128
- });
129
- ```
130
-
131
- With this middleware in place, any agent call handled by this Mastra server instance will automatically have the `temperature-scale` set in its `RuntimeContext` based on the user's inferred country, and tools like `weatherTool` will use it accordingly.