@secondlayer/mcp 4.5.2 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -58,27 +58,6 @@ function getClient() {
58
58
  }
59
59
  return instance;
60
60
  }
61
- var keyHint = " — set SL_API_KEY to an sk-sl_ API key from " + "https://secondlayer.tools/platform/api-keys for write and account operations";
62
- async function apiRequest(method, path, body) {
63
- const apiKey = readApiKey();
64
- const baseUrl = process.env.SECONDLAYER_API_URL || process.env.SL_API_URL || "http://127.0.0.1:3800";
65
- const res = await fetch(`${baseUrl}${path}`, {
66
- method,
67
- headers: {
68
- "Content-Type": "application/json",
69
- ...apiKey ? { Authorization: `Bearer ${apiKey}` } : {}
70
- },
71
- body: body ? JSON.stringify(body) : undefined
72
- });
73
- if (!res.ok) {
74
- const text = await res.text().catch(() => "");
75
- const needsKey = !apiKey && (res.status === 401 || res.status === 403);
76
- throw Object.assign(new Error((text || `HTTP ${res.status}`) + (needsKey ? keyHint : "")), { status: res.status });
77
- }
78
- if (res.status === 204)
79
- return;
80
- return res.json();
81
- }
82
61
 
83
62
  // src/lib/format.ts
84
63
  function formatSubgraphSummary(s) {
@@ -239,8 +218,6 @@ async function buildContext(deps = { clientProvider: getClient }) {
239
218
  indexTip: orNull(snap?.indexTip),
240
219
  subgraphs: snap?.subgraphs ? snap.subgraphs.map(formatSubgraphSummary) : unavailable,
241
220
  subscriptions: orNull(snap?.subscriptions),
242
- projects: orNull(snap?.projects),
243
- apiKeys: orNull(snap?.apiKeys),
244
221
  activeOperations: orNull(snap?.activeOperations)
245
222
  },
246
223
  whatYouCanDo: buildCapabilities(),
@@ -307,31 +284,18 @@ function registerResources(server) {
307
284
  }));
308
285
  }
309
286
 
310
- // src/tools/account.ts
311
- import { z } from "zod";
312
- function registerAccountTools(server) {
313
- defineTool(server, "account_whoami", "Show the authenticated account's email and plan.", {}, async () => {
314
- const result = await apiRequest("GET", "/api/accounts/me");
315
- return jsonResponse(result);
316
- });
317
- defineTool(server, "account_create_key", "Mint a scoped streams/index read API key so the agent can self-provision access. Requires an account-level (owner) API key. The returned `key` is shown ONCE — forward it to the user to set as SL_API_KEY.", {
318
- product: z.enum(["streams", "index"]).optional().describe("Key scope (default streams)"),
319
- name: z.string().optional().describe("Optional label for the key")
320
- }, async ({ product, name }) => jsonResponse(await getClient().apiKeys.create({ product, name })));
321
- }
322
-
323
287
  // src/tools/codegen.ts
324
288
  import {
325
289
  generateIndexSchema
326
290
  } from "@secondlayer/subgraphs";
327
- import { z as z2 } from "zod";
291
+ import { z } from "zod";
328
292
  var TARGETS = ["prisma", "kysely", "drizzle", "json-schema"];
329
293
  function registerCodegenTools(server) {
330
294
  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)")
