@secondlayer/mcp 10.0.0 → 11.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 +2 -3
- package/dist/bin-http.js +208 -246
- package/dist/bin-http.js.map +9 -9
- package/dist/bin.js +208 -246
- package/dist/bin.js.map +9 -9
- package/dist/index.js +208 -246
- package/dist/index.js.map +9 -9
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -218,7 +218,6 @@ var PRODUCT_BLURBS = {
|
|
|
218
218
|
codegen: "ORM schemas for the tables you read",
|
|
219
219
|
instance: "decoder health and empty-index diagnosis",
|
|
220
220
|
archive: "signed archive verify, bootstrap/repair, quote, latest pointer",
|
|
221
|
-
setup: "one-command self-host onboarding",
|
|
222
221
|
credits: "archive credits balance at api.secondlayer.tools"
|
|
223
222
|
};
|
|
224
223
|
var PRODUCT_ORDER = [
|
|
@@ -231,7 +230,6 @@ var PRODUCT_ORDER = [
|
|
|
231
230
|
"codegen",
|
|
232
231
|
"instance",
|
|
233
232
|
"archive",
|
|
234
|
-
"setup",
|
|
235
233
|
"credits"
|
|
236
234
|
];
|
|
237
235
|
function buildCapabilities() {
|
|
@@ -436,229 +434,22 @@ function registerAccountTools(server) {
|
|
|
436
434
|
}, async ({ name }) => jsonResponse(await apiRequest("POST", "/api/keys", { name })));
|
|
437
435
|
}
|
|
438
436
|
|
|
439
|
-
// src/tools/archive.ts
|
|
437
|
+
// src/tools/archive-cli.ts
|
|
440
438
|
import { z as z2 } from "zod";
|
|
441
|
-
var FLOW = ["bootstrap", "repair"];
|
|
442
|
-
function registerArchiveTools(server, clientProvider = getClient, archiveOpsClientProvider = getArchiveOpsClient) {
|
|
443
|
-
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.", {
|
|
444
|
-
against: z2.string().describe("Archive manifest URL"),
|
|
445
|
-
fromBlock: z2.number().int().nonnegative().optional().describe("First height (inclusive)"),
|
|
446
|
-
toBlock: z2.number().int().nonnegative().optional().describe("Last height (inclusive)"),
|
|
447
|
-
target: z2.string().optional().describe("Verify target (default raw)")
|
|
448
|
-
}, async ({ against, fromBlock, toBlock, target }) => jsonResponse(await clientProvider().archive.verify({
|
|
449
|
-
against,
|
|
450
|
-
fromBlock,
|
|
451
|
-
toBlock,
|
|
452
|
-
target
|
|
453
|
-
})));
|
|
454
|
-
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.", {
|
|
455
|
-
against: z2.string().optional().describe("Override latest.json URL (default official tree)")
|
|
456
|
-
}, async ({ against }) => jsonResponse(await archiveOpsClientProvider().archive.latest(against)));
|
|
457
|
-
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.", {
|
|
458
|
-
paths: z2.array(z2.string()).describe("Partition paths to price"),
|
|
459
|
-
flow: z2.enum(FLOW).describe("bootstrap or repair")
|
|
460
|
-
}, async ({ paths, flow }) => jsonResponse(await archiveOpsClientProvider().archive.quote({ paths, flow })));
|
|
461
|
-
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()));
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
// src/tools/codegen.ts
|
|
465
|
-
import {
|
|
466
|
-
generateIndexSchema
|
|
467
|
-
} from "@secondlayer/subgraphs";
|
|
468
|
-
import { z as z3 } from "zod";
|
|
469
|
-
var TARGETS = ["prisma", "kysely", "drizzle", "json-schema"];
|
|
470
|
-
function registerCodegenTools(server) {
|
|
471
|
-
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.", {
|
|
472
|
-
target: z3.enum(TARGETS).optional().describe("Output flavor (default kysely)"),
|
|
473
|
-
tables: z3.array(z3.string()).optional().describe("Restrict to these Index tables (default: all)"),
|
|
474
|
-
schemaName: z3.string().optional().describe("Postgres schema to qualify table names with"),
|
|
475
|
-
datasourceEnv: z3.string().optional().describe("Prisma only: datasource url env var (default DATABASE_URL)")
|
|
476
|
-
}, ({ target, tables, schemaName, datasourceEnv }) => textResponse(generateIndexSchema(target ?? "kysely", {
|
|
477
|
-
tables,
|
|
478
|
-
schemaName,
|
|
479
|
-
datasourceEnv
|
|
480
|
-
})));
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
// src/tools/contracts.ts
|
|
484
|
-
import { z as z4 } from "zod";
|
|
485
|
-
function registerContractTools(server, clientProvider = getClient) {
|
|
486
|
-
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.', {
|
|
487
|
-
trait: z4.string().describe('Required. Trait to match (e.g. "sip-010").'),
|
|
488
|
-
conformance: z4.enum(["declared", "inferred", "any"]).optional().describe("declared = parsed from source, inferred = ABI shape-match, any = either (default)"),
|
|
489
|
-
include: z4.literal("abi").optional().describe(`Set to "abi" to include each contract's full ABI`),
|
|
490
|
-
limit: z4.number().optional().describe("Page size, 1–500 (default 100)"),
|
|
491
|
-
cursor: z4.string().optional().describe("Opaque cursor from a prior response's next_cursor")
|
|
492
|
-
}, async (params) => jsonResponse(await clientProvider().contracts.list(params)));
|
|
493
|
-
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.", {
|
|
494
|
-
contractId: z4.string().describe("Fully qualified contract id (e.g. SP….amm-pool-v2-01)")
|
|
495
|
-
}, async ({ contractId }) => {
|
|
496
|
-
const contract = await clientProvider().contracts.get(contractId, {
|
|
497
|
-
includeAbi: true
|
|
498
|
-
});
|
|
499
|
-
return contract ? jsonResponse(contract) : jsonResponse({
|
|
500
|
-
error: {
|
|
501
|
-
type: "not_found",
|
|
502
|
-
status: 404,
|
|
503
|
-
message: `Contract not in registry: ${contractId}`
|
|
504
|
-
}
|
|
505
|
-
}, true);
|
|
506
|
-
});
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
// src/tools/index.ts
|
|
510
|
-
import { DECODED_EVENT_TYPES } from "@secondlayer/shared";
|
|
511
|
-
import { z as z5 } from "zod";
|
|
512
|
-
var INDEX_EVENT_TYPES = DECODED_EVENT_TYPES;
|
|
513
|
-
var rangeFilters = {
|
|
514
|
-
contractId: z5.string().optional().describe("Filter by contract id"),
|
|
515
|
-
fromHeight: z5.number().optional().describe("Start block height (inclusive)"),
|
|
516
|
-
toHeight: z5.number().optional().describe("End block height (inclusive)"),
|
|
517
|
-
cursor: z5.string().optional().describe("Opaque cursor from a prior response's next_cursor"),
|
|
518
|
-
limit: z5.number().optional().describe("Max rows for this page")
|
|
519
|
-
};
|
|
520
|
-
var heightFilters = {
|
|
521
|
-
fromHeight: rangeFilters.fromHeight,
|
|
522
|
-
toHeight: rangeFilters.toHeight,
|
|
523
|
-
cursor: rangeFilters.cursor,
|
|
524
|
-
limit: rangeFilters.limit
|
|
525
|
-
};
|
|
526
|
-
function registerIndexTools(server, clientProvider = getClient) {
|
|
527
|
-
defineTool(server, "index_ft_transfers", "List decoded SIP-010 fungible-token transfers from Index. Reads are keyless.", {
|
|
528
|
-
...rangeFilters,
|
|
529
|
-
sender: z5.string().optional().describe("Filter by sender principal"),
|
|
530
|
-
recipient: z5.string().optional().describe("Filter by recipient principal"),
|
|
531
|
-
assetIdentifier: z5.string().optional().describe("Filter by asset identifier (contract::asset), e.g. SP…sbtc-token::sbtc-token")
|
|
532
|
-
}, async (params) => jsonResponse(await clientProvider().index.ftTransfers.list(params)));
|
|
533
|
-
defineTool(server, "index_nft_transfers", "List decoded SIP-009 non-fungible-token transfers from Index. Reads are keyless.", {
|
|
534
|
-
...rangeFilters,
|
|
535
|
-
sender: z5.string().optional().describe("Filter by sender principal"),
|
|
536
|
-
recipient: z5.string().optional().describe("Filter by recipient principal"),
|
|
537
|
-
assetIdentifier: z5.string().optional().describe("Filter by asset identifier (contract::asset)")
|
|
538
|
-
}, async (params) => jsonResponse(await clientProvider().index.nftTransfers.list(params)));
|
|
539
|
-
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.", {
|
|
540
|
-
eventType: z5.enum(INDEX_EVENT_TYPES).describe("Required. Decoded event type to list."),
|
|
541
|
-
...rangeFilters,
|
|
542
|
-
sender: z5.string().optional().describe("Filter by sender principal"),
|
|
543
|
-
recipient: z5.string().optional().describe("Filter by recipient principal"),
|
|
544
|
-
assetIdentifier: z5.string().optional().describe("Filter by asset identifier where applicable"),
|
|
545
|
-
trait: z5.string().optional().describe("Match contracts conforming to a trait/standard (e.g. sip-010). Mutually exclusive with contractId; contract-keyed event types only."),
|
|
546
|
-
txContext: z5.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.")
|
|
547
|
-
}, async (params) => jsonResponse(await clientProvider().index.events.list(params)));
|
|
548
|
-
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.", {
|
|
549
|
-
...rangeFilters,
|
|
550
|
-
functionName: z5.string().optional().describe("Filter by called function name"),
|
|
551
|
-
sender: z5.string().optional().describe("Filter by caller principal"),
|
|
552
|
-
trait: z5.string().optional().describe("Match contracts conforming to a trait/standard (e.g. sip-010). Mutually exclusive with contractId.")
|
|
553
|
-
}, async (params) => jsonResponse(await clientProvider().index.contractCalls.list(params)));
|
|
554
|
-
defineTool(server, "index_blocks", "List decoded blocks from Index. Reads are keyless.", { ...heightFilters }, async (params) => jsonResponse(await clientProvider().index.blocks.list(params)));
|
|
555
|
-
defineTool(server, "index_transactions", "List decoded transactions from Index. Filter by type, sender, or contract. Reads are keyless.", {
|
|
556
|
-
...rangeFilters,
|
|
557
|
-
type: z5.string().optional().describe("Filter by transaction type"),
|
|
558
|
-
sender: z5.string().optional().describe("Filter by sender principal")
|
|
559
|
-
}, async (params) => jsonResponse(await clientProvider().index.transactions.list(params)));
|
|
560
|
-
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.", {
|
|
561
|
-
contractId: z5.string().describe("Contract id (SP….name) whose print events to profile")
|
|
562
|
-
}, async (params) => jsonResponse(await clientProvider().index.printSchema(params.contractId)));
|
|
563
|
-
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()));
|
|
564
|
-
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.", {
|
|
565
|
-
requests: z5.array(z5.object({
|
|
566
|
-
path: z5.string().describe("Public /v1 read path"),
|
|
567
|
-
params: z5.record(z5.string(), z5.string()).optional()
|
|
568
|
-
})).min(1).max(10).describe("Read descriptors, executed concurrently")
|
|
569
|
-
}, async (params) => jsonResponse(await clientProvider().batch(params.requests)));
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
// src/tools/instance.ts
|
|
573
|
-
function registerInstanceTools(server, clientProvider = getClient) {
|
|
574
|
-
defineTool(server, "instance_status", "Decoder health and empty-index diagnosis from GET /public/status. If state is empty-index, next tool is archive_bootstrap or setup. 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.", {}, async () => {
|
|
575
|
-
const client = clientProvider();
|
|
576
|
-
const status = await client.instance.status();
|
|
577
|
-
const diagnosis = await client.instance.diagnose();
|
|
578
|
-
return jsonResponse({ status, diagnosis });
|
|
579
|
-
});
|
|
580
|
-
}
|
|
581
|
-
|
|
582
|
-
// src/tools/scaffold.ts
|
|
583
|
-
import {
|
|
584
|
-
generatePrintSchemaSubgraph,
|
|
585
|
-
generateSubgraphCode,
|
|
586
|
-
generateTokenSubgraphFromAbi
|
|
587
|
-
} from "@secondlayer/scaffold";
|
|
588
|
-
import { z as z6 } from "zod";
|
|
589
|
-
async function fetchAbi(clientProvider, contractId) {
|
|
590
|
-
const contract = await clientProvider().contracts.get(contractId, {
|
|
591
|
-
includeAbi: true
|
|
592
|
-
});
|
|
593
|
-
if (!contract)
|
|
594
|
-
throw new Error(`Contract not found: ${contractId}`);
|
|
595
|
-
const abi = contract.abi;
|
|
596
|
-
if (!abi) {
|
|
597
|
-
throw new Error(`No ABI available for ${contractId} (abi_status: ${contract.abi_status})`);
|
|
598
|
-
}
|
|
599
|
-
return { functions: abi.functions ?? [], abi };
|
|
600
|
-
}
|
|
601
|
-
function registerScaffoldTools(server, clientProvider = getClient) {
|
|
602
|
-
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.", {
|
|
603
|
-
contractId: z6.string().describe("Fully qualified contract ID (e.g. SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-pool-v2-01)"),
|
|
604
|
-
subgraphName: z6.string().optional().describe("Override the subgraph name (defaults to contract name)")
|
|
605
|
-
}, async ({ contractId, subgraphName }) => {
|
|
606
|
-
const printSchema = await clientProvider().index.printSchema(contractId);
|
|
607
|
-
if (printSchema && printSchema.topics.length > 0) {
|
|
608
|
-
const code = generatePrintSchemaSubgraph({
|
|
609
|
-
contractId,
|
|
610
|
-
name: subgraphName,
|
|
611
|
-
topics: printSchema.topics,
|
|
612
|
-
sample: printSchema.sample
|
|
613
|
-
});
|
|
614
|
-
return { content: [{ type: "text", text: code }] };
|
|
615
|
-
}
|
|
616
|
-
const { functions, abi } = await fetchAbi(clientProvider, contractId);
|
|
617
|
-
const token = generateTokenSubgraphFromAbi({
|
|
618
|
-
contractId,
|
|
619
|
-
abi,
|
|
620
|
-
name: subgraphName
|
|
621
|
-
});
|
|
622
|
-
if (token) {
|
|
623
|
-
return { content: [{ type: "text", text: token }] };
|
|
624
|
-
}
|
|
625
|
-
const code = generateSubgraphCode(contractId, functions, subgraphName);
|
|
626
|
-
return { content: [{ type: "text", text: code }] };
|
|
627
|
-
});
|
|
628
|
-
}
|
|
629
|
-
|
|
630
|
-
// src/tools/setup.ts
|
|
631
|
-
import { z as z7 } from "zod";
|
|
632
439
|
|
|
633
440
|
// src/lib/exec-cli.ts
|
|
634
441
|
import {
|
|
635
442
|
spawn
|
|
636
443
|
} from "node:child_process";
|
|
637
|
-
var ALLOWED = ["
|
|
444
|
+
var ALLOWED = ["bootstrap", "repair", "verify"];
|
|
638
445
|
var TIMEOUT_MS = {
|
|
639
|
-
setup: 15 * 60 * 1000,
|
|
640
446
|
bootstrap: 10 * 60 * 1000,
|
|
641
447
|
repair: 10 * 60 * 1000,
|
|
642
448
|
verify: 2 * 60 * 1000
|
|
643
449
|
};
|
|
644
|
-
var VALUE_FLAGS = new Set([
|
|
645
|
-
|
|
646
|
-
"--from-block",
|
|
647
|
-
"--to-block",
|
|
648
|
-
"--network",
|
|
649
|
-
"--node-mode",
|
|
650
|
-
"--dir"
|
|
651
|
-
]);
|
|
652
|
-
var BOOL_FLAGS = new Set(["--yes", "--json", "--apply", "--skip-bootstrap"]);
|
|
450
|
+
var VALUE_FLAGS = new Set(["--against", "--from-block", "--to-block"]);
|
|
451
|
+
var BOOL_FLAGS = new Set(["--yes", "--json", "--apply"]);
|
|
653
452
|
var FLAGS_BY_CMD = {
|
|
654
|
-
setup: new Set([
|
|
655
|
-
"--yes",
|
|
656
|
-
"--network",
|
|
657
|
-
"--node-mode",
|
|
658
|
-
"--against",
|
|
659
|
-
"--dir",
|
|
660
|
-
"--skip-bootstrap"
|
|
661
|
-
]),
|
|
662
453
|
bootstrap: new Set([
|
|
663
454
|
"--against",
|
|
664
455
|
"--yes",
|
|
@@ -733,12 +524,8 @@ async function execSecondlayer(subcommand, args, deps = {}) {
|
|
|
733
524
|
}
|
|
734
525
|
assertSafeArgs(subcommand, args);
|
|
735
526
|
const argv = [subcommand, ...args];
|
|
736
|
-
if (
|
|
737
|
-
if (!argv.includes("--yes"))
|
|
738
|
-
argv.push("--yes");
|
|
739
|
-
} else if (!argv.includes("--json")) {
|
|
527
|
+
if (!argv.includes("--json"))
|
|
740
528
|
argv.push("--json");
|
|
741
|
-
}
|
|
742
529
|
const env = deps.env ?? process.env;
|
|
743
530
|
const bin = env.SECONDLAYER_BIN || "secondlayer";
|
|
744
531
|
const cwd = deps.cwd ?? env.SECONDLAYER_CWD ?? process.cwd();
|
|
@@ -786,31 +573,15 @@ timeout after ${timeout}ms`.trim()
|
|
|
786
573
|
});
|
|
787
574
|
}
|
|
788
575
|
|
|
789
|
-
// src/tools/
|
|
576
|
+
// src/tools/archive-cli.ts
|
|
790
577
|
function cliResponse(result) {
|
|
791
578
|
return jsonResponse(result, result.code !== 0);
|
|
792
579
|
}
|
|
793
|
-
function
|
|
794
|
-
defineTool(server, "setup", "Non-interactive self-host onboarding (secondlayer setup --yes). If the index is empty, this or archive_bootstrap fills it. Bootstrap is metered against the official archive. After it returns, poll instance_status until index.decoders are ok, then archive_verify, then codegen_index_schema. Do not download parquet.", {
|
|
795
|
-
network: z7.enum(["mainnet", "testnet", "devnet"]).describe("Stacks network"),
|
|
796
|
-
nodeMode: z7.enum(["external", "stacks", "full"]).describe("Node mode: external, stacks, or full"),
|
|
797
|
-
against: z7.string().optional().describe("Archive manifest URL"),
|
|
798
|
-
dir: z7.string().optional().describe("Compose project directory"),
|
|
799
|
-
skipBootstrap: z7.boolean().optional().describe("Sync from genesis instead of restoring an archive")
|
|
800
|
-
}, async ({ network, nodeMode, against, dir, skipBootstrap }) => {
|
|
801
|
-
const args = ["--yes", "--network", network, "--node-mode", nodeMode];
|
|
802
|
-
if (against !== undefined)
|
|
803
|
-
args.push("--against", against);
|
|
804
|
-
if (dir !== undefined)
|
|
805
|
-
args.push("--dir", dir);
|
|
806
|
-
if (skipBootstrap)
|
|
807
|
-
args.push("--skip-bootstrap");
|
|
808
|
-
return cliResponse(await exec("setup", args));
|
|
809
|
-
});
|
|
580
|
+
function registerArchiveCliTools(server, exec = execSecondlayer) {
|
|
810
581
|
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.", {
|
|
811
|
-
against:
|
|
812
|
-
fromBlock:
|
|
813
|
-
toBlock:
|
|
582
|
+
against: z2.string().describe("Archive manifest URL"),
|
|
583
|
+
fromBlock: z2.number().int().nonnegative().optional().describe("Restore from this height instead of genesis"),
|
|
584
|
+
toBlock: z2.number().int().nonnegative().optional().describe("Stop at this height instead of the archive tip")
|
|
814
585
|
}, async ({ against, fromBlock, toBlock }) => {
|
|
815
586
|
const args = ["--against", against, "--yes", "--json"];
|
|
816
587
|
if (fromBlock !== undefined)
|
|
@@ -820,10 +591,10 @@ function registerSetupTools(server, exec = execSecondlayer) {
|
|
|
820
591
|
return cliResponse(await exec("bootstrap", args));
|
|
821
592
|
});
|
|
822
593
|
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.", {
|
|
823
|
-
against:
|
|
824
|
-
apply:
|
|
825
|
-
fromBlock:
|
|
826
|
-
toBlock:
|
|
594
|
+
against: z2.string().describe("Archive manifest URL"),
|
|
595
|
+
apply: z2.boolean().optional().describe("Write the repair (default plan-only)"),
|
|
596
|
+
fromBlock: z2.number().int().nonnegative().optional().describe("First height to consider"),
|
|
597
|
+
toBlock: z2.number().int().nonnegative().optional().describe("Last height to consider")
|
|
827
598
|
}, async ({ against, apply, fromBlock, toBlock }) => {
|
|
828
599
|
const args = ["--against", against, "--json"];
|
|
829
600
|
if (apply)
|
|
@@ -836,6 +607,197 @@ function registerSetupTools(server, exec = execSecondlayer) {
|
|
|
836
607
|
});
|
|
837
608
|
}
|
|
838
609
|
|
|
610
|
+
// src/tools/archive.ts
|
|
611
|
+
import { z as z3 } from "zod";
|
|
612
|
+
var FLOW = ["bootstrap", "repair"];
|
|
613
|
+
function registerArchiveTools(server, clientProvider = getClient, archiveOpsClientProvider = getArchiveOpsClient) {
|
|
614
|
+
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.", {
|
|
615
|
+
against: z3.string().describe("Archive manifest URL"),
|
|
616
|
+
fromBlock: z3.number().int().nonnegative().optional().describe("First height (inclusive)"),
|
|
617
|
+
toBlock: z3.number().int().nonnegative().optional().describe("Last height (inclusive)"),
|
|
618
|
+
target: z3.string().optional().describe("Verify target (default raw)")
|
|
619
|
+
}, async ({ against, fromBlock, toBlock, target }) => jsonResponse(await clientProvider().archive.verify({
|
|
620
|
+
against,
|
|
621
|
+
fromBlock,
|
|
622
|
+
toBlock,
|
|
623
|
+
target
|
|
624
|
+
})));
|
|
625
|
+
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.", {
|
|
626
|
+
against: z3.string().optional().describe("Override latest.json URL (default official tree)")
|
|
627
|
+
}, async ({ against }) => jsonResponse(await archiveOpsClientProvider().archive.latest(against)));
|
|
628
|
+
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.", {
|
|
629
|
+
paths: z3.array(z3.string()).describe("Partition paths to price"),
|
|
630
|
+
flow: z3.enum(FLOW).describe("bootstrap or repair")
|
|
631
|
+
}, async ({ paths, flow }) => jsonResponse(await archiveOpsClientProvider().archive.quote({ paths, flow })));
|
|
632
|
+
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()));
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
// src/tools/codegen.ts
|
|
636
|
+
import {
|
|
637
|
+
generateIndexSchema
|
|
638
|
+
} from "@secondlayer/subgraphs";
|
|
639
|
+
import { z as z4 } from "zod";
|
|
640
|
+
var TARGETS = ["prisma", "kysely", "drizzle", "json-schema"];
|
|
641
|
+
function registerCodegenTools(server) {
|
|
642
|
+
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.", {
|
|
643
|
+
target: z4.enum(TARGETS).optional().describe("Output flavor (default kysely)"),
|
|
644
|
+
tables: z4.array(z4.string()).optional().describe("Restrict to these Index tables (default: all)"),
|
|
645
|
+
schemaName: z4.string().optional().describe("Postgres schema to qualify table names with"),
|
|
646
|
+
datasourceEnv: z4.string().optional().describe("Prisma only: datasource url env var (default DATABASE_URL)")
|
|
647
|
+
}, ({ target, tables, schemaName, datasourceEnv }) => textResponse(generateIndexSchema(target ?? "kysely", {
|
|
648
|
+
tables,
|
|
649
|
+
schemaName,
|
|
650
|
+
datasourceEnv
|
|
651
|
+
})));
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
// src/tools/contracts.ts
|
|
655
|
+
import { z as z5 } from "zod";
|
|
656
|
+
function registerContractTools(server, clientProvider = getClient) {
|
|
657
|
+
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.', {
|
|
658
|
+
trait: z5.string().describe('Required. Trait to match (e.g. "sip-010").'),
|
|
659
|
+
conformance: z5.enum(["declared", "inferred", "any"]).optional().describe("declared = parsed from source, inferred = ABI shape-match, any = either (default)"),
|
|
660
|
+
include: z5.literal("abi").optional().describe(`Set to "abi" to include each contract's full ABI`),
|
|
661
|
+
limit: z5.number().optional().describe("Page size, 1–500 (default 100)"),
|
|
662
|
+
cursor: z5.string().optional().describe("Opaque cursor from a prior response's next_cursor")
|
|
663
|
+
}, async (params) => jsonResponse(await clientProvider().contracts.list(params)));
|
|
664
|
+
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.", {
|
|
665
|
+
contractId: z5.string().describe("Fully qualified contract id (e.g. SP….amm-pool-v2-01)")
|
|
666
|
+
}, async ({ contractId }) => {
|
|
667
|
+
const contract = await clientProvider().contracts.get(contractId, {
|
|
668
|
+
includeAbi: true
|
|
669
|
+
});
|
|
670
|
+
return contract ? jsonResponse(contract) : jsonResponse({
|
|
671
|
+
error: {
|
|
672
|
+
type: "not_found",
|
|
673
|
+
status: 404,
|
|
674
|
+
message: `Contract not in registry: ${contractId}`
|
|
675
|
+
}
|
|
676
|
+
}, true);
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
// src/tools/index.ts
|
|
681
|
+
import { DECODED_EVENT_TYPES } from "@secondlayer/shared";
|
|
682
|
+
import { z as z6 } from "zod";
|
|
683
|
+
var INDEX_EVENT_TYPES = DECODED_EVENT_TYPES;
|
|
684
|
+
var rangeFilters = {
|
|
685
|
+
contractId: z6.string().optional().describe("Filter by contract id"),
|
|
686
|
+
fromHeight: z6.number().optional().describe("Start block height (inclusive)"),
|
|
687
|
+
toHeight: z6.number().optional().describe("End block height (inclusive)"),
|
|
688
|
+
cursor: z6.string().optional().describe("Opaque cursor from a prior response's next_cursor"),
|
|
689
|
+
limit: z6.number().optional().describe("Max rows for this page")
|
|
690
|
+
};
|
|
691
|
+
var heightFilters = {
|
|
692
|
+
fromHeight: rangeFilters.fromHeight,
|
|
693
|
+
toHeight: rangeFilters.toHeight,
|
|
694
|
+
cursor: rangeFilters.cursor,
|
|
695
|
+
limit: rangeFilters.limit
|
|
696
|
+
};
|
|
697
|
+
function registerIndexTools(server, clientProvider = getClient) {
|
|
698
|
+
defineTool(server, "index_ft_transfers", "List decoded SIP-010 fungible-token transfers from Index. Reads are keyless.", {
|
|
699
|
+
...rangeFilters,
|
|
700
|
+
sender: z6.string().optional().describe("Filter by sender principal"),
|
|
701
|
+
recipient: z6.string().optional().describe("Filter by recipient principal"),
|
|
702
|
+
assetIdentifier: z6.string().optional().describe("Filter by asset identifier (contract::asset), e.g. SP…sbtc-token::sbtc-token")
|
|
703
|
+
}, async (params) => jsonResponse(await clientProvider().index.ftTransfers.list(params)));
|
|
704
|
+
defineTool(server, "index_nft_transfers", "List decoded SIP-009 non-fungible-token transfers from Index. Reads are keyless.", {
|
|
705
|
+
...rangeFilters,
|
|
706
|
+
sender: z6.string().optional().describe("Filter by sender principal"),
|
|
707
|
+
recipient: z6.string().optional().describe("Filter by recipient principal"),
|
|
708
|
+
assetIdentifier: z6.string().optional().describe("Filter by asset identifier (contract::asset)")
|
|
709
|
+
}, async (params) => jsonResponse(await clientProvider().index.nftTransfers.list(params)));
|
|
710
|
+
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.", {
|
|
711
|
+
eventType: z6.enum(INDEX_EVENT_TYPES).describe("Required. Decoded event type to list."),
|
|
712
|
+
...rangeFilters,
|
|
713
|
+
sender: z6.string().optional().describe("Filter by sender principal"),
|
|
714
|
+
recipient: z6.string().optional().describe("Filter by recipient principal"),
|
|
715
|
+
assetIdentifier: z6.string().optional().describe("Filter by asset identifier where applicable"),
|
|
716
|
+
trait: z6.string().optional().describe("Match contracts conforming to a trait/standard (e.g. sip-010). Mutually exclusive with contractId; contract-keyed event types only."),
|
|
717
|
+
txContext: z6.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.")
|
|
718
|
+
}, async (params) => jsonResponse(await clientProvider().index.events.list(params)));
|
|
719
|
+
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.", {
|
|
720
|
+
...rangeFilters,
|
|
721
|
+
functionName: z6.string().optional().describe("Filter by called function name"),
|
|
722
|
+
sender: z6.string().optional().describe("Filter by caller principal"),
|
|
723
|
+
trait: z6.string().optional().describe("Match contracts conforming to a trait/standard (e.g. sip-010). Mutually exclusive with contractId.")
|
|
724
|
+
}, async (params) => jsonResponse(await clientProvider().index.contractCalls.list(params)));
|
|
725
|
+
defineTool(server, "index_blocks", "List decoded blocks from Index. Reads are keyless.", { ...heightFilters }, async (params) => jsonResponse(await clientProvider().index.blocks.list(params)));
|
|
726
|
+
defineTool(server, "index_transactions", "List decoded transactions from Index. Filter by type, sender, or contract. Reads are keyless.", {
|
|
727
|
+
...rangeFilters,
|
|
728
|
+
type: z6.string().optional().describe("Filter by transaction type"),
|
|
729
|
+
sender: z6.string().optional().describe("Filter by sender principal")
|
|
730
|
+
}, async (params) => jsonResponse(await clientProvider().index.transactions.list(params)));
|
|
731
|
+
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.", {
|
|
732
|
+
contractId: z6.string().describe("Contract id (SP….name) whose print events to profile")
|
|
733
|
+
}, async (params) => jsonResponse(await clientProvider().index.printSchema(params.contractId)));
|
|
734
|
+
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()));
|
|
735
|
+
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.", {
|
|
736
|
+
requests: z6.array(z6.object({
|
|
737
|
+
path: z6.string().describe("Public /v1 read path"),
|
|
738
|
+
params: z6.record(z6.string(), z6.string()).optional()
|
|
739
|
+
})).min(1).max(10).describe("Read descriptors, executed concurrently")
|
|
740
|
+
}, async (params) => jsonResponse(await clientProvider().batch(params.requests)));
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
// src/tools/instance.ts
|
|
744
|
+
function registerInstanceTools(server, clientProvider = getClient) {
|
|
745
|
+
defineTool(server, "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.", {}, async () => {
|
|
746
|
+
const client = clientProvider();
|
|
747
|
+
const status = await client.instance.status();
|
|
748
|
+
const diagnosis = await client.instance.diagnose();
|
|
749
|
+
return jsonResponse({ status, diagnosis });
|
|
750
|
+
});
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
// src/tools/scaffold.ts
|
|
754
|
+
import {
|
|
755
|
+
generatePrintSchemaSubgraph,
|
|
756
|
+
generateSubgraphCode,
|
|
757
|
+
generateTokenSubgraphFromAbi
|
|
758
|
+
} from "@secondlayer/scaffold";
|
|
759
|
+
import { z as z7 } from "zod";
|
|
760
|
+
async function fetchAbi(clientProvider, contractId) {
|
|
761
|
+
const contract = await clientProvider().contracts.get(contractId, {
|
|
762
|
+
includeAbi: true
|
|
763
|
+
});
|
|
764
|
+
if (!contract)
|
|
765
|
+
throw new Error(`Contract not found: ${contractId}`);
|
|
766
|
+
const abi = contract.abi;
|
|
767
|
+
if (!abi) {
|
|
768
|
+
throw new Error(`No ABI available for ${contractId} (abi_status: ${contract.abi_status})`);
|
|
769
|
+
}
|
|
770
|
+
return { functions: abi.functions ?? [], abi };
|
|
771
|
+
}
|
|
772
|
+
function registerScaffoldTools(server, clientProvider = getClient) {
|
|
773
|
+
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.", {
|
|
774
|
+
contractId: z7.string().describe("Fully qualified contract ID (e.g. SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-pool-v2-01)"),
|
|
775
|
+
subgraphName: z7.string().optional().describe("Override the subgraph name (defaults to contract name)")
|
|
776
|
+
}, async ({ contractId, subgraphName }) => {
|
|
777
|
+
const printSchema = await clientProvider().index.printSchema(contractId);
|
|
778
|
+
if (printSchema && printSchema.topics.length > 0) {
|
|
779
|
+
const code = generatePrintSchemaSubgraph({
|
|
780
|
+
contractId,
|
|
781
|
+
name: subgraphName,
|
|
782
|
+
topics: printSchema.topics,
|
|
783
|
+
sample: printSchema.sample
|
|
784
|
+
});
|
|
785
|
+
return { content: [{ type: "text", text: code }] };
|
|
786
|
+
}
|
|
787
|
+
const { functions, abi } = await fetchAbi(clientProvider, contractId);
|
|
788
|
+
const token = generateTokenSubgraphFromAbi({
|
|
789
|
+
contractId,
|
|
790
|
+
abi,
|
|
791
|
+
name: subgraphName
|
|
792
|
+
});
|
|
793
|
+
if (token) {
|
|
794
|
+
return { content: [{ type: "text", text: token }] };
|
|
795
|
+
}
|
|
796
|
+
const code = generateSubgraphCode(contractId, functions, subgraphName);
|
|
797
|
+
return { content: [{ type: "text", text: code }] };
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
|
|
839
801
|
// src/tools/streams.ts
|
|
840
802
|
function registerStreamsTools(server, clientProvider = getClient) {
|
|
841
803
|
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()));
|
|
@@ -893,7 +855,7 @@ function registerSubgraphTools(server, clientProvider = getClient) {
|
|
|
893
855
|
return textResponse(await client.subgraphs.markdown(name));
|
|
894
856
|
return jsonResponse(await client.subgraphs.schema(name));
|
|
895
857
|
});
|
|
896
|
-
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.
|
|
858
|
+
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.', {
|
|
897
859
|
name: z8.string().describe("Subgraph name"),
|
|
898
860
|
table: z8.string().describe("Table name"),
|
|
899
861
|
filters: z8.record(z8.string(), z8.string()).optional().describe('Column filters — plain values or with operators (e.g. {"amount.gte": "1000", "sender": "SP..."})'),
|
|
@@ -1184,7 +1146,7 @@ var TOOL_GROUPS = [
|
|
|
1184
1146
|
{ group: "codegen", register: registerCodegenTools },
|
|
1185
1147
|
{ group: "instance", register: registerInstanceTools },
|
|
1186
1148
|
{ group: "archive", register: registerArchiveTools },
|
|
1187
|
-
{ group: "
|
|
1149
|
+
{ group: "archive", register: registerArchiveCliTools },
|
|
1188
1150
|
{ group: "account", register: registerAccountTools, hostedOnly: true }
|
|
1189
1151
|
];
|
|
1190
1152
|
|
|
@@ -1209,5 +1171,5 @@ export {
|
|
|
1209
1171
|
createServer
|
|
1210
1172
|
};
|
|
1211
1173
|
|
|
1212
|
-
//# debugId=
|
|
1174
|
+
//# debugId=1618B517EA415EF064756E2164756E21
|
|
1213
1175
|
//# sourceMappingURL=index.js.map
|