> For the complete documentation index, see [llms.txt](https://chaincontext.gitbook.io/help-center/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://chaincontext.gitbook.io/help-center/building/building-tools.md).

# Building Tools

## Overview

Tools are MCP functions that AI agents can call. Each tool has a name, description, input parameters, and a **block stack** — a visual pipeline of blocks that execute in order to produce a result.

## Creating a tool

1. Go to your project → **Tools** tab
2. Click **New Tool** (or start from a marketplace template)
3. Configure the tool name, description, and interaction type (read or write)
4. Build your block stack using the visual editor

## Block types

### contract\_call

Calls a read-only function on your smart contract.

* **Function:** select from the contract's ABI
* **Network:** which chain to call (filtered by project mode)
* **Arguments:** map input parameters or static values to function arguments
* **Output:** the return value(s) from the contract function

<details>

<summary>How output fields are derived from the ABI</summary>

Output fields are automatically derived from the ABI return types (Rules 1–5):

* Named outputs keep their names
* Unnamed outputs become `value` (single) or `value_0`, `value_1` (multiple)
* Tuples are flattened with dot notation
* Arrays are capped at 10 elements

</details>

### build\_unsigned\_tx

Generates an unsigned transaction for a write function.

{% hint style="danger" %}
ChainContext **never** signs or submits transactions — it returns the raw transaction data and a WalletConnect URI so the user's wallet can sign.
{% endhint %}

* **Function:** select a write/payable function from the ABI
* **Return format:** `raw` (hex-encoded calldata), `walletconnect` (URI for wallet deep-linking), or `both`
* Output fields: `rawTx`, `gas`, `walletConnectUri`

### data\_source

Fetches data from built-in adapters:

| Source          | Data available                                   |
| --------------- | ------------------------------------------------ |
| **CoinGecko**   | Token prices, market data, trending tokens       |
| **DexScreener** | DEX pair data, liquidity, price charts           |
| **Etherscan**   | Transaction history, token transfers, gas prices |

Each adapter exposes specific endpoints with their own parameters. The block config UI shows available endpoints and auto-populates output fields.

### http\_request

{% hint style="warning" %}
Studio plan only. Not available on Free or Builder plans.
{% endhint %}

Call any external HTTP API.

* **Method:** GET, POST, PUT, DELETE
* **URL:** supports `{{variable}}` interpolation
* **Headers and body:** configurable with variable references
* **Output:** parsed JSON response

### transform

Reshape data between blocks. Available operations:

| Operation       | Description                                 |
| --------------- | ------------------------------------------- |
| `math`          | Arithmetic (`+`, `-`, `*`, `/`, `%`, `**`)  |
| `format_number` | Decimal places, locale formatting           |
| `format_date`   | Date/time formatting                        |
| `concatenate`   | Join strings                                |
| `template`      | String template with `{{var}}` placeholders |
| `map`           | Transform array elements                    |
| `filter`        | Filter arrays by condition                  |
| `sort`          | Sort arrays by field                        |
| `pick`          | Select specific fields from an object       |
| `flatten`       | Flatten nested arrays                       |
| `aggregate`     | Sum, average, min, max, count               |
| `json_path`     | Extract values using JSONPath expressions   |

### condition

Branch execution based on a comparison. Supports: `eq`, `neq`, `gt`, `gte`, `lt`, `lte`, `contains`, `not_contains`, `is_empty`, `is_not_empty`.

The true and false branches each contain their own block sub-stacks.

### response\_formatter

Format the final output presented to the AI agent. Define a template string with `{{blockId.field}}` references.

## Variable interpolation

Any block field that accepts text supports `{{blockId.fieldName}}` syntax to reference output fields from previous blocks. The runtime resolves these at execution time.

{% hint style="info" %}
**Special references:**

* `{{input.paramName}}` — references the tool's input parameters
* `{{contract.address}}` — the contract address
* `{{contract.network.chainId}}` — the active network's chain ID
  {% endhint %}

## Input schema

Define the parameters that AI agents must provide when calling your tool:

* **name** — parameter name (e.g., `tokenAddress`)
* **type** — `string`, `number`, `boolean`, `address`, `uint256`, `bytes32`, etc.
* **description** — helps the AI understand what value to provide
* **required** — whether the parameter is mandatory

## Output formatting

Configure how each output field is presented:

* **Label** — human-readable name
* **Format** — number formatting, date formatting, currency symbols
* **Unit** — suffix (e.g., "ETH", "%", "USD")

## Annotations

MCP tool annotations help AI agents understand tool behavior:

| Annotation        | Default (read) | Default (write) |
| ----------------- | -------------- | --------------- |
| `readOnlyHint`    | true           | false           |
| `destructiveHint` | false          | true            |
| `idempotentHint`  | true           | false           |
| `openWorldHint`   | true           | true            |

## Marketplace templates

Browse pre-built tool templates in the **Marketplace** tab. Templates include pre-configured block stacks that you can import and customize.

## AI-generated descriptions

{% hint style="success" %}
**Builder+ plans:** Click the sparkle icon next to the tool name or description to generate an AI-written description based on your tool's configuration.
{% endhint %}
