secondlayer

tools.secondlayer由 secondlayer.tools 發布官方發布者v11.2.4更新於 Oct 30, 2026

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

已驗證Streamable HTTP可網頁執行資料庫開發者工具資料與分析

概覽

AI 產生的概覽

讓助理存取 Stacks 鏈上資料:解碼後的 Index 資料、合約探索、subgraph 生命週期、webhook 與 Streams,可用託管或自架 API。

可以做什麼
  • 讀取解碼後的 Stacks 資料:區塊、交易、合約呼叫、事件、同質化與非同質化代幣轉帳、print 結構,並支援批次讀取
  • 依 SIP trait 探索合約並取得已部署合約的 ABI
  • 建立與執行 subgraph:從觀測到的事件產生骨架、測試對應、部署、查詢資料列、回填、重建索引、停止、檢視缺口與操作紀錄
  • 管理鏈上事件 webhook:建立、更新、暫停、恢復、測試、重播、輪換簽章金鑰,檢視投遞紀錄與死信佇列
  • 檢視 Streams 鏈尖與批次 parquet 匯出清單;為 Index 資料表產生 ORM schema
適用情境
適合在 Stacks 上開發或除錯時使用:探索鏈上活動、撰寫並部署 subgraph 對應,或設定回應鏈上事件的 webhook。唯讀的 Index 與合約工具不需金鑰,也可用來快速回答鏈上資料問題。
執行需求
可使用 api.secondlayer.tools 的遠端 Streamable HTTP 端點並透過瀏覽器 OAuth 登入,或在本地以 bun 執行 npm 套件 @secondlayer/mcp。託管寫入與額度使用 SECONDLAYER_API_KEY(sk-sl_*);自架執行個體的寫入使用 secondlayer init 產生的 INSTANCE_TOKEN。SECONDLAYER_API_URL 用來選擇執行個體。部分工具僅限本地。
安裝前請注意
寫入類工具會建立、部署、重建、回填並永久刪除 subgraph,也會建立或刪除 webhook;請用操作紀錄與投遞紀錄工具核對結果。webhook 簽章金鑰只回傳一次,輪換後舊金鑰立即失效。託管使用會消耗與 SECONDLAYER_API_KEY 相關的額度。託管 API 上的 subgraph 資料來源僅限事件過濾與合約呼叫/部署。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 secondlayer,將其新增到工作區。
  2. 連接 所需的 憑證。它們會被私密儲存,絕不會在公開頁面上展示。
  3. 為需要使用其工具的對話啟用該服務。

Web executable,透過 Streamable HTTP。 遠端服務在工作區中設定後即可從網頁執行環境執行。

交給代理程式安裝

把這段提示詞貼上到 Claude Code、Codex、Cursor 等代理程式,或 SourceWeft 對話中。代理程式會讀取該伺服器的安裝指南,先向你展示發布者、端點和登入方式,經你同意後再把它新增到你的客戶端。金鑰不會寫進任何命令。

閱讀 https://sourceweft.com/mcp/tools.secondlayer%2Fsecondlayer/install.md,並按其中說明把這個 MCP 伺服器接入我的客戶端。修改任何設定之前,先告訴我它的發布者、端點和登入方式,等我確認。不要把 API 金鑰寫進命令或我會提交的檔案;問我金鑰應從哪裡取得。

檢視代理程式所依據的安裝指南

其他 MCP 客戶端

把它新增到你客戶端的 mcpServers 設定中。 客戶端會在首次連接時完成 OAuth 登入。

{
  "mcpServers": {
    "secondlayer": {
      "type": "http",
      "url": "https://api.secondlayer.tools/mcp"
    }
  }
}

README

@secondlayer/mcp

