@secondlayer/mcp 4.2.4 → 4.3.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.js CHANGED
@@ -12,6 +12,7 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
12
12
  // src/resources.ts
13
13
  import { CHAIN_TRIGGER_FIELDS } from "@secondlayer/shared";
14
14
  import { TRAIT_STANDARDS } from "@secondlayer/stacks/clarity";
15
+ import { filterFieldsByType } from "@secondlayer/subgraphs";
15
16
  import { TYPE_MAP } from "@secondlayer/subgraphs/schema";
16
17
 
17
18
  // src/lib/client.ts
@@ -121,7 +122,7 @@ var registeredToolNames = new Set;
121
122
  function getRegisteredToolNames() {
122
123
  return [...registeredToolNames];
123
124
  }
124
- function defineTool(server, name, description, schema, handler) {
125
+ function defineTool(server, name, description, schema, handler, options = {}) {
125
126
  const wrappedHandler = async (args) => {
126
127
  try {
127
128
  return await handler(args);
@@ -142,6 +143,9 @@ function defineTool(server, name, description, schema, handler) {
142
143
  };
143
144
  registeredToolNames.add(name);
144
145
  server.tool(name, description, schema, wrappedHandler);
146
+ for (const alias of options.aliases ?? []) {
147
+ server.tool(alias, `Deprecated alias for \`${name}\`. ${description}`, schema, wrappedHandler);
148
+ }
145
149
  }
146
150
 
147
151
  // src/resources.ts
@@ -150,39 +154,7 @@ var TRAIT_BLURBS = {
150
154
  "sip-010": "Fungible token standard",
151
155
  "sip-013": "Semi-fungible token standard"
152
156
  };
153
- var FILTERS_REFERENCE = [
154
- {
155
- type: "stx_transfer",
156
- fields: ["sender", "recipient", "minAmount", "maxAmount"]
157
- },
158
- { type: "stx_mint", fields: ["recipient", "minAmount"] },
159
- { type: "stx_burn", fields: ["sender", "minAmount"] },
160
- { type: "stx_lock", fields: ["lockedAddress", "minAmount"] },
161
- {
162
- type: "ft_transfer",
163
- fields: ["sender", "recipient", "assetIdentifier", "minAmount", "trait"]
164
- },
165
- {
166
- type: "ft_mint",
167
- fields: ["recipient", "assetIdentifier", "minAmount", "trait"]
168
- },
169
- {
170
- type: "ft_burn",
171
- fields: ["sender", "assetIdentifier", "minAmount", "trait"]
172
- },
173
- {
174
- type: "nft_transfer",
175
- fields: ["sender", "recipient", "assetIdentifier", "trait"]
176
- },
177
- { type: "nft_mint", fields: ["recipient", "assetIdentifier", "trait"] },
178
- { type: "nft_burn", fields: ["sender", "assetIdentifier", "trait"] },
179
- {
180
- type: "contract_call",
181
- fields: ["contractId", "functionName", "caller", "trait", "abi"]
182
- },
183
- { type: "contract_deploy", fields: ["deployer", "contractName"] },
184
- { type: "print_event", fields: ["contractId", "topic", "trait"] }
185
- ];
157
+ var FILTERS_REFERENCE = filterFieldsByType();
186
158
  var COLUMN_TYPE_DESCRIPTIONS = {
187
159
  text: "UTF-8 string",
188
160
  uint: "Unsigned integer (Clarity uint) — NUMERIC for lossless 128-bit range",
@@ -210,7 +182,8 @@ var PRODUCT_BLURBS = {
210
182
  subgraphs: "author/deploy/query custom indexes",
211
183
  subscriptions: "webhook delivery on subgraph rows or raw chain events",
212
184
  account: "identity and self-provisioned API keys",
213
- scaffold: "generate deploy-ready subgraph code from a deployed contract"
185
+ scaffold: "generate deploy-ready subgraph code from a deployed contract",
186
+ codegen: "ORM schemas for the tables you read"
214
187
  };
215
188
  var PRODUCT_ORDER = [
216
189
  "index",
@@ -219,7 +192,8 @@ var PRODUCT_ORDER = [
219
192
  "subgraphs",
220
193
  "subscriptions",
221
194
  "account",
222
- "scaffold"
195
+ "scaffold",
196
+ "codegen"
223
197
  ];
224
198
  function buildCapabilities() {
225
199
  const byPrefix = new Map;
@@ -351,18 +325,37 @@ function registerAccountTools(server) {
351
325
  }, async ({ product, name }) => jsonResponse(await getClient().apiKeys.create({ product, name })));
352
326
  }
353
327
 
354
- // src/tools/contracts.ts
328
+ // src/tools/codegen.ts
329
+ import {
330
+ generateIndexSchema
331
+ } from "@secondlayer/subgraphs";
355
332
  import { z as z2 } from "zod";
333
+ var TARGETS = ["prisma", "kysely", "drizzle", "json-schema"];
334
+ function registerCodegenTools(server) {
335
+ 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.", {
336
+ target: z2.enum(TARGETS).optional().describe("Output flavor (default kysely)"),
337
+ tables: z2.array(z2.string()).optional().describe("Restrict to these Index tables (default: all)"),
338
+ schemaName: z2.string().optional().describe("Postgres schema to qualify table names with"),
339
+ datasourceEnv: z2.string().optional().describe("Prisma only: datasource url env var (default DATABASE_URL)")
340
+ }, ({ target, tables, schemaName, datasourceEnv }) => textResponse(generateIndexSchema(target ?? "kysely", {
341
+ tables,
342
+ schemaName,
343
+ datasourceEnv
344
+ })));
345
+ }
346
+
347
+ // src/tools/contracts.ts
348
+ import { z as z3 } from "zod";
356
349
  function registerContractTools(server, clientProvider = getClient) {
357
350
  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.', {
358
- trait: z2.string().describe('Required. Trait to match (e.g. "sip-010").'),
359
- conformance: z2.enum(["declared", "inferred", "any"]).optional().describe("declared = parsed from source, inferred = ABI shape-match, any = either (default)"),
360
- include: z2.literal("abi").optional().describe(`Set to "abi" to include each contract's full ABI`),
361
- limit: z2.number().optional().describe("Page size, 1–500 (default 100)"),
362
- cursor: z2.string().optional().describe("Opaque cursor from a prior response's next_cursor")
351
+ trait: z3.string().describe('Required. Trait to match (e.g. "sip-010").'),
352
+ conformance: z3.enum(["declared", "inferred", "any"]).optional().describe("declared = parsed from source, inferred = ABI shape-match, any = either (default)"),
353
+ include: z3.literal("abi").optional().describe(`Set to "abi" to include each contract's full ABI`),
354
+ limit: z3.number().optional().describe("Page size, 1–500 (default 100)"),
355
+ cursor: z3.string().optional().describe("Opaque cursor from a prior response's next_cursor")
363
356
  }, async (params) => jsonResponse(await clientProvider().contracts.list(params)));
364
- defineTool(server, "get_contract_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 scaffold_from_contract.", {
365
- contractId: z2.string().describe("Fully qualified contract id (e.g. SP….amm-pool-v2-01)")
357
+ 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 scaffold_from_contract.", {
358
+ contractId: z3.string().describe("Fully qualified contract id (e.g. SP….amm-pool-v2-01)")
366
359
  }, async ({ contractId }) => {
367
360
  const contract = await clientProvider().contracts.get(contractId, {
368
361
  includeAbi: true
@@ -374,19 +367,19 @@ function registerContractTools(server, clientProvider = getClient) {
374
367
  message: `Contract not in registry: ${contractId}`
375
368
  }
376
369
  }, true);
377
- });
370
+ }, { aliases: ["get_contract_abi"] });
378
371
  }
