secondlayer

Official registry Search and web

Stacks chain data: contracts, events, transfers, subgraph scaffolds. Hosted with browser sign-in.

Install

Add this to your client's MCP configuration (Claude Desktop: claude_desktop_config.json; Cursor: .cursor/mcp.json; VS Code and others use the same "mcpServers" shape).

Remote (streamable-http)
Claude Code
claude mcp add --transport http secondlayer 'https://api.secondlayer.tools/mcp'
JSON configuration (Claude Desktop, Cursor, VS Code)
{
    "mcpServers": {
        "secondlayer": {
            "type": "http",
            "url": "https://api.secondlayer.tools/mcp"
        }
    }
}
NPM package @secondlayer/mcp
Claude Code
claude mcp add secondlayer -e 'SECONDLAYER_API_KEY=<your secondlayer_api_key>' -e 'SECONDLAYER_API_URL=http://127.0.0.1:3800' -- npx -y @secondlayer/mcp@11.2.4
JSON configuration (Claude Desktop, Cursor, VS Code)
{
    "mcpServers": {
        "secondlayer": {
            "command": "npx",
            "args": [
                "-y",
                "@secondlayer/mcp@11.2.4"
            ],
            "env": {
                "SECONDLAYER_API_KEY": "<your secondlayer_api_key>",
                "SECONDLAYER_API_URL": "http://127.0.0.1:3800"
            }
        }
    }
}

Environment variables

  • SECONDLAYER_API_KEY secret Account API key (sk-sl_*) for the hosted API: credits, writes.
  • SECONDLAYER_API_URL Instance API URL. Use https://api.secondlayer.tools for hosted.

Documentation

From the project's README on GitHub, refreshed weekly. Links open on GitHub.

Contents
  1. Secondlayer
  2. Quickstart
  3. Read it from your instance
  4. Packages
  5. Self-host
  6. Built on Secondlayer
  7. Development
  8. License

Secondlayer

Your app needs Stacks data that no public API has — your contract, your schema, your uptime. Today that means writing an indexer.

Secondlayer is the runtime instead: decoded chain data in your own database, backfilled from genesis, reorg-safe, kept current. Get tables and a REST API out of the box, or stream rows into your own schema — Postgres, SQLite, or anything you already run — and serve them however you already serve things.

Run it hosted on api.secondlayer.tools (account key, 1M rows free every month) or self-host: Postgres plus one container, on your hardware.

Hosted quickstart: https://www.secondlayer.tools/docs. Self-host: https://www.secondlayer.tools/docs/self-host.

curl "http://127.0.0.1:3800/v1/index/events?event_type=ft_transfer&limit=5"

Quickstart

bun add -g @secondlayer/cli
secondlayer init --network mainnet
cd docker/oss && docker compose up -d
secondlayer observer --mode indexer --endpoint secondlayer:3700
secondlayer bootstrap --against <manifest>
secondlayer verify all --against <manifest>

# Index a contract into a typed, queryable Postgres table
export SL_API_URL=http://127.0.0.1:3800
secondlayer subgraphs scaffold SP1234ABCD.my-contract -o subgraphs/my-contract.ts
secondlayer subgraphs deploy subgraphs/my-contract.ts --start-block <recent-block>
secondlayer subgraphs query my-contract <table> --sort _block_height --order desc

A webhook fires on raw chain events:

secondlayer webhooks create amm-swaps \
  --url https://my-app.com/webhook \
  --trigger '{"type":"contract_call","contractId":"SP....amm","functionName":"swap-*"}'

Docs → self-host · CLI → packages/cli/README.md.

Read it from your instance

SDK default is http://127.0.0.1:3800 (or SL_API_URL).

import { SecondLayer } from "@secondlayer/sdk";

const sl = new SecondLayer();
const { rows, next_cursor, tip } = await sl.subgraphs.rows("my-contract", "<table>", {
  order: "desc",
  limit: 25,
});
curl "http://127.0.0.1:3800/v1/subgraphs/my-contract/<table>?_limit=25"

Pages are _id-keyset: pass ?cursor=<next_cursor> to resume, _order=asc|desc for direction.

MCP — bunx -p @secondlayer/mcp secondlayer-mcp (default local API). Set INSTANCE_TOKEN from secondlayer init for writes on your instance; against api.secondlayer.tools it uses SECONDLAYER_API_KEY instead (the key follows the host). See MCP README.

Packages

Two TypeScript SDKs, one chooser: @secondlayer/sdk talks to this instance (query subgraphs, manage webhooks); @secondlayer/stacks is low-level chain primitives (Clarity decoding, reads). Most apps only need sdk.

PackageDescription
@secondlayer/clisecondlayer binary — init, bootstrap, verify, deploy
@secondlayer/sdkTypeScript SDK — Streams, Index, subgraphs, webhooks
@secondlayer/mcpMCP server — instance tools for agents
@secondlayer/stacksviem-style Stacks client — public/wallet, BNS
@secondlayer/verifyCheck a Stacks block yourself: Bitcoin headers, signers, state proofs
@secondlayer/subgraphsdefineSubgraph() — schema, triggers, handlers
@secondlayer/sharedShared db, schemas, crypto helpers
@secondlayer/apiREST API for the instance

Self-host

git clone https://github.com/ryanwaits/secondlayer
cd secondlayer/docker/oss
secondlayer init --network mainnet
docker compose up -d

OSS quickstart.

Built on Secondlayer

  • robinhood-bridge: Stacks SIP-010 to Robinhood Chain and back, behind 2-of-2 keys. Demo token only.

Development

bun install && bun run build && bun run test

Releases flow through Changesets: bun run version to bump, bun run release to publish.

License

MIT

Frequently asked questions

What is secondlayer?

Stacks chain data: contracts, events, transfers, subgraph scaffolds. Hosted with browser sign-in.

How do I install secondlayer?

It runs as a remote server. In Claude Code: claude mcp add --transport http secondlayer 'https://api.secondlayer.tools/mcp'. For other clients, paste the JSON configuration from this page into their MCP settings.

Does secondlayer need an API key?

Yes. It expects SECONDLAYER_API_KEY, which you set in its configuration.

Is secondlayer open source?

Yes. Its code is on GitHub under the MIT license.

Who maintains secondlayer?

It is published by ryanwaits. AI.tn lists it but does not maintain or endorse it.

From the official MCP Registry. Listing is not an endorsement: review a server's code and permissions before giving it access to your data.