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

# Local Server

The `@secondlayer/mcp` package runs the server over stdio, with all 20 tools.

```json .mcp.json
{
  "mcpServers": {
    "secondlayer": {
      "command": "npx",
      "args": ["-y", "@secondlayer/mcp"],
      "env": {
        "SECONDLAYER_API_URL": "https://api.secondlayer.tools",
        "SECONDLAYER_API_KEY": "<sk-sl_ key from /account/keys>"
      }
    }
  }
}
```

A client's JSON `env` can't read your shell, so this block holds the hosted values from [Keys and Billing](https://www.secondlayer.tools/docs/authentication.md) literally.

## Your Own Instance

On your box, set these instead of the key ([Self-host](https://www.secondlayer.tools/docs/self-host.md#use-these-docs-on-your-box)):

| Variable | Value |
| --- | --- |
| `SECONDLAYER_API_URL` | `http://127.0.0.1:3800` |
| `INSTANCE_TOKEN` | From `.env.local` |

## Over HTTP

The same package's `secondlayer-mcp-http` command serves it over HTTP behind your own URL, with sessions and an optional `SECONDLAYER_MCP_SECRET` bearer.

The local server runs every tool, including subgraph deploys: [Sign-in and Permissions](https://www.secondlayer.tools/docs/mcp/permissions.md) says what each key allows.

## Read next

- [Keys and Billing](https://www.secondlayer.tools/docs/authentication.md)
- [Self-host](https://www.secondlayer.tools/docs/self-host.md)
- [Sign-in and Permissions](https://www.secondlayer.tools/docs/mcp/permissions.md)

## Notes for agents

- Install: 'bunx @secondlayer/mcp' (or npx -y) with SECONDLAYER_API_URL and INSTANCE_TOKEN for the instance. For hosted account tools also set SECONDLAYER_API_KEY.
- 'secondlayer-mcp-http' serves the same tools over HTTP; set SECONDLAYER_MCP_SECRET or authentication is disabled.

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