379
372
 
380
373
  // src/tools/index.ts
381
374
  import { DECODED_EVENT_TYPES } from "@secondlayer/shared";
382
- import { z as z3 } from "zod";
375
+ import { z as z4 } from "zod";
383
376
  var INDEX_EVENT_TYPES = DECODED_EVENT_TYPES;
384
377
  var rangeFilters = {
385
- contractId: z3.string().optional().describe("Filter by contract id"),
386
- fromHeight: z3.number().optional().describe("Start block height (inclusive)"),
387
- toHeight: z3.number().optional().describe("End block height (inclusive)"),
388
- cursor: z3.string().optional().describe("Opaque cursor from a prior response's next_cursor"),
389
- limit: z3.number().optional().describe("Max rows for this page")
378
+ contractId: z4.string().optional().describe("Filter by contract id"),
379
+ fromHeight: z4.number().optional().describe("Start block height (inclusive)"),
380
+ toHeight: z4.number().optional().describe("End block height (inclusive)"),
381
+ cursor: z4.string().optional().describe("Opaque cursor from a prior response's next_cursor"),
382
+ limit: z4.number().optional().describe("Max rows for this page")
390
383
  };
391
384
  var heightFilters = {
392
385
  fromHeight: rangeFilters.fromHeight,
@@ -397,51 +390,51 @@ var heightFilters = {
397
390
  function registerIndexTools(server, clientProvider = getClient) {
398
391
  defineTool(server, "index_ft_transfers", "List decoded SIP-010 fungible-token transfers from the Index (decoded layer). Anonymous reads allowed (free-tier API keys are rejected — Build+ required).", {
399
392
  ...rangeFilters,
400
- sender: z3.string().optional().describe("Filter by sender principal"),
401
- recipient: z3.string().optional().describe("Filter by recipient principal")
393
+ sender: z4.string().optional().describe("Filter by sender principal"),
394
+ recipient: z4.string().optional().describe("Filter by recipient principal")
402
395
  }, async (params) => jsonResponse(await clientProvider().index.ftTransfers.list(params)));
403
396
  defineTool(server, "index_nft_transfers", "List decoded SIP-009 non-fungible-token transfers from the Index. Anonymous reads allowed (free-tier keys rejected).", {
404
397
  ...rangeFilters,
405
- sender: z3.string().optional().describe("Filter by sender principal"),
406
- recipient: z3.string().optional().describe("Filter by recipient principal"),
407
- assetIdentifier: z3.string().optional().describe("Filter by asset identifier (contract::asset)")
398
+ sender: z4.string().optional().describe("Filter by sender principal"),
399
+ recipient: z4.string().optional().describe("Filter by recipient principal"),
400
+ assetIdentifier: z4.string().optional().describe("Filter by asset identifier (contract::asset)")
408
401
  }, async (params) => jsonResponse(await clientProvider().index.nftTransfers.list(params)));
409
402
  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.", {
410
- eventType: z3.enum(INDEX_EVENT_TYPES).describe("Required. Decoded event type to list."),
403
+ eventType: z4.enum(INDEX_EVENT_TYPES).describe("Required. Decoded event type to list."),
411
404
  ...rangeFilters,
412
- sender: z3.string().optional().describe("Filter by sender principal"),
413
- recipient: z3.string().optional().describe("Filter by recipient principal"),
414
- assetIdentifier: z3.string().optional().describe("Filter by asset identifier where applicable"),
415
- trait: z3.string().optional().describe("Match contracts conforming to a trait/standard (e.g. sip-010). Mutually exclusive with contractId; contract-keyed event types only."),
416
- txContext: z3.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.")
405
+ sender: z4.string().optional().describe("Filter by sender principal"),
406
+ recipient: z4.string().optional().describe("Filter by recipient principal"),
407
+ assetIdentifier: z4.string().optional().describe("Filter by asset identifier where applicable"),
408
+ trait: z4.string().optional().describe("Match contracts conforming to a trait/standard (e.g. sip-010). Mutually exclusive with contractId; contract-keyed event types only."),
409
+ txContext: z4.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.")
417
410
  }, async (params) => jsonResponse(await clientProvider().index.events.list(params)));
418
411
  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.", {
419
412
  ...rangeFilters,
420
- functionName: z3.string().optional().describe("Filter by called function name"),
421
- sender: z3.string().optional().describe("Filter by caller principal"),
422
- trait: z3.string().optional().describe("Match contracts conforming to a trait/standard (e.g. sip-010). Mutually exclusive with contractId.")
413
+ functionName: z4.string().optional().describe("Filter by called function name"),
414
+ sender: z4.string().optional().describe("Filter by caller principal"),
415
+ trait: z4.string().optional().describe("Match contracts conforming to a trait/standard (e.g. sip-010). Mutually exclusive with contractId.")
423
416
  }, async (params) => jsonResponse(await clientProvider().index.contractCalls.list(params)));
