@secondlayer/mcp 3.9.0 → 4.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 +20 -20
- package/dist/bin-http.js +163 -541
- package/dist/bin-http.js.map +13 -15
- package/dist/bin.js +163 -541
- package/dist/bin.js.map +13 -15
- package/dist/index.js +163 -541
- package/dist/index.js.map +13 -15
- package/package.json +5 -5
package/dist/bin.js
CHANGED
|
@@ -10,26 +10,54 @@ import { fileURLToPath } from "node:url";
|
|
|
10
10
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
11
11
|
|
|
12
12
|
// src/resources.ts
|
|
13
|
-
import { CHAIN_TRIGGER_FIELDS
|
|
13
|
+
import { CHAIN_TRIGGER_FIELDS } from "@secondlayer/shared";
|
|
14
14
|
import { TRAIT_STANDARDS } from "@secondlayer/stacks/clarity";
|
|
15
15
|
import { TYPE_MAP } from "@secondlayer/subgraphs/schema";
|
|
16
16
|
|
|
17
17
|
// src/lib/client.ts
|
|
18
|
-
import { SecondLayer } from "@secondlayer/sdk";
|
|
18
|
+
import { SecondLayer, readX402Receipt, withX402 } from "@secondlayer/sdk";
|
|
19
|
+
import { privateKeyToAccount } from "@secondlayer/stacks/accounts";
|
|
19
20
|
var instance = null;
|
|
20
21
|
function readApiKey() {
|
|
21
22
|
return process.env.SL_API_KEY;
|
|
22
23
|
}
|
|
24
|
+
function buildFetchImpl() {
|
|
25
|
+
const key = process.env.X402_PRIVATE_KEY;
|
|
26
|
+
if (!key)
|
|
27
|
+
return;
|
|
28
|
+
const account = privateKeyToAccount(key);
|
|
29
|
+
const topUpUsd = Number(process.env.X402_TOPUP_USD ?? "");
|
|
30
|
+
const paid = withX402(fetch, {
|
|
31
|
+
account,
|
|
32
|
+
...Number.isFinite(topUpUsd) && topUpUsd > 0 ? {
|
|
33
|
+
topUp: {
|
|
34
|
+
usd: topUpUsd,
|
|
35
|
+
whenBelow: Number(process.env.X402_TOPUP_WHEN_BELOW ?? "0.5")
|
|
36
|
+
}
|
|
37
|
+
} : {}
|
|
38
|
+
});
|
|
39
|
+
const wrapped = async (input, init) => {
|
|
40
|
+
const res = await paid(input, init);
|
|
41
|
+
const receipt = readX402Receipt(res);
|
|
42
|
+
if (receipt) {
|
|
43
|
+
console.error(`[x402] paid call settled tier=${receipt.state ?? "confirmed"} txid=${receipt.txid}`);
|
|
44
|
+
}
|
|
45
|
+
return res;
|
|
46
|
+
};
|
|
47
|
+
return wrapped;
|
|
48
|
+
}
|
|
23
49
|
function getClient() {
|
|
24
50
|
if (!instance) {
|
|
25
51
|
const apiKey = readApiKey();
|
|
26
52
|
const baseUrl = process.env.SECONDLAYER_API_URL;
|
|
27
53
|
const dumpsBaseUrl = process.env.SL_STREAMS_DUMPS_URL;
|
|
54
|
+
const fetchImpl = buildFetchImpl();
|
|
28
55
|
instance = new SecondLayer({
|
|
29
56
|
...apiKey ? { apiKey } : {},
|
|
30
57
|
origin: "mcp",
|
|
31
58
|
...baseUrl ? { baseUrl } : {},
|
|
32
|
-
...dumpsBaseUrl ? { dumpsBaseUrl } : {}
|
|
59
|
+
...dumpsBaseUrl ? { dumpsBaseUrl } : {},
|
|
60
|
+
...fetchImpl ? { fetchImpl } : {}
|
|
33
61
|
});
|
|
34
62
|
}
|
|
35
63
|
return instance;
|
|
@@ -170,25 +198,21 @@ var COLUMN_TYPES = [
|
|
|
170
198
|
}
|
|
171
199
|
];
|
|
172
200
|
var PRODUCT_BLURBS = {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
contracts: "trait-based contract discovery",
|
|
201
|
+
index: "decoded L2 events, transfers, contract calls, blocks, transactions",
|
|
202
|
+
streams: "bulk parquet dumps of the raw chain event firehose",
|
|
203
|
+
contracts: "trait-based contract discovery and ABIs",
|
|
177
204
|
subgraphs: "author/deploy/query custom indexes",
|
|
178
205
|
subscriptions: "webhook delivery on subgraph rows or raw chain events",
|
|
179
|
-
account: "identity
|
|
180
|
-
|
|
181
|
-
scaffold: "generate typed contract clients from a deployment or ABI"
|
|
206
|
+
account: "identity and self-provisioned API keys",
|
|
207
|
+
scaffold: "generate deploy-ready subgraph code from a deployed contract"
|
|
182
208
|
};
|
|
183
209
|
var PRODUCT_ORDER = [
|
|
184
|
-
"datasets",
|
|
185
210
|
"index",
|
|
186
211
|
"streams",
|
|
187
212
|
"contracts",
|
|
188
213
|
"subgraphs",
|
|
189
214
|
"subscriptions",
|
|
190
215
|
"account",
|
|
191
|
-
"project",
|
|
192
216
|
"scaffold"
|
|
193
217
|
];
|
|
194
218
|
function buildCapabilities() {
|
|
@@ -210,11 +234,17 @@ function buildCapabilities() {
|
|
|
210
234
|
});
|
|
211
235
|
return {
|
|
212
236
|
products,
|
|
213
|
-
discoverFirst: "Call
|
|
237
|
+
discoverFirst: "Call index_discover / contracts_find to learn what exists (and which filters each surface accepts) before querying."
|
|
214
238
|
};
|
|
215
239
|
}
|
|
240
|
+
var X402_CAPABILITY = {
|
|
241
|
+
what: "Index and Streams reads (/v1/index/*, /v1/streams/*) accept x402 v2 pay-per-call (network stacks:1, sponsored transfers — the payer holds sBTC/STX/USDCx, never gas). Index grants 1,000 free reads/day/IP before any 402; a paid Streams call opens a 500-call/1h PAYMENT-SESSION.",
|
|
242
|
+
paidWrites: "POST /v1/subgraphs (x402 $2) deploys a subgraph owned by the paying wallet — live from deploy, 7-day TTL, renewable via POST /v1/subgraphs/{name}/renew ($0.50/wk); claiming the account clears the expiry.",
|
|
243
|
+
prepaid: "POST /v1/x402/deposit?usd=N loads a prepaid tab (PAYMENT-BALANCE token, $0.25 min) — calls debit it instantly, no per-call on-chain settle. GET /v1/x402/balance reads it.",
|
|
244
|
+
discovery: "GET /v1/x402/supported on the API host for scheme, assets, prices, quotas, sessions, and prepaid metadata.",
|
|
245
|
+
autopay: "Set X402_PRIVATE_KEY (a Stacks private key holding an accepted token) and this MCP server pays 402 challenges automatically (sessions replayed). Add X402_TOPUP_USD (and optionally X402_TOPUP_WHEN_BELOW) for an autonomous prepaid tab that refills itself. Receipts are logged per paid call."
|
|
246
|
+
};
|
|
216
247
|
var READ_AUTH_TIERS = {
|
|
217
|
-
datasets: "open — no API key required",
|
|
218
248
|
index: "anonymous reads allowed; free-tier API keys are rejected (Build+ required)",
|
|
219
249
|
streams: "API key required (SL_API_KEY) — keyless calls return 401",
|
|
220
250
|
subgraphs: "public subgraphs anon-readable at /v1/subgraphs/<name>/<table> ({ rows, next_cursor, tip } cursor envelope); private subgraphs need the owning account's API key (anon → 404); writes require an API key"
|
|
@@ -224,7 +254,10 @@ async function buildContext(deps = { clientProvider: getClient }) {
|
|
|
224
254
|
const orNull = (v) => v == null ? unavailable : v;
|
|
225
255
|
const snap = await deps.clientProvider().context().catch(() => null);
|
|
226
256
|
return {
|
|
227
|
-
authState: {
|
|
257
|
+
authState: {
|
|
258
|
+
apiKeySet: Boolean(process.env.SL_API_KEY),
|
|
259
|
+
x402WalletSet: Boolean(process.env.X402_PRIVATE_KEY)
|
|
260
|
+
},
|
|
228
261
|
whatExists: {
|
|
229
262
|
account: orNull(snap?.account),
|
|
230
263
|
streamsTip: orNull(snap?.streamsTip),
|
|
@@ -236,7 +269,8 @@ async function buildContext(deps = { clientProvider: getClient }) {
|
|
|
236
269
|
activeOperations: orNull(snap?.activeOperations)
|
|
237
270
|
},
|
|
238
271
|
whatYouCanDo: buildCapabilities(),
|
|
239
|
-
readAuthTiers: READ_AUTH_TIERS
|
|
272
|
+
readAuthTiers: READ_AUTH_TIERS,
|
|
273
|
+
payPerCall: X402_CAPABILITY
|
|
240
274
|
};
|
|
241
275
|
}
|
|
242
276
|
function registerResources(server) {
|
|
@@ -285,29 +319,6 @@ function registerResources(server) {
|
|
|
285
319
|
}
|
|
286
320
|
]
|
|
287
321
|
}));
|
|
288
|
-
server.resource("streams-filters", "secondlayer://streams-filters", {
|
|
289
|
-
description: "Streams firehose vocabulary — the decoded event types and the filter fields accepted by streams_events / streams_consume."
|
|
290
|
-
}, async () => ({
|
|
291
|
-
contents: [
|
|
292
|
-
{
|
|
293
|
-
uri: "secondlayer://streams-filters",
|
|
294
|
-
mimeType: "application/json",
|
|
295
|
-
text: JSON.stringify({
|
|
296
|
-
eventTypes: [...DECODED_EVENT_TYPES],
|
|
297
|
-
filters: {
|
|
298
|
-
types: "include only these event types (array)",
|
|
299
|
-
notTypes: "exclude these event types (array)",
|
|
300
|
-
contractId: "match a contract id",
|
|
301
|
-
sender: "match the sender principal",
|
|
302
|
-
recipient: "match the recipient principal",
|
|
303
|
-
assetIdentifier: "match the asset identifier (contract::asset)",
|
|
304
|
-
fromHeight: "start block height (inclusive)",
|
|
305
|
-
toHeight: "end block height (inclusive)"
|
|
306
|
-
}
|
|
307
|
-
}, null, 2)
|
|
308
|
-
}
|
|
309
|
-
]
|
|
310
|
-
}));
|
|
311
322
|
server.resource("chain-triggers", "secondlayer://chain-triggers", {
|
|
312
323
|
description: "Chain-subscription trigger types and the filter fields each accepts (for subscriptions_create triggers)."
|
|
313
324
|
}, async () => ({
|
|
@@ -328,50 +339,13 @@ function registerAccountTools(server) {
|
|
|
328
339
|
const result = await apiRequest("GET", "/api/accounts/me");
|
|
329
340
|
return jsonResponse(result);
|
|
330
341
|
});
|
|
331
|
-
defineTool(server, "account_update", "Update the authenticated account's profile. Requires an API key.", {
|
|
332
|
-
displayName: z.string().optional().describe("Display name"),
|
|
333
|
-
bio: z.string().optional().describe("Profile bio"),
|
|
334
|
-
slug: z.string().optional().describe("Account URL slug")
|
|
335
|
-
}, async ({ displayName, bio, slug }) => {
|
|
336
|
-
const body = {};
|
|
337
|
-
if (displayName !== undefined)
|
|
338
|
-
body.display_name = displayName;
|
|
339
|
-
if (bio !== undefined)
|
|
340
|
-
body.bio = bio;
|
|
341
|
-
if (slug !== undefined)
|
|
342
|
-
body.slug = slug;
|
|
343
|
-
const result = await apiRequest("PATCH", "/api/accounts/me", body);
|
|
344
|
-
return jsonResponse(result);
|
|
345
|
-
});
|
|
346
|
-
defineTool(server, "account_billing", "Show the account's plan and subscription/billing status. Requires an API key. (Plan upgrade / Stripe portal / checkout are deliberately not agent tools — they are session-only human-payment flows; use account_set_caps to bound spend.)", {}, async () => {
|
|
347
|
-
const result = await apiRequest("GET", "/api/billing/status");
|
|
348
|
-
return jsonResponse(result);
|
|
349
|
-
});
|
|
350
342
|
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.", {
|
|
351
343
|
product: z.enum(["streams", "index"]).optional().describe("Key scope (default streams)"),
|
|
352
344
|
name: z.string().optional().describe("Optional label for the key")
|
|
353
345
|
}, async ({ product, name }) => jsonResponse(await getClient().apiKeys.create({ product, name })));
|
|
354
|
-
defineTool(server, "account_list_keys", "List the account's API keys (metadata only — prefix, name, status, product, tier, last used; never the plaintext). Requires an account-level (owner) API key.", {}, async () => jsonResponse(await getClient().apiKeys.list()));
|
|
355
|
-
defineTool(server, "account_revoke_key", "Revoke an API key by id. Requests using that key stop working immediately. Requires an account-level (owner) API key.", { id: z.string().describe("Key id from account_list_keys") }, async ({ id }) => jsonResponse(await getClient().apiKeys.revoke(id)));
|
|
356
|
-
defineTool(server, "account_usage", "Show the current billing period's usage snapshot: spend (with cap/projection), compute, storage, and per-project breakdown. Requires an API key.", {}, async () => jsonResponse(await apiRequest("GET", "/api/accounts/usage")));
|
|
357
|
-
defineTool(server, "account_get_caps", "Show the account's spend caps and alert threshold. Requires an account-level (owner) API key.", {}, async () => jsonResponse(await apiRequest("GET", "/api/billing/caps")));
|
|
358
|
-
defineTool(server, "account_set_caps", "Set the account's spend caps and alert threshold (no payment — just bounds spend). Requires an account-level (owner) API key.", {
|
|
359
|
-
monthlyCapCents: z.number().int().nonnegative().optional().describe("Total monthly spend cap in cents"),
|
|
360
|
-
computeCapCents: z.number().int().nonnegative().optional().describe("Compute spend cap in cents"),
|
|
361
|
-
storageCapCents: z.number().int().nonnegative().optional().describe("Storage spend cap in cents"),
|
|
362
|
-
alertThresholdPct: z.number().int().min(1).max(100).optional().describe("Percent of cap that triggers an alert (1-100)")
|
|
363
|
-
}, async (caps) => {
|
|
364
|
-
const body = {};
|
|
365
|
-
for (const [k, v] of Object.entries(caps)) {
|
|
366
|
-
if (v !== undefined)
|
|
367
|
-
body[k] = v;
|
|
368
|
-
}
|
|
369
|
-
return jsonResponse(await apiRequest("PATCH", "/api/billing/caps", body));
|
|
370
|
-
});
|
|
371
346
|
}
|
|
372
347
|
|
|
373
348
|
// src/tools/contracts.ts
|
|
374
|
-
import { generateContractInterface } from "@secondlayer/scaffold";
|
|
375
349
|
import { z as z2 } from "zod/v4";
|
|
376
350
|
function registerContractTools(server, clientProvider = getClient) {
|
|
377
351
|
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.', {
|
|
@@ -381,7 +355,7 @@ function registerContractTools(server, clientProvider = getClient) {
|
|
|
381
355
|
limit: z2.number().optional().describe("Page size, 1–500 (default 100)"),
|
|
382
356
|
cursor: z2.string().optional().describe("Opaque cursor from a prior response's next_cursor")
|
|
383
357
|
}, async (params) => jsonResponse(await clientProvider().contracts.list(params)));
|
|
384
|
-
defineTool(server, "get_contract_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.
|
|
358
|
+
defineTool(server, "get_contract_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.", {
|
|
385
359
|
contractId: z2.string().describe("Fully qualified contract id (e.g. SP….amm-pool-v2-01)")
|
|
386
360
|
}, async ({ contractId }) => {
|
|
387
361
|
const contract = await clientProvider().contracts.get(contractId, {
|
|
@@ -395,72 +369,18 @@ function registerContractTools(server, clientProvider = getClient) {
|
|
|
395
369
|
}
|
|
396
370
|
}, true);
|
|
397
371
|
});
|
|
398
|
-
defineTool(server, "generate_contract_interface", "Generate a typed TypeScript contract-client interface (typed methods + map/var/constant readers) from a deployed contract's ABI (fetched from the registry). Returns not_found if the contract isn't in the registry.", {
|
|
399
|
-
contractId: z2.string().describe("Fully qualified contract id (e.g. SP….amm-pool-v2-01)")
|
|
400
|
-
}, async ({ contractId }) => {
|
|
401
|
-
const c = await clientProvider().contracts.get(contractId, {
|
|
402
|
-
includeAbi: true
|
|
403
|
-
});
|
|
404
|
-
if (!c || !c.abi) {
|
|
405
|
-
return jsonResponse({
|
|
406
|
-
error: {
|
|
407
|
-
type: "not_found",
|
|
408
|
-
status: 404,
|
|
409
|
-
message: `Contract not in registry: ${contractId}`
|
|
410
|
-
}
|
|
411
|
-
}, true);
|
|
412
|
-
}
|
|
413
|
-
const [address, contractName] = contractId.split(".");
|
|
414
|
-
const name = (contractName ?? contractId).replace(/[^a-zA-Z0-9]/g, "_");
|
|
415
|
-
const code = generateContractInterface([
|
|
416
|
-
{
|
|
417
|
-
name,
|
|
418
|
-
address,
|
|
419
|
-
contractName: contractName ?? "",
|
|
420
|
-
abi: c.abi
|
|
421
|
-
}
|
|
422
|
-
]);
|
|
423
|
-
return { content: [{ type: "text", text: code }] };
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
// src/tools/datasets.ts
|
|
428
|
-
import { z as z3 } from "zod/v4";
|
|
429
|
-
function registerDatasetTools(server, clientProvider = getClient) {
|
|
430
|
-
defineTool(server, "datasets_list", "List the Foundation Datasets catalog with freshness — the discovery endpoint for what dataset slugs exist and how current each is. Reads are public.", {}, async () => {
|
|
431
|
-
const catalog = await clientProvider().datasets.listDatasets();
|
|
432
|
-
return jsonResponse(catalog);
|
|
433
|
-
});
|
|
434
|
-
defineTool(server, "datasets_query", 'Query ANY Foundation Dataset by slug — every family returned by datasets_list is queryable, including bespoke ones (bns/resolve with {"fqn":"alice.btc"}, bns/names, bns/namespaces, network-health/summary) and any dataset added later. Accepts family ("sbtc-events") or path ("sbtc/events") slug forms. Filters are passed through as documented query params (e.g. {"sender": "SP...", "from_block": "150000"}). Returns { rows, next_cursor, tip }; single-record datasets like bns/resolve return 0-or-1 rows (empty = not found). Call datasets_list first to discover slugs and their filters.', {
|
|
435
|
-
slug: z3.string().describe("Dataset slug from datasets_list (e.g. stx-transfers)"),
|
|
436
|
-
filters: z3.record(z3.string(), z3.string()).optional().describe("Documented per-dataset query params (snake_case values)"),
|
|
437
|
-
limit: z3.number().optional().describe("Max rows for this page"),
|
|
438
|
-
cursor: z3.string().optional().describe("Opaque cursor from a prior response's next_cursor")
|
|
439
|
-
}, async ({ slug, filters, limit, cursor }) => {
|
|
440
|
-
const params = { ...filters ?? {} };
|
|
441
|
-
if (limit !== undefined)
|
|
442
|
-
params.limit = limit;
|
|
443
|
-
if (cursor !== undefined)
|
|
444
|
-
params.cursor = cursor;
|
|
445
|
-
const result = await clientProvider().datasets.get(slug, params);
|
|
446
|
-
return jsonResponse(result);
|
|
447
|
-
});
|
|
448
372
|
}
|
|
449
373
|
|
|
450
374
|
// src/tools/index.ts
|
|
451
|
-
import { DECODED_EVENT_TYPES
|
|
452
|
-
import {
|
|
453
|
-
|
|
454
|
-
generateIndexSchema
|
|
455
|
-
} from "@secondlayer/subgraphs";
|
|
456
|
-
import { z as z4 } from "zod/v4";
|
|
457
|
-
var INDEX_EVENT_TYPES = DECODED_EVENT_TYPES2;
|
|
375
|
+
import { DECODED_EVENT_TYPES } from "@secondlayer/shared";
|
|
376
|
+
import { z as z3 } from "zod/v4";
|
|
377
|
+
var INDEX_EVENT_TYPES = DECODED_EVENT_TYPES;
|
|
458
378
|
var rangeFilters = {
|
|
459
|
-
contractId:
|
|
460
|
-
fromHeight:
|
|
461
|
-
toHeight:
|
|
462
|
-
cursor:
|
|
463
|
-
limit:
|
|
379
|
+
contractId: z3.string().optional().describe("Filter by contract id"),
|
|
380
|
+
fromHeight: z3.number().optional().describe("Start block height (inclusive)"),
|
|
381
|
+
toHeight: z3.number().optional().describe("End block height (inclusive)"),
|
|
382
|
+
cursor: z3.string().optional().describe("Opaque cursor from a prior response's next_cursor"),
|
|
383
|
+
limit: z3.number().optional().describe("Max rows for this page")
|
|
464
384
|
};
|
|
465
385
|
var heightFilters = {
|
|
466
386
|
fromHeight: rangeFilters.fromHeight,
|
|
@@ -468,126 +388,52 @@ var heightFilters = {
|
|
|
468
388
|
cursor: rangeFilters.cursor,
|
|
469
389
|
limit: rangeFilters.limit
|
|
470
390
|
};
|
|
471
|
-
var notFound = (message) => jsonResponse({ error: { type: "not_found", status: 404, message } }, true);
|
|
472
391
|
function registerIndexTools(server, clientProvider = getClient) {
|
|
473
392
|
defineTool(server, "index_ft_transfers", "List decoded SIP-010 fungible-token transfers from the Index (L2 decoded layer). Anonymous reads allowed (free-tier API keys are rejected — Build+ required).", {
|
|
474
393
|
...rangeFilters,
|
|
475
|
-
sender:
|
|
476
|
-
recipient:
|
|
394
|
+
sender: z3.string().optional().describe("Filter by sender principal"),
|
|
395
|
+
recipient: z3.string().optional().describe("Filter by recipient principal")
|
|
477
396
|
}, async (params) => jsonResponse(await clientProvider().index.ftTransfers.list(params)));
|
|
478
397
|
defineTool(server, "index_nft_transfers", "List decoded SIP-009 non-fungible-token transfers from the Index. Anonymous reads allowed (free-tier keys rejected).", {
|
|
479
398
|
...rangeFilters,
|
|
480
|
-
sender:
|
|
481
|
-
recipient:
|
|
482
|
-
assetIdentifier:
|
|
399
|
+
sender: z3.string().optional().describe("Filter by sender principal"),
|
|
400
|
+
recipient: z3.string().optional().describe("Filter by recipient principal"),
|
|
401
|
+
assetIdentifier: z3.string().optional().describe("Filter by asset identifier (contract::asset)")
|
|
483
402
|
}, async (params) => jsonResponse(await clientProvider().index.nftTransfers.list(params)));
|
|
484
403
|
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.", {
|
|
485
|
-
eventType:
|
|
404
|
+
eventType: z3.enum(INDEX_EVENT_TYPES).describe("Required. Decoded event type to list."),
|
|
486
405
|
...rangeFilters,
|
|
487
|
-
sender:
|
|
488
|
-
recipient:
|
|
489
|
-
assetIdentifier:
|
|
490
|
-
trait:
|
|
406
|
+
sender: z3.string().optional().describe("Filter by sender principal"),
|
|
407
|
+
recipient: z3.string().optional().describe("Filter by recipient principal"),
|
|
408
|
+
assetIdentifier: z3.string().optional().describe("Filter by asset identifier where applicable"),
|
|
409
|
+
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.")
|
|
491
410
|
}, async (params) => jsonResponse(await clientProvider().index.events.list(params)));
|
|
492
411
|
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.", {
|
|
493
412
|
...rangeFilters,
|
|
494
|
-
functionName:
|
|
495
|
-
sender:
|
|
496
|
-
trait:
|
|
413
|
+
functionName: z3.string().optional().describe("Filter by called function name"),
|
|
414
|
+
sender: z3.string().optional().describe("Filter by caller principal"),
|
|
415
|
+
trait: z3.string().optional().describe("Match contracts conforming to a trait/standard (e.g. sip-010). Mutually exclusive with contractId.")
|
|
497
416
|
}, async (params) => jsonResponse(await clientProvider().index.contractCalls.list(params)));
|
|
498
|
-
defineTool(server, "index_canonical", "List the canonical Stacks block sequence from the Index (height + hash). Anonymous reads allowed (free-tier keys rejected).", { ...heightFilters }, async (params) => jsonResponse(await clientProvider().index.canonical.list(params)));
|
|
499
417
|
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)));
|
|
500
|
-
defineTool(server, "index_block", "Get a single block from the Index by height or block hash. Returns not_found if unknown.", {
|
|
501
|
-
ref: z4.string().describe("Block height (digits) or block hash (0x… string)")
|
|
502
|
-
}, async ({ ref }) => {
|
|
503
|
-
const block = await clientProvider().index.blocks.get(/^\d+$/.test(ref) ? Number(ref) : ref);
|
|
504
|
-
return block ? jsonResponse(block) : notFound(`No block for ref ${ref}`);
|
|
505
|
-
});
|
|
506
418
|
defineTool(server, "index_transactions", "List decoded transactions from the Index. Filter by type, sender, or contract. Anonymous reads allowed (free-tier keys rejected).", {
|
|
507
419
|
...rangeFilters,
|
|
508
|
-
type:
|
|
509
|
-
sender:
|
|
420
|
+
type: z3.string().optional().describe("Filter by transaction type"),
|
|
421
|
+
sender: z3.string().optional().describe("Filter by sender principal")
|
|
510
422
|
}, async (params) => jsonResponse(await clientProvider().index.transactions.list(params)));
|
|
511
|
-
defineTool(server, "index_transaction", "Get a single transaction from the Index by tx_id. Returns not_found if unknown.", { txId: z4.string().describe("Transaction id (0x… hash)") }, async ({ txId }) => {
|
|
512
|
-
const tx = await clientProvider().index.transactions.get(txId);
|
|
513
|
-
return tx ? jsonResponse(tx) : notFound(`No transaction for ${txId}`);
|
|
514
|
-
});
|
|
515
|
-
defineTool(server, "index_transaction_proof", "Fetch a transaction's inclusion proof (raw tx + signed Nakamoto block header + merkle path) so it can be verified trustlessly client-side with the SDK's verifyTransactionProof. Returns not_found if the tx/block is unknown; a 503 means the proof can't be assembled on this deployment right now (PROOF_TX_SET_INCOMPLETE, or PROOF_NODE_UNAVAILABLE when the stacks-node header source isn't configured).", { txId: z4.string().describe("Transaction id (0x… hash)") }, async ({ txId }) => {
|
|
516
|
-
const proof = await clientProvider().index.transactions.getProof(txId);
|
|
517
|
-
return proof ? jsonResponse(proof) : notFound(`No proof available for ${txId}`);
|
|
518
|
-
});
|
|
519
|
-
defineTool(server, "index_stacking", "List decoded PoX-4 stacking actions from the Index (stack-stx, delegate-stx, etc.). Anonymous reads allowed (free-tier keys rejected).", {
|
|
520
|
-
...heightFilters,
|
|
521
|
-
functionName: z4.string().optional().describe("Filter by PoX function name"),
|
|
522
|
-
stacker: z4.string().optional().describe("Filter by stacker principal"),
|
|
523
|
-
caller: z4.string().optional().describe("Filter by caller principal")
|
|
524
|
-
}, async (params) => jsonResponse(await clientProvider().index.stacking.list(params)));
|
|
525
|
-
defineTool(server, "index_mempool", "List pending (unconfirmed) transactions from the Index mempool. Sequence-cursor paginated (no height range). Anonymous reads allowed (free-tier keys rejected).", {
|
|
526
|
-
sender: z4.string().optional().describe("Filter by sender principal"),
|
|
527
|
-
type: z4.string().optional().describe("Filter by transaction type"),
|
|
528
|
-
contractId: z4.string().optional().describe("Filter to pending calls to a single contract"),
|
|
529
|
-
cursor: z4.string().optional().describe("Opaque cursor from a prior response's next_cursor"),
|
|
530
|
-
limit: z4.number().optional().describe("Max rows for this page")
|
|
531
|
-
}, async (params) => jsonResponse(await clientProvider().index.mempool.list(params)));
|
|
532
|
-
defineTool(server, "index_mempool_tx", "Get a single pending transaction from the Index mempool by tx_id. Returns not_found once it is mined or dropped.", { txId: z4.string().describe("Transaction id (0x… hash)") }, async ({ txId }) => {
|
|
533
|
-
const tx = await clientProvider().index.mempool.get(txId);
|
|
534
|
-
return tx ? jsonResponse(tx) : notFound(`No pending tx for ${txId}`);
|
|
535
|
-
});
|
|
536
423
|
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()));
|
|
537
|
-
defineTool(server, "
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
}, async (
|
|
543
|
-
const out = generateIndexSchema(target, { tables, schemaName });
|
|
544
|
-
return { content: [{ type: "text", text: out }] };
|
|
545
|
-
});
|
|
546
|
-
}
|
|
547
|
-
|
|
548
|
-
// src/tools/projects.ts
|
|
549
|
-
import { z as z5 } from "zod/v4";
|
|
550
|
-
function registerProjectTools(server, clientProvider = getClient) {
|
|
551
|
-
defineTool(server, "project_list", "List the account's projects. Requires an account-level (owner) API key.", {}, async () => jsonResponse(await clientProvider().projects.list()));
|
|
552
|
-
defineTool(server, "project_get", "Get a single project by slug.", { slug: z5.string().describe("Project slug") }, async ({ slug }) => jsonResponse(await clientProvider().projects.get(slug)));
|
|
553
|
-
defineTool(server, "project_create", "Create a project. The slug is derived from the name when omitted. Requires an account-level (owner) API key.", {
|
|
554
|
-
name: z5.string().describe("Project name"),
|
|
555
|
-
slug: z5.string().optional().describe("URL slug (auto-derived from name if omitted)"),
|
|
556
|
-
network: z5.string().optional().describe("Network (e.g. mainnet, testnet)"),
|
|
557
|
-
nodeRpc: z5.string().optional().describe("Custom node RPC URL")
|
|
558
|
-
}, async ({ name, slug, network, nodeRpc }) => jsonResponse(await clientProvider().projects.create({
|
|
559
|
-
name,
|
|
560
|
-
slug,
|
|
561
|
-
network,
|
|
562
|
-
nodeRpc
|
|
563
|
-
})));
|
|
564
|
-
defineTool(server, "project_update", "Update a project. `slug` selects the project; `newSlug` renames it. Requires an account-level (owner) API key.", {
|
|
565
|
-
slug: z5.string().describe("Slug of the project to update"),
|
|
566
|
-
newSlug: z5.string().optional().describe("New slug (renames the project)"),
|
|
567
|
-
name: z5.string().optional().describe("New display name"),
|
|
568
|
-
network: z5.string().optional().describe("Network (e.g. mainnet, testnet)"),
|
|
569
|
-
nodeRpc: z5.string().optional().describe("Custom node RPC URL"),
|
|
570
|
-
settings: z5.record(z5.string(), z5.unknown()).optional().describe("Arbitrary project settings to merge")
|
|
571
|
-
}, async ({ slug, newSlug, name, network, nodeRpc, settings }) => jsonResponse(await clientProvider().projects.update(slug, {
|
|
572
|
-
...newSlug !== undefined ? { slug: newSlug } : {},
|
|
573
|
-
...name !== undefined ? { name } : {},
|
|
574
|
-
...network !== undefined ? { network } : {},
|
|
575
|
-
...nodeRpc !== undefined ? { nodeRpc } : {},
|
|
576
|
-
...settings !== undefined ? { settings } : {}
|
|
577
|
-
})));
|
|
578
|
-
defineTool(server, "project_delete", "Delete a project permanently. The account's last remaining project cannot be deleted.", { slug: z5.string().describe("Project slug") }, async ({ slug }) => jsonResponse(await clientProvider().projects.delete(slug)));
|
|
579
|
-
defineTool(server, "project_team_list", "List a project's team members and pending invitations.", { slug: z5.string().describe("Project slug") }, async ({ slug }) => jsonResponse(await clientProvider().projects.team(slug)));
|
|
424
|
+
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.", {
|
|
425
|
+
requests: z3.array(z3.object({
|
|
426
|
+
path: z3.string().describe("Public /v1 read path"),
|
|
427
|
+
params: z3.record(z3.string(), z3.string()).optional()
|
|
428
|
+
})).min(1).max(10).describe("Read descriptors, executed concurrently")
|
|
429
|
+
}, async (params) => jsonResponse(await clientProvider().batch(params.requests)));
|
|
580
430
|
}
|
|
581
431
|
|
|
582
432
|
// src/tools/scaffold.ts
|
|
583
|
-
import {
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
import { TRAIT_STANDARDS as TRAIT_STANDARDS2 } from "@secondlayer/stacks/clarity";
|
|
588
|
-
import { z as z6 } from "zod/v4";
|
|
589
|
-
async function fetchAbi(contractId) {
|
|
590
|
-
const contract = await getClient().contracts.get(contractId, {
|
|
433
|
+
import { generateSubgraphCode } from "@secondlayer/scaffold";
|
|
434
|
+
import { z as z4 } from "zod/v4";
|
|
435
|
+
async function fetchAbi(clientProvider, contractId) {
|
|
436
|
+
const contract = await clientProvider().contracts.get(contractId, {
|
|
591
437
|
includeAbi: true
|
|
592
438
|
});
|
|
593
439
|
if (!contract)
|
|
@@ -598,134 +444,26 @@ async function fetchAbi(contractId) {
|
|
|
598
444
|
}
|
|
599
445
|
return { functions: abi.functions ?? [], maps: abi.maps ?? [] };
|
|
600
446
|
}
|
|
601
|
-
function registerScaffoldTools(server) {
|
|
602
|
-
defineTool(server, "scaffold_from_trait", "Generate a deploy-ready subgraph scaffold that indexes EVERY contract conforming to a SIP trait (no specific contract needed) — sip-009 → an nft_transfer source, sip-010/sip-013 → ft_transfer. Use scaffold_from_contract/abi instead when targeting one contract. See the secondlayer://traits resource for valid trait ids.", {
|
|
603
|
-
trait: z6.enum(TRAIT_STANDARDS2).describe("SIP standard to index (sip-009 | sip-010 | sip-013)"),
|
|
604
|
-
subgraphName: z6.string().optional().describe("Override the subgraph name (defaults to <trait>-transfers)")
|
|
605
|
-
}, async ({ trait, subgraphName }) => {
|
|
606
|
-
const code = generateTraitSubgraph({ trait, name: subgraphName });
|
|
607
|
-
return { content: [{ type: "text", text: code }] };
|
|
608
|
-
});
|
|
447
|
+
function registerScaffoldTools(server, clientProvider = getClient) {
|
|
609
448
|
defineTool(server, "scaffold_from_contract", "Generate a subgraph scaffold from a deployed Stacks contract. Fetches the ABI automatically.", {
|
|
610
|
-
contractId:
|
|
611
|
-
subgraphName:
|
|
449
|
+
contractId: z4.string().describe("Fully qualified contract ID (e.g. SP102V8P0F7JX67ARQ77WEA3D3CFB5XW39REDT0AM.amm-pool-v2-01)"),
|
|
450
|
+
subgraphName: z4.string().optional().describe("Override the subgraph name (defaults to contract name)")
|
|
612
451
|
}, async ({ contractId, subgraphName }) => {
|
|
613
|
-
const { functions, maps } = await fetchAbi(contractId);
|
|
452
|
+
const { functions, maps } = await fetchAbi(clientProvider, contractId);
|
|
614
453
|
const code = generateSubgraphCode(contractId, functions, subgraphName, maps);
|
|
615
454
|
return { content: [{ type: "text", text: code }] };
|
|
616
455
|
});
|
|
617
|
-
defineTool(server, "scaffold_from_abi", "Generate a subgraph scaffold from a provided ABI JSON. Use when you already have the ABI.", {
|
|
618
|
-
abi: z6.string().describe("ABI JSON string (the full contract ABI object)"),
|
|
619
|
-
contractId: z6.string().describe("Fully qualified contract ID"),
|
|
620
|
-
subgraphName: z6.string().optional().describe("Override the subgraph name")
|
|
621
|
-
}, async ({ abi, contractId, subgraphName }) => {
|
|
622
|
-
let parsed;
|
|
623
|
-
try {
|
|
624
|
-
parsed = JSON.parse(abi);
|
|
625
|
-
} catch {
|
|
626
|
-
return {
|
|
627
|
-
content: [{ type: "text", text: "Invalid ABI JSON" }],
|
|
628
|
-
isError: true
|
|
629
|
-
};
|
|
630
|
-
}
|
|
631
|
-
const code = generateSubgraphCode(contractId, parsed.functions ?? [], subgraphName, parsed.maps ?? []);
|
|
632
|
-
return { content: [{ type: "text", text: code }] };
|
|
633
|
-
});
|
|
634
456
|
}
|
|
635
457
|
|
|
636
458
|
// src/tools/streams.ts
|
|
637
|
-
import { AuthError } from "@secondlayer/sdk";
|
|
638
|
-
import { DECODED_EVENT_TYPES as DECODED_EVENT_TYPES3 } from "@secondlayer/shared";
|
|
639
|
-
import { z as z7 } from "zod/v4";
|
|
640
|
-
var STREAMS_EVENT_TYPES = DECODED_EVENT_TYPES3;
|
|
641
|
-
async function withStreamsAuthHint(fn) {
|
|
642
|
-
try {
|
|
643
|
-
return await fn();
|
|
644
|
-
} catch (err) {
|
|
645
|
-
if (err instanceof AuthError) {
|
|
646
|
-
throw Object.assign(new Error(err.message + keyHint), { status: 401 });
|
|
647
|
-
}
|
|
648
|
-
throw err;
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
459
|
function registerStreamsTools(server, clientProvider = getClient) {
|
|
652
|
-
defineTool(server, "
|
|
653
|
-
defineTool(server, "streams_events", "List raw chain events from the Streams firehose. Streams requires an API key (SL_API_KEY). Filter by event types, principals, contract, asset, or block range; page with cursor.", {
|
|
654
|
-
types: z7.array(z7.enum(STREAMS_EVENT_TYPES)).optional().describe("Event types to include"),
|
|
655
|
-
notTypes: z7.array(z7.enum(STREAMS_EVENT_TYPES)).optional().describe("Event types to exclude (applied after types)"),
|
|
656
|
-
contractId: z7.string().optional().describe("Filter by contract id"),
|
|
657
|
-
sender: z7.string().optional().describe("Filter by sender principal"),
|
|
658
|
-
recipient: z7.string().optional().describe("Filter by recipient principal"),
|
|
659
|
-
assetIdentifier: z7.string().optional().describe("Filter by asset identifier"),
|
|
660
|
-
fromHeight: z7.number().optional().describe("Start block height (inclusive)"),
|
|
661
|
-
toHeight: z7.number().optional().describe("End block height (inclusive)"),
|
|
662
|
-
cursor: z7.string().optional().describe("Opaque cursor from a prior response"),
|
|
663
|
-
limit: z7.number().optional().describe("Max events for this page")
|
|
664
|
-
}, async (params) => withStreamsAuthHint(async () => jsonResponse(await clientProvider().streams.events.list(params))));
|
|
665
|
-
defineTool(server, "streams_consume", "Consume a bounded, reorg-aware run of Streams events from a cursor. Walks up to maxPages pages and returns the events, any reorgs observed, and a resume `cursor` to pass back as fromCursor next call — the agent-native consume/resume primitive. Streams requires an API key (SL_API_KEY).", {
|
|
666
|
-
fromCursor: z7.string().optional().describe("Resume cursor from a prior consume (omit to start at genesis)"),
|
|
667
|
-
types: z7.array(z7.enum(STREAMS_EVENT_TYPES)).optional().describe("Event types to include"),
|
|
668
|
-
notTypes: z7.array(z7.enum(STREAMS_EVENT_TYPES)).optional().describe("Event types to exclude"),
|
|
669
|
-
contractId: z7.string().optional().describe("Filter by contract id"),
|
|
670
|
-
sender: z7.string().optional().describe("Filter by sender principal"),
|
|
671
|
-
recipient: z7.string().optional().describe("Filter by recipient principal"),
|
|
672
|
-
assetIdentifier: z7.string().optional().describe("Filter by asset identifier"),
|
|
673
|
-
batchSize: z7.number().optional().describe("Events per page (1–1000, default 100)"),
|
|
674
|
-
maxPages: z7.number().optional().describe("Max pages to walk this call (1–20, default 5)"),
|
|
675
|
-
finalizedOnly: z7.boolean().optional().describe("Only emit finalized events; skip reorg handling")
|
|
676
|
-
}, async (params) => withStreamsAuthHint(async () => {
|
|
677
|
-
const maxPages = Math.min(Math.max(params.maxPages ?? 5, 1), 20);
|
|
678
|
-
const batchSize = Math.min(Math.max(params.batchSize ?? 100, 1), 1000);
|
|
679
|
-
const events = [];
|
|
680
|
-
const reorgs = [];
|
|
681
|
-
const result = await clientProvider().streams.events.consume({
|
|
682
|
-
fromCursor: params.fromCursor ?? null,
|
|
683
|
-
mode: "bounded",
|
|
684
|
-
finalizedOnly: params.finalizedOnly,
|
|
685
|
-
types: params.types,
|
|
686
|
-
notTypes: params.notTypes,
|
|
687
|
-
contractId: params.contractId,
|
|
688
|
-
sender: params.sender,
|
|
689
|
-
recipient: params.recipient,
|
|
690
|
-
assetIdentifier: params.assetIdentifier,
|
|
691
|
-
batchSize,
|
|
692
|
-
maxPages,
|
|
693
|
-
onBatch: (batch) => {
|
|
694
|
-
events.push(...batch);
|
|
695
|
-
},
|
|
696
|
-
onReorg: (reorg) => {
|
|
697
|
-
reorgs.push(reorg);
|
|
698
|
-
}
|
|
699
|
-
});
|
|
700
|
-
return jsonResponse({
|
|
701
|
-
events,
|
|
702
|
-
reorgs,
|
|
703
|
-
cursor: result.cursor,
|
|
704
|
-
pages: result.pages
|
|
705
|
-
});
|
|
706
|
-
}));
|
|
707
|
-
defineTool(server, "streams_event_by_txid", "List all Streams events emitted by a single transaction. Streams requires an API key (SL_API_KEY).", { txId: z7.string().describe("Transaction id (0x… hash)") }, async ({ txId }) => withStreamsAuthHint(async () => jsonResponse(await clientProvider().streams.events.byTxId(txId))));
|
|
708
|
-
defineTool(server, "streams_block_events", "List all Streams events in a single block, by height or block hash. Streams requires an API key (SL_API_KEY).", {
|
|
709
|
-
heightOrHash: z7.string().describe("Block height (digits) or block hash (0x… string)")
|
|
710
|
-
}, async ({ heightOrHash }) => withStreamsAuthHint(async () => jsonResponse(await clientProvider().streams.blocks.events(/^\d+$/.test(heightOrHash) ? Number(heightOrHash) : heightOrHash))));
|
|
711
|
-
defineTool(server, "streams_reorgs", "List chain reorgs observed by Streams since a cursor. Streams requires an API key (SL_API_KEY).", {
|
|
712
|
-
since: z7.string().describe("Cursor to list reorgs since (block:index or ISO timestamp)"),
|
|
713
|
-
limit: z7.number().optional().describe("Max reorgs to return")
|
|
714
|
-
}, async (params) => withStreamsAuthHint(async () => jsonResponse(await clientProvider().streams.reorgs.list(params))));
|
|
715
|
-
defineTool(server, "streams_canonical", "Get the canonical block at a given height from Streams (height + hashes + is_canonical). Streams requires an API key (SL_API_KEY).", { height: z7.number().describe("Block height") }, async ({ height }) => withStreamsAuthHint(async () => jsonResponse(await clientProvider().streams.canonical(height))));
|
|
716
|
-
defineTool(server, "streams_usage", "Your own Streams consumption (events today + this month) and tier limits (rate limit, retention). Streams requires an API key (SL_API_KEY).", {}, async () => withStreamsAuthHint(async () => jsonResponse(await clientProvider().streams.usage())));
|
|
717
|
-
defineTool(server, "streams_dumps", "List the Streams bulk parquet dumps manifest — coverage range, latest_finalized_cursor, and per-file metadata (block range, row count, size, sha256, signed URL). This is the cold backfill path for downloading all raw data; fetch the file URLs directly (e.g. with DuckDB). Requires the dumps base URL to be configured (SL_STREAMS_DUMPS_URL).", {}, async () => jsonResponse(await clientProvider().streams.dumps.list()));
|
|
460
|
+
defineTool(server, "streams_dumps", "List the Streams bulk parquet dumps manifest — coverage range, latest_finalized_cursor, and per-file metadata (block range, row count, size, sha256, signed URL). This is the cold backfill path for downloading all raw data; fetch the file URLs directly (e.g. with DuckDB). Requires the dumps base URL to be configured (SL_STREAMS_DUMPS_URL). Live Streams reads (tip, events, consume) are REST-only: see /v1/streams/* in the OpenAPI spec.", {}, async () => jsonResponse(await clientProvider().streams.dumps.list()));
|
|
718
461
|
}
|
|
719
462
|
|
|
720
463
|
// src/tools/subgraphs.ts
|
|
721
464
|
import { bundleSubgraphCode } from "@secondlayer/bundler";
|
|
722
465
|
import { ByoBreakingChangeError } from "@secondlayer/sdk";
|
|
723
|
-
import {
|
|
724
|
-
generateDrizzleSchema,
|
|
725
|
-
generateKyselySchema,
|
|
726
|
-
generatePrismaSchema
|
|
727
|
-
} from "@secondlayer/subgraphs";
|
|
728
|
-
import { z as z8 } from "zod/v4";
|
|
466
|
+
import { z as z5 } from "zod/v4";
|
|
729
467
|
function registerSubgraphTools(server, clientProvider = getClient) {
|
|
730
468
|
defineTool(server, "subgraphs_list", "List all deployed subgraphs. Returns summary fields only, including visibility — public subgraphs are anon-readable at /v1/subgraphs/<name>.", {}, async () => {
|
|
731
469
|
const { data } = await clientProvider().subgraphs.list();
|
|
@@ -738,38 +476,22 @@ function registerSubgraphTools(server, clientProvider = getClient) {
|
|
|
738
476
|
]
|
|
739
477
|
};
|
|
740
478
|
});
|
|
741
|
-
defineTool(server, "subgraphs_get", "Get full details of a subgraph including schema, health, and table columns.", { name:
|
|
479
|
+
defineTool(server, "subgraphs_get", "Get full details of a subgraph including schema, health, and table columns.", { name: z5.string().describe("Subgraph name") }, async ({ name }) => {
|
|
742
480
|
const detail = await clientProvider().subgraphs.get(name);
|
|
743
481
|
return {
|
|
744
482
|
content: [{ type: "text", text: JSON.stringify(detail, null, 2) }]
|
|
745
483
|
};
|
|
746
484
|
});
|
|
747
|
-
defineTool(server, "subgraphs_spec", "Get generated API documentation for a subgraph. Defaults to compact agent schema; supports OpenAPI JSON and Markdown.", {
|
|
748
|
-
name: z8.string().describe("Subgraph name"),
|
|
749
|
-
format: z8.enum(["agent", "openapi", "markdown"]).optional().describe("Spec format to return. Defaults to agent."),
|
|
750
|
-
serverUrl: z8.string().optional().describe("Override the server URL embedded in generated docs.")
|
|
751
|
-
}, async ({ name, format = "agent", serverUrl }) => {
|
|
752
|
-
const options = serverUrl ? { serverUrl } : undefined;
|
|
753
|
-
const spec = format === "openapi" ? await clientProvider().subgraphs.openapi(name, options) : format === "markdown" ? await clientProvider().subgraphs.markdown(name, options) : await clientProvider().subgraphs.schema(name, options);
|
|
754
|
-
return {
|
|
755
|
-
content: [
|
|
756
|
-
{
|
|
757
|
-
type: "text",
|
|
758
|
-
text: typeof spec === "string" ? spec : JSON.stringify(spec, null, 2)
|
|
759
|
-
}
|
|
760
|
-
]
|
|
761
|
-
};
|
|
762
|
-
});
|
|
763
485
|
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.', {
|
|
764
|
-
name:
|
|
765
|
-
table:
|
|
766
|
-
filters:
|
|
767
|
-
sort:
|
|
768
|
-
order:
|
|
769
|
-
limit:
|
|
770
|
-
offset:
|
|
771
|
-
fields:
|
|
772
|
-
count:
|
|
486
|
+
name: z5.string().describe("Subgraph name"),
|
|
487
|
+
table: z5.string().describe("Table name"),
|
|
488
|
+
filters: z5.record(z5.string(), z5.string()).optional().describe('Column filters — plain values or with operators (e.g. {"amount.gte": "1000", "sender": "SP..."})'),
|
|
489
|
+
sort: z5.string().optional().describe("Column to sort by"),
|
|
490
|
+
order: z5.enum(["asc", "desc"]).optional().describe("Sort order"),
|
|
491
|
+
limit: z5.number().max(200).optional().describe("Max rows (default 50, max 200)"),
|
|
492
|
+
offset: z5.number().optional().describe("Offset for pagination"),
|
|
493
|
+
fields: z5.string().optional().describe('Comma-separated column list to return (e.g. "sender,amount")'),
|
|
494
|
+
count: z5.boolean().optional().describe("If true, return row count instead of rows")
|
|
773
495
|
}, async ({
|
|
774
496
|
name,
|
|
775
497
|
table,
|
|
@@ -801,25 +523,10 @@ function registerSubgraphTools(server, clientProvider = getClient) {
|
|
|
801
523
|
content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
|
|
802
524
|
};
|
|
803
525
|
});
|
|
804
|
-
defineTool(server, "
|
|
805
|
-
name:
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
count: z8.boolean().optional().describe("Include COUNT(*) of matching rows"),
|
|
809
|
-
countDistinct: z8.array(z8.string()).optional().describe("Columns to count distinct values of"),
|
|
810
|
-
sum: z8.array(z8.string()).optional().describe("Numeric columns to sum (lossless string result)"),
|
|
811
|
-
min: z8.array(z8.string()).optional().describe("Numeric columns to take the minimum of"),
|
|
812
|
-
max: z8.array(z8.string()).optional().describe("Numeric columns to take the maximum of")
|
|
813
|
-
}, async ({ name, table, filters, count, countDistinct, sum, min, max }) => {
|
|
814
|
-
const result = await clientProvider().subgraphs.queryTableAggregate(name, table, { filters, count, countDistinct, sum, min, max });
|
|
815
|
-
return {
|
|
816
|
-
content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
|
|
817
|
-
};
|
|
818
|
-
});
|
|
819
|
-
defineTool(server, "subgraphs_reindex", "Reindex a subgraph from a specific block range. Returns an operationId — poll subgraphs_operation to track progress to completion.", {
|
|
820
|
-
name: z8.string().describe("Subgraph name"),
|
|
821
|
-
fromBlock: z8.number().optional().describe("Start block (defaults to beginning)"),
|
|
822
|
-
toBlock: z8.number().optional().describe("End block (defaults to latest)")
|
|
526
|
+
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.", {
|
|
527
|
+
name: z5.string().describe("Subgraph name"),
|
|
528
|
+
fromBlock: z5.number().optional().describe("Start block (defaults to beginning)"),
|
|
529
|
+
toBlock: z5.number().optional().describe("End block (defaults to latest)")
|
|
823
530
|
}, async ({ name, fromBlock, toBlock }) => {
|
|
824
531
|
const result = await clientProvider().subgraphs.reindex(name, {
|
|
825
532
|
fromBlock,
|
|
@@ -829,19 +536,10 @@ function registerSubgraphTools(server, clientProvider = getClient) {
|
|
|
829
536
|
content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
|
|
830
537
|
};
|
|
831
538
|
});
|
|
832
|
-
defineTool(server, "
|
|
833
|
-
name:
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
const result = operationId ? await clientProvider().subgraphs.getOperation(name, operationId) : await clientProvider().subgraphs.operations(name);
|
|
837
|
-
return {
|
|
838
|
-
content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
|
|
839
|
-
};
|
|
840
|
-
});
|
|
841
|
-
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 — poll subgraphs_operation to track progress.", {
|
|
842
|
-
name: z8.string().describe("Subgraph name"),
|
|
843
|
-
fromBlock: z8.number().int().nonnegative().describe("Start block (inclusive)"),
|
|
844
|
-
toBlock: z8.number().int().nonnegative().describe("End block (inclusive)")
|
|
539
|
+
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.", {
|
|
540
|
+
name: z5.string().describe("Subgraph name"),
|
|
541
|
+
fromBlock: z5.number().int().nonnegative().describe("Start block (inclusive)"),
|
|
542
|
+
toBlock: z5.number().int().nonnegative().describe("End block (inclusive)")
|
|
845
543
|
}, async ({ name, fromBlock, toBlock }) => {
|
|
846
544
|
const result = await clientProvider().subgraphs.backfill(name, {
|
|
847
545
|
fromBlock,
|
|
@@ -851,17 +549,17 @@ function registerSubgraphTools(server, clientProvider = getClient) {
|
|
|
851
549
|
content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
|
|
852
550
|
};
|
|
853
551
|
});
|
|
854
|
-
defineTool(server, "subgraphs_stop", "Cancel an in-flight reindex or backfill operation for a subgraph. Returns the stop request status;
|
|
552
|
+
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 }) => {
|
|
855
553
|
const result = await clientProvider().subgraphs.stop(name);
|
|
856
554
|
return {
|
|
857
555
|
content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
|
|
858
556
|
};
|
|
859
557
|
});
|
|
860
558
|
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.", {
|
|
861
|
-
name:
|
|
862
|
-
limit:
|
|
863
|
-
offset:
|
|
864
|
-
resolved:
|
|
559
|
+
name: z5.string().describe("Subgraph name"),
|
|
560
|
+
limit: z5.number().int().positive().optional().describe("Max gaps to return"),
|
|
561
|
+
offset: z5.number().int().nonnegative().optional().describe("Pagination offset"),
|
|
562
|
+
resolved: z5.boolean().optional().describe("Filter by resolved state (omit for unresolved only)")
|
|
865
563
|
}, async ({ name, limit, offset, resolved }) => {
|
|
866
564
|
const result = await clientProvider().subgraphs.gaps(name, {
|
|
867
565
|
limit,
|
|
@@ -872,16 +570,16 @@ function registerSubgraphTools(server, clientProvider = getClient) {
|
|
|
872
570
|
content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
|
|
873
571
|
};
|
|
874
572
|
});
|
|
875
|
-
defineTool(server, "subgraphs_delete", "Delete a subgraph permanently.", { name:
|
|
573
|
+
defineTool(server, "subgraphs_delete", "Delete a subgraph permanently.", { name: z5.string().describe("Subgraph name") }, async ({ name }) => {
|
|
876
574
|
const result = await clientProvider().subgraphs.delete(name);
|
|
877
575
|
return { content: [{ type: "text", text: result.message }] };
|
|
878
576
|
});
|
|
879
577
|
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.", {
|
|
880
|
-
code:
|
|
881
|
-
startBlock:
|
|
882
|
-
databaseUrl:
|
|
883
|
-
dryRun:
|
|
884
|
-
visibility:
|
|
578
|
+
code: z5.string().describe("TypeScript source code containing a defineSubgraph() call"),
|
|
579
|
+
startBlock: z5.number().int().nonnegative().optional().describe("Override the definition startBlock for this deploy"),
|
|
580
|
+
databaseUrl: z5.string().optional().describe("BYO data plane: Postgres connection string to host the subgraph's schema and rows in your own database"),
|
|
581
|
+
dryRun: z5.boolean().optional().describe("Validate and preview the deploy (schema/DDL, BYO connection) without writing changes"),
|
|
582
|
+
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.")
|
|
885
583
|
}, async ({ code, startBlock, databaseUrl, dryRun, visibility }) => {
|
|
886
584
|
const bundled = await bundleSubgraphCode(code);
|
|
887
585
|
try {
|
|
@@ -915,58 +613,23 @@ function registerSubgraphTools(server, clientProvider = getClient) {
|
|
|
915
613
|
throw err;
|
|
916
614
|
}
|
|
917
615
|
});
|
|
918
|
-
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:
|
|
616
|
+
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 }) => {
|
|
919
617
|
const result = await clientProvider().subgraphs.publish(name);
|
|
920
618
|
return {
|
|
921
619
|
content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
|
|
922
620
|
};
|
|
923
621
|
});
|
|
924
|
-
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:
|
|
622
|
+
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 }) => {
|
|
925
623
|
const result = await clientProvider().subgraphs.unpublish(name);
|
|
926
624
|
return {
|
|
927
625
|
content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
|
|
928
626
|
};
|
|
929
627
|
});
|
|
930
|
-
defineTool(server, "subgraphs_read_source", "Fetch the deployed TypeScript source of a subgraph (plus its stored version). Returns a readOnly payload for subgraphs deployed before source capture — in that case the caller should redeploy via CLI before editing.", { name: z8.string().describe("Subgraph name") }, async ({ name }) => {
|
|
931
|
-
const source = await clientProvider().subgraphs.getSource(name);
|
|
932
|
-
return {
|
|
933
|
-
content: [{ type: "text", text: JSON.stringify(source, null, 2) }]
|
|
934
|
-
};
|
|
935
|
-
});
|
|
936
|
-
defineTool(server, "subgraphs_codegen", "Generate a typed ORM schema (Prisma, Drizzle, or Kysely) for a subgraph's tables so they can be queried from a BYO database. Pass either `code` (defineSubgraph source) or `name` (a deployed subgraph — its captured source is used). Returns the schema as text.", {
|
|
937
|
-
code: z8.string().optional().describe("defineSubgraph() source (mutually exclusive with name)"),
|
|
938
|
-
name: z8.string().optional().describe("Deployed subgraph name (mutually exclusive with code)"),
|
|
939
|
-
target: z8.enum(["prisma", "drizzle", "kysely"]).optional().describe("ORM target (default prisma)"),
|
|
940
|
-
schemaName: z8.string().optional().describe("Postgres schema name (defaults to subgraph_<name>)")
|
|
941
|
-
}, async ({ code, name, target = "prisma", schemaName }) => {
|
|
942
|
-
if (code && name || !code && !name) {
|
|
943
|
-
throw new Error("Provide exactly one of `code` or `name`.");
|
|
944
|
-
}
|
|
945
|
-
let source = code;
|
|
946
|
-
if (name) {
|
|
947
|
-
const stored = await clientProvider().subgraphs.getSource(name);
|
|
948
|
-
if (!stored.sourceCode) {
|
|
949
|
-
throw new Error(`Subgraph "${name}" has no captured source (deployed before source capture). Redeploy it, or pass its source as \`code\`.`);
|
|
950
|
-
}
|
|
951
|
-
source = stored.sourceCode;
|
|
952
|
-
}
|
|
953
|
-
const bundled = await bundleSubgraphCode(source);
|
|
954
|
-
const def = {
|
|
955
|
-
name: bundled.name,
|
|
956
|
-
version: bundled.version,
|
|
957
|
-
description: bundled.description,
|
|
958
|
-
sources: bundled.sources,
|
|
959
|
-
schema: bundled.schema,
|
|
960
|
-
handlers: {}
|
|
961
|
-
};
|
|
962
|
-
const out = target === "drizzle" ? generateDrizzleSchema(def, { schemaName }) : target === "kysely" ? generateKyselySchema(def, { schemaName }) : generatePrismaSchema(def, { schemaName });
|
|
963
|
-
return { content: [{ type: "text", text: out }] };
|
|
964
|
-
});
|
|
965
628
|
}
|
|
966
629
|
|
|
967
630
|
// src/tools/subscriptions.ts
|
|
968
631
|
import { CHAIN_TRIGGER_TYPES } from "@secondlayer/shared";
|
|
969
|
-
import { z as
|
|
632
|
+
import { z as z6 } from "zod/v4";
|
|
970
633
|
function registerSubscriptionTools(server, clientProvider = getClient) {
|
|
971
634
|
defineTool(server, "subscriptions_list", "List all subscriptions for the current account. Returns summary fields (no secrets).", {}, async () => {
|
|
972
635
|
const { data } = await clientProvider().subscriptions.list();
|
|
@@ -974,34 +637,34 @@ function registerSubscriptionTools(server, clientProvider = getClient) {
|
|
|
974
637
|
content: [{ type: "text", text: JSON.stringify(data, null, 2) }]
|
|
975
638
|
};
|
|
976
639
|
});
|
|
977
|
-
defineTool(server, "subscriptions_get", "Get full detail for a subscription (filter, auth, retry config, circuit state).", { id:
|
|
640
|
+
defineTool(server, "subscriptions_get", "Get full detail for a subscription (filter, auth, retry config, circuit state).", { id: z6.string().describe("Subscription id") }, async ({ id }) => {
|
|
978
641
|
const detail = await clientProvider().subscriptions.get(id);
|
|
979
642
|
return {
|
|
980
643
|
content: [{ type: "text", text: JSON.stringify(detail, null, 2) }]
|
|
981
644
|
};
|
|
982
645
|
});
|
|
983
646
|
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.", {
|
|
984
|
-
name:
|
|
985
|
-
subgraphName:
|
|
986
|
-
tableName:
|
|
987
|
-
triggers:
|
|
988
|
-
type:
|
|
989
|
-
contractId:
|
|
990
|
-
functionName:
|
|
991
|
-
caller:
|
|
992
|
-
sender:
|
|
993
|
-
recipient:
|
|
994
|
-
assetIdentifier:
|
|
995
|
-
deployer:
|
|
996
|
-
contractName:
|
|
997
|
-
topic:
|
|
998
|
-
lockedAddress:
|
|
999
|
-
trait:
|
|
1000
|
-
minAmount:
|
|
1001
|
-
maxAmount:
|
|
647
|
+
name: z6.string().describe("Human-readable name, unique per account"),
|
|
648
|
+
subgraphName: z6.string().optional().describe("Subgraph to subscribe to (subgraph subscription)"),
|
|
649
|
+
tableName: z6.string().optional().describe("Table within the subgraph (subgraph subscription)"),
|
|
650
|
+
triggers: z6.array(z6.object({
|
|
651
|
+
type: z6.enum(CHAIN_TRIGGER_TYPES),
|
|
652
|
+
contractId: z6.string().optional(),
|
|
653
|
+
functionName: z6.string().optional(),
|
|
654
|
+
caller: z6.string().optional(),
|
|
655
|
+
sender: z6.string().optional(),
|
|
656
|
+
recipient: z6.string().optional(),
|
|
657
|
+
assetIdentifier: z6.string().optional(),
|
|
658
|
+
deployer: z6.string().optional(),
|
|
659
|
+
contractName: z6.string().optional(),
|
|
660
|
+
topic: z6.string().optional(),
|
|
661
|
+
lockedAddress: z6.string().optional(),
|
|
662
|
+
trait: z6.string().optional(),
|
|
663
|
+
minAmount: z6.union([z6.string(), z6.number()]).optional(),
|
|
664
|
+
maxAmount: z6.union([z6.string(), z6.number()]).optional()
|
|
1002
665
|
})).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."),
|
|
1003
|
-
url:
|
|
1004
|
-
format:
|
|
666
|
+
url: z6.string().describe("Webhook URL"),
|
|
667
|
+
format: z6.enum([
|
|
1005
668
|
"standard-webhooks",
|
|
1006
669
|
"inngest",
|
|
1007
670
|
"trigger",
|
|
@@ -1009,9 +672,9 @@ function registerSubscriptionTools(server, clientProvider = getClient) {
|
|
|
1009
672
|
"cloudevents",
|
|
1010
673
|
"raw"
|
|
1011
674
|
]).optional().describe("Wire format (default standard-webhooks)"),
|
|
1012
|
-
runtime:
|
|
1013
|
-
filter:
|
|
1014
|
-
authConfig:
|
|
675
|
+
runtime: z6.enum(["inngest", "trigger", "cloudflare", "node"]).optional().describe("Receiver runtime label (display only)"),
|
|
676
|
+
filter: z6.record(z6.string(), z6.unknown()).optional().describe('Scalar filter DSL, e.g. {"amount": {"gte": 100}, "sender": "SP..."}'),
|
|
677
|
+
authConfig: z6.record(z6.string(), z6.unknown()).optional().describe('Receiver auth sent with each delivery, e.g. {"type": "bearer", "token": "..."}')
|
|
1015
678
|
}, async (input) => {
|
|
1016
679
|
const res = await clientProvider().subscriptions.create(input);
|
|
1017
680
|
return {
|
|
@@ -1019,12 +682,12 @@ function registerSubscriptionTools(server, clientProvider = getClient) {
|
|
|
1019
682
|
};
|
|
1020
683
|
});
|
|
1021
684
|
defineTool(server, "subscriptions_update", "Patch a subscription (name, url, filter, authConfig, format, runtime, retry, timeout, concurrency).", {
|
|
1022
|
-
id:
|
|
1023
|
-
name:
|
|
1024
|
-
url:
|
|
1025
|
-
filter:
|
|
1026
|
-
authConfig:
|
|
1027
|
-
format:
|
|
685
|
+
id: z6.string(),
|
|
686
|
+
name: z6.string().optional().describe("Rename the subscription"),
|
|
687
|
+
url: z6.string().optional(),
|
|
688
|
+
filter: z6.record(z6.string(), z6.unknown()).optional(),
|
|
689
|
+
authConfig: z6.record(z6.string(), z6.unknown()).optional().describe("Receiver auth sent with each delivery (bearer/etc.)"),
|
|
690
|
+
format: z6.enum([
|
|
1028
691
|
"standard-webhooks",
|
|
1029
692
|
"inngest",
|
|
1030
693
|
"trigger",
|
|
@@ -1032,51 +695,33 @@ function registerSubscriptionTools(server, clientProvider = getClient) {
|
|
|
1032
695
|
"cloudevents",
|
|
1033
696
|
"raw"
|
|
1034
697
|
]).optional(),
|
|
1035
|
-
runtime:
|
|
1036
|
-
maxRetries:
|
|
1037
|
-
timeoutMs:
|
|
1038
|
-
concurrency:
|
|
698
|
+
runtime: z6.enum(["inngest", "trigger", "cloudflare", "node"]).nullable().optional(),
|
|
699
|
+
maxRetries: z6.number().int().min(0).optional(),
|
|
700
|
+
timeoutMs: z6.number().int().min(100).optional(),
|
|
701
|
+
concurrency: z6.number().int().min(1).optional()
|
|
1039
702
|
}, async ({ id, ...patch }) => {
|
|
1040
703
|
const res = await clientProvider().subscriptions.update(id, patch);
|
|
1041
704
|
return {
|
|
1042
705
|
content: [{ type: "text", text: JSON.stringify(res, null, 2) }]
|
|
1043
706
|
};
|
|
1044
707
|
});
|
|
1045
|
-
defineTool(server, "
|
|
1046
|
-
const res = await clientProvider().subscriptions.pause(id);
|
|
1047
|
-
return {
|
|
1048
|
-
content: [{ type: "text", text: JSON.stringify(res, null, 2) }]
|
|
1049
|
-
};
|
|
1050
|
-
});
|
|
1051
|
-
defineTool(server, "subscriptions_resume", "Resume a paused or circuit-open subscription and reset circuit failures.", { id: z9.string() }, async ({ id }) => {
|
|
1052
|
-
const res = await clientProvider().subscriptions.resume(id);
|
|
1053
|
-
return {
|
|
1054
|
-
content: [{ type: "text", text: JSON.stringify(res, null, 2) }]
|
|
1055
|
-
};
|
|
1056
|
-
});
|
|
1057
|
-
defineTool(server, "subscriptions_delete", "Delete a subscription. Pending outbox rows are cascade-deleted.", { id: z9.string() }, async ({ id }) => {
|
|
708
|
+
defineTool(server, "subscriptions_delete", "Delete a subscription. Pending outbox rows are cascade-deleted.", { id: z6.string() }, async ({ id }) => {
|
|
1058
709
|
const res = await clientProvider().subscriptions.delete(id);
|
|
1059
710
|
return {
|
|
1060
711
|
content: [{ type: "text", text: JSON.stringify(res, null, 2) }]
|
|
1061
712
|
};
|
|
1062
713
|
});
|
|
1063
|
-
defineTool(server, "
|
|
1064
|
-
const res = await clientProvider().subscriptions.rotateSecret(id);
|
|
1065
|
-
return {
|
|
1066
|
-
content: [{ type: "text", text: JSON.stringify(res, null, 2) }]
|
|
1067
|
-
};
|
|
1068
|
-
});
|
|
1069
|
-
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 — check subscriptions_recent_deliveries. Returns {ok, statusCode, error, durationMs, deliveryId}.", { id: z9.string().describe("Subscription id") }, async ({ id }) => {
|
|
714
|
+
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 }) => {
|
|
1070
715
|
const res = await clientProvider().subscriptions.test(id);
|
|
1071
716
|
return {
|
|
1072
717
|
content: [{ type: "text", text: JSON.stringify(res, null, 2) }]
|
|
1073
718
|
};
|
|
1074
719
|
});
|
|
1075
720
|
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.", {
|
|
1076
|
-
id:
|
|
1077
|
-
fromBlock:
|
|
1078
|
-
toBlock:
|
|
1079
|
-
force:
|
|
721
|
+
id: z6.string(),
|
|
722
|
+
fromBlock: z6.number().int().nonnegative(),
|
|
723
|
+
toBlock: z6.number().int().nonnegative(),
|
|
724
|
+
force: z6.string().optional().describe("Idempotency suffix to force a duplicate replay of the range")
|
|
1080
725
|
}, async ({ id, fromBlock, toBlock, force }) => {
|
|
1081
726
|
const res = await clientProvider().subscriptions.replay(id, {
|
|
1082
727
|
fromBlock,
|
|
@@ -1087,27 +732,6 @@ function registerSubscriptionTools(server, clientProvider = getClient) {
|
|
|
1087
732
|
content: [{ type: "text", text: JSON.stringify(res, null, 2) }]
|
|
1088
733
|
};
|
|
1089
734
|
});
|
|
1090
|
-
defineTool(server, "subscriptions_dead", "Return the last 100 dead-letter outbox rows for a subscription.", { id: z9.string() }, async ({ id }) => {
|
|
1091
|
-
const { data } = await clientProvider().subscriptions.dead(id);
|
|
1092
|
-
return {
|
|
1093
|
-
content: [{ type: "text", text: JSON.stringify(data, null, 2) }]
|
|
1094
|
-
};
|
|
1095
|
-
});
|
|
1096
|
-
defineTool(server, "subscriptions_requeue_dead", "Requeue one dead-letter outbox row for delivery retry.", {
|
|
1097
|
-
id: z9.string(),
|
|
1098
|
-
outboxId: z9.string()
|
|
1099
|
-
}, async ({ id, outboxId }) => {
|
|
1100
|
-
const res = await clientProvider().subscriptions.requeueDead(id, outboxId);
|
|
1101
|
-
return {
|
|
1102
|
-
content: [{ type: "text", text: JSON.stringify(res, null, 2) }]
|
|
1103
|
-
};
|
|
1104
|
-
});
|
|
1105
|
-
defineTool(server, "subscriptions_recent_deliveries", "Return the last 100 delivery attempts (attempt #, status code, duration, truncated response).", { id: z9.string() }, async ({ id }) => {
|
|
1106
|
-
const { data } = await clientProvider().subscriptions.recentDeliveries(id);
|
|
1107
|
-
return {
|
|
1108
|
-
content: [{ type: "text", text: JSON.stringify(data, null, 2) }]
|
|
1109
|
-
};
|
|
1110
|
-
});
|
|
1111
735
|
}
|
|
1112
736
|
|
|
1113
737
|
// src/server.ts
|
|
@@ -1122,8 +746,6 @@ function createServer() {
|
|
|
1122
746
|
registerSubgraphTools(server);
|
|
1123
747
|
registerSubscriptionTools(server);
|
|
1124
748
|
registerAccountTools(server);
|
|
1125
|
-
registerProjectTools(server);
|
|
1126
|
-
registerDatasetTools(server);
|
|
1127
749
|
registerIndexTools(server);
|
|
1128
750
|
registerStreamsTools(server);
|
|
1129
751
|
registerContractTools(server);
|
|
@@ -1136,5 +758,5 @@ var server = createServer();
|
|
|
1136
758
|
var transport = new StdioServerTransport;
|
|
1137
759
|
await server.connect(transport);
|
|
1138
760
|
|
|
1139
|
-
//# debugId=
|
|
761
|
+
//# debugId=63BF73C1A0B18EDD64756E2164756E21
|
|
1140
762
|
//# sourceMappingURL=bin.js.map
|