@secondlayer/mcp 4.2.4 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin-http.js +143 -149
- package/dist/bin-http.js.map +9 -8
- package/dist/bin.js +143 -149
- package/dist/bin.js.map +9 -8
- package/dist/index.js +143 -149
- package/dist/index.js.map +9 -8
- package/package.json +4 -4
package/dist/bin-http.js
CHANGED
|
@@ -15,6 +15,7 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
|
15
15
|
// src/resources.ts
|
|
16
16
|
import { CHAIN_TRIGGER_FIELDS } from "@secondlayer/shared";
|
|
17
17
|
import { TRAIT_STANDARDS } from "@secondlayer/stacks/clarity";
|
|
18
|
+
import { filterFieldsByType } from "@secondlayer/subgraphs";
|
|
18
19
|
import { TYPE_MAP } from "@secondlayer/subgraphs/schema";
|
|
19
20
|
|
|
20
21
|
// src/lib/client.ts
|
|
@@ -124,7 +125,7 @@ var registeredToolNames = new Set;
|
|
|
124
125
|
function getRegisteredToolNames() {
|
|
125
126
|
return [...registeredToolNames];
|
|
126
127
|
}
|
|
127
|
-
function defineTool(server, name, description, schema, handler) {
|
|
128
|
+
function defineTool(server, name, description, schema, handler, options = {}) {
|
|
128
129
|
const wrappedHandler = async (args) => {
|
|
129
130
|
try {
|
|
130
131
|
return await handler(args);
|
|
@@ -145,6 +146,9 @@ function defineTool(server, name, description, schema, handler) {
|
|
|
145
146
|
};
|
|
146
147
|
registeredToolNames.add(name);
|
|
147
148
|
server.tool(name, description, schema, wrappedHandler);
|
|
149
|
+
for (const alias of options.aliases ?? []) {
|
|
150
|
+
server.tool(alias, `Deprecated alias for \`${name}\`. ${description}`, schema, wrappedHandler);
|
|
151
|
+
}
|
|
148
152
|
}
|
|
149
153
|
|
|
150
154
|
// src/resources.ts
|
|
@@ -153,39 +157,7 @@ var TRAIT_BLURBS = {
|
|
|
153
157
|
"sip-010": "Fungible token standard",
|
|
154
158
|
"sip-013": "Semi-fungible token standard"
|
|
155
159
|
};
|
|
156
|
-
var FILTERS_REFERENCE =
|
|
157
|
-
{
|
|
158
|
-
type: "stx_transfer",
|
|
159
|
-
fields: ["sender", "recipient", "minAmount", "maxAmount"]
|
|
160
|
-
},
|
|
161
|
-
{ type: "stx_mint", fields: ["recipient", "minAmount"] },
|
|
162
|
-
{ type: "stx_burn", fields: ["sender", "minAmount"] },
|
|
163
|
-
{ type: "stx_lock", fields: ["lockedAddress", "minAmount"] },
|
|
164
|
-
{
|
|
165
|
-
type: "ft_transfer",
|
|
166
|
-
fields: ["sender", "recipient", "assetIdentifier", "minAmount", "trait"]
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
type: "ft_mint",
|
|
170
|
-
fields: ["recipient", "assetIdentifier", "minAmount", "trait"]
|
|
171
|
-
},
|
|
172
|
-
{
|
|
173
|
-
type: "ft_burn",
|
|
174
|
-
fields: ["sender", "assetIdentifier", "minAmount", "trait"]
|
|
175
|
-
},
|
|
176
|
-
{
|
|
177
|
-
type: "nft_transfer",
|
|
178
|
-
fields: ["sender", "recipient", "assetIdentifier", "trait"]
|
|
179
|
-
},
|
|
180
|
-
{ type: "nft_mint", fields: ["recipient", "assetIdentifier", "trait"] },
|
|
181
|
-
{ type: "nft_burn", fields: ["sender", "assetIdentifier", "trait"] },
|
|
182
|
-
{
|
|
183
|
-
type: "contract_call",
|
|
184
|
-
fields: ["contractId", "functionName", "caller", "trait", "abi"]
|
|
185
|
-
},
|
|
186
|
-
{ type: "contract_deploy", fields: ["deployer", "contractName"] },
|
|
187
|
-
{ type: "print_event", fields: ["contractId", "topic", "trait"] }
|
|
188
|
-
];
|
|
160
|
+
var FILTERS_REFERENCE = filterFieldsByType();
|
|
189
161
|
var COLUMN_TYPE_DESCRIPTIONS = {
|
|
190
162
|
text: "UTF-8 string",
|
|
191
163
|
uint: "Unsigned integer (Clarity uint) — NUMERIC for lossless 128-bit range",
|
|
@@ -213,7 +185,8 @@ var PRODUCT_BLURBS = {
|
|
|
213
185
|
subgraphs: "author/deploy/query custom indexes",
|
|
214
186
|
subscriptions: "webhook delivery on subgraph rows or raw chain events",
|
|
215
187
|
account: "identity and self-provisioned API keys",
|
|
216
|
-
scaffold: "generate deploy-ready subgraph code from a deployed contract"
|
|
188
|
+
scaffold: "generate deploy-ready subgraph code from a deployed contract",
|
|
189
|
+
codegen: "ORM schemas for the tables you read"
|
|
217
190
|
};
|
|
218
191
|
var PRODUCT_ORDER = [
|
|
219
192
|
"index",
|
|
@@ -222,7 +195,8 @@ var PRODUCT_ORDER = [
|
|
|
222
195
|
"subgraphs",
|
|
223
196
|
"subscriptions",
|
|
224
197
|
"account",
|
|
225
|
-
"scaffold"
|
|
198
|
+
"scaffold",
|
|
199
|
+
"codegen"
|
|
226
200
|
];
|
|
227
201
|
function buildCapabilities() {
|
|
228
202
|
const byPrefix = new Map;
|
|
@@ -354,18 +328,37 @@ function registerAccountTools(server) {
|
|
|
354
328
|
}, async ({ product, name }) => jsonResponse(await getClient().apiKeys.create({ product, name })));
|
|
355
329
|
}
|
|
356
330
|
|
|
357
|
-
// src/tools/
|
|
331
|
+
// src/tools/codegen.ts
|
|
332
|
+
import {
|
|
333
|
+
generateIndexSchema
|
|
334
|
+
} from "@secondlayer/subgraphs";
|
|
358
335
|
import { z as z2 } from "zod";
|
|
336
|
+
var TARGETS = ["prisma", "kysely", "drizzle", "json-schema"];
|
|
337
|
+
function registerCodegenTools(server) {
|
|
338
|
+
defineTool(server, "codegen_index_schema", "Generate an ORM schema for the Index tables (blocks, transactions, decoded_events, …) — the same output as `sl codegen index`. Returns the file contents as text; write it wherever your project keeps its schema. Use `tables` to emit only what you read.", {
|
|
339
|
+
target: z2.enum(TARGETS).optional().describe("Output flavor (default kysely)"),
|
|
340
|
+
tables: z2.array(z2.string()).optional().describe("Restrict to these Index tables (default: all)"),
|
|
341
|
+
schemaName: z2.string().optional().describe("Postgres schema to qualify table names with"),
|
|
342
|
+
datasourceEnv: z2.string().optional().describe("Prisma only: datasource url env var (default DATABASE_URL)")
|
|
343
|
+
}, ({ target, tables, schemaName, datasourceEnv }) => textResponse(generateIndexSchema(target ?? "kysely", {
|
|
344
|
+
tables,
|
|
345
|
+
schemaName,
|
|
346
|
+
datasourceEnv
|
|
347
|
+
})));
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
// src/tools/contracts.ts
|
|
351
|
+
import { z as z3 } from "zod";
|
|
359
352
|
function registerContractTools(server, clientProvider = getClient) {
|
|
360
353
|
defineTool(server, "contracts_find", 'Discover deployed Stacks contracts conforming to a trait (e.g. "sip-010", "sip-009", "sip-013"). The discovery endpoint for "which contracts implement X". Reads are public.', {
|
|
361
|
-
trait:
|
|
362
|
-
conformance:
|
|
363
|
-
include:
|
|
364
|
-
limit:
|
|
365
|
-
cursor:
|
|
354
|
+
trait: z3.string().describe('Required. Trait to match (e.g. "sip-010").'),
|
|
355
|
+
conformance: z3.enum(["declared", "inferred", "any"]).optional().describe("declared = parsed from source, inferred = ABI shape-match, any = either (default)"),
|
|
356
|
+
include: z3.literal("abi").optional().describe(`Set to "abi" to include each contract's full ABI`),
|
|
357
|
+
limit: z3.number().optional().describe("Page size, 1–500 (default 100)"),
|
|
358
|
+
cursor: z3.string().optional().describe("Opaque cursor from a prior response's next_cursor")
|
|
366
359
|
}, async (params) => jsonResponse(await clientProvider().contracts.list(params)));
|
|
367
|
-
defineTool(server, "
|
|
368
|
-
contractId:
|
|
360
|
+
defineTool(server, "contracts_get_abi", "Fetch a single deployed contract's ABI from the registry (prod-safe). Returns the contract's metadata + full ABI (functions, maps, variables, fungible/non-fungible tokens). Returns not_found if the contract isn't in the registry. Use it to inspect a contract before scaffold_from_contract.", {
|
|
361
|
+
contractId: z3.string().describe("Fully qualified contract id (e.g. SP….amm-pool-v2-01)")
|
|
369
362
|
}, async ({ contractId }) => {
|
|
370
363
|
const contract = await clientProvider().contracts.get(contractId, {
|
|
371
364
|
includeAbi: true
|
|
@@ -377,19 +370,19 @@ function registerContractTools(server, clientProvider = getClient) {
|
|
|
377
370
|
message: `Contract not in registry: ${contractId}`
|
|
378
371
|
}
|
|
379
372
|
}, true);
|
|
380
|
-
});
|
|
373
|
+
}, { aliases: ["get_contract_abi"] });
|
|
381
374
|
}
|
|
382
375
|
|
|
383
376
|
// src/tools/index.ts
|
|
384
377
|
import { DECODED_EVENT_TYPES } from "@secondlayer/shared";
|
|
385
|
-
import { z as
|
|
378
|
+
import { z as z4 } from "zod";
|
|
386
379
|
var INDEX_EVENT_TYPES = DECODED_EVENT_TYPES;
|
|
387
380
|
var rangeFilters = {
|
|
388
|
-
contractId:
|
|
389
|
-
fromHeight:
|
|
390
|
-
toHeight:
|
|
391
|
-
cursor:
|
|
392
|
-
limit:
|
|
381
|
+
contractId: z4.string().optional().describe("Filter by contract id"),
|
|
382
|
+
fromHeight: z4.number().optional().describe("Start block height (inclusive)"),
|
|
383
|
+
toHeight: z4.number().optional().describe("End block height (inclusive)"),
|
|
384
|
+
cursor: z4.string().optional().describe("Opaque cursor from a prior response's next_cursor"),
|
|
385
|
+
limit: z4.number().optional().describe("Max rows for this page")
|
|
393
386
|
};
|
|
394
387
|
var heightFilters = {
|
|
395
388
|
fromHeight: rangeFilters.fromHeight,
|
|
@@ -400,51 +393,51 @@ var heightFilters = {
|
|
|
400
393
|
function registerIndexTools(server, clientProvider = getClient) {
|
|
401
394
|
defineTool(server, "index_ft_transfers", "List decoded SIP-010 fungible-token transfers from the Index (decoded layer). Anonymous reads allowed (free-tier API keys are rejected — Build+ required).", {
|
|
402
395
|
...rangeFilters,
|
|
403
|
-
sender:
|
|
404
|
-
recipient:
|
|
396
|
+
sender: z4.string().optional().describe("Filter by sender principal"),
|
|
397
|
+
recipient: z4.string().optional().describe("Filter by recipient principal")
|
|
405
398
|
}, async (params) => jsonResponse(await clientProvider().index.ftTransfers.list(params)));
|
|
406
399
|
defineTool(server, "index_nft_transfers", "List decoded SIP-009 non-fungible-token transfers from the Index. Anonymous reads allowed (free-tier keys rejected).", {
|
|
407
400
|
...rangeFilters,
|
|
408
|
-
sender:
|
|
409
|
-
recipient:
|
|
410
|
-
assetIdentifier:
|
|
401
|
+
sender: z4.string().optional().describe("Filter by sender principal"),
|
|
402
|
+
recipient: z4.string().optional().describe("Filter by recipient principal"),
|
|
403
|
+
assetIdentifier: z4.string().optional().describe("Filter by asset identifier (contract::asset)")
|
|
411
404
|
}, async (params) => jsonResponse(await clientProvider().index.nftTransfers.list(params)));
|
|
412
405
|
defineTool(server, "index_events", "List decoded chain events from the Index by event type. Use this for event types without a dedicated tool (stx_*, ft_mint/burn, nft_mint/burn, print), and for trait-scoped queries: set `trait` (e.g. sip-010) to match all contracts conforming to a standard — pair with contracts_find to discover traits. For ft/nft transfers without a trait prefer index_ft_transfers / index_nft_transfers.", {
|
|
413
|
-
eventType:
|
|
406
|
+
eventType: z4.enum(INDEX_EVENT_TYPES).describe("Required. Decoded event type to list."),
|
|
414
407
|
...rangeFilters,
|
|
415
|
-
sender:
|
|
416
|
-
recipient:
|
|
417
|
-
assetIdentifier:
|
|
418
|
-
trait:
|
|
419
|
-
txContext:
|
|
408
|
+
sender: z4.string().optional().describe("Filter by sender principal"),
|
|
409
|
+
recipient: z4.string().optional().describe("Filter by recipient principal"),
|
|
410
|
+
assetIdentifier: z4.string().optional().describe("Filter by asset identifier where applicable"),
|
|
411
|
+
trait: z4.string().optional().describe("Match contracts conforming to a trait/standard (e.g. sip-010). Mutually exclusive with contractId; contract-keyed event types only."),
|
|
412
|
+
txContext: z4.boolean().optional().describe("Join the submitting transaction into each event (tx_sender, tx_type, tx_status, tx_contract_id, tx_function_name). For print events it's the only source of the submitting sender.")
|
|
420
413
|
}, async (params) => jsonResponse(await clientProvider().index.events.list(params)));
|
|
421
414
|
defineTool(server, "index_contract_calls", "List decoded contract calls from the Index (function name, args, result). Set `trait` (e.g. sip-010) to match calls to all contracts conforming to a standard. Note: contract-call cursors are a SEPARATE keyspace from event cursors — they are not interchangeable.", {
|
|
422
415
|
...rangeFilters,
|
|
423
|
-
functionName:
|
|
424
|
-
sender:
|
|
425
|
-
trait:
|
|
416
|
+
functionName: z4.string().optional().describe("Filter by called function name"),
|
|
417
|
+
sender: z4.string().optional().describe("Filter by caller principal"),
|
|
418
|
+
trait: z4.string().optional().describe("Match contracts conforming to a trait/standard (e.g. sip-010). Mutually exclusive with contractId.")
|
|
426
419
|
}, async (params) => jsonResponse(await clientProvider().index.contractCalls.list(params)));
|
|
427
420
|
defineTool(server, "index_blocks", "List decoded blocks from the Index. Anonymous reads allowed (free-tier keys rejected).", { ...heightFilters }, async (params) => jsonResponse(await clientProvider().index.blocks.list(params)));
|
|
428
421
|
defineTool(server, "index_transactions", "List decoded transactions from the Index. Filter by type, sender, or contract. Anonymous reads allowed (free-tier keys rejected).", {
|
|
429
422
|
...rangeFilters,
|
|
430
|
-
type:
|
|
431
|
-
sender:
|
|
423
|
+
type: z4.string().optional().describe("Filter by transaction type"),
|
|
424
|
+
sender: z4.string().optional().describe("Filter by sender principal")
|
|
432
425
|
}, async (params) => jsonResponse(await clientProvider().index.transactions.list(params)));
|
|
433
426
|
defineTool(server, "index_print_schema", "Empirical per-topic print payload schemas for a contract, inferred from sampled on-chain events: each topic's fields with observed Clarity types, decoded TS types, subgraph column types, and presence rates. Use before writing print_event subgraph handlers to learn what's on e.data. Anonymous read.", {
|
|
434
|
-
contractId:
|
|
427
|
+
contractId: z4.string().describe("Contract id (SP….name) whose print events to profile")
|
|
435
428
|
}, async (params) => jsonResponse(await clientProvider().index.printSchema(params.contractId)));
|
|
436
429
|
defineTool(server, "index_discover", "Discover the Index vocabulary: every event type and its columns, allowed/equality filters, and required-non-null fields (and which types accept `trait`). Read this before building Index queries instead of guessing filters. Anonymous read.", {}, async () => jsonResponse(await clientProvider().index.discover()));
|
|
437
430
|
defineTool(server, "batch_query", "Run up to 10 public /v1 reads in one round trip (POST /v1/batch). Each item keeps its own auth/quota/pay-per-call semantics; results return in order with per-item status. Paths must start with /v1/index, /v1/subgraphs, /v1/streams, or /v1/contracts.", {
|
|
438
|
-
requests:
|
|
439
|
-
path:
|
|
440
|
-
params:
|
|
431
|
+
requests: z4.array(z4.object({
|
|
432
|
+
path: z4.string().describe("Public /v1 read path"),
|
|
433
|
+
params: z4.record(z4.string(), z4.string()).optional()
|
|
441
434
|
})).min(1).max(10).describe("Read descriptors, executed concurrently")
|
|
442
435
|
}, async (params) => jsonResponse(await clientProvider().batch(params.requests)));
|
|
443
436
|
}
|
|
444
437
|
|
|
445
438
|
// src/tools/scaffold.ts
|
|
446
439
|
import { generateSubgraphCode } from "@secondlayer/scaffold";
|
|
447
|
-
import { z as
|
|
440
|
+
import { z as z5 } from "zod";
|
|
448
441
|
async function fetchAbi(clientProvider, contractId) {
|
|
449
442
|
const contract = await clientProvider().contracts.get(contractId, {
|
|
450
443
|
includeAbi: true
|
|
@@ -455,15 +448,15 @@ async function fetchAbi(clientProvider, contractId) {
|
|
|
455
448
|
if (!abi) {
|
|
456
449
|
throw new Error(`No ABI available for ${contractId} (abi_status: ${contract.abi_status})`);
|
|
457
450
|
}
|
|
458
|
-
return { functions: abi.functions ?? []
|
|
451
|
+
return { functions: abi.functions ?? [] };
|
|
459
452
|
}
|
|
460
453
|
function registerScaffoldTools(server, clientProvider = getClient) {
|
|
461
454
|
defineTool(server, "scaffold_from_contract", "Generate a subgraph scaffold from a deployed Stacks contract. Fetches the ABI automatically.", {
|
|
462
|
-
contractId:
|
|
463
|
-
subgraphName:
|
|
455
|
+
contractId: z5.string().describe("Fully qualified contract ID (e.g. SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-pool-v2-01)"),
|
|
456
|
+
subgraphName: z5.string().optional().describe("Override the subgraph name (defaults to contract name)")
|
|
464
457
|
}, async ({ contractId, subgraphName }) => {
|
|
465
|
-
const { functions
|
|
466
|
-
const code = generateSubgraphCode(contractId, functions, subgraphName
|
|
458
|
+
const { functions } = await fetchAbi(clientProvider, contractId);
|
|
459
|
+
const code = generateSubgraphCode(contractId, functions, subgraphName);
|
|
467
460
|
return { content: [{ type: "text", text: code }] };
|
|
468
461
|
});
|
|
469
462
|
}
|
|
@@ -476,26 +469,26 @@ function registerStreamsTools(server, clientProvider = getClient) {
|
|
|
476
469
|
// src/tools/subgraphs.ts
|
|
477
470
|
import { bundleSubgraphCode } from "@secondlayer/bundler";
|
|
478
471
|
import { ByoBreakingChangeError } from "@secondlayer/sdk";
|
|
479
|
-
import { z as
|
|
472
|
+
import { z as z6 } from "zod";
|
|
480
473
|
function registerSubgraphTools(server, clientProvider = getClient) {
|
|
481
474
|
defineTool(server, "subgraphs_list", "List all deployed subgraphs. Returns summary fields only, including visibility — public subgraphs are anon-readable at /v1/subgraphs/<name>.", {}, async () => {
|
|
482
475
|
const { data } = await clientProvider().subgraphs.list();
|
|
483
476
|
return jsonResponse(data.map(formatSubgraphSummary));
|
|
484
477
|
});
|
|
485
|
-
defineTool(server, "subgraphs_get", "Get full details of a subgraph including schema, health, and table columns.", { name:
|
|
478
|
+
defineTool(server, "subgraphs_get", "Get full details of a subgraph including schema, health, and table columns.", { name: z6.string().describe("Subgraph name") }, async ({ name }) => {
|
|
486
479
|
const detail = await clientProvider().subgraphs.get(name);
|
|
487
480
|
return jsonResponse(detail);
|
|
488
481
|
});
|
|
489
482
|
defineTool(server, "subgraphs_query", 'Query rows from a subgraph table (max 200 rows). Filters support operators: "amount.gte": "1000", "sender.neq": "SP...", "name.like": "%token%". Available operators: eq, neq, gt, gte, lt, lte, like. To TAIL new rows (no streaming over MCP): sort=_id, order=desc for the latest, then poll forward with the filter {"_id.gt": "<last _id seen>"}, order=asc. Fetch one row by id with {"_id": "<id>"}. Public subgraphs are also keyless over HTTP at GET /v1/subgraphs/<name>/<table> — { rows, next_cursor, tip } envelope, resume with ?cursor=<next_cursor> + _order=asc|desc (no _offset/_sort on /v1); hand that URL to third parties.', {
|
|
490
|
-
name:
|
|
491
|
-
table:
|
|
492
|
-
filters:
|
|
493
|
-
sort:
|
|
494
|
-
order:
|
|
495
|
-
limit:
|
|
496
|
-
offset:
|
|
497
|
-
fields:
|
|
498
|
-
count:
|
|
483
|
+
name: z6.string().describe("Subgraph name"),
|
|
484
|
+
table: z6.string().describe("Table name"),
|
|
485
|
+
filters: z6.record(z6.string(), z6.string()).optional().describe('Column filters — plain values or with operators (e.g. {"amount.gte": "1000", "sender": "SP..."})'),
|
|
486
|
+
sort: z6.string().optional().describe("Column to sort by"),
|
|
487
|
+
order: z6.enum(["asc", "desc"]).optional().describe("Sort order"),
|
|
488
|
+
limit: z6.number().max(200).optional().describe("Max rows (default 50, max 200)"),
|
|
489
|
+
offset: z6.number().optional().describe("Offset for pagination"),
|
|
490
|
+
fields: z6.string().optional().describe('Comma-separated column list to return (e.g. "sender,amount")'),
|
|
491
|
+
count: z6.boolean().optional().describe("If true, return row count instead of rows")
|
|
499
492
|
}, async ({
|
|
500
493
|
name,
|
|
501
494
|
table,
|
|
@@ -523,9 +516,9 @@ function registerSubgraphTools(server, clientProvider = getClient) {
|
|
|
523
516
|
return jsonResponse(result);
|
|
524
517
|
});
|
|
525
518
|
defineTool(server, "subgraphs_reindex", "Reindex a subgraph from a specific block range. Returns an operationId — check subgraphs_get (health) or the REST operations endpoint to track progress to completion.", {
|
|
526
|
-
name:
|
|
527
|
-
fromBlock:
|
|
528
|
-
toBlock:
|
|
519
|
+
name: z6.string().describe("Subgraph name"),
|
|
520
|
+
fromBlock: z6.number().optional().describe("Start block (defaults to beginning)"),
|
|
521
|
+
toBlock: z6.number().optional().describe("End block (defaults to latest)")
|
|
529
522
|
}, async ({ name, fromBlock, toBlock }) => {
|
|
530
523
|
const result = await clientProvider().subgraphs.reindex(name, {
|
|
531
524
|
fromBlock,
|
|
@@ -534,9 +527,9 @@ function registerSubgraphTools(server, clientProvider = getClient) {
|
|
|
534
527
|
return jsonResponse(result);
|
|
535
528
|
});
|
|
536
529
|
defineTool(server, "subgraphs_backfill", "Backfill a subgraph over a block range. Non-destructive forward fill (does not drop existing data) — unlike subgraphs_reindex, and the only data-fill path for BYO subgraphs (reindex is blocked there). Both blocks required. Returns an operationId — check subgraphs_get (health) or the REST operations endpoint to track progress.", {
|
|
537
|
-
name:
|
|
538
|
-
fromBlock:
|
|
539
|
-
toBlock:
|
|
530
|
+
name: z6.string().describe("Subgraph name"),
|
|
531
|
+
fromBlock: z6.number().int().nonnegative().describe("Start block (inclusive)"),
|
|
532
|
+
toBlock: z6.number().int().nonnegative().describe("End block (inclusive)")
|
|
540
533
|
}, async ({ name, fromBlock, toBlock }) => {
|
|
541
534
|
const result = await clientProvider().subgraphs.backfill(name, {
|
|
542
535
|
fromBlock,
|
|
@@ -544,15 +537,15 @@ function registerSubgraphTools(server, clientProvider = getClient) {
|
|
|
544
537
|
});
|
|
545
538
|
return jsonResponse(result);
|
|
546
539
|
});
|
|
547
|
-
defineTool(server, "subgraphs_stop", "Cancel an in-flight reindex or backfill operation for a subgraph. Returns the stop request status; check subgraphs_get (health) or the REST operations endpoint to confirm it reaches a terminal state.", { name:
|
|
540
|
+
defineTool(server, "subgraphs_stop", "Cancel an in-flight reindex or backfill operation for a subgraph. Returns the stop request status; check subgraphs_get (health) or the REST operations endpoint to confirm it reaches a terminal state.", { name: z6.string().describe("Subgraph name") }, async ({ name }) => {
|
|
548
541
|
const result = await clientProvider().subgraphs.stop(name);
|
|
549
542
|
return jsonResponse(result);
|
|
550
543
|
});
|
|
551
544
|
defineTool(server, "subgraphs_gaps", "List indexing gaps (missing block ranges) for a subgraph. Each gap reports start/end/size, reason, and detected/resolved timestamps. Feed an unresolved gap's range into subgraphs_backfill to fill it. Defaults to unresolved gaps.", {
|
|
552
|
-
name:
|
|
553
|
-
limit:
|
|
554
|
-
offset:
|
|
555
|
-
resolved:
|
|
545
|
+
name: z6.string().describe("Subgraph name"),
|
|
546
|
+
limit: z6.number().int().positive().optional().describe("Max gaps to return"),
|
|
547
|
+
offset: z6.number().int().nonnegative().optional().describe("Pagination offset"),
|
|
548
|
+
resolved: z6.boolean().optional().describe("Filter by resolved state (omit for unresolved only)")
|
|
556
549
|
}, async ({ name, limit, offset, resolved }) => {
|
|
557
550
|
const result = await clientProvider().subgraphs.gaps(name, {
|
|
558
551
|
limit,
|
|
@@ -561,16 +554,16 @@ function registerSubgraphTools(server, clientProvider = getClient) {
|
|
|
561
554
|
});
|
|
562
555
|
return jsonResponse(result);
|
|
563
556
|
});
|
|
564
|
-
defineTool(server, "subgraphs_delete", "Delete a subgraph permanently.", { name:
|
|
557
|
+
defineTool(server, "subgraphs_delete", "Delete a subgraph permanently.", { name: z6.string().describe("Subgraph name") }, async ({ name }) => {
|
|
565
558
|
const result = await clientProvider().subgraphs.delete(name);
|
|
566
559
|
return textResponse(result.message);
|
|
567
560
|
});
|
|
568
561
|
defineTool(server, "subgraphs_deploy", "Deploy a subgraph from TypeScript code. Pass the full defineSubgraph() source — it will be bundled, validated, and deployed. Optional startBlock overrides the source definition for this deploy. Set dryRun to validate and preview the schema/DDL without writing anything. Set databaseUrl to deploy to your own Postgres (BYO data plane) — the server verifies the connection first; with dryRun it returns the DDL + grant script. A breaking BYO schema change is refused and returns a migration plan (drop + rebuild DDL) instead of deploying. Visibility defaults: managed deploys are public (anon-readable at /v1/subgraphs/<name>, name claimed in the global public namespace), BYO deploys are private. Call `subgraphs_reindex` separately if you need a forced reindex.", {
|
|
569
|
-
code:
|
|
570
|
-
startBlock:
|
|
571
|
-
databaseUrl:
|
|
572
|
-
dryRun:
|
|
573
|
-
visibility:
|
|
562
|
+
code: z6.string().describe("TypeScript source code containing a defineSubgraph() call"),
|
|
563
|
+
startBlock: z6.number().int().nonnegative().optional().describe("Override the definition startBlock for this deploy"),
|
|
564
|
+
databaseUrl: z6.string().optional().describe("BYO data plane: Postgres connection string to host the subgraph's schema and rows in your own database"),
|
|
565
|
+
dryRun: z6.boolean().optional().describe("Validate and preview the deploy (schema/DDL, BYO connection) without writing changes"),
|
|
566
|
+
visibility: z6.enum(["public", "private"]).optional().describe("Read visibility: public = anon /v1 reads + global name claim; private = owning account's key only. Defaults: managed → public, BYO → private.")
|
|
574
567
|
}, async ({ code, startBlock, databaseUrl, dryRun, visibility }) => {
|
|
575
568
|
const bundled = await bundleSubgraphCode(code);
|
|
576
569
|
try {
|
|
@@ -595,11 +588,11 @@ function registerSubgraphTools(server, clientProvider = getClient) {
|
|
|
595
588
|
throw err;
|
|
596
589
|
}
|
|
597
590
|
});
|
|
598
|
-
defineTool(server, "subgraphs_publish", "Make a subgraph publicly readable at /v1/subgraphs/<name> — anyone (or any agent) can read it without a key. Claims the name in the global public namespace; fails with PUBLIC_NAME_TAKEN if another account holds it.", { name:
|
|
591
|
+
defineTool(server, "subgraphs_publish", "Make a subgraph publicly readable at /v1/subgraphs/<name> — anyone (or any agent) can read it without a key. Claims the name in the global public namespace; fails with PUBLIC_NAME_TAKEN if another account holds it.", { name: z6.string().describe("Subgraph name") }, async ({ name }) => {
|
|
599
592
|
const result = await clientProvider().subgraphs.publish(name);
|
|
600
593
|
return jsonResponse(result);
|
|
601
594
|
});
|
|
602
|
-
defineTool(server, "subgraphs_unpublish", "Make a subgraph private again — /v1 reads then require the owning account's bearer key, and the global public name claim is released.", { name:
|
|
595
|
+
defineTool(server, "subgraphs_unpublish", "Make a subgraph private again — /v1 reads then require the owning account's bearer key, and the global public name claim is released.", { name: z6.string().describe("Subgraph name") }, async ({ name }) => {
|
|
603
596
|
const result = await clientProvider().subgraphs.unpublish(name);
|
|
604
597
|
return jsonResponse(result);
|
|
605
598
|
});
|
|
@@ -607,38 +600,38 @@ function registerSubgraphTools(server, clientProvider = getClient) {
|
|
|
607
600
|
|
|
608
601
|
// src/tools/subscriptions.ts
|
|
609
602
|
import { CHAIN_TRIGGER_TYPES } from "@secondlayer/shared";
|
|
610
|
-
import { z as
|
|
603
|
+
import { z as z7 } from "zod";
|
|
611
604
|
function registerSubscriptionTools(server, clientProvider = getClient) {
|
|
612
605
|
defineTool(server, "subscriptions_list", "List all subscriptions for the current account. Returns summary fields (no secrets).", {}, async () => {
|
|
613
606
|
const { data } = await clientProvider().subscriptions.list();
|
|
614
607
|
return jsonResponse(data);
|
|
615
608
|
});
|
|
616
|
-
defineTool(server, "subscriptions_get", "Get full detail for a subscription (filter, auth, retry config, circuit state).", { id:
|
|
609
|
+
defineTool(server, "subscriptions_get", "Get full detail for a subscription (filter, auth, retry config, circuit state).", { id: z7.string().describe("Subscription id") }, async ({ id }) => {
|
|
617
610
|
const detail = await clientProvider().subscriptions.get(id);
|
|
618
611
|
return jsonResponse(detail);
|
|
619
612
|
});
|
|
620
613
|
defineTool(server, "subscriptions_create", "Create a subscription. Two kinds (mutually exclusive): a SUBGRAPH subscription fires on a subgraph table's rows (set subgraphName + tableName + optional filter); a CHAIN subscription fires on raw chain events with no subgraph (set triggers). Returns `signingSecret` ONCE — forward it to the user so they can wire it into their receiver.", {
|
|
621
|
-
name:
|
|
622
|
-
subgraphName:
|
|
623
|
-
tableName:
|
|
624
|
-
triggers:
|
|
625
|
-
type:
|
|
626
|
-
contractId:
|
|
627
|
-
functionName:
|
|
628
|
-
caller:
|
|
629
|
-
sender:
|
|
630
|
-
recipient:
|
|
631
|
-
assetIdentifier:
|
|
632
|
-
deployer:
|
|
633
|
-
contractName:
|
|
634
|
-
topic:
|
|
635
|
-
lockedAddress:
|
|
636
|
-
trait:
|
|
637
|
-
minAmount:
|
|
638
|
-
maxAmount:
|
|
614
|
+
name: z7.string().describe("Human-readable name, unique per account"),
|
|
615
|
+
subgraphName: z7.string().optional().describe("Subgraph to subscribe to (subgraph subscription)"),
|
|
616
|
+
tableName: z7.string().optional().describe("Table within the subgraph (subgraph subscription)"),
|
|
617
|
+
triggers: z7.array(z7.object({
|
|
618
|
+
type: z7.enum(CHAIN_TRIGGER_TYPES),
|
|
619
|
+
contractId: z7.string().optional(),
|
|
620
|
+
functionName: z7.string().optional(),
|
|
621
|
+
caller: z7.string().optional(),
|
|
622
|
+
sender: z7.string().optional(),
|
|
623
|
+
recipient: z7.string().optional(),
|
|
624
|
+
assetIdentifier: z7.string().optional(),
|
|
625
|
+
deployer: z7.string().optional(),
|
|
626
|
+
contractName: z7.string().optional(),
|
|
627
|
+
topic: z7.string().optional(),
|
|
628
|
+
lockedAddress: z7.string().optional(),
|
|
629
|
+
trait: z7.string().optional(),
|
|
630
|
+
minAmount: z7.union([z7.string(), z7.number()]).optional(),
|
|
631
|
+
maxAmount: z7.union([z7.string(), z7.number()]).optional()
|
|
639
632
|
})).optional().describe("Chain triggers (chain subscription) — provide INSTEAD of subgraphName/tableName. Each targets a raw chain event/tx; string fields accept `*` wildcards, `trait` scopes to a SIP/trait. Per-type accepted fields: see the secondlayer://chain-triggers resource. Forward-looking: starts at chain tip, no backfill."),
|
|
640
|
-
url:
|
|
641
|
-
format:
|
|
633
|
+
url: z7.string().describe("Webhook URL"),
|
|
634
|
+
format: z7.enum([
|
|
642
635
|
"standard-webhooks",
|
|
643
636
|
"inngest",
|
|
644
637
|
"trigger",
|
|
@@ -646,20 +639,20 @@ function registerSubscriptionTools(server, clientProvider = getClient) {
|
|
|
646
639
|
"cloudevents",
|
|
647
640
|
"raw"
|
|
648
641
|
]).optional().describe("Wire format (default standard-webhooks)"),
|
|
649
|
-
runtime:
|
|
650
|
-
filter:
|
|
651
|
-
authConfig:
|
|
642
|
+
runtime: z7.enum(["inngest", "trigger", "cloudflare", "node"]).optional().describe("Receiver runtime label (display only)"),
|
|
643
|
+
filter: z7.record(z7.string(), z7.unknown()).optional().describe('Scalar filter DSL, e.g. {"amount": {"gte": 100}, "sender": "SP..."}'),
|
|
644
|
+
authConfig: z7.record(z7.string(), z7.unknown()).optional().describe('Receiver auth sent with each delivery, e.g. {"type": "bearer", "token": "..."}')
|
|
652
645
|
}, async (input) => {
|
|
653
646
|
const res = await clientProvider().subscriptions.create(input);
|
|
654
647
|
return jsonResponse(res);
|
|
655
648
|
});
|
|
656
649
|
defineTool(server, "subscriptions_update", "Patch a subscription (name, url, filter, authConfig, format, runtime, retry, timeout, concurrency).", {
|
|
657
|
-
id:
|
|
658
|
-
name:
|
|
659
|
-
url:
|
|
660
|
-
filter:
|
|
661
|
-
authConfig:
|
|
662
|
-
format:
|
|
650
|
+
id: z7.string(),
|
|
651
|
+
name: z7.string().optional().describe("Rename the subscription"),
|
|
652
|
+
url: z7.string().optional(),
|
|
653
|
+
filter: z7.record(z7.string(), z7.unknown()).optional(),
|
|
654
|
+
authConfig: z7.record(z7.string(), z7.unknown()).optional().describe("Receiver auth sent with each delivery (bearer/etc.)"),
|
|
655
|
+
format: z7.enum([
|
|
663
656
|
"standard-webhooks",
|
|
664
657
|
"inngest",
|
|
665
658
|
"trigger",
|
|
@@ -667,27 +660,27 @@ function registerSubscriptionTools(server, clientProvider = getClient) {
|
|
|
667
660
|
"cloudevents",
|
|
668
661
|
"raw"
|
|
669
662
|
]).optional(),
|
|
670
|
-
runtime:
|
|
671
|
-
maxRetries:
|
|
672
|
-
timeoutMs:
|
|
673
|
-
concurrency:
|
|
663
|
+
runtime: z7.enum(["inngest", "trigger", "cloudflare", "node"]).nullable().optional(),
|
|
664
|
+
maxRetries: z7.number().int().min(0).optional(),
|
|
665
|
+
timeoutMs: z7.number().int().min(100).optional(),
|
|
666
|
+
concurrency: z7.number().int().min(1).optional()
|
|
674
667
|
}, async ({ id, ...patch }) => {
|
|
675
668
|
const res = await clientProvider().subscriptions.update(id, patch);
|
|
676
669
|
return jsonResponse(res);
|
|
677
670
|
});
|
|
678
|
-
defineTool(server, "subscriptions_delete", "Delete a subscription. Pending outbox rows are cascade-deleted.", { id:
|
|
671
|
+
defineTool(server, "subscriptions_delete", "Delete a subscription. Pending outbox rows are cascade-deleted.", { id: z7.string() }, async ({ id }) => {
|
|
679
672
|
const res = await clientProvider().subscriptions.delete(id);
|
|
680
673
|
return jsonResponse(res);
|
|
681
674
|
});
|
|
682
|
-
defineTool(server, "subscriptions_test", "Send a one-off test webhook to a subscription's URL (built for its format, SSRF-guarded). Logged as a delivery row. Returns {ok, statusCode, error, durationMs, deliveryId}.", { id:
|
|
675
|
+
defineTool(server, "subscriptions_test", "Send a one-off test webhook to a subscription's URL (built for its format, SSRF-guarded). Logged as a delivery row. Returns {ok, statusCode, error, durationMs, deliveryId}.", { id: z7.string().describe("Subscription id") }, async ({ id }) => {
|
|
683
676
|
const res = await clientProvider().subscriptions.test(id);
|
|
684
677
|
return jsonResponse(res);
|
|
685
678
|
});
|
|
686
679
|
defineTool(server, "subscriptions_replay", "Replay a block range for a subscription. Replays run at 10% of batch capacity — use sparingly. Pass `force` (a short idempotency suffix) to re-run a range that was already replayed.", {
|
|
687
|
-
id:
|
|
688
|
-
fromBlock:
|
|
689
|
-
toBlock:
|
|
690
|
-
force:
|
|
680
|
+
id: z7.string(),
|
|
681
|
+
fromBlock: z7.number().int().nonnegative(),
|
|
682
|
+
toBlock: z7.number().int().nonnegative(),
|
|
683
|
+
force: z7.string().optional().describe("Idempotency suffix to force a duplicate replay of the range")
|
|
691
684
|
}, async ({ id, fromBlock, toBlock, force }) => {
|
|
692
685
|
const res = await clientProvider().subscriptions.replay(id, {
|
|
693
686
|
fromBlock,
|
|
@@ -713,6 +706,7 @@ function createServer() {
|
|
|
713
706
|
registerIndexTools(server);
|
|
714
707
|
registerStreamsTools(server);
|
|
715
708
|
registerContractTools(server);
|
|
709
|
+
registerCodegenTools(server);
|
|
716
710
|
registerResources(server);
|
|
717
711
|
return server;
|
|
718
712
|
}
|
|
@@ -803,5 +797,5 @@ httpServer.listen(port, () => {
|
|
|
803
797
|
console.error("Warning: SECONDLAYER_MCP_SECRET not set, authentication disabled");
|
|
804
798
|
});
|
|
805
799
|
|
|
806
|
-
//# debugId=
|
|
800
|
+
//# debugId=1F6FB5DD9503BE4D64756E2164756E21
|
|
807
801
|
//# sourceMappingURL=bin-http.js.map
|