@secondlayer/mcp 4.5.1 → 4.5.3
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 +115 -150
- package/dist/bin-http.js.map +6 -7
- package/dist/bin.js +115 -150
- package/dist/bin.js.map +6 -7
- package/dist/index.js +115 -150
- package/dist/index.js.map +6 -7
- package/package.json +3 -3
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 `sl init`.
|
|
77
73
|
|
|
78
74
|
### `subscriptions_create` kinds
|
|
79
75
|
|
package/dist/bin-http.js
CHANGED
|
@@ -53,44 +53,23 @@ function buildFetchImpl() {
|
|
|
53
53
|
function getClient() {
|
|
54
54
|
if (!instance) {
|
|
55
55
|
const apiKey = readApiKey();
|
|
56
|
-
const baseUrl = process.env.SECONDLAYER_API_URL;
|
|
56
|
+
const baseUrl = process.env.SECONDLAYER_API_URL || process.env.SL_API_URL || "http://127.0.0.1:3800";
|
|
57
57
|
const dumpsBaseUrl = process.env.SL_STREAMS_DUMPS_URL;
|
|
58
58
|
const fetchImpl = buildFetchImpl();
|
|
59
59
|
instance = new SecondLayer({
|
|
60
60
|
...apiKey ? { apiKey } : {},
|
|
61
61
|
origin: "mcp",
|
|
62
|
-
|
|
62
|
+
baseUrl,
|
|
63
63
|
...dumpsBaseUrl ? { dumpsBaseUrl } : {},
|
|
64
64
|
...fetchImpl ? { fetchImpl } : {}
|
|
65
65
|
});
|
|
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 || "https://api.secondlayer.tools";
|
|
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) {
|
|
93
|
-
const apiUrl = process.env.SECONDLAYER_API_URL || "
|
|
72
|
+
const apiUrl = process.env.SECONDLAYER_API_URL || process.env.SL_API_URL || "http://127.0.0.1:3800";
|
|
94
73
|
return {
|
|
95
74
|
name: s.name,
|
|
96
75
|
status: s.status,
|
|
@@ -315,31 +294,18 @@ function registerResources(server) {
|
|
|
315
294
|
}));
|
|
316
295
|
}
|
|
317
296
|
|
|
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
297
|
// src/tools/codegen.ts
|
|
332
298
|
import {
|
|
333
299
|
generateIndexSchema
|
|
334
300
|
} from "@secondlayer/subgraphs";
|
|
335
|
-
import { z
|
|
301
|
+
import { z } from "zod";
|
|
336
302
|
var TARGETS = ["prisma", "kysely", "drizzle", "json-schema"];
|
|
337
303
|
function registerCodegenTools(server) {
|
|
338
304
|
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:
|
|
305
|
+
target: z.enum(TARGETS).optional().describe("Output flavor (default kysely)"),
|
|
306
|
+
tables: z.array(z.string()).optional().describe("Restrict to these Index tables (default: all)"),
|
|
307
|
+
schemaName: z.string().optional().describe("Postgres schema to qualify table names with"),
|
|
308
|
+
datasourceEnv: z.string().optional().describe("Prisma only: datasource url env var (default DATABASE_URL)")
|
|
343
309
|
}, ({ target, tables, schemaName, datasourceEnv }) => textResponse(generateIndexSchema(target ?? "kysely", {
|
|
344
310
|
tables,
|
|
345
311
|
schemaName,
|
|
@@ -348,17 +314,17 @@ function registerCodegenTools(server) {
|
|
|
348
314
|
}
|
|
349
315
|
|
|
350
316
|
// src/tools/contracts.ts
|
|
351
|
-
import { z as
|
|
317
|
+
import { z as z2 } from "zod";
|
|
352
318
|
function registerContractTools(server, clientProvider = getClient) {
|
|
353
319
|
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:
|
|
320
|
+
trait: z2.string().describe('Required. Trait to match (e.g. "sip-010").'),
|
|
321
|
+
conformance: z2.enum(["declared", "inferred", "any"]).optional().describe("declared = parsed from source, inferred = ABI shape-match, any = either (default)"),
|
|
322
|
+
include: z2.literal("abi").optional().describe(`Set to "abi" to include each contract's full ABI`),
|
|
323
|
+
limit: z2.number().optional().describe("Page size, 1–500 (default 100)"),
|
|
324
|
+
cursor: z2.string().optional().describe("Opaque cursor from a prior response's next_cursor")
|
|
359
325
|
}, async (params) => jsonResponse(await clientProvider().contracts.list(params)));
|
|
360
326
|
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:
|
|
327
|
+
contractId: z2.string().describe("Fully qualified contract id (e.g. SP….amm-pool-v2-01)")
|
|
362
328
|
}, async ({ contractId }) => {
|
|
363
329
|
const contract = await clientProvider().contracts.get(contractId, {
|
|
364
330
|
includeAbi: true
|
|
@@ -375,14 +341,14 @@ function registerContractTools(server, clientProvider = getClient) {
|
|
|
375
341
|
|
|
376
342
|
// src/tools/index.ts
|
|
377
343
|
import { DECODED_EVENT_TYPES } from "@secondlayer/shared";
|
|
378
|
-
import { z as
|
|
344
|
+
import { z as z3 } from "zod";
|
|
379
345
|
var INDEX_EVENT_TYPES = DECODED_EVENT_TYPES;
|
|
380
346
|
var rangeFilters = {
|
|
381
|
-
contractId:
|
|
382
|
-
fromHeight:
|
|
383
|
-
toHeight:
|
|
384
|
-
cursor:
|
|
385
|
-
limit:
|
|
347
|
+
contractId: z3.string().optional().describe("Filter by contract id"),
|
|
348
|
+
fromHeight: z3.number().optional().describe("Start block height (inclusive)"),
|
|
349
|
+
toHeight: z3.number().optional().describe("End block height (inclusive)"),
|
|
350
|
+
cursor: z3.string().optional().describe("Opaque cursor from a prior response's next_cursor"),
|
|
351
|
+
limit: z3.number().optional().describe("Max rows for this page")
|
|
386
352
|
};
|
|
387
353
|
var heightFilters = {
|
|
388
354
|
fromHeight: rangeFilters.fromHeight,
|
|
@@ -393,52 +359,52 @@ var heightFilters = {
|
|
|
393
359
|
function registerIndexTools(server, clientProvider = getClient) {
|
|
394
360
|
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
361
|
...rangeFilters,
|
|
396
|
-
sender:
|
|
397
|
-
recipient:
|
|
398
|
-
assetIdentifier:
|
|
362
|
+
sender: z3.string().optional().describe("Filter by sender principal"),
|
|
363
|
+
recipient: z3.string().optional().describe("Filter by recipient principal"),
|
|
364
|
+
assetIdentifier: z3.string().optional().describe("Filter by asset identifier (contract::asset), e.g. SP…sbtc-token::sbtc-token")
|
|
399
365
|
}, async (params) => jsonResponse(await clientProvider().index.ftTransfers.list(params)));
|
|
400
366
|
defineTool(server, "index_nft_transfers", "List decoded SIP-009 non-fungible-token transfers from the Index. Anonymous reads allowed (free-tier keys rejected).", {
|
|
401
367
|
...rangeFilters,
|
|
402
|
-
sender:
|
|
403
|
-
recipient:
|
|
404
|
-
assetIdentifier:
|
|
368
|
+
sender: z3.string().optional().describe("Filter by sender principal"),
|
|
369
|
+
recipient: z3.string().optional().describe("Filter by recipient principal"),
|
|
370
|
+
assetIdentifier: z3.string().optional().describe("Filter by asset identifier (contract::asset)")
|
|
405
371
|
}, async (params) => jsonResponse(await clientProvider().index.nftTransfers.list(params)));
|
|
406
372
|
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:
|
|
373
|
+
eventType: z3.enum(INDEX_EVENT_TYPES).describe("Required. Decoded event type to list."),
|
|
408
374
|
...rangeFilters,
|
|
409
|
-
sender:
|
|
410
|
-
recipient:
|
|
411
|
-
assetIdentifier:
|
|
412
|
-
trait:
|
|
413
|
-
txContext:
|
|
375
|
+
sender: z3.string().optional().describe("Filter by sender principal"),
|
|
376
|
+
recipient: z3.string().optional().describe("Filter by recipient principal"),
|
|
377
|
+
assetIdentifier: z3.string().optional().describe("Filter by asset identifier where applicable"),
|
|
378
|
+
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."),
|
|
379
|
+
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
380
|
}, async (params) => jsonResponse(await clientProvider().index.events.list(params)));
|
|
415
381
|
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
382
|
...rangeFilters,
|
|
417
|
-
functionName:
|
|
418
|
-
sender:
|
|
419
|
-
trait:
|
|
383
|
+
functionName: z3.string().optional().describe("Filter by called function name"),
|
|
384
|
+
sender: z3.string().optional().describe("Filter by caller principal"),
|
|
385
|
+
trait: z3.string().optional().describe("Match contracts conforming to a trait/standard (e.g. sip-010). Mutually exclusive with contractId.")
|
|
420
386
|
}, async (params) => jsonResponse(await clientProvider().index.contractCalls.list(params)));
|
|
421
387
|
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
388
|
defineTool(server, "index_transactions", "List decoded transactions from the Index. Filter by type, sender, or contract. Anonymous reads allowed (free-tier keys rejected).", {
|
|
423
389
|
...rangeFilters,
|
|
424
|
-
type:
|
|
425
|
-
sender:
|
|
390
|
+
type: z3.string().optional().describe("Filter by transaction type"),
|
|
391
|
+
sender: z3.string().optional().describe("Filter by sender principal")
|
|
426
392
|
}, async (params) => jsonResponse(await clientProvider().index.transactions.list(params)));
|
|
427
393
|
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:
|
|
394
|
+
contractId: z3.string().describe("Contract id (SP….name) whose print events to profile")
|
|
429
395
|
}, async (params) => jsonResponse(await clientProvider().index.printSchema(params.contractId)));
|
|
430
396
|
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
397
|
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:
|
|
398
|
+
requests: z3.array(z3.object({
|
|
399
|
+
path: z3.string().describe("Public /v1 read path"),
|
|
400
|
+
params: z3.record(z3.string(), z3.string()).optional()
|
|
435
401
|
})).min(1).max(10).describe("Read descriptors, executed concurrently")
|
|
436
402
|
}, async (params) => jsonResponse(await clientProvider().batch(params.requests)));
|
|
437
403
|
}
|
|
438
404
|
|
|
439
405
|
// src/tools/scaffold.ts
|
|
440
406
|
import { generateSubgraphCode } from "@secondlayer/scaffold";
|
|
441
|
-
import { z as
|
|
407
|
+
import { z as z4 } from "zod";
|
|
442
408
|
async function fetchAbi(clientProvider, contractId) {
|
|
443
409
|
const contract = await clientProvider().contracts.get(contractId, {
|
|
444
410
|
includeAbi: true
|
|
@@ -453,8 +419,8 @@ async function fetchAbi(clientProvider, contractId) {
|
|
|
453
419
|
}
|
|
454
420
|
function registerScaffoldTools(server, clientProvider = getClient) {
|
|
455
421
|
defineTool(server, "scaffold_from_contract", "Generate a subgraph scaffold from a deployed Stacks contract. Fetches the ABI automatically.", {
|
|
456
|
-
contractId:
|
|
457
|
-
subgraphName:
|
|
422
|
+
contractId: z4.string().describe("Fully qualified contract ID (e.g. SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-pool-v2-01)"),
|
|
423
|
+
subgraphName: z4.string().optional().describe("Override the subgraph name (defaults to contract name)")
|
|
458
424
|
}, async ({ contractId, subgraphName }) => {
|
|
459
425
|
const { functions } = await fetchAbi(clientProvider, contractId);
|
|
460
426
|
const code = generateSubgraphCode(contractId, functions, subgraphName);
|
|
@@ -470,26 +436,26 @@ function registerStreamsTools(server, clientProvider = getClient) {
|
|
|
470
436
|
// src/tools/subgraphs.ts
|
|
471
437
|
import { bundleSubgraphCode } from "@secondlayer/bundler";
|
|
472
438
|
import { ByoBreakingChangeError } from "@secondlayer/sdk";
|
|
473
|
-
import { z as
|
|
439
|
+
import { z as z5 } from "zod";
|
|
474
440
|
function registerSubgraphTools(server, clientProvider = getClient) {
|
|
475
441
|
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
442
|
const { data } = await clientProvider().subgraphs.list();
|
|
477
443
|
return jsonResponse(data.map(formatSubgraphSummary));
|
|
478
444
|
});
|
|
479
|
-
defineTool(server, "subgraphs_get", "Get full details of a subgraph including schema, health, and table columns.", { name:
|
|
445
|
+
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
446
|
const detail = await clientProvider().subgraphs.get(name);
|
|
481
447
|
return jsonResponse(detail);
|
|
482
448
|
});
|
|
483
449
|
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:
|
|
450
|
+
name: z5.string().describe("Subgraph name"),
|
|
451
|
+
table: z5.string().describe("Table name"),
|
|
452
|
+
filters: z5.record(z5.string(), z5.string()).optional().describe('Column filters — plain values or with operators (e.g. {"amount.gte": "1000", "sender": "SP..."})'),
|
|
453
|
+
sort: z5.string().optional().describe("Column to sort by"),
|
|
454
|
+
order: z5.enum(["asc", "desc"]).optional().describe("Sort order"),
|
|
455
|
+
limit: z5.number().max(200).optional().describe("Max rows (default 50, max 200)"),
|
|
456
|
+
offset: z5.number().optional().describe("Offset for pagination"),
|
|
457
|
+
fields: z5.string().optional().describe('Comma-separated column list to return (e.g. "sender,amount")'),
|
|
458
|
+
count: z5.boolean().optional().describe("If true, return row count instead of rows")
|
|
493
459
|
}, async ({
|
|
494
460
|
name,
|
|
495
461
|
table,
|
|
@@ -517,15 +483,15 @@ function registerSubgraphTools(server, clientProvider = getClient) {
|
|
|
517
483
|
return jsonResponse(result);
|
|
518
484
|
});
|
|
519
485
|
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:
|
|
486
|
+
name: z5.string().describe("Subgraph name")
|
|
521
487
|
}, async ({ name }) => {
|
|
522
488
|
const result = await clientProvider().subgraphs.reindex(name);
|
|
523
489
|
return jsonResponse(result);
|
|
524
490
|
});
|
|
525
491
|
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:
|
|
492
|
+
name: z5.string().describe("Subgraph name"),
|
|
493
|
+
fromBlock: z5.number().int().nonnegative().describe("Start block (inclusive)"),
|
|
494
|
+
toBlock: z5.number().int().nonnegative().describe("End block (inclusive)")
|
|
529
495
|
}, async ({ name, fromBlock, toBlock }) => {
|
|
530
496
|
const result = await clientProvider().subgraphs.backfill(name, {
|
|
531
497
|
fromBlock,
|
|
@@ -533,15 +499,15 @@ function registerSubgraphTools(server, clientProvider = getClient) {
|
|
|
533
499
|
});
|
|
534
500
|
return jsonResponse(result);
|
|
535
501
|
});
|
|
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:
|
|
502
|
+
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
503
|
const result = await clientProvider().subgraphs.stop(name);
|
|
538
504
|
return jsonResponse(result);
|
|
539
505
|
});
|
|
540
506
|
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:
|
|
507
|
+
name: z5.string().describe("Subgraph name"),
|
|
508
|
+
limit: z5.number().int().positive().optional().describe("Max gaps to return"),
|
|
509
|
+
offset: z5.number().int().nonnegative().optional().describe("Pagination offset"),
|
|
510
|
+
resolved: z5.boolean().optional().describe("Filter by resolved state (omit for unresolved only)")
|
|
545
511
|
}, async ({ name, limit, offset, resolved }) => {
|
|
546
512
|
const result = await clientProvider().subgraphs.gaps(name, {
|
|
547
513
|
limit,
|
|
@@ -550,16 +516,16 @@ function registerSubgraphTools(server, clientProvider = getClient) {
|
|
|
550
516
|
});
|
|
551
517
|
return jsonResponse(result);
|
|
552
518
|
});
|
|
553
|
-
defineTool(server, "subgraphs_delete", "Delete a subgraph permanently.", { name:
|
|
519
|
+
defineTool(server, "subgraphs_delete", "Delete a subgraph permanently.", { name: z5.string().describe("Subgraph name") }, async ({ name }) => {
|
|
554
520
|
const result = await clientProvider().subgraphs.delete(name);
|
|
555
521
|
return textResponse(result.message);
|
|
556
522
|
});
|
|
557
523
|
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.", {
|
|
558
|
-
code:
|
|
559
|
-
startBlock:
|
|
560
|
-
databaseUrl:
|
|
561
|
-
dryRun:
|
|
562
|
-
visibility:
|
|
524
|
+
code: z5.string().describe("TypeScript source code containing a defineSubgraph() call"),
|
|
525
|
+
startBlock: z5.number().int().nonnegative().optional().describe("Override the definition startBlock for this deploy"),
|
|
526
|
+
databaseUrl: z5.string().optional().describe("BYO data plane: Postgres connection string to host the subgraph's schema and rows in your own database"),
|
|
527
|
+
dryRun: z5.boolean().optional().describe("Validate and preview the deploy (schema/DDL, BYO connection) without writing changes"),
|
|
528
|
+
visibility: z5.enum(["public", "private"]).optional().describe("Read visibility: public = anon /v1 reads + global name claim; private = owning account's key only. Defaults: managed → public, BYO → private.")
|
|
563
529
|
}, async ({ code, startBlock, databaseUrl, dryRun, visibility }) => {
|
|
564
530
|
const bundled = await bundleSubgraphCode(code);
|
|
565
531
|
try {
|
|
@@ -584,11 +550,11 @@ function registerSubgraphTools(server, clientProvider = getClient) {
|
|
|
584
550
|
throw err;
|
|
585
551
|
}
|
|
586
552
|
});
|
|
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:
|
|
553
|
+
defineTool(server, "subgraphs_publish", "Make a subgraph publicly readable at /v1/subgraphs/<name> — anyone (or any agent) can read it without a key. Claims the name in the global public namespace; fails with PUBLIC_NAME_TAKEN if another account holds it.", { name: z5.string().describe("Subgraph name") }, async ({ name }) => {
|
|
588
554
|
const result = await clientProvider().subgraphs.publish(name);
|
|
589
555
|
return jsonResponse(result);
|
|
590
556
|
});
|
|
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:
|
|
557
|
+
defineTool(server, "subgraphs_unpublish", "Make a subgraph private again — /v1 reads then require the owning account's bearer key, and the global public name claim is released.", { name: z5.string().describe("Subgraph name") }, async ({ name }) => {
|
|
592
558
|
const result = await clientProvider().subgraphs.unpublish(name);
|
|
593
559
|
return jsonResponse(result);
|
|
594
560
|
});
|
|
@@ -596,38 +562,38 @@ function registerSubgraphTools(server, clientProvider = getClient) {
|
|
|
596
562
|
|
|
597
563
|
// src/tools/subscriptions.ts
|
|
598
564
|
import { CHAIN_TRIGGER_TYPES } from "@secondlayer/shared";
|
|
599
|
-
import { z as
|
|
565
|
+
import { z as z6 } from "zod";
|
|
600
566
|
function registerSubscriptionTools(server, clientProvider = getClient) {
|
|
601
567
|
defineTool(server, "subscriptions_list", "List all subscriptions for the current account. Returns summary fields (no secrets).", {}, async () => {
|
|
602
568
|
const { data } = await clientProvider().subscriptions.list();
|
|
603
569
|
return jsonResponse(data);
|
|
604
570
|
});
|
|
605
|
-
defineTool(server, "subscriptions_get", "Get full detail for a subscription (filter, auth, retry config, circuit state).", { id:
|
|
571
|
+
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
572
|
const detail = await clientProvider().subscriptions.get(id);
|
|
607
573
|
return jsonResponse(detail);
|
|
608
574
|
});
|
|
609
575
|
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:
|
|
576
|
+
name: z6.string().describe("Human-readable name, unique per account"),
|
|
577
|
+
subgraphName: z6.string().optional().describe("Subgraph to subscribe to (subgraph subscription)"),
|
|
578
|
+
tableName: z6.string().optional().describe("Table within the subgraph (subgraph subscription)"),
|
|
579
|
+
triggers: z6.array(z6.object({
|
|
580
|
+
type: z6.enum(CHAIN_TRIGGER_TYPES),
|
|
581
|
+
contractId: z6.string().optional(),
|
|
582
|
+
functionName: z6.string().optional(),
|
|
583
|
+
caller: z6.string().optional(),
|
|
584
|
+
sender: z6.string().optional(),
|
|
585
|
+
recipient: z6.string().optional(),
|
|
586
|
+
assetIdentifier: z6.string().optional(),
|
|
587
|
+
deployer: z6.string().optional(),
|
|
588
|
+
contractName: z6.string().optional(),
|
|
589
|
+
topic: z6.string().optional(),
|
|
590
|
+
lockedAddress: z6.string().optional(),
|
|
591
|
+
trait: z6.string().optional(),
|
|
592
|
+
minAmount: z6.union([z6.string(), z6.number()]).optional(),
|
|
593
|
+
maxAmount: z6.union([z6.string(), z6.number()]).optional()
|
|
628
594
|
})).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:
|
|
595
|
+
url: z6.string().describe("Webhook URL"),
|
|
596
|
+
format: z6.enum([
|
|
631
597
|
"standard-webhooks",
|
|
632
598
|
"inngest",
|
|
633
599
|
"trigger",
|
|
@@ -635,20 +601,20 @@ function registerSubscriptionTools(server, clientProvider = getClient) {
|
|
|
635
601
|
"cloudevents",
|
|
636
602
|
"raw"
|
|
637
603
|
]).optional().describe("Wire format (default standard-webhooks)"),
|
|
638
|
-
runtime:
|
|
639
|
-
filter:
|
|
640
|
-
authConfig:
|
|
604
|
+
runtime: z6.enum(["inngest", "trigger", "cloudflare", "node"]).optional().describe("Receiver runtime label (display only)"),
|
|
605
|
+
filter: z6.record(z6.string(), z6.unknown()).optional().describe('Scalar filter DSL, e.g. {"amount": {"gte": 100}, "sender": "SP..."}'),
|
|
606
|
+
authConfig: z6.record(z6.string(), z6.unknown()).optional().describe('Receiver auth sent with each delivery, e.g. {"type": "bearer", "token": "..."}')
|
|
641
607
|
}, async (input) => {
|
|
642
608
|
const res = await clientProvider().subscriptions.create(input);
|
|
643
609
|
return jsonResponse(res);
|
|
644
610
|
});
|
|
645
611
|
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:
|
|
612
|
+
id: z6.string(),
|
|
613
|
+
name: z6.string().optional().describe("Rename the subscription"),
|
|
614
|
+
url: z6.string().optional(),
|
|
615
|
+
filter: z6.record(z6.string(), z6.unknown()).optional(),
|
|
616
|
+
authConfig: z6.record(z6.string(), z6.unknown()).optional().describe("Receiver auth sent with each delivery (bearer/etc.)"),
|
|
617
|
+
format: z6.enum([
|
|
652
618
|
"standard-webhooks",
|
|
653
619
|
"inngest",
|
|
654
620
|
"trigger",
|
|
@@ -656,27 +622,27 @@ function registerSubscriptionTools(server, clientProvider = getClient) {
|
|
|
656
622
|
"cloudevents",
|
|
657
623
|
"raw"
|
|
658
624
|
]).optional(),
|
|
659
|
-
runtime:
|
|
660
|
-
maxRetries:
|
|
661
|
-
timeoutMs:
|
|
662
|
-
concurrency:
|
|
625
|
+
runtime: z6.enum(["inngest", "trigger", "cloudflare", "node"]).nullable().optional(),
|
|
626
|
+
maxRetries: z6.number().int().min(0).optional(),
|
|
627
|
+
timeoutMs: z6.number().int().min(100).optional(),
|
|
628
|
+
concurrency: z6.number().int().min(1).optional()
|
|
663
629
|
}, async ({ id, ...patch }) => {
|
|
664
630
|
const res = await clientProvider().subscriptions.update(id, patch);
|
|
665
631
|
return jsonResponse(res);
|
|
666
632
|
});
|
|
667
|
-
defineTool(server, "subscriptions_delete", "Delete a subscription. Pending outbox rows are cascade-deleted.", { id:
|
|
633
|
+
defineTool(server, "subscriptions_delete", "Delete a subscription. Pending outbox rows are cascade-deleted.", { id: z6.string() }, async ({ id }) => {
|
|
668
634
|
const res = await clientProvider().subscriptions.delete(id);
|
|
669
635
|
return jsonResponse(res);
|
|
670
636
|
});
|
|
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:
|
|
637
|
+
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
638
|
const res = await clientProvider().subscriptions.test(id);
|
|
673
639
|
return jsonResponse(res);
|
|
674
640
|
});
|
|
675
641
|
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:
|
|
642
|
+
id: z6.string(),
|
|
643
|
+
fromBlock: z6.number().int().nonnegative(),
|
|
644
|
+
toBlock: z6.number().int().nonnegative(),
|
|
645
|
+
force: z6.string().optional().describe("Idempotency suffix to force a duplicate replay of the range")
|
|
680
646
|
}, async ({ id, fromBlock, toBlock, force }) => {
|
|
681
647
|
const res = await clientProvider().subscriptions.replay(id, {
|
|
682
648
|
fromBlock,
|
|
@@ -698,7 +664,6 @@ function createServer() {
|
|
|
698
664
|
registerScaffoldTools(server);
|
|
699
665
|
registerSubgraphTools(server);
|
|
700
666
|
registerSubscriptionTools(server);
|
|
701
|
-
registerAccountTools(server);
|
|
702
667
|
registerIndexTools(server);
|
|
703
668
|
registerStreamsTools(server);
|
|
704
669
|
registerContractTools(server);
|
|
@@ -793,5 +758,5 @@ httpServer.listen(port, () => {
|
|
|
793
758
|
console.error("Warning: SECONDLAYER_MCP_SECRET not set, authentication disabled");
|
|
794
759
|
});
|
|
795
760
|
|
|
796
|
-
//# debugId=
|
|
761
|
+
//# debugId=A5B0624749536DF364756E2164756E21
|
|
797
762
|
//# sourceMappingURL=bin-http.js.map
|