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

# Attach Phone Number To Agent

> Use the add_agent_phone_number MCP tool on the DialNexa remote MCP server.

<span data-api-safety-label="changes-state"><Badge color="yellow" size="sm" shape="pill">Changes state - verify before retry</Badge></span>

Links an organization phone number to an agent for inbound or outbound calls. Takes effect immediately for every version of the agent. Refused when the agent has no published version, already has 3 numbers in that direction, the number is linked to another agent in that direction (unlink it there first), or a default number is used for inbound. Get phone number IDs from list\_organization\_phone\_numbers.

## Parameters

| Name | Type | Required | Description |
| - | - | - | - |
| `agent_id` | `string` | Yes | The agent ID, e.g. agent\_abc123 |
| `phone_number_id` | `string` | Yes | The phone number ID, e.g. phn\_abc123 |
| `direction` | enum: `inbound` \| `outbound` | Yes | inbound: the number rings this agent. outbound: the agent calls from it. |

## Complete input schema

```json theme={null}
{
  "type": "object",
  "properties": {
    "agent_id": {
      "type": "string",
      "description": "The agent ID, e.g. agent_abc123"
    },
    "phone_number_id": {
      "type": "string",
      "description": "The phone number ID, e.g. phn_abc123"
    },
    "direction": {
      "type": "string",
      "enum": [
        "inbound",
        "outbound"
      ],
      "description": "inbound: the number rings this agent. outbound: the agent calls from it."
    }
  },
  "required": [
    "agent_id",
    "phone_number_id",
    "direction"
  ],
  "additionalProperties": false,
  "$schema": "http://json-schema.org/draft-07/schema#"
}
```

## Registered output schema

```json theme={null}
{
  "type": "object",
  "properties": {
    "phone_number_id": {
      "description": "The linked number, prefixed phn_"
    },
    "agent_id": {
      "description": "The agent, prefixed agent_"
    },
    "direction": {
      "description": "inbound or outbound"
    },
    "linked_at": {
      "description": "When the link was made"
    }
  },
  "additionalProperties": true,
  "$schema": "http://json-schema.org/draft-07/schema#"
}
```

## Before you call

* Connect and initialize the MCP client with OAuth or an API key for the intended workspace.
* Provide the required parameters: `agent_id`, `phone_number_id`, `direction`.

## Example MCP request

Send `tools/call` after your client completes MCP initialization. Replace placeholder values with IDs and inputs from your workspace. For object and array parameters, follow the nested requirements in the parameter description instead of treating an empty value as complete.

```json theme={null}
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "add_agent_phone_number",
    "arguments": {
      "agent_id": "agent_abc123",
      "phone_number_id": "phn_abc123",
      "direction": "inbound"
    }
  }
}
```

Successful results include `structuredContent` and a text content block containing the same JSON. Check `isError` first, then read `structuredContent` or parse `content[0].text`. See [MCP responses and errors](/docs/mcp-tools/errors) for the full envelope and failure behavior.

## Verify the result

Confirm the response is not marked `isError`. Call [List Organization Phone Numbers](/docs/mcp-tools/phone-numbers/list-organization-phone-numbers) to read the affected resource. Verify that the intended state is visible before making another change.

## Retry safety

This tool changes workspace state. After a timeout, read the affected resource before retrying so you do not create duplicate or conflicting changes.

## Related MCP tools

* [List Organization Phone Numbers](/docs/mcp-tools/phone-numbers/list-organization-phone-numbers): `list_organization_phone_numbers`
* [Get Organization Phone Number](/docs/mcp-tools/phone-numbers/get-organization-phone-number): `get_organization_phone_number`
* [Search Plivo Numbers](/docs/mcp-tools/phone-numbers/search-plivo-numbers): `search_plivo_numbers`

## Related guides

* [Connect to the DialNexa MCP server](/docs/mcp-tools/overview)
* [Phone Numbers MCP tools](/docs/mcp-tools/phone-numbers/overview)
* [MCP responses and errors](/docs/mcp-tools/errors)
