Open History to see the last commit
1---
2id: ServerTool
3title: ServerTool
4---
5
6Defined in: packages/ai/src/activities/chat/tools/tool-definition.ts:86
7
8Marker type for server-side tools
9
10## Extends
11
12- [`Tool`](Tool.md)\<`TInput`, `TOutput`, `TName`, `TContext`\>.`ToolApprovalCapabilityMarker`\<`TNeedsApproval`, `TApprovalSchema`\>
13
14## Type Parameters
15
16### TInput
17
18`TInput` *extends* [`SchemaInput`](../type-aliases/SchemaInput.md) \| `undefined` = `undefined`
19
20### TOutput
21
22`TOutput` *extends* [`SchemaInput`](../type-aliases/SchemaInput.md) \| `undefined` = `undefined`
23
24### TName
25
26`TName` *extends* `string` = `string`
27
28### TContext
29
30`TContext` = `unknown`
31
32### TNeedsApproval
33
34`TNeedsApproval` *extends* `boolean` = `false`
35
36### TApprovalSchema
37
38`TApprovalSchema` *extends*
39 \| [`ApprovalSchemaConfig`](../type-aliases/ApprovalSchemaConfig.md)
40 \| `undefined` = `undefined`
41
42## Properties
43
44### \_\_toolSide
45
46```ts
47__toolSide: "server";
48```
49
50Defined in: packages/ai/src/activities/chat/tools/tool-definition.ts:97
51
52***
53
54### \[toolApprovalCapability\]?
55
56```ts
57readonly optional [toolApprovalCapability]?: object;
58```
59
60Defined in: packages/ai/src/activities/chat/tools/tool-definition.ts:26
61
62#### approvalSchema
63
64```ts
65approvalSchema: TApprovalSchema;
66```
67
68#### needsApproval
69
70```ts
71needsApproval: TNeedsApproval;
72```
73
74#### Inherited from
75
76```ts
77ToolApprovalCapabilityMarker.[toolApprovalCapability]
78```
79
80***
81
82### approvalSchema?
83
84```ts
85optional approvalSchema?: TApprovalSchema;
86```
87
88Defined in: packages/ai/src/activities/chat/tools/tool-definition.ts:101
89
90***
91
92### description
93
94```ts
95description: string;
96```
97
98Defined in: packages/ai/src/types.ts:989
99
100Clear description of what the tool does.
101
102This is crucial - the model uses this to decide when to call the tool.
103Be specific about what the tool does, what parameters it needs, and what it returns.
104
105#### Example
106
107```ts
108"Get the current weather in a given location. Returns temperature, conditions, and forecast."
109```
110
111#### Inherited from
112
113[`Tool`](Tool.md).[`description`](Tool.md#description)
114
115***
116
117### execute?
118
119```ts
120optional execute?: ToolExecuteFunction<TInput, TOutput, TContext>;
121```
122
123Defined in: packages/ai/src/types.ts:1069
124
125Optional function to execute when the model calls this tool.
126
127If provided, the SDK will automatically execute the function with the model's arguments
128and feed the result back to the model. This enables autonomous tool use loops.
129
130Can return any value - will be automatically stringified if needed.
131
132#### Param
133
134**args**
135
136The arguments parsed from the model's tool call (validated against inputSchema)
137
138#### Returns
139
140Result to send back to the model (validated against outputSchema if provided)
141
142#### Example
143
144```ts
145execute: async (args) => {
146 const weather = await fetchWeather(args.location);
147 return weather; // Can return object or string
148}
149```
150
151#### Inherited from
152
153[`Tool`](Tool.md).[`execute`](Tool.md#execute)
154
155***
156
157### execution?
158
159```ts
160optional execution?: "task";
161```
162
163Defined in: packages/ai/src/activities/chat/tools/tool-definition.ts:102
164
165***
166
167### inputSchema?
168
169```ts
170optional inputSchema?: TInput;
171```
172
173Defined in: packages/ai/src/activities/chat/tools/tool-definition.ts:98
174
175Schema describing the tool's input parameters.
176
177Can be any Standard JSON Schema compliant schema (Zod, ArkType, Valibot, etc.) or a plain JSON Schema object.
178Defines the structure and types of arguments the tool accepts.
179The model will generate arguments matching this schema.
180Standard JSON Schema compliant schemas are converted to JSON Schema for LLM providers.
181
182#### See
183
184 - https://standardschema.dev/json-schema
185 - https://json-schema.org/
186
187#### Examples
188
189```ts
190// Using Zod v4+ schema (natively supports Standard JSON Schema)
191import { z } from 'zod';
192z.object({
193 location: z.string().describe("City name or coordinates"),
194 unit: z.enum(["celsius", "fahrenheit"]).optional()
195})
196```
197
198```ts
199// Using ArkType (natively supports Standard JSON Schema)
200import { type } from 'arktype';
201type({
202 location: 'string',
203 unit: "'celsius' | 'fahrenheit'"
204})
205```
206
207```ts
208// Using plain JSON Schema
209{
210 type: 'object',
211 properties: {
212 location: { type: 'string', description: 'City name or coordinates' },
213 unit: { type: 'string', enum: ['celsius', 'fahrenheit'] }
214 },
215 required: ['location']
216}
217```
218
219#### Overrides
220
221[`Tool`](Tool.md).[`inputSchema`](Tool.md#inputschema)
222
223***
224
225### lazy?
226
227```ts
228optional lazy?: boolean;
229```
230
231Defined in: packages/ai/src/types.ts:1075
232
233If true, this tool is lazy and will only be sent to the LLM after being discovered via the lazy tool discovery mechanism. Works with both chat() (the synthetic discovery tool) and Code Mode (kept out of the system prompt and revealed via discover_tools).
234
235#### Inherited from
236
237[`Tool`](Tool.md).[`lazy`](Tool.md#lazy)
238
239***
240
241### metadata?
242
243```ts
244optional metadata?: Record<string, any>;
245```
246
247Defined in: packages/ai/src/types.ts:1086
248
249Additional metadata for adapters or custom extensions
250
251#### Inherited from
252
253[`Tool`](Tool.md).[`metadata`](Tool.md#metadata)
254
255***
256
257### name
258
259```ts
260name: TName;
261```
262
263Defined in: packages/ai/src/types.ts:979
264
265Unique name of the tool (used by the model to call it).
266
267Should be descriptive and follow naming conventions (e.g., snake_case or camelCase).
268Must be unique within the tools array.
269
270#### Example
271
272```ts
273"get_weather", "search_database", "sendEmail"
274```
275
276#### Inherited from
277
278[`Tool`](Tool.md).[`name`](Tool.md#name)
279
280***
281
282### needsApproval?
283
284```ts
285optional needsApproval?: TNeedsApproval;
286```
287
288Defined in: packages/ai/src/activities/chat/tools/tool-definition.ts:100
289
290If true, tool execution requires user approval before running. Works with both server and client tools.
291
292#### Overrides
293
294[`Tool`](Tool.md).[`needsApproval`](Tool.md#needsapproval)
295
296***
297
298### outputSchema?
299
300```ts
301optional outputSchema?: TOutput;
302```
303
304Defined in: packages/ai/src/activities/chat/tools/tool-definition.ts:99
305
306Optional schema for validating tool output.
307
308Can be any Standard JSON Schema compliant schema or a plain JSON Schema object.
309If provided with a Standard Schema compliant schema, tool results will be validated
310against this schema before being sent back to the model. This catches bugs in tool
311implementations and ensures consistent output formatting.
312
313Note: This is client-side validation only - not sent to LLM providers.
314Note: Plain JSON Schema output validation is not performed at runtime.
315
316#### Example
317
318```ts
319// Using Zod
320z.object({
321 temperature: z.number(),
322 conditions: z.string(),
323 forecast: z.array(z.string()).optional()
324})
325```
326
327#### Overrides
328
329[`Tool`](Tool.md).[`outputSchema`](Tool.md#outputschema)
330
331***
332
333### replay?
334
335```ts
336optional replay?: "safe" | "never";
337```
338
339Defined in: packages/ai/src/types.ts:1083
340
341Whether a host may run this tool again after a crash cut the run
342between the call and its result. `'safe'` runs it again. Omit the
343field, or set `'never'`, when a second run is not safe. The host
344writes the model note. `chat()` does not read this field.
345
346#### Inherited from
347
348[`Tool`](Tool.md).[`replay`](Tool.md#replay)