295
+ target: z.enum(TARGETS).optional().describe("Output flavor (default kysely)"),
296
+ tables: z.array(z.string()).optional().describe("Restrict to these Index tables (default: all)"),
297
+ schemaName: z.string().optional().describe("Postgres schema to qualify table names with"),
298
+ datasourceEnv: z.string().optional().describe("Prisma only: datasource url env var (default DATABASE_URL)")
335
299
  }, ({ target, tables, schemaName, datasourceEnv }) => textResponse(generateIndexSchema(target ?? "kysely", {
336
300
  tables,
337
301
  schemaName,
@@ -340,17 +304,17 @@ function registerCodegenTools(server) {
340
304
  }
341
305
 
342
306
  // src/tools/contracts.ts
343
- import { z as z3 } from "zod";
307
+ import { z as z2 } from "zod";
344
308
  function registerContractTools(server, clientProvider = getClient) {
345
309
  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.', {
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")
310
+ trait: z2.string().describe('Required. Trait to match (e.g. "sip-010").'),
311
+ conformance: z2.enum(["declared", "inferred", "any"]).optional().describe("declared = parsed from source, inferred = ABI shape-match, any = either (default)"),
312
+ include: z2.literal("abi").optional().describe(`Set to "abi" to include each contract's full ABI`),
313
+ limit: z2.number().optional().describe("Page size, 1–500 (default 100)"),
314
+ cursor: z2.string().optional().describe("Opaque cursor from a prior response's next_cursor")
351
315
  }, async (params) => jsonResponse(await clientProvider().contracts.list(params)));
352
316
  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)")
317
+ contractId: z2.string().describe("Fully qualified contract id (e.g. SP….amm-pool-v2-01)")
354
318
  }, async ({ contractId }) => {
355
319
  const contract = await clientProvider().contracts.get(contractId, {
356
320
  includeAbi: true
@@ -367,14 +331,14 @@ function registerContractTools(server, clientProvider = getClient) {
367
331
 
368
332
  // src/tools/index.ts
369
333
  import { DECODED_EVENT_TYPES } from "@secondlayer/shared";
370
- import { z as z4 } from "zod";
334
+ import { z as z3 } from "zod";
371
335
  var INDEX_EVENT_TYPES = DECODED_EVENT_TYPES;
372
336
  var rangeFilters = {
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")
337
+ contractId: z3.string().optional().describe("Filter by contract id"),
338
+ fromHeight: z3.number().optional().describe("Start block height (inclusive)"),
339
+ toHeight: z3.number().optional().describe("End block height (inclusive)"),
340
+ cursor: z3.string().optional().describe("Opaque cursor from a prior response's next_cursor"),
341
+ limit: z3.number().optional().describe("Max rows for this page")
378
342
  };
379
343
  var heightFilters = {
380
344
  fromHeight: rangeFilters.fromHeight,
@@ -385,52 +349,52 @@ var heightFilters = {
385
349
  function registerIndexTools(server, clientProvider = getClient) {
386
350
  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).", {
387
351
  ...rangeFilters,
388
- sender: z4.string().optional().describe("Filter by sender principal"),
389
- recipient: z4.string().optional().describe("Filter by recipient principal"),
390
- assetIdentifier: z4.string().optional().describe("Filter by asset identifier (contract::asset), e.g. SP…sbtc-token::sbtc-token")
352
+ sender: z3.string().optional().describe("Filter by sender principal"),
353
+ recipient: z3.string().optional().describe("Filter by recipient principal"),
354
+ assetIdentifier: z3.string().optional().describe("Filter by asset identifier (contract::asset), e.g. SP…sbtc-token::sbtc-token")
391
355
  }, async (params) => jsonResponse(await clientProvider().index.ftTransfers.list(params)));
392
356
  defineTool(server, "index_nft_transfers", "List decoded SIP-009 non-fungible-token transfers from the Index. Anonymous reads allowed (free-tier keys rejected).", {
393
357
  ...rangeFilters,
394
- sender: z4.string().optional().describe("Filter by sender principal"),
395
- recipient: z4.string().optional().describe("Filter by recipient principal"),
396
- assetIdentifier: z4.string().optional().describe("Filter by asset identifier (contract::asset)")
358
+ sender: z3.string().optional().describe("Filter by sender principal"),
359
+ recipient: z3.string().optional().describe("Filter by recipient principal"),
360
+ assetIdentifier: z3.string().optional().describe("Filter by asset identifier (contract::asset)")
397
361
  }, async (params) => jsonResponse(await clientProvider().index.nftTransfers.list(params)));
398
362
  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.", {
399
- eventType: z4.enum(INDEX_EVENT_TYPES).describe("Required. Decoded event type to list."),
363
+ eventType: z3.enum(INDEX_EVENT_TYPES).describe("Required. Decoded event type to list."),
400
364
  ...rangeFilters,
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 where applicable"),
404
- 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."),
405
- 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.")
365
+ sender: z3.string().optional().describe("Filter by sender principal"),
366
+ recipient: z3.string().optional().describe("Filter by recipient principal"),
367
+ assetIdentifier: z3.string().optional().describe("Filter by asset identifier where applicable"),
368
+ 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."),
369
+ 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.")
406
370
  }, async (params) => jsonResponse(await clientProvider().index.events.list(params)));
407
371
  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.", {
408
372
  ...rangeFilters,
409
- functionName: z4.string().optional().describe("Filter by called function name"),
410
- sender: z4.string().optional().describe("Filter by caller principal"),
411
- trait: z4.string().optional().describe("Match contracts conforming to a trait/standard (e.g. sip-010). Mutually exclusive with contractId.")
373
+ functionName: z3.string().optional().describe("Filter by called function name"),
374
+ sender: z3.string().optional().describe("Filter by caller principal"),
375
+ trait: z3.string().optional().describe("Match contracts conforming to a trait/standard (e.g. sip-010). Mutually exclusive with contractId.")
412
376
  }, async (params) => jsonResponse(await clientProvider().index.contractCalls.list(params)));
