@secondlayer/mcp 11.4.0 → 11.5.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/dist/bin-http.js +142 -138
- package/dist/bin-http.js.map +3 -3
- package/dist/bin.js +142 -138
- package/dist/bin.js.map +3 -3
- package/dist/index.js +142 -138
- package/dist/index.js.map +3 -3
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -96,6 +96,7 @@ function isHostedArchiveUrl(url) {
|
|
|
96
96
|
}
|
|
97
97
|
|
|
98
98
|
// src/lib/tool.ts
|
|
99
|
+
import { z } from "zod";
|
|
99
100
|
var registeredToolNames = new Set;
|
|
100
101
|
var serverToolNames = new WeakMap;
|
|
101
102
|
var serverToolFilters = new WeakMap;
|
|
@@ -149,7 +150,10 @@ function defineTool(server, name, description, schema, handler) {
|
|
|
149
150
|
const names = serverToolNames.get(server) ?? new Set;
|
|
150
151
|
names.add(name);
|
|
151
152
|
serverToolNames.set(server, names);
|
|
152
|
-
server.tool(name, description, schema, wrappedHandler);
|
|
153
|
+
const registered = server.tool(name, description, schema, wrappedHandler);
|
|
154
|
+
if (registered) {
|
|
155
|
+
registered.inputSchema = z.strictObject(schema);
|
|
156
|
+
}
|
|
153
157
|
}
|
|
154
158
|
|
|
155
159
|
// src/resources.ts
|
|
@@ -448,21 +452,21 @@ async function buildSamplesResource(contractId, clientProvider = getClient) {
|
|
|
448
452
|
}
|
|
449
453
|
|
|
450
454
|
// src/tools/account.ts
|
|
451
|
-
import { z } from "zod";
|
|
455
|
+
import { z as z2 } from "zod";
|
|
452
456
|
function registerAccountTools(server, request = apiRequest, currentKey = readApiKey) {
|
|
453
457
|
defineTool(server, "account_whoami", "Show the archive account email at api.secondlayer.tools, not the self-host instance.", {}, async () => {
|
|
454
458
|
const result = await request("GET", "/api/accounts/me");
|
|
455
459
|
return jsonResponse(result);
|
|
456
460
|
});
|
|
457
461
|
defineTool(server, "account_create_key", "Mint an account key (sk-sl_*) for archive credits, quote, and fetch at api.secondlayer.tools. The returned `key` is shown ONCE.", {
|
|
458
|
-
name:
|
|
462
|
+
name: z2.string().optional().describe("Optional label for the key")
|
|
459
463
|
}, async ({ name }) => jsonResponse(await request("POST", "/api/keys", { name })));
|
|
460
464
|
defineTool(server, "account_list_keys", "List this account's active account keys at api.secondlayer.tools: id, prefix, name, last read. Never returns a secret. Use an id with account_rotate_key.", {}, async () => {
|
|
461
465
|
const keys = await activeAccountKeys(request);
|
|
462
466
|
return jsonResponse({ keys });
|
|
463
467
|
});
|
|
464
468
|
defineTool(server, "account_rotate_key", "Replace an account key's secret at api.secondlayer.tools, keeping its name. The old secret gets 401 at once, with no grace period, so everything using it breaks until updated: get human confirmation first. The returned key is shown ONCE. Refuses the key this server runs on.", {
|
|
465
|
-
id:
|
|
469
|
+
id: z2.string().uuid().describe("Key id from account_list_keys")
|
|
466
470
|
}, async ({ id }) => {
|
|
467
471
|
const { keys } = await request("GET", "/api/keys");
|
|
468
472
|
const row = keys.find((k) => k.id === id);
|
|
@@ -478,7 +482,7 @@ async function activeAccountKeys(request) {
|
|
|
478
482
|
}
|
|
479
483
|
|
|
480
484
|
// src/tools/archive-cli.ts
|
|
481
|
-
import { z as
|
|
485
|
+
import { z as z3 } from "zod";
|
|
482
486
|
|
|
483
487
|
// src/lib/exec-cli.ts
|
|
484
488
|
import {
|
|
@@ -622,9 +626,9 @@ function cliResponse(result) {
|
|
|
622
626
|
}
|
|
623
627
|
function registerArchiveCliTools(server, exec = execSecondlayer) {
|
|
624
628
|
defineTool(server, "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.", {
|
|
625
|
-
against:
|
|
626
|
-
fromBlock:
|
|
627
|
-
toBlock:
|
|
629
|
+
against: z3.string().describe("Archive manifest URL"),
|
|
630
|
+
fromBlock: z3.number().int().nonnegative().optional().describe("Restore from this height instead of genesis"),
|
|
631
|
+
toBlock: z3.number().int().nonnegative().optional().describe("Stop at this height instead of the archive tip")
|
|
628
632
|
}, async ({ against, fromBlock, toBlock }) => {
|
|
629
633
|
const args = ["--against", against, "--yes", "--json"];
|
|
630
634
|
if (fromBlock !== undefined)
|
|
@@ -634,10 +638,10 @@ function registerArchiveCliTools(server, exec = execSecondlayer) {
|
|
|
634
638
|
return cliResponse(await exec("bootstrap", args));
|
|
635
639
|
});
|
|
636
640
|
defineTool(server, "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.", {
|
|
637
|
-
against:
|
|
638
|
-
apply:
|
|
639
|
-
fromBlock:
|
|
640
|
-
toBlock:
|
|
641
|
+
against: z3.string().describe("Archive manifest URL"),
|
|
642
|
+
apply: z3.boolean().optional().describe("Write the repair (default plan-only)"),
|
|
643
|
+
fromBlock: z3.number().int().nonnegative().optional().describe("First height to consider"),
|
|
644
|
+
toBlock: z3.number().int().nonnegative().optional().describe("Last height to consider")
|
|
641
645
|
}, async ({ against, apply, fromBlock, toBlock }) => {
|
|
642
646
|
const args = ["--against", against, "--json"];
|
|
643
647
|
if (apply)
|
|
@@ -651,14 +655,14 @@ function registerArchiveCliTools(server, exec = execSecondlayer) {
|
|
|
651
655
|
}
|
|
652
656
|
|
|
653
657
|
// src/tools/archive.ts
|
|
654
|
-
import { z as
|
|
658
|
+
import { z as z4 } from "zod";
|
|
655
659
|
var FLOW = ["bootstrap", "repair"];
|
|
656
660
|
function registerArchiveTools(server, clientProvider = getClient, archiveOpsClientProvider = getArchiveOpsClient) {
|
|
657
661
|
defineTool(server, "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.", {
|
|
658
|
-
against:
|
|
659
|
-
fromBlock:
|
|
660
|
-
toBlock:
|
|
661
|
-
target:
|
|
662
|
+
against: z4.string().describe("Archive manifest URL"),
|
|
663
|
+
fromBlock: z4.number().int().nonnegative().optional().describe("First height (inclusive)"),
|
|
664
|
+
toBlock: z4.number().int().nonnegative().optional().describe("Last height (inclusive)"),
|
|
665
|
+
target: z4.string().optional().describe("Verify target (default raw)")
|
|
662
666
|
}, async ({ against, fromBlock, toBlock, target }) => jsonResponse(await clientProvider().archive.verify({
|
|
663
667
|
against,
|
|
664
668
|
fromBlock,
|
|
@@ -666,11 +670,11 @@ function registerArchiveTools(server, clientProvider = getClient, archiveOpsClie
|
|
|
666
670
|
target
|
|
667
671
|
})));
|
|
668
672
|
defineTool(server, "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.", {
|
|
669
|
-
against:
|
|
673
|
+
against: z4.string().optional().describe("Override latest.json URL (default official tree)")
|
|
670
674
|
}, async ({ against }) => jsonResponse(await archiveOpsClientProvider().archive.latest(against)));
|
|
671
675
|
defineTool(server, "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.", {
|
|
672
|
-
paths:
|
|
673
|
-
flow:
|
|
676
|
+
paths: z4.array(z4.string()).describe("Partition paths to price"),
|
|
677
|
+
flow: z4.enum(FLOW).describe("bootstrap or repair")
|
|
674
678
|
}, async ({ paths, flow }) => jsonResponse(await archiveOpsClientProvider().archive.quote({ paths, flow })));
|
|
675
679
|
defineTool(server, "credits_balance", "Archive credits balance at api.secondlayer.tools. Needs SECONDLAYER_API_KEY (sk-sl_*); INSTANCE_TOKEN is the instance.", {}, async () => jsonResponse(await archiveOpsClientProvider().archive.credits.balance()));
|
|
676
680
|
}
|
|
@@ -679,14 +683,14 @@ function registerArchiveTools(server, clientProvider = getClient, archiveOpsClie
|
|
|
679
683
|
import {
|
|
680
684
|
generateIndexSchema
|
|
681
685
|
} from "@secondlayer/subgraphs";
|
|
682
|
-
import { z as
|
|
686
|
+
import { z as z5 } from "zod";
|
|
683
687
|
var TARGETS = ["prisma", "kysely", "drizzle", "json-schema"];
|
|
684
688
|
function registerCodegenTools(server) {
|
|
685
689
|
defineTool(server, "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.", {
|
|
686
|
-
target:
|
|
687
|
-
tables:
|
|
688
|
-
schemaName:
|
|
689
|
-
datasourceEnv:
|
|
690
|
+
target: z5.enum(TARGETS).optional().describe("Output flavor (default kysely)"),
|
|
691
|
+
tables: z5.array(z5.string()).optional().describe("Restrict to these Index tables (default: all)"),
|
|
692
|
+
schemaName: z5.string().optional().describe("Postgres schema to qualify table names with"),
|
|
693
|
+
datasourceEnv: z5.string().optional().describe("Prisma only: datasource url env var (default DATABASE_URL)")
|
|
690
694
|
}, ({ target, tables, schemaName, datasourceEnv }) => textResponse(generateIndexSchema(target ?? "kysely", {
|
|
691
695
|
tables,
|
|
692
696
|
schemaName,
|
|
@@ -695,17 +699,17 @@ function registerCodegenTools(server) {
|
|
|
695
699
|
}
|
|
696
700
|
|
|
697
701
|
// src/tools/contracts.ts
|
|
698
|
-
import { z as
|
|
702
|
+
import { z as z6 } from "zod";
|
|
699
703
|
function registerContractTools(server, clientProvider = getClient) {
|
|
700
704
|
defineTool(server, "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.', {
|
|
701
|
-
trait:
|
|
702
|
-
conformance:
|
|
703
|
-
include:
|
|
704
|
-
limit:
|
|
705
|
-
cursor:
|
|
705
|
+
trait: z6.string().describe('Required. Trait to match (e.g. "sip-010").'),
|
|
706
|
+
conformance: z6.enum(["declared", "inferred", "any"]).optional().describe("declared = parsed from source, inferred = ABI shape-match, any = either (default)"),
|
|
707
|
+
include: z6.literal("abi").optional().describe(`Set to "abi" to include each contract's full ABI`),
|
|
708
|
+
limit: z6.number().optional().describe("Page size, 1–500 (default 100)"),
|
|
709
|
+
cursor: z6.string().optional().describe("Opaque cursor from a prior response's next_cursor")
|
|
706
710
|
}, async (params) => jsonResponse(await clientProvider().contracts.list(params)));
|
|
707
711
|
defineTool(server, "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.", {
|
|
708
|
-
contractId:
|
|
712
|
+
contractId: z6.string().describe("Fully qualified contract id (e.g. SP….amm-pool-v2-01)")
|
|
709
713
|
}, async ({ contractId }) => {
|
|
710
714
|
const contract = await clientProvider().contracts.get(contractId, {
|
|
711
715
|
includeAbi: true
|
|
@@ -722,17 +726,17 @@ function registerContractTools(server, clientProvider = getClient) {
|
|
|
722
726
|
|
|
723
727
|
// src/tools/index.ts
|
|
724
728
|
import { DECODED_EVENT_TYPES } from "@secondlayer/shared";
|
|
725
|
-
import { z as
|
|
729
|
+
import { z as z7 } from "zod";
|
|
726
730
|
var INDEX_EVENT_TYPES = DECODED_EVENT_TYPES;
|
|
727
731
|
var rangeFilters = {
|
|
728
|
-
contractId:
|
|
729
|
-
fromHeight:
|
|
730
|
-
toHeight:
|
|
731
|
-
cursor:
|
|
732
|
-
limit:
|
|
732
|
+
contractId: z7.string().optional().describe("Filter by contract id"),
|
|
733
|
+
fromHeight: z7.number().optional().describe("Start block height (inclusive)"),
|
|
734
|
+
toHeight: z7.number().optional().describe("End block height (inclusive)"),
|
|
735
|
+
cursor: z7.string().optional().describe("Opaque cursor from a prior response's next_cursor"),
|
|
736
|
+
limit: z7.number().optional().describe("Max rows for this page")
|
|
733
737
|
};
|
|
734
738
|
var orderFilter = {
|
|
735
|
-
order:
|
|
739
|
+
order: z7.enum(["asc", "desc"]).optional().describe("asc (default) reads oldest first; desc reads newest first. A cursor only resumes under the order that issued it.")
|
|
736
740
|
};
|
|
737
741
|
var heightFilters = {
|
|
738
742
|
fromHeight: rangeFilters.fromHeight,
|
|
@@ -744,47 +748,47 @@ function registerIndexTools(server, clientProvider = getClient) {
|
|
|
744
748
|
defineTool(server, "index_ft_transfers", "List decoded SIP-010 fungible-token transfers from Index. Reads are keyless.", {
|
|
745
749
|
...rangeFilters,
|
|
746
750
|
...orderFilter,
|
|
747
|
-
sender:
|
|
748
|
-
recipient:
|
|
749
|
-
assetIdentifier:
|
|
751
|
+
sender: z7.string().optional().describe("Filter by sender principal"),
|
|
752
|
+
recipient: z7.string().optional().describe("Filter by recipient principal"),
|
|
753
|
+
assetIdentifier: z7.string().optional().describe("Filter by asset identifier (contract::asset), e.g. SP…sbtc-token::sbtc-token")
|
|
750
754
|
}, async (params) => jsonResponse(await clientProvider().index.ftTransfers.list(params)));
|
|
751
755
|
defineTool(server, "index_nft_transfers", "List decoded SIP-009 non-fungible-token transfers from Index. Reads are keyless.", {
|
|
752
756
|
...rangeFilters,
|
|
753
757
|
...orderFilter,
|
|
754
|
-
sender:
|
|
755
|
-
recipient:
|
|
756
|
-
assetIdentifier:
|
|
758
|
+
sender: z7.string().optional().describe("Filter by sender principal"),
|
|
759
|
+
recipient: z7.string().optional().describe("Filter by recipient principal"),
|
|
760
|
+
assetIdentifier: z7.string().optional().describe("Filter by asset identifier (contract::asset)")
|
|
757
761
|
}, async (params) => jsonResponse(await clientProvider().index.nftTransfers.list(params)));
|
|
758
762
|
defineTool(server, "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.", {
|
|
759
|
-
eventType:
|
|
763
|
+
eventType: z7.enum(INDEX_EVENT_TYPES).describe("Required. Decoded event type to list."),
|
|
760
764
|
...rangeFilters,
|
|
761
765
|
...orderFilter,
|
|
762
|
-
sender:
|
|
763
|
-
recipient:
|
|
764
|
-
assetIdentifier:
|
|
765
|
-
trait:
|
|
766
|
-
txContext:
|
|
766
|
+
sender: z7.string().optional().describe("Filter by sender principal"),
|
|
767
|
+
recipient: z7.string().optional().describe("Filter by recipient principal"),
|
|
768
|
+
assetIdentifier: z7.string().optional().describe("Filter by asset identifier where applicable"),
|
|
769
|
+
trait: z7.string().optional().describe("Match contracts conforming to a trait/standard (e.g. sip-010). Mutually exclusive with contractId; contract-keyed event types only."),
|
|
770
|
+
txContext: z7.boolean().optional().describe("Join the submitting transaction into each event (tx_sender, tx_type, tx_status, tx_contract_id, tx_function_name). For print events it's the only source of the submitting sender.")
|
|
767
771
|
}, async (params) => jsonResponse(await clientProvider().index.events.list(params)));
|
|
768
772
|
defineTool(server, "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.", {
|
|
769
773
|
...rangeFilters,
|
|
770
|
-
functionName:
|
|
771
|
-
sender:
|
|
772
|
-
trait:
|
|
774
|
+
functionName: z7.string().optional().describe("Filter by called function name"),
|
|
775
|
+
sender: z7.string().optional().describe("Filter by caller principal"),
|
|
776
|
+
trait: z7.string().optional().describe("Match contracts conforming to a trait/standard (e.g. sip-010). Mutually exclusive with contractId.")
|
|
773
777
|
}, async (params) => jsonResponse(await clientProvider().index.contractCalls.list(params)));
|
|
774
778
|
defineTool(server, "index_blocks", "List decoded blocks from Index. Reads are keyless.", { ...heightFilters }, async (params) => jsonResponse(await clientProvider().index.blocks.list(params)));
|
|
775
779
|
defineTool(server, "index_transactions", "List decoded transactions from Index. Filter by type, sender, or contract. Reads are keyless.", {
|
|
776
780
|
...rangeFilters,
|
|
777
|
-
type:
|
|
778
|
-
sender:
|
|
781
|
+
type: z7.string().optional().describe("Filter by transaction type"),
|
|
782
|
+
sender: z7.string().optional().describe("Filter by sender principal")
|
|
779
783
|
}, async (params) => jsonResponse(await clientProvider().index.transactions.list(params)));
|
|
780
784
|
defineTool(server, "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.", {
|
|
781
|
-
contractId:
|
|
785
|
+
contractId: z7.string().describe("Contract id (SP….name) whose print events to profile")
|
|
782
786
|
}, async (params) => jsonResponse(await clientProvider().index.printSchema(params.contractId)));
|
|
783
787
|
defineTool(server, "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.", {}, async () => jsonResponse(await clientProvider().index.discover()));
|
|
784
788
|
defineTool(server, "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.", {
|
|
785
|
-
requests:
|
|
786
|
-
path:
|
|
787
|
-
params:
|
|
789
|
+
requests: z7.array(z7.object({
|
|
790
|
+
path: z7.string().describe("Public /v1 read path"),
|
|
791
|
+
params: z7.record(z7.string(), z7.string()).optional()
|
|
788
792
|
})).min(1).max(10).describe("Read descriptors, executed concurrently")
|
|
789
793
|
}, async (params) => jsonResponse(await clientProvider().batch(params.requests)));
|
|
790
794
|
}
|
|
@@ -805,7 +809,7 @@ import {
|
|
|
805
809
|
generateSubgraphCode,
|
|
806
810
|
generateTokenSubgraphFromAbi
|
|
807
811
|
} from "@secondlayer/scaffold";
|
|
808
|
-
import { z as
|
|
812
|
+
import { z as z8 } from "zod";
|
|
809
813
|
async function fetchAbi(clientProvider, contractId) {
|
|
810
814
|
const contract = await clientProvider().contracts.get(contractId, {
|
|
811
815
|
includeAbi: true
|
|
@@ -820,8 +824,8 @@ async function fetchAbi(clientProvider, contractId) {
|
|
|
820
824
|
}
|
|
821
825
|
function registerScaffoldTools(server, clientProvider = getClient) {
|
|
822
826
|
defineTool(server, "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.", {
|
|
823
|
-
contractId:
|
|
824
|
-
subgraphName:
|
|
827
|
+
contractId: z8.string().describe("Fully qualified contract ID (e.g. SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-pool-v2-01)"),
|
|
828
|
+
subgraphName: z8.string().optional().describe("Override the subgraph name (defaults to contract name)")
|
|
825
829
|
}, async ({ contractId, subgraphName }) => {
|
|
826
830
|
const printSchema = await clientProvider().index.printSchema(contractId);
|
|
827
831
|
if (printSchema && printSchema.topics.length > 0) {
|
|
@@ -863,7 +867,7 @@ import { DECODED_EVENT_TYPES as DECODED_EVENT_TYPES2 } from "@secondlayer/shared
|
|
|
863
867
|
import {
|
|
864
868
|
runSubgraphTest
|
|
865
869
|
} from "@secondlayer/subgraphs/testing";
|
|
866
|
-
import { z as
|
|
870
|
+
import { z as z9 } from "zod";
|
|
867
871
|
function eventTypeFor(filter) {
|
|
868
872
|
if (filter.type === "contract_deploy")
|
|
869
873
|
return null;
|
|
@@ -889,13 +893,13 @@ function registerSubgraphTools(server, clientProvider = getClient) {
|
|
|
889
893
|
const { data } = await clientProvider().subgraphs.list();
|
|
890
894
|
return jsonResponse(data.map(formatSubgraphSummary));
|
|
891
895
|
});
|
|
892
|
-
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:
|
|
896
|
+
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: z9.string().describe("Subgraph name") }, async ({ name }) => {
|
|
893
897
|
const detail = await clientProvider().subgraphs.status(name);
|
|
894
898
|
return jsonResponse(detail);
|
|
895
899
|
});
|
|
896
900
|
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.", {
|
|
897
|
-
name:
|
|
898
|
-
format:
|
|
901
|
+
name: z9.string().describe("Subgraph name"),
|
|
902
|
+
format: z9.enum(["agent", "openapi", "markdown"]).optional().describe("agent = JSON schema for tool use (default), openapi = OpenAPI JSON, markdown = docs.md")
|
|
899
903
|
}, async ({ name, format }) => {
|
|
900
904
|
const client = clientProvider();
|
|
901
905
|
if (format === "openapi")
|
|
@@ -905,15 +909,15 @@ function registerSubgraphTools(server, clientProvider = getClient) {
|
|
|
905
909
|
return jsonResponse(await client.subgraphs.schema(name));
|
|
906
910
|
});
|
|
907
911
|
defineTool(server, "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.', {
|
|
908
|
-
name:
|
|
909
|
-
table:
|
|
910
|
-
filters:
|
|
911
|
-
sort:
|
|
912
|
-
order:
|
|
913
|
-
limit:
|
|
914
|
-
cursor:
|
|
915
|
-
fields:
|
|
916
|
-
count:
|
|
912
|
+
name: z9.string().describe("Subgraph name"),
|
|
913
|
+
table: z9.string().describe("Table name"),
|
|
914
|
+
filters: z9.record(z9.string(), z9.string()).optional().describe('Column filters — plain values or with operators (e.g. {"amount.gte": "1000", "sender": "SP..."})'),
|
|
915
|
+
sort: z9.string().optional().describe("Column to sort by"),
|
|
916
|
+
order: z9.enum(["asc", "desc"]).optional().describe("Sort order"),
|
|
917
|
+
limit: z9.number().max(200).optional().describe("Max rows (default 50, max 200)"),
|
|
918
|
+
cursor: z9.string().optional().describe("Resume from a previous response's nextCursor"),
|
|
919
|
+
fields: z9.string().optional().describe('Comma-separated column list to return (e.g. "sender,amount")'),
|
|
920
|
+
count: z9.boolean().optional().describe("If true, return row count instead of rows")
|
|
917
921
|
}, async ({
|
|
918
922
|
name,
|
|
919
923
|
table,
|
|
@@ -943,15 +947,15 @@ function registerSubgraphTools(server, clientProvider = getClient) {
|
|
|
943
947
|
return jsonResponse({ ...capped, nextCursor: next_cursor, tip });
|
|
944
948
|
});
|
|
945
949
|
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.", {
|
|
946
|
-
name:
|
|
950
|
+
name: z9.string().describe("Subgraph name")
|
|
947
951
|
}, async ({ name }) => {
|
|
948
952
|
const result = await clientProvider().subgraphs.reindex(name);
|
|
949
953
|
return jsonResponse(result);
|
|
950
954
|
});
|
|
951
955
|
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.", {
|
|
952
|
-
name:
|
|
953
|
-
fromBlock:
|
|
954
|
-
toBlock:
|
|
956
|
+
name: z9.string().describe("Subgraph name"),
|
|
957
|
+
fromBlock: z9.number().int().nonnegative().describe("Start block (inclusive)"),
|
|
958
|
+
toBlock: z9.number().int().nonnegative().describe("End block (inclusive)")
|
|
955
959
|
}, async ({ name, fromBlock, toBlock }) => {
|
|
956
960
|
const result = await clientProvider().subgraphs.backfill(name, {
|
|
957
961
|
fromBlock,
|
|
@@ -959,15 +963,15 @@ function registerSubgraphTools(server, clientProvider = getClient) {
|
|
|
959
963
|
});
|
|
960
964
|
return jsonResponse(result);
|
|
961
965
|
});
|
|
962
|
-
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:
|
|
966
|
+
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: z9.string().describe("Subgraph name") }, async ({ name }) => {
|
|
963
967
|
const result = await clientProvider().subgraphs.stop(name);
|
|
964
968
|
return jsonResponse(result);
|
|
965
969
|
});
|
|
966
970
|
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.", {
|
|
967
|
-
name:
|
|
968
|
-
limit:
|
|
969
|
-
offset:
|
|
970
|
-
resolved:
|
|
971
|
+
name: z9.string().describe("Subgraph name"),
|
|
972
|
+
limit: z9.number().int().positive().optional().describe("Max gaps to return"),
|
|
973
|
+
offset: z9.number().int().nonnegative().optional().describe("Pagination offset"),
|
|
974
|
+
resolved: z9.boolean().optional().describe("Filter by resolved state (omit for unresolved only)")
|
|
971
975
|
}, async ({ name, limit, offset, resolved }) => {
|
|
972
976
|
const result = await clientProvider().subgraphs.gaps(name, {
|
|
973
977
|
limit,
|
|
@@ -977,20 +981,20 @@ function registerSubgraphTools(server, clientProvider = getClient) {
|
|
|
977
981
|
return jsonResponse(result);
|
|
978
982
|
});
|
|
979
983
|
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.", {
|
|
980
|
-
name:
|
|
981
|
-
operationId:
|
|
984
|
+
name: z9.string().describe("Subgraph name"),
|
|
985
|
+
operationId: z9.string().optional().describe("Fetch one operation by id (the operationId returned by reindex/backfill/stop); omit for recent history")
|
|
982
986
|
}, async ({ name, operationId }) => {
|
|
983
987
|
const client = clientProvider();
|
|
984
988
|
return jsonResponse(operationId ? await client.subgraphs.getOperation(name, operationId) : await client.subgraphs.operations(name));
|
|
985
989
|
});
|
|
986
|
-
defineTool(server, "subgraphs_delete", "Delete a subgraph permanently.", { name:
|
|
990
|
+
defineTool(server, "subgraphs_delete", "Delete a subgraph permanently.", { name: z9.string().describe("Subgraph name") }, async ({ name }) => {
|
|
987
991
|
const result = await clientProvider().subgraphs.delete(name);
|
|
988
992
|
return textResponse(result.message);
|
|
989
993
|
});
|
|
990
994
|
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.", {
|
|
991
|
-
code:
|
|
992
|
-
startBlock:
|
|
993
|
-
dryRun:
|
|
995
|
+
code: z9.string().describe("TypeScript source code containing a defineSubgraph() call"),
|
|
996
|
+
startBlock: z9.number().int().nonnegative().optional().describe("Override the definition startBlock for this deploy"),
|
|
997
|
+
dryRun: z9.boolean().optional().describe("Validate schema/DDL only — does not run handlers. Use subgraphs_test to prove a mapping writes rows.")
|
|
994
998
|
}, async ({ code, startBlock, dryRun }) => {
|
|
995
999
|
const bundled = await bundleSubgraphCode(code);
|
|
996
1000
|
const result = await clientProvider().subgraphs.deploy({
|
|
@@ -1006,10 +1010,10 @@ function registerSubgraphTools(server, clientProvider = getClient) {
|
|
|
1006
1010
|
return jsonResponse(result);
|
|
1007
1011
|
});
|
|
1008
1012
|
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.", {
|
|
1009
|
-
code:
|
|
1010
|
-
fromHeight:
|
|
1011
|
-
toHeight:
|
|
1012
|
-
limit:
|
|
1013
|
+
code: z9.string().describe("TypeScript source containing a defineSubgraph() call"),
|
|
1014
|
+
fromHeight: z9.number().int().nonnegative().describe("Start block height (inclusive)"),
|
|
1015
|
+
toHeight: z9.number().int().nonnegative().optional().describe("End block height (inclusive); default fromHeight+100"),
|
|
1016
|
+
limit: z9.number().int().positive().max(200).optional().describe("Max Index rows per source (default 50, max 200)")
|
|
1013
1017
|
}, async ({ code, fromHeight, toHeight, limit }) => {
|
|
1014
1018
|
const bundled = await bundleSubgraphCode(code);
|
|
1015
1019
|
const def = await loadBundledDefinition(bundled.handlerCode);
|
|
@@ -1090,36 +1094,36 @@ function registerSubgraphTools(server, clientProvider = getClient) {
|
|
|
1090
1094
|
|
|
1091
1095
|
// src/tools/webhooks.ts
|
|
1092
1096
|
import { CHAIN_TRIGGER_TYPES } from "@secondlayer/shared";
|
|
1093
|
-
import { z as
|
|
1097
|
+
import { z as z10 } from "zod";
|
|
1094
1098
|
function registerWebhookTools(server, clientProvider = getClient) {
|
|
1095
1099
|
defineTool(server, "webhooks_list", "List all webhooks for the current account. Returns summary fields (no secrets).", {}, async () => {
|
|
1096
1100
|
const { data } = await clientProvider().webhooks.list();
|
|
1097
1101
|
return jsonResponse(data);
|
|
1098
1102
|
});
|
|
1099
|
-
defineTool(server, "webhooks_get", "Get full detail for a webhook (triggers, auth, retry config, circuit state).", { id:
|
|
1103
|
+
defineTool(server, "webhooks_get", "Get full detail for a webhook (triggers, auth, retry config, circuit state).", { id: z10.string().describe("Webhook id") }, async ({ id }) => {
|
|
1100
1104
|
const detail = await clientProvider().webhooks.get(id);
|
|
1101
1105
|
return jsonResponse(detail);
|
|
1102
1106
|
});
|
|
1103
1107
|
defineTool(server, "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.", {
|
|
1104
|
-
name:
|
|
1105
|
-
triggers:
|
|
1106
|
-
type:
|
|
1107
|
-
contractId:
|
|
1108
|
-
functionName:
|
|
1109
|
-
caller:
|
|
1110
|
-
sender:
|
|
1111
|
-
recipient:
|
|
1112
|
-
assetIdentifier:
|
|
1113
|
-
deployer:
|
|
1114
|
-
contractName:
|
|
1115
|
-
topic:
|
|
1116
|
-
lockedAddress:
|
|
1117
|
-
trait:
|
|
1118
|
-
minAmount:
|
|
1119
|
-
maxAmount:
|
|
1108
|
+
name: z10.string().describe("Human-readable name, unique per account"),
|
|
1109
|
+
triggers: z10.array(z10.object({
|
|
1110
|
+
type: z10.enum(CHAIN_TRIGGER_TYPES),
|
|
1111
|
+
contractId: z10.string().optional(),
|
|
1112
|
+
functionName: z10.string().optional(),
|
|
1113
|
+
caller: z10.string().optional(),
|
|
1114
|
+
sender: z10.string().optional(),
|
|
1115
|
+
recipient: z10.string().optional(),
|
|
1116
|
+
assetIdentifier: z10.string().optional(),
|
|
1117
|
+
deployer: z10.string().optional(),
|
|
1118
|
+
contractName: z10.string().optional(),
|
|
1119
|
+
topic: z10.string().optional(),
|
|
1120
|
+
lockedAddress: z10.string().optional(),
|
|
1121
|
+
trait: z10.string().optional(),
|
|
1122
|
+
minAmount: z10.union([z10.string(), z10.number()]).optional(),
|
|
1123
|
+
maxAmount: z10.union([z10.string(), z10.number()]).optional()
|
|
1120
1124
|
})).describe("Chain triggers. 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."),
|
|
1121
|
-
url:
|
|
1122
|
-
format:
|
|
1125
|
+
url: z10.string().describe("Webhook URL"),
|
|
1126
|
+
format: z10.enum([
|
|
1123
1127
|
"standard-webhooks",
|
|
1124
1128
|
"inngest",
|
|
1125
1129
|
"trigger",
|
|
@@ -1127,17 +1131,17 @@ function registerWebhookTools(server, clientProvider = getClient) {
|
|
|
1127
1131
|
"cloudevents",
|
|
1128
1132
|
"raw"
|
|
1129
1133
|
]).optional().describe("Wire format (default standard-webhooks)"),
|
|
1130
|
-
authConfig:
|
|
1134
|
+
authConfig: z10.record(z10.string(), z10.unknown()).optional().describe('Receiver auth sent with each delivery, e.g. {"type": "bearer", "token": "..."}')
|
|
1131
1135
|
}, async (input) => {
|
|
1132
1136
|
const res = await clientProvider().webhooks.create(input);
|
|
1133
1137
|
return jsonResponse(res);
|
|
1134
1138
|
});
|
|
1135
1139
|
defineTool(server, "webhooks_update", "Patch a webhook (name, url, authConfig, format, retry, timeout, concurrency).", {
|
|
1136
|
-
id:
|
|
1137
|
-
name:
|
|
1138
|
-
url:
|
|
1139
|
-
authConfig:
|
|
1140
|
-
format:
|
|
1140
|
+
id: z10.string(),
|
|
1141
|
+
name: z10.string().optional().describe("Rename the webhook"),
|
|
1142
|
+
url: z10.string().optional(),
|
|
1143
|
+
authConfig: z10.record(z10.string(), z10.unknown()).optional().describe("Receiver auth sent with each delivery (bearer/etc.)"),
|
|
1144
|
+
format: z10.enum([
|
|
1141
1145
|
"standard-webhooks",
|
|
1142
1146
|
"inngest",
|
|
1143
1147
|
"trigger",
|
|
@@ -1145,35 +1149,35 @@ function registerWebhookTools(server, clientProvider = getClient) {
|
|
|
1145
1149
|
"cloudevents",
|
|
1146
1150
|
"raw"
|
|
1147
1151
|
]).optional(),
|
|
1148
|
-
maxRetries:
|
|
1149
|
-
timeoutMs:
|
|
1150
|
-
concurrency:
|
|
1152
|
+
maxRetries: z10.number().int().min(0).optional(),
|
|
1153
|
+
timeoutMs: z10.number().int().min(100).optional(),
|
|
1154
|
+
concurrency: z10.number().int().min(1).optional()
|
|
1151
1155
|
}, async ({ id, ...patch }) => {
|
|
1152
1156
|
const res = await clientProvider().webhooks.update(id, patch);
|
|
1153
1157
|
return jsonResponse(res);
|
|
1154
1158
|
});
|
|
1155
|
-
defineTool(server, "webhooks_delete", "Delete a webhook. Pending outbox rows are cascade-deleted.", { id:
|
|
1159
|
+
defineTool(server, "webhooks_delete", "Delete a webhook. Pending outbox rows are cascade-deleted.", { id: z10.string() }, async ({ id }) => {
|
|
1156
1160
|
const res = await clientProvider().webhooks.delete(id);
|
|
1157
1161
|
return jsonResponse(res);
|
|
1158
1162
|
});
|
|
1159
|
-
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:
|
|
1163
|
+
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: z10.string().describe("Webhook id") }, async ({ id }) => {
|
|
1160
1164
|
const res = await clientProvider().webhooks.test(id);
|
|
1161
1165
|
return jsonResponse(res);
|
|
1162
1166
|
});
|
|
1163
|
-
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:
|
|
1164
|
-
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:
|
|
1165
|
-
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:
|
|
1166
|
-
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:
|
|
1167
|
-
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:
|
|
1167
|
+
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: z10.string().describe("Webhook id") }, async ({ id }) => jsonResponse(await clientProvider().webhooks.pause(id)));
|
|
1168
|
+
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: z10.string().describe("Webhook id") }, async ({ id }) => jsonResponse(await clientProvider().webhooks.resume(id)));
|
|
1169
|
+
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: z10.string().describe("Webhook id") }, async ({ id }) => jsonResponse(await clientProvider().webhooks.rotateSecret(id)));
|
|
1170
|
+
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: z10.string().describe("Webhook id") }, async ({ id }) => jsonResponse(await clientProvider().webhooks.deliveries(id)));
|
|
1171
|
+
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: z10.string().describe("Webhook id") }, async ({ id }) => jsonResponse(await clientProvider().webhooks.dead(id)));
|
|
1168
1172
|
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.", {
|
|
1169
|
-
id:
|
|
1170
|
-
outboxId:
|
|
1173
|
+
id: z10.string().describe("Webhook id"),
|
|
1174
|
+
outboxId: z10.string().describe("Outbox id of the dead delivery (from webhooks_dead)")
|
|
1171
1175
|
}, async ({ id, outboxId }) => jsonResponse(await clientProvider().webhooks.requeue(id, outboxId)));
|
|
1172
1176
|
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.", {
|
|
1173
|
-
id:
|
|
1174
|
-
fromBlock:
|
|
1175
|
-
toBlock:
|
|
1176
|
-
force:
|
|
1177
|
+
id: z10.string(),
|
|
1178
|
+
fromBlock: z10.number().int().nonnegative(),
|
|
1179
|
+
toBlock: z10.number().int().nonnegative(),
|
|
1180
|
+
force: z10.string().optional().describe("Idempotency suffix to force a duplicate replay of the range")
|
|
1177
1181
|
}, async ({ id, fromBlock, toBlock, force }) => {
|
|
1178
1182
|
const res = await clientProvider().webhooks.replay(id, {
|
|
1179
1183
|
fromBlock,
|
|
@@ -1289,5 +1293,5 @@ export {
|
|
|
1289
1293
|
createServer
|
|
1290
1294
|
};
|
|
1291
1295
|
|
|
1292
|
-
//# debugId=
|
|
1296
|
+
//# debugId=CDDD871AD0093C1964756E2164756E21
|
|
1293
1297
|
//# sourceMappingURL=index.js.map
|