Build / MCP

MCP

The whole Secondlayer surface as Model Context Protocol tools, over one connection, with the same auth as the SDK and CLI.

The server ships as @secondlayer/mcp and speaks stdio. Add it to any MCP client (Claude Code, Cursor, Claude Desktop):

{
  "mcpServers": {
    "secondlayer": {
      "command": "npx",
      "args": ["-y", "@secondlayer/mcp"],
      "env": { "SL_API_KEY": "sk-sl_..." }
    }
  }
}

SL_API_KEY is optional; leave it out for anonymous reads (see Authentication).

An HTTP transport (@secondlayer/mcp-http) adds session management and optional SECONDLAYER_MCP_SECRET bearer auth for hosting the server behind a URL.

Pay-per-call (x402)

For accountless usage, set a Stacks key and the server auto-pays HTTP 402 challenges per call:

X402_PRIVATE_KEY=...          # signs x402 payments
X402_TOPUP_USD=5.00           # optional: auto top-up the prepaid balance
X402_TOPUP_WHEN_BELOW=$0.50   # optional: top-up threshold
SurfaceReadsWrites
IndexAnonymous or any key; see Authentication
Contracts, ScaffoldPublic, no key
SubgraphsPublic subgraphs keyless; private need your keyNeed your key
Streams, Subscriptions, AccountNeed your keyNeed your key

Read these resources before calling tools:

ResourceWhat it returns
secondlayer://contextLive snapshot: your subgraphs, subscriptions, account, chain tips, auth state, and what you can do. Read first.
secondlayer://filtersEvent filter types and the fields each accepts
secondlayer://column-typesSubgraph column types, SQL mappings, and options
secondlayer://traitsSIP standards you can classify and scaffold against (sip-009/010/013)
secondlayer://chain-triggersChain-subscription trigger types and their filter fields

For Index specifically, call index_discover to learn every event type, its columns, and the filters it accepts before building queries.

Thirty-three tools across six domains. Reads are cursor-paginated; writes that kick off work (reindex, backfill, replay, deploy) return an operationId to poll.

Index — decoded reads

ToolWhat it does
index_eventsDecoded events by eventType (stx/ft/nft mint·burn, print, …), with trait scoping
index_ft_transfersDecoded SIP-010 fungible-token transfers
index_nft_transfersDecoded SIP-009 non-fungible-token transfers
index_contract_callsDecoded contract calls: function, args, result
index_transactionsDecoded transactions, filterable by type/sender/contract
index_blocksDecoded blocks
index_discoverThe Index vocabulary: event types, columns, allowed filters
index_print_schemaPer-topic print payload schemas for a contract, inferred from on-chain history; read before writing print_event handlers
batch_queryUp to 10 public /v1 reads in one round trip

Subgraphs — your own indexer

ToolWhat it does
subgraphs_deployDeploy from defineSubgraph() source (managed or BYO Postgres; dryRun previews DDL)
subgraphs_listList your deployed subgraphs
subgraphs_getFull detail: schema, health, table columns
subgraphs_queryQuery a table with operator filters (amount.gte, name.like, …)
subgraphs_gapsList missing block ranges
subgraphs_backfillNon-destructive forward fill of a block range
subgraphs_reindexDrop + reprocess a block range
subgraphs_stopCancel an in-flight reindex/backfill
subgraphs_publishClaim the global public name; anon-readable at /v1/subgraphs/<name>
subgraphs_unpublishMake it private again
subgraphs_deleteDelete a subgraph and its data

Streams — raw firehose

ToolWhat it does
streams_dumpsList the signed bulk dumps manifest (cold backfill). Live Streams reads are REST-only at /v1/streams/*.

Subscriptions — webhooks

ToolWhat it does
subscriptions_createCreate a subgraph- or chain-triggered webhook (returns signingSecret once)
subscriptions_listList subscriptions
subscriptions_getFull detail: filter, auth, retry, circuit state
subscriptions_updatePatch url, filter, auth, retry, timeout, concurrency
subscriptions_testSend a one-off SSRF-guarded test delivery
subscriptions_replayReplay a block range
subscriptions_deleteDelete a subscription

Contracts & scaffold

ToolWhat it does
contracts_findDiscover deployed contracts conforming to a trait (sip-010/009/013)
get_contract_abiFetch a deployed contract's full ABI from the registry
scaffold_from_contractGenerate a subgraph scaffold from a contract's ABI

Account

ToolWhat it does
account_whoamiThe authenticated account's email and plan
account_create_keyMint a scoped streams/index read key (returned once)
  • One-time secrets. account_create_key and subscriptions_create return a key/secret exactly once: forward it to the user.
  • Cursors are opaque and per-keyspace: contract-call cursors are not interchangeable with event cursors.
  • Tail without streaming. For subgraph tables, sort _id desc for the latest, then poll forward with {"_id.gt": "<last id>"}, order asc.
  • See the REST API for the underlying endpoints.