424
417
  defineTool(server, "index_blocks", "List decoded blocks from the Index. Anonymous reads allowed (free-tier keys rejected).", { ...heightFilters }, async (params) => jsonResponse(await clientProvider().index.blocks.list(params)));
425
418
  defineTool(server, "index_transactions", "List decoded transactions from the Index. Filter by type, sender, or contract. Anonymous reads allowed (free-tier keys rejected).", {
426
419
  ...rangeFilters,
427
- type: z3.string().optional().describe("Filter by transaction type"),
428
- sender: z3.string().optional().describe("Filter by sender principal")
420
+ type: z4.string().optional().describe("Filter by transaction type"),
421
+ sender: z4.string().optional().describe("Filter by sender principal")
429
422
  }, async (params) => jsonResponse(await clientProvider().index.transactions.list(params)));
430
423
  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.", {
431
- contractId: z3.string().describe("Contract id (SP….name) whose print events to profile")
424
+ contractId: z4.string().describe("Contract id (SP….name) whose print events to profile")
432
425
  }, async (params) => jsonResponse(await clientProvider().index.printSchema(params.contractId)));
433
426
  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()));
434
427
  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.", {
435
- requests: z3.array(z3.object({
436
- path: z3.string().describe("Public /v1 read path"),
437
- params: z3.record(z3.string(), z3.string()).optional()
428
+ requests: z4.array(z4.object({
429
+ path: z4.string().describe("Public /v1 read path"),
430
+ params: z4.record(z4.string(), z4.string()).optional()
438
431
  })).min(1).max(10).describe("Read descriptors, executed concurrently")
439
432
  }, async (params) => jsonResponse(await clientProvider().batch(params.requests)));
440
433
  }