413
377
  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)));
414
378
  defineTool(server, "index_transactions", "List decoded transactions from the Index. Filter by type, sender, or contract. Anonymous reads allowed (free-tier keys rejected).", {
415
379
  ...rangeFilters,
416
- type: z4.string().optional().describe("Filter by transaction type"),
417
- sender: z4.string().optional().describe("Filter by sender principal")
380
+ type: z3.string().optional().describe("Filter by transaction type"),
381
+ sender: z3.string().optional().describe("Filter by sender principal")
418
382
  }, async (params) => jsonResponse(await clientProvider().index.transactions.list(params)));
419
383
  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.", {
420
- contractId: z4.string().describe("Contract id (SP….name) whose print events to profile")
384
+ contractId: z3.string().describe("Contract id (SP….name) whose print events to profile")
421
385
  }, async (params) => jsonResponse(await clientProvider().index.printSchema(params.contractId)));
422
386
  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()));
423
387
  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.", {
424
- requests: z4.array(z4.object({
425
- path: z4.string().describe("Public /v1 read path"),
426
- params: z4.record(z4.string(), z4.string()).optional()
388
+ requests: z3.array(z3.object({
389
+ path: z3.string().describe("Public /v1 read path"),
390
+ params: z3.record(z3.string(), z3.string()).optional()
427
391
  })).min(1).max(10).describe("Read descriptors, executed concurrently")
428
392
  }, async (params) => jsonResponse(await clientProvider().batch(params.requests)));
429
393
  }
430
394
 
431
395
  // src/tools/scaffold.ts
432
396
  import { generateSubgraphCode } from "@secondlayer/scaffold";
