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