441
434
 
442
435
  // src/tools/scaffold.ts
443
436
  import { generateSubgraphCode } from "@secondlayer/scaffold";
444
- import { z as z4 } from "zod";
437
+ import { z as z5 } from "zod";
445
438
  async function fetchAbi(clientProvider, contractId) {
446
439
  const contract = await clientProvider().contracts.get(contractId, {
447
440
  includeAbi: true
@@ -452,15 +445,15 @@ async function fetchAbi(clientProvider, contractId) {
452
445
  if (!abi) {
453
446
  throw new Error(`No ABI available for ${contractId} (abi_status: ${contract.abi_status})`);
454
447
  }
455
- return { functions: abi.functions ?? [], maps: abi.maps ?? [] };
448
+ return { functions: abi.functions ?? [] };
456
449
  }
457
450
  function registerScaffoldTools(server, clientProvider = getClient) {
458
451
  defineTool(server, "scaffold_from_contract", "Generate a subgraph scaffold from a deployed Stacks contract. Fetches the ABI automatically.", {
459
- contractId: z4.string().describe("Fully qualified contract ID (e.g. SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-pool-v2-01)"),
460
- subgraphName: z4.string().optional().describe("Override the subgraph name (defaults to contract name)")
452
+ contractId: z5.string().describe("Fully qualified contract ID (e.g. SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-pool-v2-01)"),
453
+ subgraphName: z5.string().optional().describe("Override the subgraph name (defaults to contract name)")
461
454
  }, async ({ contractId, subgraphName }) => {
462
- const { functions, maps } = await fetchAbi(clientProvider, contractId);
463
- const code = generateSubgraphCode(contractId, functions, subgraphName, maps);
455
+ const { functions } = await fetchAbi(clientProvider, contractId);
456
+ const code = generateSubgraphCode(contractId, functions, subgraphName);
464
457
  return { content: [{ type: "text", text: code }] };
465
458
  });
466
459
  }
@@ -473,26 +466,26 @@ function registerStreamsTools(server, clientProvider = getClient) {
473
466
  // src/tools/subgraphs.ts
474
467
  import { bundleSubgraphCode } from "@secondlayer/bundler";
475
468
  import { ByoBreakingChangeError } from "@secondlayer/sdk";
476
- import { z as z5 } from "zod";
469
+ import { z as z6 } from "zod";
477
470
  function registerSubgraphTools(server, clientProvider = getClient) {
478
471
  defineTool(server, "subgraphs_list", "List all deployed subgraphs. Returns summary fields only, including visibility — public subgraphs are anon-readable at /v1/subgraphs/<name>.", {}, async () => {
479
472
  const { data } = await clientProvider().subgraphs.list();
480
473
  return jsonResponse(data.map(formatSubgraphSummary));
481
474
  });
482
- defineTool(server, "subgraphs_get", "Get full details of a subgraph including schema, health, and table columns.", { name: z5.string().describe("Subgraph name") }, async ({ name }) => {
475
+ defineTool(server, "subgraphs_get", "Get full details of a subgraph including schema, health, and table columns.", { name: z6.string().describe("Subgraph name") }, async ({ name }) => {
483
476
  const detail = await clientProvider().subgraphs.get(name);
484
477
  return jsonResponse(detail);
485
478
  });
486
479
  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. Fetch one row by id with {"_id": "<id>"}. Public subgraphs are also keyless 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.', {
487
- name: z5.string().describe("Subgraph name"),
488
- table: z5.string().describe("Table name"),
489
- filters: z5.record(z5.string(), z5.string()).optional().describe('Column filters — plain values or with operators (e.g. {"amount.gte": "1000", "sender": "SP..."})'),
490
- sort: z5.string().optional().describe("Column to sort by"),
491
- order: z5.enum(["asc", "desc"]).optional().describe("Sort order"),
492
- limit: z5.number().max(200).optional().describe("Max rows (default 50, max 200)"),
493
- offset: z5.number().optional().describe("Offset for pagination"),
494
- fields: z5.string().optional().describe('Comma-separated column list to return (e.g. "sender,amount")'),
495
- count: z5.boolean().optional().describe("If true, return row count instead of rows")
480
+ name: z6.string().describe("Subgraph name"),
481
+ table: z6.string().describe("Table name"),
482
+ filters: z6.record(z6.string(), z6.string()).optional().describe('Column filters — plain values or with operators (e.g. {"amount.gte": "1000", "sender": "SP..."})'),
483
+ sort: z6.string().optional().describe("Column to sort by"),
484
+ order: z6.enum(["asc", "desc"]).optional().describe("Sort order"),
485
+ limit: z6.number().max(200).optional().describe("Max rows (default 50, max 200)"),
486
+ offset: z6.number().optional().describe("Offset for pagination"),
487
+ fields: z6.string().optional().describe('Comma-separated column list to return (e.g. "sender,amount")'),
488
+ count: z6.boolean().optional().describe("If true, return row count instead of rows")
496
489
  }, async ({
497
490
  name,
498
491
  table,
@@ -520,9 +513,9 @@ function registerSubgraphTools(server, clientProvider = getClient) {
520
513
  return jsonResponse(result);
521
514
  });
522
515
  defineTool(server, "subgraphs_reindex", "Reindex a subgraph from a specific block range. Returns an operationId — check subgraphs_get (health) or the REST operations endpoint to track progress to completion.", {
523
- name: z5.string().describe("Subgraph name"),
524
- fromBlock: z5.number().optional().describe("Start block (defaults to beginning)"),
525
- toBlock: z5.number().optional().describe("End block (defaults to latest)")
516
+ name: z6.string().describe("Subgraph name"),
517
+ fromBlock: z6.number().optional().describe("Start block (defaults to beginning)"),
518
+ toBlock: z6.number().optional().describe("End block (defaults to latest)")
526
519
  }, async ({ name, fromBlock, toBlock }) => {
527
520
  const result = await clientProvider().subgraphs.reindex(name, {
528
521
  fromBlock,
@@ -531,9 +524,9 @@ function registerSubgraphTools(server, clientProvider = getClient) {
531
524
  return jsonResponse(result);
532
525
  });
533
526
  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_get (health) or the REST operations endpoint to track progress.", {
534
- name: z5.string().describe("Subgraph name"),
535
- fromBlock: z5.number().int().nonnegative().describe("Start block (inclusive)"),
536
- toBlock: z5.number().int().nonnegative().describe("End block (inclusive)")
527
+ name: z6.string().describe("Subgraph name"),
528
+ fromBlock: z6.number().int().nonnegative().describe("Start block (inclusive)"),
529
+ toBlock: z6.number().int().nonnegative().describe("End block (inclusive)")
537
530
  }, async ({ name, fromBlock, toBlock }) => {
538
531
  const result = await clientProvider().subgraphs.backfill(name, {
539
532
  fromBlock,
@@ -541,15 +534,15 @@ function registerSubgraphTools(server, clientProvider = getClient) {
541
534
  });
542
535
  return jsonResponse(result);
543
536
  });
544
- defineTool(server, "subgraphs_stop", "Cancel an in-flight reindex or backfill operation for a subgraph. Returns the stop request status; check subgraphs_get (health) or the REST operations endpoint to confirm it reaches a terminal state.", { name: z5.string().describe("Subgraph name") }, async ({ name }) => {
537
+ defineTool(server, "subgraphs_stop", "Cancel an in-flight reindex or backfill operation for a subgraph. Returns the stop request status; check subgraphs_get (health) or the REST operations endpoint to confirm it reaches a terminal state.", { name: z6.string().describe("Subgraph name") }, async ({ name }) => {
545
538
  const result = await clientProvider().subgraphs.stop(name);
546
539
  return jsonResponse(result);
547
540
  });
548
541
  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.", {
549
- name: z5.string().describe("Subgraph name"),
550
- limit: z5.number().int().positive().optional().describe("Max gaps to return"),
551
- offset: z5.number().int().nonnegative().optional().describe("Pagination offset"),
552
- resolved: z5.boolean().optional().describe("Filter by resolved state (omit for unresolved only)")
542
+ name: z6.string().describe("Subgraph name"),
543
+ limit: z6.number().int().positive().optional().describe("Max gaps to return"),
544
+ offset: z6.number().int().nonnegative().optional().describe("Pagination offset"),
545
+ resolved: z6.boolean().optional().describe("Filter by resolved state (omit for unresolved only)")
553
546
  }, async ({ name, limit, offset, resolved }) => {
554
547
  const result = await clientProvider().subgraphs.gaps(name, {
555
548
  limit,
@@ -558,16 +551,16 @@ function registerSubgraphTools(server, clientProvider = getClient) {
558
551
  });
559
552
  return jsonResponse(result);
560
553
  });
561
- defineTool(server, "subgraphs_delete", "Delete a subgraph permanently.", { name: z5.string().describe("Subgraph name") }, async ({ name }) => {
554
+ defineTool(server, "subgraphs_delete", "Delete a subgraph permanently.", { name: z6.string().describe("Subgraph name") }, async ({ name }) => {
562
555
  const result = await clientProvider().subgraphs.delete(name);
563
556
  return textResponse(result.message);
564
557
  });
565
558
  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. Set dryRun to validate and preview the schema/DDL without writing anything. Set databaseUrl to deploy to your own Postgres (BYO data plane) — the server verifies the connection first; with dryRun it returns the DDL + grant script. A breaking BYO schema change is refused and returns a migration plan (drop + rebuild DDL) instead of deploying. Visibility defaults: managed deploys are public (anon-readable at /v1/subgraphs/<name>, name claimed in the global public namespace), BYO deploys are private. Call `subgraphs_reindex` separately if you need a forced reindex.", {
566
- code: z5.string().describe("TypeScript source code containing a defineSubgraph() call"),
567
- startBlock: z5.number().int().nonnegative().optional().describe("Override the definition startBlock for this deploy"),
568
- databaseUrl: z5.string().optional().describe("BYO data plane: Postgres connection string to host the subgraph's schema and rows in your own database"),
569
- dryRun: z5.boolean().optional().describe("Validate and preview the deploy (schema/DDL, BYO connection) without writing changes"),
570
- visibility: z5.enum(["public", "private"]).optional().describe("Read visibility: public = anon /v1 reads + global name claim; private = owning account's key only. Defaults: managed → public, BYO → private.")
559
+ code: z6.string().describe("TypeScript source code containing a defineSubgraph() call"),
560
+ startBlock: z6.number().int().nonnegative().optional().describe("Override the definition startBlock for this deploy"),
561
+ databaseUrl: z6.string().optional().describe("BYO data plane: Postgres connection string to host the subgraph's schema and rows in your own database"),
562
+ dryRun: z6.boolean().optional().describe("Validate and preview the deploy (schema/DDL, BYO connection) without writing changes"),
563
+ visibility: z6.enum(["public", "private"]).optional().describe("Read visibility: public = anon /v1 reads + global name claim; private = owning account's key only. Defaults: managed → public, BYO → private.")
571
564
  }, async ({ code, startBlock, databaseUrl, dryRun, visibility }) => {
572
565
  const bundled = await bundleSubgraphCode(code);
573
566
  try {
@@ -592,11 +585,11 @@ function registerSubgraphTools(server, clientProvider = getClient) {
592
585
  throw err;
593
586
  }
594
587
  });
595
- defineTool(server, "subgraphs_publish", "Make a subgraph publicly readable at /v1/subgraphs/<name> — anyone (or any agent) can read it without a key. Claims the name in the global public namespace; fails with PUBLIC_NAME_TAKEN if another account holds it.", { name: z5.string().describe("Subgraph name") }, async ({ name }) => {
588
+ defineTool(server, "subgraphs_publish", "Make a subgraph publicly readable at /v1/subgraphs/<name> — anyone (or any agent) can read it without a key. Claims the name in the global public namespace; fails with PUBLIC_NAME_TAKEN if another account holds it.", { name: z6.string().describe("Subgraph name") }, async ({ name }) => {
596
589
  const result = await clientProvider().subgraphs.publish(name);
597
590
  return jsonResponse(result);
598
591
  });
599
- defineTool(server, "subgraphs_unpublish", "Make a subgraph private again — /v1 reads then require the owning account's bearer key, and the global public name claim is released.", { name: z5.string().describe("Subgraph name") }, async ({ name }) => {
592
+ defineTool(server, "subgraphs_unpublish", "Make a subgraph private again — /v1 reads then require the owning account's bearer key, and the global public name claim is released.", { name: z6.string().describe("Subgraph name") }, async ({ name }) => {
600
593
  const result = await clientProvider().subgraphs.unpublish(name);
601
594
  return jsonResponse(result);
602
595
  });
@@ -604,38 +597,38 @@ function registerSubgraphTools(server, clientProvider = getClient) {
604
597
 
605
598
  // src/tools/subscriptions.ts
606
599
  import { CHAIN_TRIGGER_TYPES } from "@secondlayer/shared";
607
- import { z as z6 } from "zod";
600
+ import { z as z7 } from "zod";
608
601
  function registerSubscriptionTools(server, clientProvider = getClient) {
609
602
  defineTool(server, "subscriptions_list", "List all subscriptions for the current account. Returns summary fields (no secrets).", {}, async () => {
610
603
  const { data } = await clientProvider().subscriptions.list();
611
604
  return jsonResponse(data);
612
605
  });
613
- defineTool(server, "subscriptions_get", "Get full detail for a subscription (filter, auth, retry config, circuit state).", { id: z6.string().describe("Subscription id") }, async ({ id }) => {
606
+ defineTool(server, "subscriptions_get", "Get full detail for a subscription (filter, auth, retry config, circuit state).", { id: z7.string().describe("Subscription id") }, async ({ id }) => {
614
607
  const detail = await clientProvider().subscriptions.get(id);
615
608
  return jsonResponse(detail);
616
609
  });
617
610
  defineTool(server, "subscriptions_create", "Create a subscription. Two kinds (mutually exclusive): a SUBGRAPH subscription fires on a subgraph table's rows (set subgraphName + tableName + optional filter); a CHAIN subscription 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.", {
618
- name: z6.string().describe("Human-readable name, unique per account"),
619
- subgraphName: z6.string().optional().describe("Subgraph to subscribe to (subgraph subscription)"),
620
- tableName: z6.string().optional().describe("Table within the subgraph (subgraph subscription)"),
621
- triggers: z6.array(z6.object({
622
- type: z6.enum(CHAIN_TRIGGER_TYPES),
623
- contractId: z6.string().optional(),
624
- functionName: z6.string().optional(),
625
- caller: z6.string().optional(),
626
- sender: z6.string().optional(),
627
- recipient: z6.string().optional(),
628
- assetIdentifier: z6.string().optional(),
629
- deployer: z6.string().optional(),
630
- contractName: z6.string().optional(),
631
- topic: z6.string().optional(),
632
- lockedAddress: z6.string().optional(),
633
- trait: z6.string().optional(),
634
- minAmount: z6.union([z6.string(), z6.number()]).optional(),
635
- maxAmount: z6.union([z6.string(), z6.number()]).optional()
611
+ name: z7.string().describe("Human-readable name, unique per account"),
612
+ subgraphName: z7.string().optional().describe("Subgraph to subscribe to (subgraph subscription)"),
613
+ tableName: z7.string().optional().describe("Table within the subgraph (subgraph subscription)"),
614
+ triggers: z7.array(z7.object({
615
+ type: z7.enum(CHAIN_TRIGGER_TYPES),
616
+ contractId: z7.string().optional(),
617
+ functionName: z7.string().optional(),
618
+ caller: z7.string().optional(),
619
+ sender: z7.string().optional(),
620
+ recipient: z7.string().optional(),
621
+ assetIdentifier: z7.string().optional(),
622
+ deployer: z7.string().optional(),
623
+ contractName: z7.string().optional(),
624
+ topic: z7.string().optional(),
625
+ lockedAddress: z7.string().optional(),
626
+ trait: z7.string().optional(),
627
+ minAmount: z7.union([z7.string(), z7.number()]).optional(),
628
+ maxAmount: z7.union([z7.string(), z7.number()]).optional()
636
629
  })).optional().describe("Chain triggers (chain subscription) — 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."),
637
- url: z6.string().describe("Webhook URL"),
638
- format: z6.enum([
630
+ url: z7.string().describe("Webhook URL"),
631
+ format: z7.enum([
639
632
  "standard-webhooks",
640
633
  "inngest",
641
634
  "trigger",
@@ -643,20 +636,20 @@ function registerSubscriptionTools(server, clientProvider = getClient) {
643
636
  "cloudevents",
644
637
  "raw"
645
638
  ]).optional().describe("Wire format (default standard-webhooks)"),
646
- runtime: z6.enum(["inngest", "trigger", "cloudflare", "node"]).optional().describe("Receiver runtime label (display only)"),
647
- filter: z6.record(z6.string(), z6.unknown()).optional().describe('Scalar filter DSL, e.g. {"amount": {"gte": 100}, "sender": "SP..."}'),
648
- authConfig: z6.record(z6.string(), z6.unknown()).optional().describe('Receiver auth sent with each delivery, e.g. {"type": "bearer", "token": "..."}')
639
+ runtime: z7.enum(["inngest", "trigger", "cloudflare", "node"]).optional().describe("Receiver runtime label (display only)"),
640
+ filter: z7.record(z7.string(), z7.unknown()).optional().describe('Scalar filter DSL, e.g. {"amount": {"gte": 100}, "sender": "SP..."}'),
641
+ authConfig: z7.record(z7.string(), z7.unknown()).optional().describe('Receiver auth sent with each delivery, e.g. {"type": "bearer", "token": "..."}')
649
642
  }, async (input) => {
650
643
  const res = await clientProvider().subscriptions.create(input);
651
644
  return jsonResponse(res);
652
645
  });
653
646
  defineTool(server, "subscriptions_update", "Patch a subscription (name, url, filter, authConfig, format, runtime, retry, timeout, concurrency).", {
654
- id: z6.string(),
655
- name: z6.string().optional().describe("Rename the subscription"),
656
- url: z6.string().optional(),
657
- filter: z6.record(z6.string(), z6.unknown()).optional(),
658
- authConfig: z6.record(z6.string(), z6.unknown()).optional().describe("Receiver auth sent with each delivery (bearer/etc.)"),
659
- format: z6.enum([
647
+ id: z7.string(),
648
+ name: z7.string().optional().describe("Rename the subscription"),
649
+ url: z7.string().optional(),
650
+ filter: z7.record(z7.string(), z7.unknown()).optional(),
651
+ authConfig: z7.record(z7.string(), z7.unknown()).optional().describe("Receiver auth sent with each delivery (bearer/etc.)"),
652
+ format: z7.enum([
660
653
  "standard-webhooks",
661
654
  "inngest",
662
655
  "trigger",
@@ -664,27 +657,27 @@ function registerSubscriptionTools(server, clientProvider = getClient) {
664
657
  "cloudevents",
665
658
  "raw"
666
659
  ]).optional(),
667
- runtime: z6.enum(["inngest", "trigger", "cloudflare", "node"]).nullable().optional(),
668
- maxRetries: z6.number().int().min(0).optional(),
669
- timeoutMs: z6.number().int().min(100).optional(),
670
- concurrency: z6.number().int().min(1).optional()
660
+ runtime: z7.enum(["inngest", "trigger", "cloudflare", "node"]).nullable().optional(),
661
+ maxRetries: z7.number().int().min(0).optional(),
662
+ timeoutMs: z7.number().int().min(100).optional(),
663
+ concurrency: z7.number().int().min(1).optional()
671
664
  }, async ({ id, ...patch }) => {
672
665
  const res = await clientProvider().subscriptions.update(id, patch);
673
666
  return jsonResponse(res);
674
667
  });
675
- defineTool(server, "subscriptions_delete", "Delete a subscription. Pending outbox rows are cascade-deleted.", { id: z6.string() }, async ({ id }) => {
668
+ defineTool(server, "subscriptions_delete", "Delete a subscription. Pending outbox rows are cascade-deleted.", { id: z7.string() }, async ({ id }) => {
676
669
  const res = await clientProvider().subscriptions.delete(id);
677
670
  return jsonResponse(res);
678
671
  });
679
- defineTool(server, "subscriptions_test", "Send a one-off test webhook to a subscription's URL (built for its format, SSRF-guarded). Logged as a delivery row. Returns {ok, statusCode, error, durationMs, deliveryId}.", { id: z6.string().describe("Subscription id") }, async ({ id }) => {
672
+ defineTool(server, "subscriptions_test", "Send a one-off test webhook to a subscription's URL (built for its format, SSRF-guarded). Logged as a delivery row. Returns {ok, statusCode, error, durationMs, deliveryId}.", { id: z7.string().describe("Subscription id") }, async ({ id }) => {
680
673
  const res = await clientProvider().subscriptions.test(id);
681
674
  return jsonResponse(res);
682
675
  });
683
676
  defineTool(server, "subscriptions_replay", "Replay a block range for a subscription. Replays run at 10% of batch capacity — use sparingly. Pass `force` (a short idempotency suffix) to re-run a range that was already replayed.", {
684
- id: z6.string(),
685
- fromBlock: z6.number().int().nonnegative(),
686
- toBlock: z6.number().int().nonnegative(),
687
- force: z6.string().optional().describe("Idempotency suffix to force a duplicate replay of the range")
677
+ id: z7.string(),
678
+ fromBlock: z7.number().int().nonnegative(),
679
+ toBlock: z7.number().int().nonnegative(),
680
+ force: z7.string().optional().describe("Idempotency suffix to force a duplicate replay of the range")
688
681
  }, async ({ id, fromBlock, toBlock, force }) => {
689
682
  const res = await clientProvider().subscriptions.replay(id, {
690
683
  fromBlock,
@@ -710,6 +703,7 @@ function createServer() {
710
703
  registerIndexTools(server);
711
704
  registerStreamsTools(server);
712
705
  registerContractTools(server);
706
+ registerCodegenTools(server);
713
707
  registerResources(server);
714
708
  return server;
715
709
  }
@@ -719,5 +713,5 @@ var server = createServer();
719
713
  var transport = new StdioServerTransport;
720
714
  await server.connect(transport);
721
715
 
722
- //# debugId=A0926ACBEBBC3C5064756E2164756E21
716
+ //# debugId=8D577F42C433C3A164756E2164756E21
723
717
  //# sourceMappingURL=bin.js.map