433
- import { z as z5 } from "zod";
397
+ import { z as z4 } from "zod";
434
398
  async function fetchAbi(clientProvider, contractId) {
435
399
  const contract = await clientProvider().contracts.get(contractId, {
436
400
  includeAbi: true
@@ -445,8 +409,8 @@ async function fetchAbi(clientProvider, contractId) {
445
409
  }
446
410
  function registerScaffoldTools(server, clientProvider = getClient) {
447
411
  defineTool(server, "scaffold_from_contract", "Generate a subgraph scaffold from a deployed Stacks contract. Fetches the ABI automatically.", {
448
- contractId: z5.string().describe("Fully qualified contract ID (e.g. SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-pool-v2-01)"),
449
- subgraphName: z5.string().optional().describe("Override the subgraph name (defaults to contract name)")
412
+ contractId: z4.string().describe("Fully qualified contract ID (e.g. SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-pool-v2-01)"),
413
+ subgraphName: z4.string().optional().describe("Override the subgraph name (defaults to contract name)")
450
414
  }, async ({ contractId, subgraphName }) => {
451
415
  const { functions } = await fetchAbi(clientProvider, contractId);
452
416
  const code = generateSubgraphCode(contractId, functions, subgraphName);
@@ -461,27 +425,26 @@ function registerStreamsTools(server, clientProvider = getClient) {
461
425
 
462
426
  // src/tools/subgraphs.ts
463
427
  import { bundleSubgraphCode } from "@secondlayer/bundler";
464
- import { ByoBreakingChangeError } from "@secondlayer/sdk";
465
- import { z as z6 } from "zod";
428
+ import { z as z5 } from "zod";
466
429
  function registerSubgraphTools(server, clientProvider = getClient) {
467
430
  defineTool(server, "subgraphs_list", "List all deployed subgraphs. Returns summary fields only, including visibility — public subgraphs are anon-readable at /v1/subgraphs/<name>.", {}, async () => {
468
431
  const { data } = await clientProvider().subgraphs.list();
469
432
  return jsonResponse(data.map(formatSubgraphSummary));
470
433
  });
471
- defineTool(server, "subgraphs_get", "Get full details of a subgraph including schema, health, and table columns.", { name: z6.string().describe("Subgraph name") }, async ({ name }) => {
434
+ defineTool(server, "subgraphs_get", "Get full details of a subgraph including schema, health, and table columns.", { name: z5.string().describe("Subgraph name") }, async ({ name }) => {
472
435
  const detail = await clientProvider().subgraphs.get(name);
473
436
  return jsonResponse(detail);
474
437
  });
475
438
  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 — when tailing with a `fields` list, include "_id" in it or the next poll filter cannot be formed. 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.', {
476
- name: z6.string().describe("Subgraph name"),
477
- table: z6.string().describe("Table name"),
478
- filters: z6.record(z6.string(), z6.string()).optional().describe('Column filters — plain values or with operators (e.g. {"amount.gte": "1000", "sender": "SP..."})'),
479
- sort: z6.string().optional().describe("Column to sort by"),
480
- order: z6.enum(["asc", "desc"]).optional().describe("Sort order"),
481
- limit: z6.number().max(200).optional().describe("Max rows (default 50, max 200)"),
482
- offset: z6.number().optional().describe("Offset for pagination"),
483
- fields: z6.string().optional().describe('Comma-separated column list to return (e.g. "sender,amount")'),
484
- count: z6.boolean().optional().describe("If true, return row count instead of rows")
439
+ name: z5.string().describe("Subgraph name"),
440
+ table: z5.string().describe("Table name"),
441
+ filters: z5.record(z5.string(), z5.string()).optional().describe('Column filters — plain values or with operators (e.g. {"amount.gte": "1000", "sender": "SP..."})'),
442
+ sort: z5.string().optional().describe("Column to sort by"),
443
+ order: z5.enum(["asc", "desc"]).optional().describe("Sort order"),
444
+ limit: z5.number().max(200).optional().describe("Max rows (default 50, max 200)"),
445
+ offset: z5.number().optional().describe("Offset for pagination"),
446
+ fields: z5.string().optional().describe('Comma-separated column list to return (e.g. "sender,amount")'),
447
+ count: z5.boolean().optional().describe("If true, return row count instead of rows")
485
448
  }, async ({
486
449
  name,
487
450
  table,
@@ -509,15 +472,15 @@ function registerSubgraphTools(server, clientProvider = getClient) {
509
472
  return jsonResponse(result);
510
473
  });
511
474
  defineTool(server, "subgraphs_reindex", "Reindex a subgraph: drops and rebuilds the whole subgraph from its start block to chain tip. Takes no block range — use subgraphs_backfill to process a specific range. Returns an operationId — check subgraphs_get (health) or the REST operations endpoint to track progress to completion.", {
512
- name: z6.string().describe("Subgraph name")
475
+ name: z5.string().describe("Subgraph name")
513
476
  }, async ({ name }) => {
514
477
  const result = await clientProvider().subgraphs.reindex(name);
515
478
  return jsonResponse(result);
516
479
  });
517
480
  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.", {
518
- name: z6.string().describe("Subgraph name"),
519
- fromBlock: z6.number().int().nonnegative().describe("Start block (inclusive)"),
520
- toBlock: z6.number().int().nonnegative().describe("End block (inclusive)")
481
+ name: z5.string().describe("Subgraph name"),
482
+ fromBlock: z5.number().int().nonnegative().describe("Start block (inclusive)"),
483
+ toBlock: z5.number().int().nonnegative().describe("End block (inclusive)")
521
484
  }, async ({ name, fromBlock, toBlock }) => {
522
485
  const result = await clientProvider().subgraphs.backfill(name, {
523
486
  fromBlock,
@@ -525,15 +488,15 @@ function registerSubgraphTools(server, clientProvider = getClient) {
525
488
  });
526
489
  return jsonResponse(result);
527
490
  });
528
- 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 }) => {
491
+ 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 }) => {
529
492
  const result = await clientProvider().subgraphs.stop(name);
530
493
  return jsonResponse(result);
531
494
  });
532
495
  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.", {
533
- name: z6.string().describe("Subgraph name"),
534
- limit: z6.number().int().positive().optional().describe("Max gaps to return"),
535
- offset: z6.number().int().nonnegative().optional().describe("Pagination offset"),
536
- resolved: z6.boolean().optional().describe("Filter by resolved state (omit for unresolved only)")
496
+ name: z5.string().describe("Subgraph name"),
497
+ limit: z5.number().int().positive().optional().describe("Max gaps to return"),
498
+ offset: z5.number().int().nonnegative().optional().describe("Pagination offset"),
499
+ resolved: z5.boolean().optional().describe("Filter by resolved state (omit for unresolved only)")
537
500
  }, async ({ name, limit, offset, resolved }) => {
538
501
  const result = await clientProvider().subgraphs.gaps(name, {
539
502
  limit,
@@ -542,84 +505,65 @@ function registerSubgraphTools(server, clientProvider = getClient) {
542
505
  });
543
506
  return jsonResponse(result);
544
507
  });
545
- defineTool(server, "subgraphs_delete", "Delete a subgraph permanently.", { name: z6.string().describe("Subgraph name") }, async ({ name }) => {
508
+ defineTool(server, "subgraphs_delete", "Delete a subgraph permanently.", { name: z5.string().describe("Subgraph name") }, async ({ name }) => {
546
509
  const result = await clientProvider().subgraphs.delete(name);
547
510
  return textResponse(result.message);
548
511
  });
549
- 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.", {
550
- code: z6.string().describe("TypeScript source code containing a defineSubgraph() call"),
551
- startBlock: z6.number().int().nonnegative().optional().describe("Override the definition startBlock for this deploy"),
552
- databaseUrl: z6.string().optional().describe("BYO data plane: Postgres connection string to host the subgraph's schema and rows in your own database"),
553
- dryRun: z6.boolean().optional().describe("Validate and preview the deploy (schema/DDL, BYO connection) without writing changes"),
554
- 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.")
555
- }, async ({ code, startBlock, databaseUrl, dryRun, visibility }) => {
512
+ 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. Call `subgraphs_reindex` separately if you need a forced reindex.", {
513
+ code: z5.string().describe("TypeScript source code containing a defineSubgraph() call"),
514
+ startBlock: z5.number().int().nonnegative().optional().describe("Override the definition startBlock for this deploy"),
515
+ dryRun: z5.boolean().optional().describe("Validate and preview the deploy (schema/DDL) without writing changes")
516
+ }, async ({ code, startBlock, dryRun }) => {
556
517
  const bundled = await bundleSubgraphCode(code);
557
- try {
558
- const result = await clientProvider().subgraphs.deploy({
559
- name: bundled.name,
560
- version: bundled.version,
561
- description: bundled.description,
562
- sources: bundled.sources,
563
- schema: bundled.schema,
564
- handlerCode: bundled.handlerCode,
565
- sourceCode: code,
566
- ...startBlock !== undefined ? { startBlock } : {},
567
- ...databaseUrl !== undefined ? { databaseUrl } : {},
568
- ...dryRun !== undefined ? { dryRun } : {},
569
- ...visibility !== undefined ? { visibility } : {}
570
- });
571
- return jsonResponse(result);
572
- } catch (err) {
573
- if (err instanceof ByoBreakingChangeError) {
574
- return jsonResponse({ byoBreakingChange: true, ...err.details });
575
- }
576
- throw err;
577
- }
578
- });
579
- 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 }) => {
580
- const result = await clientProvider().subgraphs.publish(name);
581
- return jsonResponse(result);
582
- });
583
- 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 }) => {
584
- const result = await clientProvider().subgraphs.unpublish(name);
518
+ const result = await clientProvider().subgraphs.deploy({
519
+ name: bundled.name,
520
+ version: bundled.version,
521
+ description: bundled.description,
522
+ sources: bundled.sources,
523
+ schema: bundled.schema,
524
+ handlerCode: bundled.handlerCode,
525
+ sourceCode: code,
526
+ ...startBlock !== undefined ? { startBlock } : {},
527
+ ...dryRun !== undefined ? { dryRun } : {}
528
+ });
585
529
  return jsonResponse(result);
586
530
  });
