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