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

# Sign-in and Permissions

An agent reads with browser sign-in or a key, and deploys subgraphs only on the local server.

| Surface | Reads | Writes |
| --- | --- | --- |
| Index, Streams, Contracts | Hosted: `SECONDLAYER_API_KEY`. Self-host: open on loopback | — |
| Proofs | Free, no key | — |
| Account (`account_whoami`, `billing_status`) | Hosted: sign-in or `SECONDLAYER_API_KEY` | — |
| Subgraphs, Webhooks | Hosted: sign-in or `SECONDLAYER_API_KEY`. Self-host: open on loopback | `subgraphs_deploy` only, on the local server. Hosted: `SECONDLAYER_API_KEY`. Self-host: `INSTANCE_TOKEN` |

A token sent on a loopback read that did not need it is ignored, never rejected.

## Revoke Access

- An app can't make, rotate or revoke keys.
- Revoke an app under Apps on [/account/keys](/account/keys).

## Notes for agents

- subgraphs_deploy: run subgraphs_test first, then dryRun to preview the DDL.
- Subgraph tools: list, status, query, test, deploy. Webhook tools: list, deliveries. Hosted (sign-in or key) serves list, status, query and both webhook tools, read-only; test and deploy are local. Webhook writes are CLI --json.
- An app signed in over OAuth cannot create, rotate or revoke keys.

## 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`
