<!-- source: https://www.secondlayer.tools/docs/mcp/tools -->

# Tools

Read `secondlayer://context` first, then any other resource you need, before calling tools.

## Resources

| Resource | What it returns |
| --- | --- |
| `secondlayer://chain-triggers` | Chain-webhook trigger types and the filter fields each accepts. |
| `secondlayer://column-types` | Subgraph column types, SQL mappings, and options |
| `secondlayer://context` | Live agent context — what exists (your subgraphs, webhooks, account), what you can do, and read-auth tiers. |
| `secondlayer://filters` | Event filter types and their available fields |
| `secondlayer://traits` | SIP trait standards the platform can classify and scaffold against — the valid values for contracts_find `trait`. |
| `secondlayer://samples/{contractId}` | Decoded camelCase print samples for a contract (schema + up to 5 events). |

For Index, call `contracts_find` and `index_print_schema` first to learn what a contract emits.

## Every Tool

Reads are cursor-paginated. The server stays at 20 tools or fewer; create, update, replay and other admin verbs are `secondlayer <noun> ... --json` in the CLI. Account tools register only when `SECONDLAYER_API_URL` is the hosted API.

### Subgraphs

| Tool | What it does |
| --- | --- |
| `subgraphs_deploy` | Deploy a subgraph from TypeScript code. Local only. |
| `subgraphs_list` | List all deployed subgraphs. |
| `subgraphs_query` | Query rows from a subgraph table (max 200 rows), reading the open /v1 surface — { rows, next_cursor, tip } envelope, cursor-paginated (no offset). |
| `subgraphs_status` | Get full details of a subgraph including schema, health (incl. health.emptyMapping when processed events wrote 0 rows), and table columns. |
| `subgraphs_test` | Prove a subgraph mapping writes rows against Index data before deploy. Local only. |

### Webhooks

| Tool | What it does |
| --- | --- |
| `webhooks_deliveries` | List recent delivery attempts for a webhook — status code, attempt count, error, duration, timestamps. |
| `webhooks_list` | List all webhooks for the current account. |

### Index

| Tool | What it does |
| --- | --- |
| `batch_query` | Run up to 10 public /v1 reads in one round trip (POST /v1/batch). |
| `index_events` | List chain events from the Index by event type. |
| `index_print_schema` | Empirical per-topic print payload schemas for a contract, inferred from sampled on-chain events: each topic's fields with observed Clarity types, decoded TS types, subgraph column types, and presence rates. |
| `index_rune_activity` | List Bitcoin Runes etch, mint, transfer, and burn events. |
| `index_rune_balances` | List current Bitcoin Runes balances per unspent output. |
| `index_runes` | List the Bitcoin Runes catalog: identity, supply, mints, and mint terms. |
| `index_state_writes` | List the exact contract-state writes each block committed, in node order: {block_height, ordinal, tx_index, key, value_hex}. |

### Streams

| Tool | What it does |
| --- | --- |
| `streams_tip` | Current canonical chain tip as Streams sees it: block height/hash, burn height, finalized_height, lag_seconds, and the oldest seekable height/cursor for this key's retention window. |

### Contracts

| Tool | What it does |
| --- | --- |
| `contracts_find` | Discover deployed Stacks contracts conforming to a trait (e.g. "sip-010", "sip-009", "sip-013"). |
| `contracts_get_abi` | Fetch a single deployed contract's ABI from the registry (prod-safe). |

### Proofs

| Tool | What it does |
| --- | --- |
| `proofs_inspect` | Proof inventory for one Stacks block: the state writes the block committed (not checked here) and the free /v1/proofs routes that serve every byte. |

### Account

| Tool | What it does |
| --- | --- |
| `account_whoami` | Show the archive account email at api.secondlayer.tools, not the self-host instance. Hosted only. |
| `billing_status` | Read-only credits state for the account at api.secondlayer.tools: prepaid balance, this month's spend, auto-refill config, this month's usage and the 24h burn rate. Hosted only. |

- Cursors are opaque and per keyspace: contract-call cursors are not interchangeable with event cursors.
- For subgraph tables, every page with rows returns `next_cursor`: poll with `cursor = next_cursor ?? cursor` to tail without streaming.
- The underlying endpoints: [API reference](https://www.secondlayer.tools/docs/api-reference.md).

## Read next

- [API](https://www.secondlayer.tools/docs/api-reference.md)

## Notes for agents

- Read tools: contracts_find and index_print_schema to learn what exists, then index_events (every event type, including transfers); cursor-paginate.
- Read 'secondlayer://context' first (instance state, chain tips, capabilities), plus 'secondlayer://filters' and 'secondlayer://chain-triggers'.
- Tools marked Local only are not on the hosted server.

## Setup

Ensure setup once, skipping any step already done:
- CLI: `bun add -g @secondlayer/cli`
- Instance: `secondlayer init` writes `INSTANCE_TOKEN`. Loopback `/v1` reads need no key.
- Hosted reads: export `SECONDLAYER_API_KEY` (`sk-sl_*`) or buy credits with `secondlayer credits buy` (`balance`, `refill`), then `secondlayer whoami`