Gives your coding agent direct access to Stacks data, on the hosted API (api.secondlayer.tools) or on your own instance: Index (decoded rows), Subgraphs (tables you define, served from your account or instance), and Streams (raw inputs). Exposes the golden-path tools only: Index reads, the subgraph lifecycle, webhooks, contract discovery/scaffolding, instance status, archive verify/bootstrap, and hosted credits/quote. Everything else (single-record lookups, mempool, stacking, proofs, live Streams reads) is available over REST /v1 + OpenAPI. There is no consume tool.

Hosted

No install: the hosted API serves the read tools over Streamable HTTP, with a browser sign-in.

bash
claude mcp add --transport http secondlayer https://api.secondlayer.tools/mcp

Clients without OAuth send Authorization: Bearer <sk-sl_ key>. Subgraph deploys, webhooks, archive, codegen and instance tools are local only. See /docs/mcp.

Install

bash
bun add @secondlayer/mcp

Auth

Most reads are public: index_* and contracts_find work with no key. Subgraph tools need an INSTANCE_TOKEN past loopback, and so does GET /v1/subgraphs/<name>/<table> over HTTP ({ rows, next_cursor, tip } cursor envelope); on loopback it is open. There is no per-subgraph public or private flag. streams_dumps needs no key: the dumps manifest is public; the tool only needs SL_STREAMS_DUMPS_URL configured. streams_tip is key-mandatory (keyless → 401). Live Streams list reads are REST-only (GET /v1/streams/*). Writes (deploy, reindex, delete, webhooks) need a key, and the key follows the host: on https://api.secondlayer.tools the server uses SECONDLAYER_API_KEY (sk-sl_*) automatically; anywhere else it uses INSTANCE_TOKEN from secondlayer init. Hosted credits/quote use SECONDLAYER_API_KEY too. On the hosted API, subgraph sources are limited to event filters and contract_call/contract_deploy (422 SOURCE_NOT_HOSTABLE otherwise); set startBlock. Read secondlayer://context first: it reports auth state and read-auth tiers.

Quick Start — Stdio (IDE)

Add to your Claude Desktop or Cursor config:

json
{  "mcpServers": {    "secondlayer": {      "command": "bunx",      "args": ["-p", "@secondlayer/mcp", "secondlayer-mcp"],      "env": {        "SECONDLAYER_API_URL": "http://127.0.0.1:3800",        "INSTANCE_TOKEN": "..."      }    }  }}

Quick Start — HTTP (Remote)

bash
export SECONDLAYER_API_URL=http://127.0.0.1:3800export INSTANCE_TOKEN=<from secondlayer init>export SECONDLAYER_MCP_SECRET=your-secretbunx -p @secondlayer/mcp secondlayer-mcp-http# Listening on port 3100

Environment Variables

VariableRequiredDefaultDescription
INSTANCE_TOKENWrites on your instance—From secondlayer init. Required for write tools elsewhere than api.secondlayer.tools; reads are public. Not sent to the hosted API.
SECONDLAYER_API_KEYHosted API, credits/quote/latest—sk-sl_*, used automatically when SECONDLAYER_API_URL is https://api.secondlayer.tools.
SECONDLAYER_API_URLNohttp://127.0.0.1:3800Instance API, or https://api.secondlayer.tools for hosted.
SECONDLAYER_BINCLI toolssecondlayer on PATHPath to the CLI binary (bootstrap, repair).
SECONDLAYER_CWDCLI toolsprocess cwdCompose project directory.
SECONDLAYER_MCP_PORTNo3100HTTP transport port.
SECONDLAYER_MCP_SECRETNo—Bearer token for HTTP auth. Disabled if unset.

Tools

DomainTools
Index (9)index_events, index_ft_transfers, index_nft_transfers, index_contract_calls, index_blocks, index_transactions, index_print_schema, index_discover, batch_query
Subgraphs (12)subgraphs_list, subgraphs_status, subgraphs_spec, subgraphs_scaffold, subgraphs_deploy, subgraphs_delete, subgraphs_query, subgraphs_backfill, subgraphs_reindex, subgraphs_stop, subgraphs_operations, subgraphs_gaps
Webhooks (13)webhooks_create, webhooks_list, webhooks_get, webhooks_update, webhooks_delete, webhooks_test, webhooks_pause, webhooks_resume, webhooks_rotate_secret, webhooks_deliveries, webhooks_dead, webhooks_requeue, webhooks_replay
Streams (2)streams_tip, streams_dumps
Contracts (2)contracts_find, contracts_get_abi
Instance (1)instance_status
Archive (5)archive_verify, archive_bootstrap, archive_repair, archive_latest, archive_quote
Credits (1)credits_balance (needs SECONDLAYER_API_KEY)
Account (4)account_whoami, account_create_key, account_list_keys, account_rotate_key (only when pointed at https://api.secondlayer.tools)

Verify after mutating: subgraphs_operations for deploy/reindex/backfill/stop, webhooks_deliveries for create/test/replay. Empty index: archive_bootstrap, poll instance_status until decoders are ok, then archive_verify, then codegen_index_schema.

Periphery surfaces (single block/tx lookups, mempool, stacking, proofs, credits/caps, live Streams reads/SSE) are REST-only: see the OpenAPI spec at the API host. Live Streams list reads use GET /v1/streams/events.

Point the server at your instance with SECONDLAYER_API_URL (default http://127.0.0.1:3800). Writes use INSTANCE_TOKEN from secondlayer init. account_* tools appear only when the server is pointed at https://api.secondlayer.tools.

webhooks_create triggers

Webhooks fire on raw chain events. Pass a triggers array (contract / event / function / trait), e.g. [{ "type": "contract_call", "contractId": "SP....amm", "functionName": "swap-*" }]. To react to subgraph rows, read the table from your own Postgres or poll the subgraph API.

subgraphs_query enhancements

  • fields — comma-separated column projection (e.g. "sender,amount_x")
  • count — boolean, returns row count instead of rows
  • Filter operators: eq, neq, gt, gte, lt, lte, like
  • Max limit: 200

Resources

URIDescription
secondlayer://contextLive state — what exists (your subgraphs, webhooks, account), what you can do, and read-auth tiers. Read first.
secondlayer://filtersSubgraph source filter types and their fields
secondlayer://column-typesColumn type mappings and options
secondlayer://traitsSIP trait standards (valid trait values)
secondlayer://chain-triggersChain-webhook trigger types and fields

Error Handling

All tools return structured errors with isError: true:

json
{ "error": { "type": "not_found", "status": 404, "message": "Subgraph not found" } }
Error typeStatusWhen
unauthorized401Invalid or missing API key
not_found404Resource doesn't exist
rate_limited429Too many requests
server_error5xxServer-side failure
errorotherValidation, bundling, etc.

Bundle/deploy errors use descriptive prefixes: "Bundle failed:", "Module evaluation failed:", "Validation failed:". HTTP transport enforces a 1MB body limit (413) and JSON parse safety (400). Scaffold ABI fetch has a 10s timeout.

Programmatic Usage

typescript
import { createServer } from "@secondlayer/mcp";
const server = createServer();// Connect to your own transport

License

MIT

來源:packages/mcp/README.md,提交 7869d72

工具

47

subgraphs_scaffold

Generate a subgraph from observed print events when available; ABI token transfers or public functions only when the contract has never printed. Review the TypeScript, run subgraphs_test until ok: true with written >= 1, read skipped, then subgraphs_deploy. dryRun is DDL only.

輸入參數contractId必填subgraphName

subgraphs_list

List all deployed subgraphs. Returns summary fields only; read rows with subgraphs_query.

無需輸入參數。

subgraphs_status

Get full details of a subgraph including schema, health (incl. health.emptyMapping when processed events wrote 0 rows), and table columns.

輸入參數name必填

subgraphs_spec

Fetch a subgraph's self-describing spec — the tables, columns, filters, and read URLs a consumer needs, without guessing. `agent` (default) returns the compact JSON schema built for tool use, `openapi` the OpenAPI document for the subgraph's read routes, `markdown` human-readable docs. Read it before writing queries against an unfamiliar subgraph.

輸入參數name必填format

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). Filters support operators: "amount.gte": "1000", "sender.neq": "SP...", "name.like": "%token%". Available operators: eq, neq, gt, gte, lt, lte, like. Every page with rows returns next_cursor (null only when empty): pass it back as `cursor` to read the next page. To TAIL new rows (no streaming over MCP), poll with cursor = next_cursor ?? the cursor you sent. Fetch one row by id with {"_id": "<id>"}. The same rows are readable over HTTP at GET /v1/subgraphs/<name>/<table>; hand that URL to third parties.

輸入參數name必填sortcountlimitordertable必填cursorfieldsfilters

subgraphs_reindex

Reindex a subgraph: drops and rebuilds the whole subgraph from its start block to chain tip. Takes no block range — use subgraphs_backfill to process a specific range. Returns an operationId — check subgraphs_status (health) or the REST operations endpoint to track progress to completion.

輸入參數name必填

subgraphs_backfill

Backfill a subgraph over a block range. Non-destructive forward fill (does not drop existing data) — unlike subgraphs_reindex, and the only data-fill path for BYO subgraphs (reindex is blocked there). Both blocks required. Returns an operationId — check subgraphs_status (health) or the REST operations endpoint to track progress.

輸入參數name必填toBlock必填fromBlock必填

subgraphs_stop

Cancel an in-flight reindex or backfill operation for a subgraph. Returns the stop request status; check subgraphs_status (health) or the REST operations endpoint to confirm it reaches a terminal state.

輸入參數name必填

subgraphs_gaps

List indexing gaps (missing block ranges) for a subgraph. Each gap reports start/end/size, reason, and detected/resolved timestamps. Feed an unresolved gap's range into subgraphs_backfill to fill it. Defaults to unresolved gaps.

輸入參數name必填limitoffsetresolved

subgraphs_operations

Operation history for a subgraph (deploy/reindex/backfill/stop), newest first — status, block range, progress, and error. THIS IS THE VERIFY CALL: after subgraphs_deploy, subgraphs_reindex, subgraphs_backfill, or subgraphs_stop, poll it with the returned operationId until `status` is terminal (completed/failed/cancelled) before reporting success. Omit operationId for the recent history.

輸入參數name必填operationId

subgraphs_delete

Delete a subgraph permanently.

輸入參數name必填

subgraphs_deploy

Deploy a subgraph from TypeScript code. Pass the full defineSubgraph() source — it will be bundled, validated, and deployed. Optional startBlock overrides the source definition for this deploy. dryRun validates schema/DDL only and does not run handlers — call subgraphs_test first and deploy only when it returns ok: true with written >= 1. Call subgraphs_reindex separately if you need a forced reindex.

輸入參數code必填dryRunstartBlock

subgraphs_test

Prove a subgraph mapping writes rows against Index data before deploy. Pass full defineSubgraph() source plus a height range. Returns ok/written/tables; EMPTY_MAPPING means events matched but 0 rows were written — read hint for observed event.data keys and do not invent fields. subgraphs_deploy dryRun is DDL only; do not deploy until ok: true with written >= 1.

輸入參數code必填limittoHeightfromHeight必填

webhooks_list

List all webhooks for the current account. Returns summary fields (no secrets).

無需輸入參數。

webhooks_get

Get full detail for a webhook (triggers, auth, retry config, circuit state).

輸入參數id必填

webhooks_create

Create a webhook that fires on raw chain events (set triggers). Returns `signingSecret` ONCE — forward it to the user so they can wire it into their receiver.

輸入參數url必填name必填formattriggers必填authConfig

webhooks_update

Patch a webhook (name, url, authConfig, format, retry, timeout, concurrency).

輸入參數id必填urlnameformattimeoutMsauthConfigmaxRetriesconcurrency

webhooks_delete

Delete a webhook. Pending outbox rows are cascade-deleted.

輸入參數id必填

webhooks_test

Send a one-off test webhook to a webhook's URL (built for its format, SSRF-guarded). Logged as a delivery row. Returns {ok, statusCode, error, durationMs, deliveryId}.

輸入參數id必填

webhooks_pause

Pause a webhook: stops delivery attempts and stops queueing new ones. Nothing is deleted — resume picks the webhook back up from the tip. Verify with webhooks_get (status).

輸入參數id必填

webhooks_resume

Resume a paused webhook (also clears a tripped circuit breaker). Deliveries restart from the current tip — use webhooks_replay for the blocks missed while paused. Verify with webhooks_get (status).

輸入參數id必填

webhooks_rotate_secret

Rotate a webhook's signing secret. Returns the NEW `signingSecret` ONCE — forward it to the user; deliveries signed with the old secret stop verifying as soon as this returns, so the receiver must be updated.

輸入參數id必填

webhooks_deliveries

List recent delivery attempts for a webhook — status code, attempt count, error, duration, timestamps. THIS IS THE VERIFY CALL: after webhooks_create, webhooks_test, or webhooks_replay, read it to confirm the webhook actually landed (and to see the receiver's response when it didn't) instead of trusting the enqueue result.

輸入參數id必填

webhooks_dead

List a webhook's dead-letter queue — deliveries that exhausted their retries, with the outbox id, payload, and last error. Diagnose the receiver first (webhooks_get for the URL/auth, webhooks_test for a live probe), then requeue rows with webhooks_requeue.

輸入參數id必填

webhooks_requeue

Requeue ONE dead-lettered delivery for another attempt, by its outbox id from webhooks_dead. Fix the receiver first — a requeue against a still-broken endpoint just dies again. Verify with webhooks_deliveries.

輸入參數id必填outboxId必填

webhooks_replay

Replay a block range for a webhook. Replays run at 10% of batch capacity — use sparingly. Pass `force` (a short idempotency suffix) to re-run a range that was already replayed.

輸入參數id必填forcetoBlock必填fromBlock必填

index_ft_transfers

List decoded SIP-010 fungible-token transfers from Index. Reads are keyless.

輸入參數limitordercursorsendertoHeightrecipientcontractIdfromHeightassetIdentifier

index_nft_transfers

List decoded SIP-009 non-fungible-token transfers from Index. Reads are keyless.

輸入參數limitordercursorsendertoHeightrecipientcontractIdfromHeightassetIdentifier

index_events

List decoded chain events from the Index by event type. Use this for event types without a dedicated tool (stx_*, ft_mint/burn, nft_mint/burn, print), and for trait-scoped queries: set `trait` (e.g. sip-010) to match all contracts conforming to a standard — pair with contracts_find to discover traits. For ft/nft transfers without a trait prefer index_ft_transfers / index_nft_transfers.

輸入參數limitordertraitcursorsendertoHeighteventType必填recipienttxContextcontractIdfromHeightassetIdentifier

index_contract_calls

List decoded contract calls from the Index (function name, args, result). Set `trait` (e.g. sip-010) to match calls to all contracts conforming to a standard. Note: contract-call cursors are a SEPARATE keyspace from event cursors — they are not interchangeable.

輸入參數limittraitcursorsendertoHeightcontractIdfromHeightfunctionName

index_blocks

List decoded blocks from Index. Reads are keyless.

輸入參數limitcursortoHeightfromHeight

index_transactions

List decoded transactions from Index. Filter by type, sender, or contract. Reads are keyless.

輸入參數typelimitcursorsendertoHeightcontractIdfromHeight

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. Use before writing print_event subgraph handlers to learn what's on e.data. Anonymous read.

輸入參數contractId必填

index_discover

Discover the Index vocabulary: every event type and its columns, allowed/equality filters, and required-non-null fields (and which types accept `trait`). Read this before building Index queries instead of guessing filters. Anonymous read.

無需輸入參數。

batch_query

Run up to 10 public /v1 reads in one round trip (POST /v1/batch). Each item keeps its own auth/quota/pay-per-call semantics; results return in order with per-item status. Paths must start with /v1/index, /v1/subgraphs, /v1/streams, or /v1/contracts.

輸入參數requests必填

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. Call it before a cursor walk to know where the stream ends, and after an ingest to check lag.

無需輸入參數。

streams_dumps

List the Streams bulk parquet dumps manifest — coverage range, latest_finalized_cursor, and per-file metadata (block range, row count, size, sha256, signed URL). This is the cold backfill path for downloading all raw data; fetch the file URLs directly (e.g. with DuckDB). Requires the dumps base URL to be configured (SL_STREAMS_DUMPS_URL). For live reads use REST GET /v1/streams/events; for tip/lag use streams_tip.

無需輸入參數。

contracts_find

Discover deployed Stacks contracts conforming to a trait (e.g. "sip-010", "sip-009", "sip-013"). The discovery endpoint for "which contracts implement X". Reads are public.

輸入參數limittrait必填cursorincludeconformance

contracts_get_abi

Fetch a single deployed contract's ABI from the registry (prod-safe). Returns the contract's metadata + full ABI (functions, maps, variables, fungible/non-fungible tokens). Returns not_found if the contract isn't in the registry. Use it to inspect a contract before subgraphs_scaffold.

輸入參數contractId必填

codegen_index_schema

Generate an ORM schema for the Index tables (blocks, transactions, decoded_events, …) — the same output as `sl codegen index`. Returns the file contents as text; write it wherever your project keeps its schema. Use `tables` to emit only what you read.

輸入參數tablestargetschemaNamedatasourceEnv

instance_status

Decoder health and empty-index diagnosis from GET /public/status. If state is empty-index, next tool is archive_bootstrap. Poll until index.decoders are ok before treating Index as ready — do not start decoders. Then archive_verify, then codegen_index_schema. Do not download parquet.

無需輸入參數。

archive_verify

Read-only, free compare of this instance against a signed archive (POST /v1/archive/verify). unanchored means pin a key or check the URL — not that the instance is fine. After bootstrap, poll instance_status until decoders ok, then this, then codegen_index_schema. Do not download parquet.

輸入參數targetagainst必填toBlockfromBlock

archive_latest

Signed pointer to the official archive tree (hosted). Needs SECONDLAYER_API_KEY (sk-sl_*), not INSTANCE_TOKEN. Use the returned origin as --against for archive_bootstrap. Do not download parquet.

輸入參數against

archive_quote

Price a hosted archive fetch (metered). Needs SECONDLAYER_API_KEY (sk-sl_*), not INSTANCE_TOKEN. Quote happens here; bootstrap/repair also quote inside the CLI. Do not download parquet.

輸入參數flow必填paths必填

credits_balance

Archive credits balance at api.secondlayer.tools. Needs SECONDLAYER_API_KEY (sk-sl_*); INSTANCE_TOKEN is the instance.

無需輸入參數。

archive_bootstrap

Restore verified history into this instance (secondlayer bootstrap --against … --yes --json). Metered against the official archive; quote happens inside the CLI. After bootstrap, poll instance_status until decoders ok, then archive_verify, then codegen_index_schema. Do not download parquet.

輸入參數against必填toBlockfromBlock

archive_repair

Plan (default) or apply a repair of local chain data against a signed archive. Metered when apply fetches from the official archive. After apply, poll instance_status until decoders ok, then archive_verify. Do not download parquet.

輸入參數applyagainst必填toBlockfromBlock

版本歷史

1
  1. v11.2.4最新Oct 30, 2026

評分

已滿足適用檢查項的 100%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通必需25 分
  • 已宣告認證方式必需10 分
  • 已列出工具15 分
  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分