@mastra/mcp-docs-server 0.13.30-alpha.0 → 0.13.30-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.
- package/.docs/organized/changelogs/%40mastra%2Fagent-builder.md +9 -9
- package/.docs/organized/changelogs/%40mastra%2Fai-sdk.md +15 -0
- package/.docs/organized/changelogs/%40mastra%2Fclient-js.md +15 -15
- package/.docs/organized/changelogs/%40mastra%2Fcore.md +35 -35
- package/.docs/organized/changelogs/%40mastra%2Fdeployer-cloud.md +17 -17
- package/.docs/organized/changelogs/%40mastra%2Fdeployer.md +24 -24
- package/.docs/organized/changelogs/%40mastra%2Fmcp-docs-server.md +15 -15
- package/.docs/organized/changelogs/%40mastra%2Fmemory.md +16 -16
- package/.docs/organized/changelogs/%40mastra%2Fpg.md +16 -16
- package/.docs/organized/changelogs/%40mastra%2Fplayground-ui.md +31 -31
- package/.docs/organized/changelogs/%40mastra%2Freact.md +20 -0
- package/.docs/organized/changelogs/%40mastra%2Fserver.md +15 -15
- package/.docs/organized/changelogs/create-mastra.md +19 -19
- package/.docs/organized/changelogs/mastra.md +27 -27
- package/.docs/organized/code-examples/agent.md +0 -1
- package/.docs/organized/code-examples/agui.md +2 -2
- package/.docs/organized/code-examples/client-side-tools.md +2 -2
- package/.docs/raw/agents/adding-voice.mdx +118 -25
- package/.docs/raw/agents/agent-memory.mdx +73 -89
- package/.docs/raw/agents/guardrails.mdx +1 -1
- package/.docs/raw/agents/overview.mdx +39 -7
- package/.docs/raw/agents/using-tools.mdx +95 -0
- package/.docs/raw/deployment/overview.mdx +9 -11
- package/.docs/raw/frameworks/agentic-uis/ai-sdk.mdx +1 -1
- package/.docs/raw/frameworks/servers/express.mdx +2 -2
- package/.docs/raw/getting-started/installation.mdx +34 -85
- package/.docs/raw/getting-started/mcp-docs-server.mdx +13 -1
- package/.docs/raw/index.mdx +49 -14
- package/.docs/raw/observability/ai-tracing/exporters/otel.mdx +3 -0
- package/.docs/raw/reference/observability/ai-tracing/exporters/otel.mdx +6 -0
- package/.docs/raw/reference/scorers/answer-relevancy.mdx +105 -7
- package/.docs/raw/reference/scorers/answer-similarity.mdx +266 -16
- package/.docs/raw/reference/scorers/bias.mdx +107 -6
- package/.docs/raw/reference/scorers/completeness.mdx +131 -8
- package/.docs/raw/reference/scorers/content-similarity.mdx +107 -8
- package/.docs/raw/reference/scorers/context-precision.mdx +234 -18
- package/.docs/raw/reference/scorers/context-relevance.mdx +418 -35
- package/.docs/raw/reference/scorers/faithfulness.mdx +122 -8
- package/.docs/raw/reference/scorers/hallucination.mdx +125 -8
- package/.docs/raw/reference/scorers/keyword-coverage.mdx +141 -9
- package/.docs/raw/reference/scorers/noise-sensitivity.mdx +478 -6
- package/.docs/raw/reference/scorers/prompt-alignment.mdx +351 -102
- package/.docs/raw/reference/scorers/textual-difference.mdx +134 -6
- package/.docs/raw/reference/scorers/tone-consistency.mdx +133 -0
- package/.docs/raw/reference/scorers/tool-call-accuracy.mdx +422 -65
- package/.docs/raw/reference/scorers/toxicity.mdx +125 -7
- package/.docs/raw/reference/workflows/workflow.mdx +33 -0
- package/.docs/raw/scorers/custom-scorers.mdx +244 -3
- package/.docs/raw/scorers/overview.mdx +8 -38
- package/.docs/raw/server-db/middleware.mdx +5 -2
- package/.docs/raw/server-db/runtime-context.mdx +178 -0
- package/.docs/raw/streaming/workflow-streaming.mdx +5 -1
- package/.docs/raw/tools-mcp/overview.mdx +25 -7
- package/.docs/raw/workflows/overview.mdx +28 -1
- package/CHANGELOG.md +14 -0
- package/package.json +4 -4
- package/.docs/raw/agents/runtime-context.mdx +0 -106
- package/.docs/raw/agents/using-tools-and-mcp.mdx +0 -241
- package/.docs/raw/getting-started/model-providers.mdx +0 -63
- package/.docs/raw/tools-mcp/runtime-context.mdx +0 -63
- /package/.docs/raw/{evals → scorers/evals-old-api}/custom-eval.mdx +0 -0
- /package/.docs/raw/{evals → scorers/evals-old-api}/overview.mdx +0 -0
- /package/.docs/raw/{evals → scorers/evals-old-api}/running-in-ci.mdx +0 -0
- /package/.docs/raw/{evals → scorers/evals-old-api}/textual-evals.mdx +0 -0
- /package/.docs/raw/{server-db → workflows}/snapshots.mdx +0 -0
|
@@ -1,241 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: "Tools and MCP | Agents | Mastra Docs"
|
|
3
|
-
description: Learn how to create tools, add them to Mastra agents, and integrate tools from MCP servers.
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# Tools and MCP
|
|
7
|
-
|
|
8
|
-
Tools are typed functions that can be executed by agents or workflows to help them carry out specific tasks like sending a message, querying a database, or calling an external API. Each tool defines its expected inputs, contains the logic to perform its operation, and may delegate execution to an MCP client for accessing external systems. They give agents a structured way to move beyond language generation and enable deterministic outcomes through well-defined interfaces.
|
|
9
|
-
|
|
10
|
-
Mastra supports two patterns for providing tools to agents:
|
|
11
|
-
|
|
12
|
-
- **Direct assignment**: Static tools available at initialization
|
|
13
|
-
- **Function-based**: Dynamic tools resolved based on runtime context
|
|
14
|
-
|
|
15
|
-
## Creating a tool
|
|
16
|
-
|
|
17
|
-
This example shows how to create a simple tool that asynchronously fetches data from a weather API:
|
|
18
|
-
|
|
19
|
-
```typescript filename="src/mastra/tools/weather-tool.ts" showLineNumbers copy
|
|
20
|
-
import { createTool } from "@mastra/core/tools";
|
|
21
|
-
import { z } from "zod";
|
|
22
|
-
|
|
23
|
-
export const weatherTool = createTool({
|
|
24
|
-
id: "weather-tool",
|
|
25
|
-
description: "Fetches the current weather for a given city",
|
|
26
|
-
inputSchema: z.object({
|
|
27
|
-
city: z.string(),
|
|
28
|
-
}),
|
|
29
|
-
execute: async ({ context }) => {
|
|
30
|
-
const { city } = context;
|
|
31
|
-
const response = await fetch(`https://weather.service?city=${city}`);
|
|
32
|
-
|
|
33
|
-
const { temperature, conditions } = await response.json();
|
|
34
|
-
|
|
35
|
-
return { temperature, conditions };
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
For details on creating and designing tools, see the [Tools Overview](../tools-mcp/overview.mdx).
|
|
41
|
-
|
|
42
|
-
## Adding tools to an agent
|
|
43
|
-
|
|
44
|
-
To make a tool available to an agent, add it to the `tools` property in the agent's configuration.
|
|
45
|
-
|
|
46
|
-
```typescript {3,12} filename="src/mastra/agents/weather-agent.ts" showLineNumbers copy
|
|
47
|
-
import { Agent } from "@mastra/core/agent";
|
|
48
|
-
import { openai } from "@ai-sdk/openai";
|
|
49
|
-
import { weatherTool } from "../tools/weather-tool";
|
|
50
|
-
|
|
51
|
-
export const weatherAgent = new Agent({
|
|
52
|
-
name: "Weather Agent",
|
|
53
|
-
instructions: `
|
|
54
|
-
You are a helpful assistant that provides weather information.
|
|
55
|
-
When asked about the weather, use the weatherTool to fetch the data.`,
|
|
56
|
-
model: openai("gpt-4o-mini"),
|
|
57
|
-
tools: {
|
|
58
|
-
weatherTool,
|
|
59
|
-
},
|
|
60
|
-
});
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
When you call the agent, it can now decide to use the configured tool based on its instructions and the user's prompt.
|
|
64
|
-
|
|
65
|
-
## Adding MCP tools to an agent
|
|
66
|
-
|
|
67
|
-
[Model Context Protocol (MCP)](https://modelcontextprotocol.io/introduction) provides a standardized way for AI models to discover and interact with external tools and resources. You can connect your Mastra agent to MCP servers to use tools provided by third parties.
|
|
68
|
-
|
|
69
|
-
For more details on MCP concepts and how to set up MCP clients and servers, see the [MCP Overview](/docs/tools-mcp/mcp-overview).
|
|
70
|
-
|
|
71
|
-
### Installation
|
|
72
|
-
|
|
73
|
-
First, install the Mastra MCP package:
|
|
74
|
-
|
|
75
|
-
```bash npm2yarn copy
|
|
76
|
-
npm install @mastra/mcp@latest
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### Using MCP tools
|
|
80
|
-
|
|
81
|
-
Because there are so many MCP server registries to choose from, we've created an [MCP Registry Registry](https://mastra.ai/mcp-registry-registry) to help you find MCP servers.
|
|
82
|
-
|
|
83
|
-
Once you have a server you want to use with your agent, import the Mastra `MCPClient` and add the server configuration.
|
|
84
|
-
|
|
85
|
-
```typescript filename="src/mastra/mcp.ts" {1,7-16}
|
|
86
|
-
import { MCPClient } from "@mastra/mcp";
|
|
87
|
-
|
|
88
|
-
// Configure MCPClient to connect to your server(s)
|
|
89
|
-
export const mcp = new MCPClient({
|
|
90
|
-
servers: {
|
|
91
|
-
filesystem: {
|
|
92
|
-
command: "npx",
|
|
93
|
-
args: [
|
|
94
|
-
"-y",
|
|
95
|
-
"@modelcontextprotocol/server-filesystem",
|
|
96
|
-
"/Users/username/Downloads",
|
|
97
|
-
],
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
});
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
Then connect your agent to the server tools:
|
|
104
|
-
|
|
105
|
-
```typescript filename="src/mastra/agents/mcpAgent.ts" {7}
|
|
106
|
-
import { Agent } from "@mastra/core/agent";
|
|
107
|
-
import { openai } from "@ai-sdk/openai";
|
|
108
|
-
import { mcp } from "../mcp";
|
|
109
|
-
|
|
110
|
-
// Create an agent and add tools from the MCP client
|
|
111
|
-
const agent = new Agent({
|
|
112
|
-
name: "Agent with MCP Tools",
|
|
113
|
-
instructions: "You can use tools from connected MCP servers.",
|
|
114
|
-
model: openai("gpt-4o-mini"),
|
|
115
|
-
tools: await mcp.getTools(),
|
|
116
|
-
});
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
When creating agents that will consume an MCP server in the same repo they need to connect to, always use function based tools to prevent race conditions.
|
|
120
|
-
|
|
121
|
-
```typescript filename="src/mastra/agents/selfReferencingAgent.ts"
|
|
122
|
-
import { Agent } from "@mastra/core/agent";
|
|
123
|
-
import { MCPServer } from "@mastra/mcp";
|
|
124
|
-
import { MCPClient } from "@mastra/mcp";
|
|
125
|
-
import { openai } from "@ai-sdk/openai";
|
|
126
|
-
|
|
127
|
-
const myAgent = new Agent({
|
|
128
|
-
name: "My Agent",
|
|
129
|
-
description: "An agent that can use tools from an http MCP server",
|
|
130
|
-
instructions: "You can use remote calculation tools.",
|
|
131
|
-
model: openai("gpt-4o-mini"),
|
|
132
|
-
tools: async () => {
|
|
133
|
-
// Tools resolve when needed, not during initialization
|
|
134
|
-
const mcpClient = new MCPClient({
|
|
135
|
-
servers: {
|
|
136
|
-
myServer: {
|
|
137
|
-
url: new URL("http://localhost:4111/api/mcp/mcpServer/mcp"),
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
});
|
|
141
|
-
return await mcpClient.getTools();
|
|
142
|
-
},
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
// This works because tools resolve after server startup
|
|
146
|
-
export const mcpServer = new MCPServer({
|
|
147
|
-
name: "My MCP Server",
|
|
148
|
-
agents: {
|
|
149
|
-
myAgent
|
|
150
|
-
},
|
|
151
|
-
});
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
For more details on configuring `MCPClient` and the difference between static and dynamic MCP server configurations, see the [MCP Overview](/docs/tools-mcp/mcp-overview).
|
|
155
|
-
|
|
156
|
-
## Accessing MCP resources
|
|
157
|
-
|
|
158
|
-
In addition to tools, MCP servers can also expose resources - data or content that can be retrieved and used in your application.
|
|
159
|
-
|
|
160
|
-
```typescript filename="src/mastra/resources.ts" {3-8}
|
|
161
|
-
import { mcp } from "./mcp";
|
|
162
|
-
|
|
163
|
-
// Get resources from all connected MCP servers
|
|
164
|
-
const resources = await mcp.getResources();
|
|
165
|
-
|
|
166
|
-
// Access resources from a specific server
|
|
167
|
-
if (resources.filesystem) {
|
|
168
|
-
const resource = resources.filesystem.find(
|
|
169
|
-
(r) => r.uri === "filesystem://Downloads",
|
|
170
|
-
);
|
|
171
|
-
console.log(`Resource: ${resource?.name}`);
|
|
172
|
-
}
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
Each resource has a URI, name, description, and MIME type. The `getResources()` method handles errors gracefully - if a server fails or doesn't support resources, it will be omitted from the results.
|
|
176
|
-
|
|
177
|
-
## Accessing MCP prompts
|
|
178
|
-
|
|
179
|
-
MCP servers can also expose prompts, which represent structured message templates or conversational context for agents.
|
|
180
|
-
|
|
181
|
-
### Listing prompts
|
|
182
|
-
|
|
183
|
-
```typescript filename="src/mastra/prompts.ts"
|
|
184
|
-
import { mcp } from "./mcp";
|
|
185
|
-
|
|
186
|
-
// Get prompts from all connected MCP servers
|
|
187
|
-
const prompts = await mcp.prompts.list();
|
|
188
|
-
|
|
189
|
-
// Access prompts from a specific server
|
|
190
|
-
if (prompts.weather) {
|
|
191
|
-
const prompt = prompts.weather.find(
|
|
192
|
-
(p) => p.name === "current"
|
|
193
|
-
);
|
|
194
|
-
console.log(`Prompt: ${prompt?.name}`);
|
|
195
|
-
}
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
Each prompt has a name, description, and (optional) version.
|
|
199
|
-
|
|
200
|
-
### Retrieving a prompt and its messages
|
|
201
|
-
|
|
202
|
-
```typescript filename="src/mastra/prompts.ts"
|
|
203
|
-
const { prompt, messages } = await mcp.prompts.get({ serverName: "weather", name: "current" });
|
|
204
|
-
console.log(prompt); // { name: "current", version: "v1", ... }
|
|
205
|
-
console.log(messages); // [ { role: "assistant", content: { type: "text", text: "..." } }, ... ]
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
## Exposing agents as tools via `MCPServer`
|
|
209
|
-
|
|
210
|
-
In addition to using tools from MCP servers, your Mastra Agents themselves can be exposed as tools to any MCP-compatible client using Mastra's `MCPServer`.
|
|
211
|
-
|
|
212
|
-
When an `Agent` instance is provided to an `MCPServer` configuration:
|
|
213
|
-
|
|
214
|
-
- It is automatically converted into a callable tool.
|
|
215
|
-
- The tool is named `ask_<agentKey>`, where `<agentKey>` is the identifier you used when adding the agent to the `MCPServer`'s `agents` configuration.
|
|
216
|
-
- The agent's `description` property (which must be a non-empty string) is used to generate the tool's description.
|
|
217
|
-
|
|
218
|
-
This allows other AI models or MCP clients to interact with your Mastra Agents as if they were standard tools, typically by "asking" them a question.
|
|
219
|
-
|
|
220
|
-
**Example `MCPServer` Configuration with an Agent:**
|
|
221
|
-
|
|
222
|
-
```typescript filename="src/mastra/mcp.ts"
|
|
223
|
-
import { Agent } from "@mastra/core/agent";
|
|
224
|
-
import { MCPServer } from "@mastra/mcp";
|
|
225
|
-
import { openai } from "@ai-sdk/openai";
|
|
226
|
-
import { weatherInfo } from "../tools/weatherInfo";
|
|
227
|
-
import { generalHelper } from "../agents/generalHelper";
|
|
228
|
-
|
|
229
|
-
const server = new MCPServer({
|
|
230
|
-
name: "My Custom Server with Agent-Tool",
|
|
231
|
-
version: "1.0.0",
|
|
232
|
-
tools: {
|
|
233
|
-
weatherInfo,
|
|
234
|
-
},
|
|
235
|
-
agents: { generalHelper }, // Exposes 'ask_generalHelper' tool
|
|
236
|
-
});
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
For an agent to be successfully converted into a tool by `MCPServer`, its `description` property must be set to a non-empty string in its constructor configuration. If the description is missing or empty, `MCPServer` will throw an error during initialization.
|
|
240
|
-
|
|
241
|
-
For more details on setting up and configuring `MCPServer`, refer to the [MCPServer reference documentation](/reference/tools/mcp-server).
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: "Model Providers | Getting Started | Mastra Docs"
|
|
3
|
-
description: "Learn how to configure and use different model providers with Mastra."
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
import { Callout } from "nextra/components"
|
|
7
|
-
|
|
8
|
-
# Model Providers
|
|
9
|
-
|
|
10
|
-
Mastra's unified model router gives you access to 541+ models from 38 providers with a single API. Switch between models and providers without changing your code. Automatic environment variable detection handles authentication, while TypeScript provides full autocomplete for every model.
|
|
11
|
-
|
|
12
|
-
## Quick Start
|
|
13
|
-
|
|
14
|
-
Simply use the `provider/model` string pattern:
|
|
15
|
-
|
|
16
|
-
```typescript showLineNumbers copy filename="src/mastra/agents/weather-agent.ts"
|
|
17
|
-
import { Agent } from "@mastra/core";
|
|
18
|
-
|
|
19
|
-
const agent = new Agent({
|
|
20
|
-
name: "WeatherAgent",
|
|
21
|
-
instructions: "You are a helpful weather assistant",
|
|
22
|
-
model: "openai/gpt-4o"
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const result = await agent.generate("What is the weather like?");
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
## Browse Providers
|
|
29
|
-
|
|
30
|
-
<Callout>
|
|
31
|
-
**[→ View all 38 providers and 7 gateways](../../models)**
|
|
32
|
-
|
|
33
|
-
Explore our complete catalog with logos, model counts, and documentation for each provider.
|
|
34
|
-
</Callout>
|
|
35
|
-
|
|
36
|
-
## Configuration
|
|
37
|
-
|
|
38
|
-
Models automatically detect API keys from environment variables.
|
|
39
|
-
|
|
40
|
-
## AI SDK Compatibility
|
|
41
|
-
|
|
42
|
-
While Mastra provides built-in support for 541+ models, you can also use [Vercel AI SDK](https://sdk.vercel.ai/providers/ai-sdk-providers) model providers for additional flexibility:
|
|
43
|
-
|
|
44
|
-
```typescript
|
|
45
|
-
import { openai } from "@ai-sdk/openai";
|
|
46
|
-
import { Agent } from "@mastra/core";
|
|
47
|
-
|
|
48
|
-
const agent = new Agent({
|
|
49
|
-
name: "AISDKAgent",
|
|
50
|
-
model: openai("gpt-4-turbo") // AI SDK model provider
|
|
51
|
-
});
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
<Callout type="info">
|
|
55
|
-
**Recommendation**: Use Mastra's built-in model router (`"provider/model"` strings) for simplicity. Use AI SDK providers only when you need specific features not available in the built-in providers.
|
|
56
|
-
</Callout>
|
|
57
|
-
|
|
58
|
-
## Learn More
|
|
59
|
-
|
|
60
|
-
- [📚 Browse All Model Providers](../../models) - Complete list with examples
|
|
61
|
-
- [🚀 Agent Documentation](../../reference/agents/agent.mdx) - Using models with agents
|
|
62
|
-
- [⚙️ Environment Variables](../getting-started/installation.mdx#add-your-api-key) - Configuration guide
|
|
63
|
-
- [🔧 Tool Configuration](../agents/using-tools-and-mcp.mdx#adding-tools-to-an-agent) - Adding tools to agents
|
|
@@ -1,63 +0,0 @@
|
|
|
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)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|