587
531
  }
588
532
 
589
533
  // src/tools/subscriptions.ts
590
534
  import { CHAIN_TRIGGER_TYPES } from "@secondlayer/shared";
591
- import { z as z7 } from "zod";
535
+ import { z as z6 } from "zod";
592
536
  function registerSubscriptionTools(server, clientProvider = getClient) {
593
537
  defineTool(server, "subscriptions_list", "List all subscriptions for the current account. Returns summary fields (no secrets).", {}, async () => {
594
538
  const { data } = await clientProvider().subscriptions.list();
595
539
  return jsonResponse(data);
596
540
  });
597
- defineTool(server, "subscriptions_get", "Get full detail for a subscription (filter, auth, retry config, circuit state).", { id: z7.string().describe("Subscription id") }, async ({ id }) => {
541
+ defineTool(server, "subscriptions_get", "Get full detail for a subscription (filter, auth, retry config, circuit state).", { id: z6.string().describe("Subscription id") }, async ({ id }) => {
598
542
  const detail = await clientProvider().subscriptions.get(id);
599
543
  return jsonResponse(detail);
600
544
  });
601
545
  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.", {
602
- name: z7.string().describe("Human-readable name, unique per account"),
603
- subgraphName: z7.string().optional().describe("Subgraph to subscribe to (subgraph subscription)"),
604
- tableName: z7.string().optional().describe("Table within the subgraph (subgraph subscription)"),
605
- triggers: z7.array(z7.object({
606
- type: z7.enum(CHAIN_TRIGGER_TYPES),
607
- contractId: z7.string().optional(),
608
- functionName: z7.string().optional(),
609
- caller: z7.string().optional(),
610
- sender: z7.string().optional(),
611
- recipient: z7.string().optional(),
612
- assetIdentifier: z7.string().optional(),
613
- deployer: z7.string().optional(),
614
- contractName: z7.string().optional(),
615
- topic: z7.string().optional(),
616
- lockedAddress: z7.string().optional(),
617
- trait: z7.string().optional(),
618
- minAmount: z7.union([z7.string(), z7.number()]).optional(),
619
- maxAmount: z7.union([z7.string(), z7.number()]).optional()
546
+ name: z6.string().describe("Human-readable name, unique per account"),
547
+ subgraphName: z6.string().optional().describe("Subgraph to subscribe to (subgraph subscription)"),
548
+ tableName: z6.string().optional().describe("Table within the subgraph (subgraph subscription)"),
549
+ triggers: z6.array(z6.object({
550
+ type: z6.enum(CHAIN_TRIGGER_TYPES),
551
+ contractId: z6.string().optional(),
552
+ functionName: z6.string().optional(),
553
+ caller: z6.string().optional(),
554
+ sender: z6.string().optional(),
555
+ recipient: z6.string().optional(),
556
+ assetIdentifier: z6.string().optional(),
557
+ deployer: z6.string().optional(),
558
+ contractName: z6.string().optional(),
559
+ topic: z6.string().optional(),
560
+ lockedAddress: z6.string().optional(),
561
+ trait: z6.string().optional(),
562
+ minAmount: z6.union([z6.string(), z6.number()]).optional(),
563
+ maxAmount: z6.union([z6.string(), z6.number()]).optional()
620
564
  })).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."),
621
- url: z7.string().describe("Webhook URL"),
622
- format: z7.enum([
565
+ url: z6.string().describe("Webhook URL"),
566
+ format: z6.enum([
623
567
  "standard-webhooks",
624
568
  "inngest",
625
569
  "trigger",
@@ -627,20 +571,20 @@ function registerSubscriptionTools(server, clientProvider = getClient) {
627
571
  "cloudevents",
628
572
  "raw"
629
573
  ]).optional().describe("Wire format (default standard-webhooks)"),
630
- runtime: z7.enum(["inngest", "trigger", "cloudflare", "node"]).optional().describe("Receiver runtime label (display only)"),
631
- filter: z7.record(z7.string(), z7.unknown()).optional().describe('Scalar filter DSL, e.g. {"amount": {"gte": 100}, "sender": "SP..."}'),
632
- authConfig: z7.record(z7.string(), z7.unknown()).optional().describe('Receiver auth sent with each delivery, e.g. {"type": "bearer", "token": "..."}')
574
+ runtime: z6.enum(["inngest", "trigger", "cloudflare", "node"]).optional().describe("Receiver runtime label (display only)"),
575
+ filter: z6.record(z6.string(), z6.unknown()).optional().describe('Scalar filter DSL, e.g. {"amount": {"gte": 100}, "sender": "SP..."}'),
576
+ authConfig: z6.record(z6.string(), z6.unknown()).optional().describe('Receiver auth sent with each delivery, e.g. {"type": "bearer", "token": "..."}')
633
577
  }, async (input) => {
634
578
  const res = await clientProvider().subscriptions.create(input);
635
579
  return jsonResponse(res);
636
580
  });
637
581
  defineTool(server, "subscriptions_update", "Patch a subscription (name, url, filter, authConfig, format, runtime, retry, timeout, concurrency).", {
638
- id: z7.string(),
639
- name: z7.string().optional().describe("Rename the subscription"),
640
- url: z7.string().optional(),
641
- filter: z7.record(z7.string(), z7.unknown()).optional(),
642
- authConfig: z7.record(z7.string(), z7.unknown()).optional().describe("Receiver auth sent with each delivery (bearer/etc.)"),
643
- format: z7.enum([
582
+ id: z6.string(),
583
+ name: z6.string().optional().describe("Rename the subscription"),
584
+ url: z6.string().optional(),
585
+ filter: z6.record(z6.string(), z6.unknown()).optional(),
586
+ authConfig: z6.record(z6.string(), z6.unknown()).optional().describe("Receiver auth sent with each delivery (bearer/etc.)"),
587
+ format: z6.enum([
644
588
  "standard-webhooks",
645
589
  "inngest",
646
590
  "trigger",
@@ -648,27 +592,27 @@ function registerSubscriptionTools(server, clientProvider = getClient) {
648
592
  "cloudevents",
649
593
  "raw"
650
594
  ]).optional(),
651
- runtime: z7.enum(["inngest", "trigger", "cloudflare", "node"]).nullable().optional(),
652
- maxRetries: z7.number().int().min(0).optional(),
653
- timeoutMs: z7.number().int().min(100).optional(),
654
- concurrency: z7.number().int().min(1).optional()
595
+ runtime: z6.enum(["inngest", "trigger", "cloudflare", "node"]).nullable().optional(),
596
+ maxRetries: z6.number().int().min(0).optional(),
597
+ timeoutMs: z6.number().int().min(100).optional(),
598
+ concurrency: z6.number().int().min(1).optional()
655
599
  }, async ({ id, ...patch }) => {
656
600
  const res = await clientProvider().subscriptions.update(id, patch);
657
601
  return jsonResponse(res);
658
602
  });
659
- defineTool(server, "subscriptions_delete", "Delete a subscription. Pending outbox rows are cascade-deleted.", { id: z7.string() }, async ({ id }) => {
603
+ defineTool(server, "subscriptions_delete", "Delete a subscription. Pending outbox rows are cascade-deleted.", { id: z6.string() }, async ({ id }) => {
660
604
  const res = await clientProvider().subscriptions.delete(id);
661
605
  return jsonResponse(res);
662
606
  });
663
- 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 }) => {
607
+ 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 }) => {
664
608
  const res = await clientProvider().subscriptions.test(id);
665
609
  return jsonResponse(res);
666
610
  });
667
611
  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.", {
668
- id: z7.string(),
669
- fromBlock: z7.number().int().nonnegative(),
670
- toBlock: z7.number().int().nonnegative(),
671
- force: z7.string().optional().describe("Idempotency suffix to force a duplicate replay of the range")
612
+ id: z6.string(),
613
+ fromBlock: z6.number().int().nonnegative(),
614
+ toBlock: z6.number().int().nonnegative(),
615
+ force: z6.string().optional().describe("Idempotency suffix to force a duplicate replay of the range")
672
616
  }, async ({ id, fromBlock, toBlock, force }) => {
673
617
  const res = await clientProvider().subscriptions.replay(id, {
674
618
  fromBlock,
@@ -690,7 +634,6 @@ function createServer() {
690
634
  registerScaffoldTools(server);
691
635
  registerSubgraphTools(server);
692
636
  registerSubscriptionTools(server);
693
- registerAccountTools(server);
694
637
  registerIndexTools(server);
695
638
  registerStreamsTools(server);
696
639
  registerContractTools(server);
@@ -702,5 +645,5 @@ export {
702
645
  createServer
703
646
  };
704
647
 
705
- //# debugId=5DCCBA27350F16E764756E2164756E21
648
+ //# debugId=56CC69399B85D1D864756E2164756E21
706
649
  //# sourceMappingURL=index.js.map