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