@secondlayer/mcp 7.5.0 → 8.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/dist/bin-http.js +82 -212
- package/dist/bin-http.js.map +5 -5
- package/dist/bin.js +82 -212
- package/dist/bin.js.map +5 -5
- package/dist/index.js +82 -212
- package/dist/index.js.map +5 -5
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ bun add @secondlayer/mcp
|
|
|
16
16
|
|
|
17
17
|
## Auth
|
|
18
18
|
|
|
19
|
-
Most reads are public: `index_*` and `contracts_find` work with no key. Subgraph tools need an `INSTANCE_TOKEN` past loopback; separately, **public** subgraphs are anon-readable over HTTP at `GET /v1/subgraphs/<name>/<table>` (`{ rows, next_cursor, tip }` cursor envelope), while private ones need the instance token (anon → 404). `streams_dumps` needs no key: the dumps manifest is public; the tool only needs `SL_STREAMS_DUMPS_URL` configured.
|
|
19
|
+
Most reads are public: `index_*` and `contracts_find` work with no key. Subgraph tools need an `INSTANCE_TOKEN` past loopback; separately, **public** subgraphs are anon-readable over HTTP at `GET /v1/subgraphs/<name>/<table>` (`{ rows, next_cursor, tip }` cursor envelope), while private ones need the instance token (anon → 404). `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: set `INSTANCE_TOKEN` from `secondlayer init`. Hosted credits/quote use `SECONDLAYER_API_KEY` (`sk-sl_*`). Read `secondlayer://context` first: it reports auth state and read-auth tiers.
|
|
20
20
|
|
|
21
21
|
## Quick Start — Stdio (IDE)
|
|
22
22
|
|
|
@@ -66,7 +66,7 @@ bunx -p @secondlayer/mcp secondlayer-mcp-http
|
|
|
66
66
|
| **Index** (9) | `index_events`, `index_ft_transfers`, `index_nft_transfers`, `index_contract_calls`, `index_blocks`, `index_transactions`, `index_print_schema`, `index_discover`, `batch_query` |
|
|
67
67
|
| **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` |
|
|
68
68
|
| **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` |
|
|
69
|
-
| **Streams** (
|
|
69
|
+
| **Streams** (2) | `streams_tip`, `streams_dumps` |
|
|
70
70
|
| **Contracts** (2) | `contracts_find`, `contracts_get_abi` |
|
|
71
71
|
| **Instance** (1) | `instance_status` |
|
|
72
72
|
| **Archive** (5) | `archive_verify`, `archive_bootstrap`, `archive_repair`, `archive_latest`, `archive_quote` |
|
|
@@ -80,8 +80,8 @@ Verify after mutating: `subgraphs_operations` for deploy/reindex/backfill/stop,
|
|
|
80
80
|
`archive_verify`, then `codegen_index_schema`.
|
|
81
81
|
|
|
82
82
|
Periphery surfaces (single block/tx lookups, mempool, stacking, proofs,
|
|
83
|
-
credits/caps, live Streams SSE) are REST-only: see the OpenAPI spec at
|
|
84
|
-
host.
|
|
83
|
+
credits/caps, live Streams reads/SSE) are REST-only: see the OpenAPI spec at
|
|
84
|
+
the API host. Live Streams list reads use `GET /v1/streams/events`.
|
|
85
85
|
|
|
86
86
|
Point the server at your instance with `SECONDLAYER_API_URL` (default
|
|
87
87
|
`http://127.0.0.1:3800`). Writes use `INSTANCE_TOKEN` from
|
package/dist/bin-http.js
CHANGED
|
@@ -191,7 +191,6 @@ var PRODUCT_BLURBS = {
|
|
|
191
191
|
contracts: "trait-based contract discovery and ABIs",
|
|
192
192
|
subgraphs: "author/scaffold/deploy/query custom indexes",
|
|
193
193
|
webhooks: "a signed POST to a URL you run, on subgraph rows or raw chain events",
|
|
194
|
-
subscriptions: "a signed POST to a URL you run, on subgraph rows or raw chain events",
|
|
195
194
|
account: "identity and self-provisioned API keys",
|
|
196
195
|
codegen: "ORM schemas for the tables you read",
|
|
197
196
|
instance: "decoder health and empty-index diagnosis",
|
|
@@ -205,7 +204,6 @@ var PRODUCT_ORDER = [
|
|
|
205
204
|
"contracts",
|
|
206
205
|
"subgraphs",
|
|
207
206
|
"webhooks",
|
|
208
|
-
"subscriptions",
|
|
209
207
|
"account",
|
|
210
208
|
"codegen",
|
|
211
209
|
"instance",
|
|
@@ -262,7 +260,6 @@ async function buildContext(deps = { clientProvider: getClient }) {
|
|
|
262
260
|
indexTip: orNull(snap?.indexTip),
|
|
263
261
|
subgraphs: snap?.subgraphs.value ? snap.subgraphs.value.map(formatSubgraphSummary) : orNull(snap?.subgraphs),
|
|
264
262
|
webhooks: orNull(snap?.webhooks),
|
|
265
|
-
subscriptions: orNull(snap?.webhooks),
|
|
266
263
|
activeOperations: orNull(snap?.activeOperations),
|
|
267
264
|
instance: instance2
|
|
268
265
|
},
|
|
@@ -810,40 +807,9 @@ function registerSetupTools(server, exec = execSecondlayer) {
|
|
|
810
807
|
}
|
|
811
808
|
|
|
812
809
|
// src/tools/streams.ts
|
|
813
|
-
import { STREAMS_EVENT_TYPES } from "@secondlayer/shared";
|
|
814
|
-
import { z as z8 } from "zod";
|
|
815
|
-
var filterValue = z8.union([z8.string(), z8.array(z8.string())]);
|
|
816
810
|
function registerStreamsTools(server, clientProvider = getClient) {
|
|
817
811
|
defineTool(server, "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.", {}, async () => jsonResponse(await clientProvider().streams.tip()));
|
|
818
|
-
defineTool(server, "
|
|
819
|
-
cursor: z8.string().optional().describe("Resume strictly after this cursor (`<block_height>:<event_index>`, e.g. 951475:3) — pass a prior response's next_cursor"),
|
|
820
|
-
fromHeight: z8.number().int().nonnegative().optional().describe("Start block height (inclusive)"),
|
|
821
|
-
toHeight: z8.number().int().nonnegative().optional().describe("End block height (inclusive)"),
|
|
822
|
-
types: z8.array(z8.enum(STREAMS_EVENT_TYPES)).optional().describe("Event types to include"),
|
|
823
|
-
notTypes: z8.array(z8.enum(STREAMS_EVENT_TYPES)).optional().describe("Event types to exclude (applied after types)"),
|
|
824
|
-
contractId: filterValue.optional().describe("Contract id, or a list of contract ids to OR together"),
|
|
825
|
-
sender: filterValue.optional().describe("Sender principal, or a list to OR together"),
|
|
826
|
-
recipient: filterValue.optional().describe("Recipient principal, or a list to OR together"),
|
|
827
|
-
assetIdentifier: z8.string().optional().describe("Asset identifier (contract::asset), e.g. SP…sbtc-token::sbtc-token"),
|
|
828
|
-
limit: z8.number().int().min(1).max(1000).optional().describe("Page size, 1–1000 (default 100)")
|
|
829
|
-
}, async (params) => jsonResponse(await clientProvider().streams.events.list(params)));
|
|
830
|
-
defineTool(server, "streams_events_by_tx", "List every event emitted by a single transaction, in emission order. Use it to explain one transaction end to end after finding it in streams_events or the Index.", {
|
|
831
|
-
txId: z8.string().describe("Transaction id (0x-prefixed)")
|
|
832
|
-
}, async ({ txId }) => jsonResponse(await clientProvider().streams.events.byTxId(txId)));
|
|
833
|
-
defineTool(server, "streams_block_events", "List every event in one block, addressed by block height or block hash. Use it to audit a block a consumer flagged, or to diff what a reorg replaced.", {
|
|
834
|
-
heightOrHash: z8.union([z8.number().int().nonnegative(), z8.string()]).describe("Block height (number) or block hash (0x-prefixed string)")
|
|
835
|
-
}, async ({ heightOrHash }) => jsonResponse(await clientProvider().streams.blocks.events(heightOrHash)));
|
|
836
|
-
defineTool(server, "streams_canonical", "Get the canonical block at a height: hash, burn block hash, parent, and whether the height is still canonical. Use it to confirm a height you already consumed was not reorged away before you trust derived state.", {
|
|
837
|
-
height: z8.number().int().nonnegative().describe("Block height")
|
|
838
|
-
}, async ({ height }) => jsonResponse(await clientProvider().streams.canonical(height)));
|
|
839
|
-
defineTool(server, "streams_reorgs", "List reorgs detected since a point in time, newest last, with the new canonical tip for each. Returns { reorgs, next_since } — resume with next_since. Call it when a consumer's derived state disagrees with streams_canonical, or on a schedule to know which heights to reprocess.", {
|
|
840
|
-
since: z8.string().describe("Required. ISO 8601 timestamp, or a `next_since` resume token from a prior response"),
|
|
841
|
-
limit: z8.number().int().positive().optional().describe("Max reorgs to return")
|
|
842
|
-
}, async ({ since, limit }) => jsonResponse(await clientProvider().streams.reorgs.list({
|
|
843
|
-
since,
|
|
844
|
-
...limit !== undefined ? { limit } : {}
|
|
845
|
-
})));
|
|
846
|
-
defineTool(server, "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 streams_events (cursor-paginated) and streams_tip.", {}, async () => jsonResponse(await clientProvider().streams.dumps.list()));
|
|
812
|
+
defineTool(server, "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.", {}, async () => jsonResponse(await clientProvider().streams.dumps.list()));
|
|
847
813
|
}
|
|
848
814
|
|
|
849
815
|
// src/tools/subgraphs.ts
|
|
@@ -856,7 +822,7 @@ import { DECODED_EVENT_TYPES as DECODED_EVENT_TYPES2 } from "@secondlayer/shared
|
|
|
856
822
|
import {
|
|
857
823
|
runSubgraphTest
|
|
858
824
|
} from "@secondlayer/subgraphs/testing";
|
|
859
|
-
import { z as
|
|
825
|
+
import { z as z8 } from "zod";
|
|
860
826
|
function eventTypeFor(filter) {
|
|
861
827
|
if (filter.type === "contract_deploy")
|
|
862
828
|
return null;
|
|
@@ -882,13 +848,13 @@ function registerSubgraphTools(server, clientProvider = getClient) {
|
|
|
882
848
|
const { data } = await clientProvider().subgraphs.list();
|
|
883
849
|
return jsonResponse(data.map(formatSubgraphSummary));
|
|
884
850
|
});
|
|
885
|
-
defineTool(server, "subgraphs_status", "Get full details of a subgraph including schema, health (incl. health.emptyMapping when processed events wrote 0 rows), and table columns.", { name:
|
|
851
|
+
defineTool(server, "subgraphs_status", "Get full details of a subgraph including schema, health (incl. health.emptyMapping when processed events wrote 0 rows), and table columns.", { name: z8.string().describe("Subgraph name") }, async ({ name }) => {
|
|
886
852
|
const detail = await clientProvider().subgraphs.status(name);
|
|
887
853
|
return jsonResponse(detail);
|
|
888
854
|
});
|
|
889
855
|
defineTool(server, "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.", {
|
|
890
|
-
name:
|
|
891
|
-
format:
|
|
856
|
+
name: z8.string().describe("Subgraph name"),
|
|
857
|
+
format: z8.enum(["agent", "openapi", "markdown"]).optional().describe("agent = JSON schema for tool use (default), openapi = OpenAPI JSON, markdown = docs.md")
|
|
892
858
|
}, async ({ name, format }) => {
|
|
893
859
|
const client = clientProvider();
|
|
894
860
|
if (format === "openapi")
|
|
@@ -898,15 +864,15 @@ function registerSubgraphTools(server, clientProvider = getClient) {
|
|
|
898
864
|
return jsonResponse(await client.subgraphs.schema(name));
|
|
899
865
|
});
|
|
900
866
|
defineTool(server, "subgraphs_query", 'Query rows from a subgraph table (max 200 rows). Filters support operators: "amount.gte": "1000", "sender.neq": "SP...", "name.like": "%token%". Available operators: eq, neq, gt, gte, lt, lte, like. To TAIL new rows (no streaming over MCP): sort=_id, order=desc for the latest, then poll forward with the filter {"_id.gt": "<last _id seen>"}, order=asc — when tailing with a `fields` list, include "_id" in it or the next poll filter cannot be formed. Fetch one row by id with {"_id": "<id>"}. The same rows are readable over HTTP at GET /v1/subgraphs/<name>/<table> — { rows, next_cursor, tip } envelope, resume with ?cursor=<next_cursor> + _order=asc|desc (no _offset/_sort on /v1); hand that URL to third parties.', {
|
|
901
|
-
name:
|
|
902
|
-
table:
|
|
903
|
-
filters:
|
|
904
|
-
sort:
|
|
905
|
-
order:
|
|
906
|
-
limit:
|
|
907
|
-
offset:
|
|
908
|
-
fields:
|
|
909
|
-
count:
|
|
867
|
+
name: z8.string().describe("Subgraph name"),
|
|
868
|
+
table: z8.string().describe("Table name"),
|
|
869
|
+
filters: z8.record(z8.string(), z8.string()).optional().describe('Column filters — plain values or with operators (e.g. {"amount.gte": "1000", "sender": "SP..."})'),
|
|
870
|
+
sort: z8.string().optional().describe("Column to sort by"),
|
|
871
|
+
order: z8.enum(["asc", "desc"]).optional().describe("Sort order"),
|
|
872
|
+
limit: z8.number().max(200).optional().describe("Max rows (default 50, max 200)"),
|
|
873
|
+
offset: z8.number().optional().describe("Offset for pagination"),
|
|
874
|
+
fields: z8.string().optional().describe('Comma-separated column list to return (e.g. "sender,amount")'),
|
|
875
|
+
count: z8.boolean().optional().describe("If true, return row count instead of rows")
|
|
910
876
|
}, async ({
|
|
911
877
|
name,
|
|
912
878
|
table,
|
|
@@ -934,15 +900,15 @@ function registerSubgraphTools(server, clientProvider = getClient) {
|
|
|
934
900
|
return jsonResponse(result);
|
|
935
901
|
});
|
|
936
902
|
defineTool(server, "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.", {
|
|
937
|
-
name:
|
|
903
|
+
name: z8.string().describe("Subgraph name")
|
|
938
904
|
}, async ({ name }) => {
|
|
939
905
|
const result = await clientProvider().subgraphs.reindex(name);
|
|
940
906
|
return jsonResponse(result);
|
|
941
907
|
});
|
|
942
908
|
defineTool(server, "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.", {
|
|
943
|
-
name:
|
|
944
|
-
fromBlock:
|
|
945
|
-
toBlock:
|
|
909
|
+
name: z8.string().describe("Subgraph name"),
|
|
910
|
+
fromBlock: z8.number().int().nonnegative().describe("Start block (inclusive)"),
|
|
911
|
+
toBlock: z8.number().int().nonnegative().describe("End block (inclusive)")
|
|
946
912
|
}, async ({ name, fromBlock, toBlock }) => {
|
|
947
913
|
const result = await clientProvider().subgraphs.backfill(name, {
|
|
948
914
|
fromBlock,
|
|
@@ -950,15 +916,15 @@ function registerSubgraphTools(server, clientProvider = getClient) {
|
|
|
950
916
|
});
|
|
951
917
|
return jsonResponse(result);
|
|
952
918
|
});
|
|
953
|
-
defineTool(server, "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:
|
|
919
|
+
defineTool(server, "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: z8.string().describe("Subgraph name") }, async ({ name }) => {
|
|
954
920
|
const result = await clientProvider().subgraphs.stop(name);
|
|
955
921
|
return jsonResponse(result);
|
|
956
922
|
});
|
|
957
923
|
defineTool(server, "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.", {
|
|
958
|
-
name:
|
|
959
|
-
limit:
|
|
960
|
-
offset:
|
|
961
|
-
resolved:
|
|
924
|
+
name: z8.string().describe("Subgraph name"),
|
|
925
|
+
limit: z8.number().int().positive().optional().describe("Max gaps to return"),
|
|
926
|
+
offset: z8.number().int().nonnegative().optional().describe("Pagination offset"),
|
|
927
|
+
resolved: z8.boolean().optional().describe("Filter by resolved state (omit for unresolved only)")
|
|
962
928
|
}, async ({ name, limit, offset, resolved }) => {
|
|
963
929
|
const result = await clientProvider().subgraphs.gaps(name, {
|
|
964
930
|
limit,
|
|
@@ -968,20 +934,20 @@ function registerSubgraphTools(server, clientProvider = getClient) {
|
|
|
968
934
|
return jsonResponse(result);
|
|
969
935
|
});
|
|
970
936
|
defineTool(server, "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.", {
|
|
971
|
-
name:
|
|
972
|
-
operationId:
|
|
937
|
+
name: z8.string().describe("Subgraph name"),
|
|
938
|
+
operationId: z8.string().optional().describe("Fetch one operation by id (the operationId returned by reindex/backfill/stop); omit for recent history")
|
|
973
939
|
}, async ({ name, operationId }) => {
|
|
974
940
|
const client = clientProvider();
|
|
975
941
|
return jsonResponse(operationId ? await client.subgraphs.getOperation(name, operationId) : await client.subgraphs.operations(name));
|
|
976
942
|
});
|
|
977
|
-
defineTool(server, "subgraphs_delete", "Delete a subgraph permanently.", { name:
|
|
943
|
+
defineTool(server, "subgraphs_delete", "Delete a subgraph permanently.", { name: z8.string().describe("Subgraph name") }, async ({ name }) => {
|
|
978
944
|
const result = await clientProvider().subgraphs.delete(name);
|
|
979
945
|
return textResponse(result.message);
|
|
980
946
|
});
|
|
981
947
|
defineTool(server, "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.", {
|
|
982
|
-
code:
|
|
983
|
-
startBlock:
|
|
984
|
-
dryRun:
|
|
948
|
+
code: z8.string().describe("TypeScript source code containing a defineSubgraph() call"),
|
|
949
|
+
startBlock: z8.number().int().nonnegative().optional().describe("Override the definition startBlock for this deploy"),
|
|
950
|
+
dryRun: z8.boolean().optional().describe("Validate schema/DDL only — does not run handlers. Use subgraphs_test to prove a mapping writes rows.")
|
|
985
951
|
}, async ({ code, startBlock, dryRun }) => {
|
|
986
952
|
const bundled = await bundleSubgraphCode(code);
|
|
987
953
|
const result = await clientProvider().subgraphs.deploy({
|
|
@@ -998,10 +964,10 @@ function registerSubgraphTools(server, clientProvider = getClient) {
|
|
|
998
964
|
return jsonResponse(result);
|
|
999
965
|
});
|
|
1000
966
|
defineTool(server, "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.", {
|
|
1001
|
-
code:
|
|
1002
|
-
fromHeight:
|
|
1003
|
-
toHeight:
|
|
1004
|
-
limit:
|
|
967
|
+
code: z8.string().describe("TypeScript source containing a defineSubgraph() call"),
|
|
968
|
+
fromHeight: z8.number().int().nonnegative().describe("Start block height (inclusive)"),
|
|
969
|
+
toHeight: z8.number().int().nonnegative().optional().describe("End block height (inclusive); default fromHeight+100"),
|
|
970
|
+
limit: z8.number().int().positive().max(200).optional().describe("Max Index rows per source (default 50, max 200)")
|
|
1005
971
|
}, async ({ code, fromHeight, toHeight, limit }) => {
|
|
1006
972
|
const bundled = await bundleSubgraphCode(code);
|
|
1007
973
|
const def = await loadBundledDefinition(bundled.handlerCode);
|
|
@@ -1082,38 +1048,38 @@ function registerSubgraphTools(server, clientProvider = getClient) {
|
|
|
1082
1048
|
|
|
1083
1049
|
// src/tools/webhooks.ts
|
|
1084
1050
|
import { CHAIN_TRIGGER_TYPES } from "@secondlayer/shared";
|
|
1085
|
-
import { z as
|
|
1051
|
+
import { z as z9 } from "zod";
|
|
1086
1052
|
function registerWebhookTools(server, clientProvider = getClient) {
|
|
1087
1053
|
defineTool(server, "webhooks_list", "List all webhooks for the current account. Returns summary fields (no secrets).", {}, async () => {
|
|
1088
1054
|
const { data } = await clientProvider().webhooks.list();
|
|
1089
1055
|
return jsonResponse(data);
|
|
1090
1056
|
});
|
|
1091
|
-
defineTool(server, "webhooks_get", "Get full detail for a webhook (filter, auth, retry config, circuit state).", { id:
|
|
1057
|
+
defineTool(server, "webhooks_get", "Get full detail for a webhook (filter, auth, retry config, circuit state).", { id: z9.string().describe("Webhook id") }, async ({ id }) => {
|
|
1092
1058
|
const detail = await clientProvider().webhooks.get(id);
|
|
1093
1059
|
return jsonResponse(detail);
|
|
1094
1060
|
});
|
|
1095
1061
|
defineTool(server, "webhooks_create", "Create a webhook. Two kinds (mutually exclusive): a SUBGRAPH webhook fires on a subgraph table's rows (set subgraphName + tableName + optional filter); a CHAIN webhook fires on raw chain events with no subgraph (set triggers). Returns `signingSecret` ONCE — forward it to the user so they can wire it into their receiver.", {
|
|
1096
|
-
name:
|
|
1097
|
-
subgraphName:
|
|
1098
|
-
tableName:
|
|
1099
|
-
triggers:
|
|
1100
|
-
type:
|
|
1101
|
-
contractId:
|
|
1102
|
-
functionName:
|
|
1103
|
-
caller:
|
|
1104
|
-
sender:
|
|
1105
|
-
recipient:
|
|
1106
|
-
assetIdentifier:
|
|
1107
|
-
deployer:
|
|
1108
|
-
contractName:
|
|
1109
|
-
topic:
|
|
1110
|
-
lockedAddress:
|
|
1111
|
-
trait:
|
|
1112
|
-
minAmount:
|
|
1113
|
-
maxAmount:
|
|
1062
|
+
name: z9.string().describe("Human-readable name, unique per account"),
|
|
1063
|
+
subgraphName: z9.string().optional().describe("Subgraph to subscribe to (subgraph webhook)"),
|
|
1064
|
+
tableName: z9.string().optional().describe("Table within the subgraph (subgraph webhook)"),
|
|
1065
|
+
triggers: z9.array(z9.object({
|
|
1066
|
+
type: z9.enum(CHAIN_TRIGGER_TYPES),
|
|
1067
|
+
contractId: z9.string().optional(),
|
|
1068
|
+
functionName: z9.string().optional(),
|
|
1069
|
+
caller: z9.string().optional(),
|
|
1070
|
+
sender: z9.string().optional(),
|
|
1071
|
+
recipient: z9.string().optional(),
|
|
1072
|
+
assetIdentifier: z9.string().optional(),
|
|
1073
|
+
deployer: z9.string().optional(),
|
|
1074
|
+
contractName: z9.string().optional(),
|
|
1075
|
+
topic: z9.string().optional(),
|
|
1076
|
+
lockedAddress: z9.string().optional(),
|
|
1077
|
+
trait: z9.string().optional(),
|
|
1078
|
+
minAmount: z9.union([z9.string(), z9.number()]).optional(),
|
|
1079
|
+
maxAmount: z9.union([z9.string(), z9.number()]).optional()
|
|
1114
1080
|
})).optional().describe("Chain triggers (chain webhook) — provide INSTEAD of subgraphName/tableName. Each targets a raw chain event/tx; string fields accept `*` wildcards, `trait` scopes to a SIP/trait. Per-type accepted fields: see the secondlayer://chain-triggers resource. Forward-looking: starts at chain tip, no backfill."),
|
|
1115
|
-
url:
|
|
1116
|
-
format:
|
|
1081
|
+
url: z9.string().describe("Webhook URL"),
|
|
1082
|
+
format: z9.enum([
|
|
1117
1083
|
"standard-webhooks",
|
|
1118
1084
|
"inngest",
|
|
1119
1085
|
"trigger",
|
|
@@ -1121,20 +1087,20 @@ function registerWebhookTools(server, clientProvider = getClient) {
|
|
|
1121
1087
|
"cloudevents",
|
|
1122
1088
|
"raw"
|
|
1123
1089
|
]).optional().describe("Wire format (default standard-webhooks)"),
|
|
1124
|
-
runtime:
|
|
1125
|
-
filter:
|
|
1126
|
-
authConfig:
|
|
1090
|
+
runtime: z9.enum(["inngest", "trigger", "cloudflare", "node"]).optional().describe("Receiver runtime label (display only)"),
|
|
1091
|
+
filter: z9.record(z9.string(), z9.unknown()).optional().describe('Scalar filter DSL, e.g. {"amount": {"gte": 100}, "sender": "SP..."}'),
|
|
1092
|
+
authConfig: z9.record(z9.string(), z9.unknown()).optional().describe('Receiver auth sent with each delivery, e.g. {"type": "bearer", "token": "..."}')
|
|
1127
1093
|
}, async (input) => {
|
|
1128
1094
|
const res = await clientProvider().webhooks.create(input);
|
|
1129
1095
|
return jsonResponse(res);
|
|
1130
1096
|
});
|
|
1131
1097
|
defineTool(server, "webhooks_update", "Patch a webhook (name, url, filter, authConfig, format, runtime, retry, timeout, concurrency).", {
|
|
1132
|
-
id:
|
|
1133
|
-
name:
|
|
1134
|
-
url:
|
|
1135
|
-
filter:
|
|
1136
|
-
authConfig:
|
|
1137
|
-
format:
|
|
1098
|
+
id: z9.string(),
|
|
1099
|
+
name: z9.string().optional().describe("Rename the webhook"),
|
|
1100
|
+
url: z9.string().optional(),
|
|
1101
|
+
filter: z9.record(z9.string(), z9.unknown()).optional(),
|
|
1102
|
+
authConfig: z9.record(z9.string(), z9.unknown()).optional().describe("Receiver auth sent with each delivery (bearer/etc.)"),
|
|
1103
|
+
format: z9.enum([
|
|
1138
1104
|
"standard-webhooks",
|
|
1139
1105
|
"inngest",
|
|
1140
1106
|
"trigger",
|
|
@@ -1142,132 +1108,36 @@ function registerWebhookTools(server, clientProvider = getClient) {
|
|
|
1142
1108
|
"cloudevents",
|
|
1143
1109
|
"raw"
|
|
1144
1110
|
]).optional(),
|
|
1145
|
-
runtime:
|
|
1146
|
-
maxRetries:
|
|
1147
|
-
timeoutMs:
|
|
1148
|
-
concurrency:
|
|
1111
|
+
runtime: z9.enum(["inngest", "trigger", "cloudflare", "node"]).nullable().optional(),
|
|
1112
|
+
maxRetries: z9.number().int().min(0).optional(),
|
|
1113
|
+
timeoutMs: z9.number().int().min(100).optional(),
|
|
1114
|
+
concurrency: z9.number().int().min(1).optional()
|
|
1149
1115
|
}, async ({ id, ...patch }) => {
|
|
1150
1116
|
const res = await clientProvider().webhooks.update(id, patch);
|
|
1151
1117
|
return jsonResponse(res);
|
|
1152
1118
|
});
|
|
1153
|
-
defineTool(server, "webhooks_delete", "Delete a webhook. Pending outbox rows are cascade-deleted.", { id:
|
|
1119
|
+
defineTool(server, "webhooks_delete", "Delete a webhook. Pending outbox rows are cascade-deleted.", { id: z9.string() }, async ({ id }) => {
|
|
1154
1120
|
const res = await clientProvider().webhooks.delete(id);
|
|
1155
1121
|
return jsonResponse(res);
|
|
1156
1122
|
});
|
|
1157
|
-
defineTool(server, "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:
|
|
1123
|
+
defineTool(server, "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: z9.string().describe("Webhook id") }, async ({ id }) => {
|
|
1158
1124
|
const res = await clientProvider().webhooks.test(id);
|
|
1159
1125
|
return jsonResponse(res);
|
|
1160
1126
|
});
|
|
1161
|
-
defineTool(server, "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:
|
|
1162
|
-
defineTool(server, "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:
|
|
1163
|
-
defineTool(server, "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:
|
|
1164
|
-
defineTool(server, "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:
|
|
1165
|
-
defineTool(server, "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:
|
|
1127
|
+
defineTool(server, "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: z9.string().describe("Webhook id") }, async ({ id }) => jsonResponse(await clientProvider().webhooks.pause(id)));
|
|
1128
|
+
defineTool(server, "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: z9.string().describe("Webhook id") }, async ({ id }) => jsonResponse(await clientProvider().webhooks.resume(id)));
|
|
1129
|
+
defineTool(server, "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: z9.string().describe("Webhook id") }, async ({ id }) => jsonResponse(await clientProvider().webhooks.rotateSecret(id)));
|
|
1130
|
+
defineTool(server, "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: z9.string().describe("Webhook id") }, async ({ id }) => jsonResponse(await clientProvider().webhooks.deliveries(id)));
|
|
1131
|
+
defineTool(server, "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: z9.string().describe("Webhook id") }, async ({ id }) => jsonResponse(await clientProvider().webhooks.dead(id)));
|
|
1166
1132
|
defineTool(server, "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.", {
|
|
1167
|
-
id:
|
|
1168
|
-
outboxId:
|
|
1133
|
+
id: z9.string().describe("Webhook id"),
|
|
1134
|
+
outboxId: z9.string().describe("Outbox id of the dead delivery (from webhooks_dead)")
|
|
1169
1135
|
}, async ({ id, outboxId }) => jsonResponse(await clientProvider().webhooks.requeue(id, outboxId)));
|
|
1170
1136
|
defineTool(server, "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.", {
|
|
1171
|
-
id:
|
|
1172
|
-
fromBlock:
|
|
1173
|
-
toBlock:
|
|
1174
|
-
force:
|
|
1175
|
-
}, async ({ id, fromBlock, toBlock, force }) => {
|
|
1176
|
-
const res = await clientProvider().webhooks.replay(id, {
|
|
1177
|
-
fromBlock,
|
|
1178
|
-
toBlock,
|
|
1179
|
-
...force !== undefined ? { force } : {}
|
|
1180
|
-
});
|
|
1181
|
-
return jsonResponse(res);
|
|
1182
|
-
});
|
|
1183
|
-
defineTool(server, "subscriptions_list", "Deprecated alias of webhooks_list. Removed next minor. List all webhooks for the current account. Returns summary fields (no secrets).", {}, async () => {
|
|
1184
|
-
const { data } = await clientProvider().webhooks.list();
|
|
1185
|
-
return jsonResponse(data);
|
|
1186
|
-
});
|
|
1187
|
-
defineTool(server, "subscriptions_get", "Deprecated alias of webhooks_get. Removed next minor. Get full detail for a webhook (filter, auth, retry config, circuit state).", { id: z10.string().describe("Webhook id") }, async ({ id }) => {
|
|
1188
|
-
const detail = await clientProvider().webhooks.get(id);
|
|
1189
|
-
return jsonResponse(detail);
|
|
1190
|
-
});
|
|
1191
|
-
defineTool(server, "subscriptions_create", "Deprecated alias of webhooks_create. Removed next minor. Create a webhook. Two kinds (mutually exclusive): a SUBGRAPH webhook fires on a subgraph table's rows (set subgraphName + tableName + optional filter); a CHAIN webhook fires on raw chain events with no subgraph (set triggers). Returns `signingSecret` ONCE — forward it to the user so they can wire it into their receiver.", {
|
|
1192
|
-
name: z10.string().describe("Human-readable name, unique per account"),
|
|
1193
|
-
subgraphName: z10.string().optional().describe("Subgraph to subscribe to (subgraph webhook)"),
|
|
1194
|
-
tableName: z10.string().optional().describe("Table within the subgraph (subgraph webhook)"),
|
|
1195
|
-
triggers: z10.array(z10.object({
|
|
1196
|
-
type: z10.enum(CHAIN_TRIGGER_TYPES),
|
|
1197
|
-
contractId: z10.string().optional(),
|
|
1198
|
-
functionName: z10.string().optional(),
|
|
1199
|
-
caller: z10.string().optional(),
|
|
1200
|
-
sender: z10.string().optional(),
|
|
1201
|
-
recipient: z10.string().optional(),
|
|
1202
|
-
assetIdentifier: z10.string().optional(),
|
|
1203
|
-
deployer: z10.string().optional(),
|
|
1204
|
-
contractName: z10.string().optional(),
|
|
1205
|
-
topic: z10.string().optional(),
|
|
1206
|
-
lockedAddress: z10.string().optional(),
|
|
1207
|
-
trait: z10.string().optional(),
|
|
1208
|
-
minAmount: z10.union([z10.string(), z10.number()]).optional(),
|
|
1209
|
-
maxAmount: z10.union([z10.string(), z10.number()]).optional()
|
|
1210
|
-
})).optional().describe("Chain triggers (chain webhook) — provide INSTEAD of subgraphName/tableName. Each targets a raw chain event/tx; string fields accept `*` wildcards, `trait` scopes to a SIP/trait. Per-type accepted fields: see the secondlayer://chain-triggers resource. Forward-looking: starts at chain tip, no backfill."),
|
|
1211
|
-
url: z10.string().describe("Webhook URL"),
|
|
1212
|
-
format: z10.enum([
|
|
1213
|
-
"standard-webhooks",
|
|
1214
|
-
"inngest",
|
|
1215
|
-
"trigger",
|
|
1216
|
-
"cloudflare",
|
|
1217
|
-
"cloudevents",
|
|
1218
|
-
"raw"
|
|
1219
|
-
]).optional().describe("Wire format (default standard-webhooks)"),
|
|
1220
|
-
runtime: z10.enum(["inngest", "trigger", "cloudflare", "node"]).optional().describe("Receiver runtime label (display only)"),
|
|
1221
|
-
filter: z10.record(z10.string(), z10.unknown()).optional().describe('Scalar filter DSL, e.g. {"amount": {"gte": 100}, "sender": "SP..."}'),
|
|
1222
|
-
authConfig: z10.record(z10.string(), z10.unknown()).optional().describe('Receiver auth sent with each delivery, e.g. {"type": "bearer", "token": "..."}')
|
|
1223
|
-
}, async (input) => {
|
|
1224
|
-
const res = await clientProvider().webhooks.create(input);
|
|
1225
|
-
return jsonResponse(res);
|
|
1226
|
-
});
|
|
1227
|
-
defineTool(server, "subscriptions_update", "Deprecated alias of webhooks_update. Removed next minor. Patch a webhook (name, url, filter, authConfig, format, runtime, retry, timeout, concurrency).", {
|
|
1228
|
-
id: z10.string(),
|
|
1229
|
-
name: z10.string().optional().describe("Rename the webhook"),
|
|
1230
|
-
url: z10.string().optional(),
|
|
1231
|
-
filter: z10.record(z10.string(), z10.unknown()).optional(),
|
|
1232
|
-
authConfig: z10.record(z10.string(), z10.unknown()).optional().describe("Receiver auth sent with each delivery (bearer/etc.)"),
|
|
1233
|
-
format: z10.enum([
|
|
1234
|
-
"standard-webhooks",
|
|
1235
|
-
"inngest",
|
|
1236
|
-
"trigger",
|
|
1237
|
-
"cloudflare",
|
|
1238
|
-
"cloudevents",
|
|
1239
|
-
"raw"
|
|
1240
|
-
]).optional(),
|
|
1241
|
-
runtime: z10.enum(["inngest", "trigger", "cloudflare", "node"]).nullable().optional(),
|
|
1242
|
-
maxRetries: z10.number().int().min(0).optional(),
|
|
1243
|
-
timeoutMs: z10.number().int().min(100).optional(),
|
|
1244
|
-
concurrency: z10.number().int().min(1).optional()
|
|
1245
|
-
}, async ({ id, ...patch }) => {
|
|
1246
|
-
const res = await clientProvider().webhooks.update(id, patch);
|
|
1247
|
-
return jsonResponse(res);
|
|
1248
|
-
});
|
|
1249
|
-
defineTool(server, "subscriptions_delete", "Deprecated alias of webhooks_delete. Removed next minor. Delete a webhook. Pending outbox rows are cascade-deleted.", { id: z10.string() }, async ({ id }) => {
|
|
1250
|
-
const res = await clientProvider().webhooks.delete(id);
|
|
1251
|
-
return jsonResponse(res);
|
|
1252
|
-
});
|
|
1253
|
-
defineTool(server, "subscriptions_test", "Deprecated alias of webhooks_test. Removed next minor. 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: z10.string().describe("Webhook id") }, async ({ id }) => {
|
|
1254
|
-
const res = await clientProvider().webhooks.test(id);
|
|
1255
|
-
return jsonResponse(res);
|
|
1256
|
-
});
|
|
1257
|
-
defineTool(server, "subscriptions_pause", "Deprecated alias of webhooks_pause. Removed next minor. 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: z10.string().describe("Webhook id") }, async ({ id }) => jsonResponse(await clientProvider().webhooks.pause(id)));
|
|
1258
|
-
defineTool(server, "subscriptions_resume", "Deprecated alias of webhooks_resume. Removed next minor. 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: z10.string().describe("Webhook id") }, async ({ id }) => jsonResponse(await clientProvider().webhooks.resume(id)));
|
|
1259
|
-
defineTool(server, "subscriptions_rotate_secret", "Deprecated alias of webhooks_rotate_secret. Removed next minor. 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: z10.string().describe("Webhook id") }, async ({ id }) => jsonResponse(await clientProvider().webhooks.rotateSecret(id)));
|
|
1260
|
-
defineTool(server, "subscriptions_deliveries", "Deprecated alias of webhooks_deliveries. Removed next minor. 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: z10.string().describe("Webhook id") }, async ({ id }) => jsonResponse(await clientProvider().webhooks.deliveries(id)));
|
|
1261
|
-
defineTool(server, "subscriptions_dead", "Deprecated alias of webhooks_dead. Removed next minor. 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: z10.string().describe("Webhook id") }, async ({ id }) => jsonResponse(await clientProvider().webhooks.dead(id)));
|
|
1262
|
-
defineTool(server, "subscriptions_requeue", "Deprecated alias of webhooks_requeue. Removed next minor. 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.", {
|
|
1263
|
-
id: z10.string().describe("Webhook id"),
|
|
1264
|
-
outboxId: z10.string().describe("Outbox id of the dead delivery (from webhooks_dead)")
|
|
1265
|
-
}, async ({ id, outboxId }) => jsonResponse(await clientProvider().webhooks.requeue(id, outboxId)));
|
|
1266
|
-
defineTool(server, "subscriptions_replay", "Deprecated alias of webhooks_replay. Removed next minor. 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.", {
|
|
1267
|
-
id: z10.string(),
|
|
1268
|
-
fromBlock: z10.number().int().nonnegative(),
|
|
1269
|
-
toBlock: z10.number().int().nonnegative(),
|
|
1270
|
-
force: z10.string().optional().describe("Idempotency suffix to force a duplicate replay of the range")
|
|
1137
|
+
id: z9.string(),
|
|
1138
|
+
fromBlock: z9.number().int().nonnegative(),
|
|
1139
|
+
toBlock: z9.number().int().nonnegative(),
|
|
1140
|
+
force: z9.string().optional().describe("Idempotency suffix to force a duplicate replay of the range")
|
|
1271
1141
|
}, async ({ id, fromBlock, toBlock, force }) => {
|
|
1272
1142
|
const res = await clientProvider().webhooks.replay(id, {
|
|
1273
1143
|
fromBlock,
|
|
@@ -1390,5 +1260,5 @@ httpServer.listen(port, () => {
|
|
|
1390
1260
|
console.error("Warning: SECONDLAYER_MCP_SECRET not set, authentication disabled");
|
|
1391
1261
|
});
|
|
1392
1262
|
|
|
1393
|
-
//# debugId=
|
|
1263
|
+
//# debugId=8824D91A2556365064756E2164756E21
|
|
1394
1264
|
//# sourceMappingURL=bin-http.js.map
|