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