> ## Documentation Index
> Fetch the complete documentation index at: https://docs.zeroruntime.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Tools & MCP

> JavaScript API reference for Tools & MCP.

## functionTool

```typescript theme={null}
function functionTool(def: ToolDefinition<P>): FunctionTool<P>
```

Create a callable FunctionTool the agent can expose to its model.

Pass a ToolDefinition describing the tool; `name` is required. The
argument schema can be a Zod schema (`input`, which takes precedence, or
`parameters` directly) or a plain JSON Schema (`parameters`); Zod schemas
are converted to JSON Schema.

<ParamField path="def" type="ToolDefinition<P>" required />

<ResponseField name="returns" type="FunctionTool<P>" />

***

## isFunctionTool

```typescript theme={null}
function isFunctionTool(obj: any): obj is FunctionTool
```

Type guard: whether `obj` is a FunctionTool (has valid `_toolInfo`).

<ParamField path="obj" type="any" required />

<ResponseField name="returns" type="obj is FunctionTool" />

***

## getToolInfo

```typescript theme={null}
function getToolInfo(tool: FunctionTool | any): FunctionToolInfoLike
```

Return the FunctionToolInfoLike metadata attached to a tool.

<ParamField path="tool" type="FunctionTool | any" required />

<ResponseField name="returns" type="FunctionToolInfoLike" />

***

## FunctionTool

A callable tool: a function that runs the tool, with its FunctionToolInfoLike
metadata attached as `_toolInfo`. Create one with functionTool.

```typescript theme={null}
type FunctionTool = { (args: P, ctx?: ToolContext): any | Promise<any>; _toolInfo: FunctionToolInfoLike; }
```

***

## FunctionToolInfo

Concrete carrier for tool metadata; see FunctionToolInfoLike.

### Constructor

```typescript theme={null}
new FunctionToolInfo(info: FunctionToolInfoLike)
```

<ParamField path="info" type="FunctionToolInfoLike" required />

***

## ToolChoice

How the model is allowed to use tools on a turn.

```typescript theme={null}
enum ToolChoice {
  AUTO = 'auto',
  NONE = 'none',
  REQUIRED = 'required',
}
```

***

## buildOpenaiSchema

```typescript theme={null}
function buildOpenaiSchema(tool: FunctionTool | any): { type: 'function'; function: { name: string; description: string; parameters: object }; }
```

Convert a tool to the OpenAI function-calling schema.

<ParamField path="tool" type="FunctionTool | any" required />

<ResponseField name="returns" type="{ type: 'function'; function: { name: string; description: string; parameters: object }; }" />

***

## buildGeminiSchema

```typescript theme={null}
function buildGeminiSchema(tool: FunctionTool | any): { name: string; description: string; parameters: object; }
```

Convert a tool to the Gemini function-declaration schema (simplified parameters).

<ParamField path="tool" type="FunctionTool | any" required />

<ResponseField name="returns" type="{ name: string; description: string; parameters: object; }" />

***

## buildNovaSonicSchema

```typescript theme={null}
function buildNovaSonicSchema(tool: FunctionTool | any): { type: 'function'; function: { name: string; description: string; parameters: object }; }
```

Convert a tool to the Nova Sonic schema (identical to OpenAI's).

<ParamField path="tool" type="FunctionTool | any" required />

<ResponseField name="returns" type="{ type: 'function'; function: { name: string; description: string; parameters: object }; }" />

***

## MCPServerStdio

Describe an MCP server run as a local subprocess communicating over stdio.

### Constructor

```typescript theme={null}
new MCPServerStdio(command: string, opts: MCPServerStdioOptions)
```

<ParamField path="command" type="string" required>
  Executable to launch.
</ParamField>

<ParamField path="args" type="string[] | null">
  Command-line arguments passed to the MCP server process. Default: `[]`.
</ParamField>

<ParamField path="env" type="Record<string, string> | null">
  Environment variables for the MCP server process. Default: `{}`.
</ParamField>

***

## MCPServerHTTP

Describe an MCP server reached over HTTP.

### Constructor

```typescript theme={null}
new MCPServerHTTP(url: string, opts: MCPServerHTTPOptions)
```

<ParamField path="url" type="string" required>
  Base URL of the MCP server.
</ParamField>

<ParamField path="headers" type="Record<string, string> | null">
  HTTP headers sent with each request to the MCP server. Default: `{}`.
</ParamField>

***

## DTMFHandler

Create a DTMFHandler.

### Constructor

```typescript theme={null}
new DTMFHandler(_opts: Record<string, any>)
```

<ParamField path="_opts" type="Record<string, any>" default="{}" />

### onDigit

```typescript theme={null}
onDigit(digit: string, callback: DTMFCallback): void
```

Register `callback` to fire each time the given single `digit` is received.

<ParamField path="digit" type="string" required />

<ParamField path="callback" type="DTMFCallback" required />

### onSequence

```typescript theme={null}
onSequence(sequence: string, callback: DTMFCallback): void
```

Register `callback` to fire when the recent digit stream ends with `sequence`.

<ParamField path="sequence" type="string" required />

<ParamField path="callback" type="DTMFCallback" required />

***

## VoiceMailDetector

Create a VoiceMailDetector.

### Constructor

```typescript theme={null}
new VoiceMailDetector(opts: VoiceMailDetectorOptions)
```

<ParamField path="llm" type="any">
  LLM used for classification. Default: `null`.
</ParamField>

<ParamField path="callback" type="VoiceMailCallback | null">
  Callback fired on detection. Default: `null`.
</ParamField>

<ParamField path="duration" type="number">
  Detection window in seconds. Default: `2.0`. Overridden by VoiceMailDetectorOptions.maxDetectionSeconds when set.
</ParamField>

<ParamField path="customPrompt" type="string | null">
  Custom classifier prompt; falls back to the built-in prompt when empty. Default: `''`.
</ParamField>

<ParamField path="autoHangup" type="boolean">
  Hang up automatically when voicemail is detected. Default: `false`.
</ParamField>

<ParamField path="detectionThreshold" type="number">
  Confidence threshold (0-1) required to count as a detection. Default: `1.0`.
</ParamField>

<ParamField path="maxDetectionSeconds" type="number | null">
  Maximum detection window in seconds; takes precedence over VoiceMailDetectorOptions.duration. Default: `null`.
</ParamField>
