x402-list-mcp 0.4.2 → 0.5.2
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/CHANGELOG.md +93 -0
- package/README.md +120 -17
- package/SKILL.md +14 -11
- package/dist/api.d.ts +55 -1
- package/dist/api.js +3 -2
- package/dist/api.js.map +1 -1
- package/dist/http.js +24 -19
- package/dist/http.js.map +1 -1
- package/dist/server.js +3 -3
- package/dist/server.js.map +1 -1
- package/dist/sessions.d.ts +25 -0
- package/dist/sessions.js +86 -0
- package/dist/sessions.js.map +1 -0
- package/dist/tools.js +356 -87
- package/dist/tools.js.map +1 -1
- package/package.json +13 -5
package/dist/tools.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
// The
|
|
1
|
+
// The 7 x402-list MCP tools: schemas, handlers, response mapping.
|
|
2
2
|
//
|
|
3
3
|
// USD PASS-THROUGH RULE: every *_usd field is copied straight from the API value.
|
|
4
4
|
// No Math.round, no multiply, no divide. pricing[].price is copied as the raw
|
|
5
5
|
// atomic-token string and labeled accordingly. There is intentionally no /100,
|
|
6
6
|
// no * 100, and no cents conversion anywhere in this file.
|
|
7
7
|
import { z } from "zod";
|
|
8
|
-
import { ApiError, getServices, getService, getServiceUptime, getServiceVolumeSeries, getServiceBuyersSeries, getFacilitators, getStatus, getNetworks, getBest, postAssess, } from "./api.js";
|
|
8
|
+
import { ApiError, getServices, getService, getServiceUptime, getServiceVolumeSeries, getServiceBuyersSeries, getFacilitators, getStatus, getNetworks, getBest, getChanges, postAssess, } from "./api.js";
|
|
9
9
|
import { trackTool } from "./track.js";
|
|
10
10
|
// Network input normalization.
|
|
11
11
|
// The API and ServiceListItem.networks[] use ABBREVIATIONS (e.g. "BSE", "SOL"),
|
|
@@ -13,33 +13,55 @@ import { trackTool } from "./track.js";
|
|
|
13
13
|
// unknown `network` value and returns everything, so without this an unfiltered
|
|
14
14
|
// result would be reported as if the filter were honored. We resolve either form
|
|
15
15
|
// to the canonical abbreviation, fetched once and cached for the process.
|
|
16
|
-
|
|
16
|
+
// A-17#4: the map is cached with a TTL and, crucially, a FAILED or empty fetch is NEVER cached.
|
|
17
|
+
// The old code memoized a single Promise for the whole process life, so one transient /networks
|
|
18
|
+
// timeout resolved to an EMPTY Map that stayed cached until redeploy, permanently breaking network
|
|
19
|
+
// name resolution (every 'Base' then read as unknown). Here a successful, non-empty fetch is cached
|
|
20
|
+
// for NETWORK_MAP_TTL_MS (the live network set grows over time, so a TTL also lets it refresh); a
|
|
21
|
+
// failure or an empty result leaves the cache untouched so the very next call retries. Concurrent
|
|
22
|
+
// callers share one in-flight fetch (dedup) without persisting its outcome on failure.
|
|
23
|
+
const NETWORK_MAP_TTL_MS = 5 * 60 * 1000;
|
|
24
|
+
let networkMapCache = null;
|
|
25
|
+
let networkMapInflight = null;
|
|
17
26
|
function getNetworkMap() {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
// treats the input as a raw abbreviation, which still works for "BSE"-style
|
|
37
|
-
// input and correctly filters to nothing for an unknown value.
|
|
27
|
+
const now = Date.now();
|
|
28
|
+
if (networkMapCache && networkMapCache.expiresAt > now)
|
|
29
|
+
return Promise.resolve(networkMapCache.map);
|
|
30
|
+
if (networkMapInflight)
|
|
31
|
+
return networkMapInflight;
|
|
32
|
+
networkMapInflight = (async () => {
|
|
33
|
+
const m = new Map();
|
|
34
|
+
try {
|
|
35
|
+
const resp = await getNetworks();
|
|
36
|
+
for (const n of resp.data) {
|
|
37
|
+
const abbr = typeof n?.abbreviation === "string" ? n.abbreviation : null;
|
|
38
|
+
if (!abbr)
|
|
39
|
+
continue;
|
|
40
|
+
m.set(abbr.toLowerCase(), abbr);
|
|
41
|
+
if (typeof n?.name === "string")
|
|
42
|
+
m.set(n.name.toLowerCase(), abbr);
|
|
43
|
+
if (typeof n?.caip2_id === "string")
|
|
44
|
+
m.set(n.caip2_id.toLowerCase(), abbr);
|
|
38
45
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
46
|
+
// Cache ONLY a real, non-empty result. An empty map means the endpoint gave nothing usable
|
|
47
|
+
// (or threw, caught below): treat it as a miss so the next call re-fetches instead of serving
|
|
48
|
+
// a poisoned empty map for the process life.
|
|
49
|
+
if (m.size > 0)
|
|
50
|
+
networkMapCache = { map: m, expiresAt: Date.now() + NETWORK_MAP_TTL_MS };
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
// Networks endpoint unreachable: return an empty map WITHOUT caching it. resolveNetwork then
|
|
54
|
+
// treats the input as a raw abbreviation (still correct for "BSE"-style input), and the next
|
|
55
|
+
// call retries a fresh fetch rather than being stuck on this one transient failure.
|
|
56
|
+
}
|
|
57
|
+
finally {
|
|
58
|
+
// Release the in-flight handle regardless of outcome. On success the TTL cache serves the next
|
|
59
|
+
// call; on failure the null handle forces a fresh retry (no poisoned promise lingers).
|
|
60
|
+
networkMapInflight = null;
|
|
61
|
+
}
|
|
62
|
+
return m;
|
|
63
|
+
})();
|
|
64
|
+
return networkMapInflight;
|
|
43
65
|
}
|
|
44
66
|
async function resolveNetwork(input) {
|
|
45
67
|
const key = input.trim().toLowerCase();
|
|
@@ -56,9 +78,14 @@ async function knownNetworksHint() {
|
|
|
56
78
|
: "the network list could not be fetched from /api/v1/networks";
|
|
57
79
|
}
|
|
58
80
|
function ok(structured) {
|
|
81
|
+
// A-17#3: the tool result already carries the object once as structuredContent. The text block
|
|
82
|
+
// is the backward-compat mirror for clients that ignore structuredContent, so it must stay, but
|
|
83
|
+
// it is emitted as COMPACT JSON (no pretty indentation) rather than a second pretty-printed copy:
|
|
84
|
+
// the pretty form roughly doubled the payload weight on top of the structured copy (221 KB for a
|
|
85
|
+
// directory snapshot). Same data, one un-indented mirror.
|
|
59
86
|
return {
|
|
60
87
|
structuredContent: structured,
|
|
61
|
-
content: [{ type: "text", text: JSON.stringify(structured
|
|
88
|
+
content: [{ type: "text", text: JSON.stringify(structured) }],
|
|
62
89
|
};
|
|
63
90
|
}
|
|
64
91
|
function fail(message) {
|
|
@@ -71,8 +98,32 @@ function describeError(e) {
|
|
|
71
98
|
return e.message;
|
|
72
99
|
return String(e);
|
|
73
100
|
}
|
|
101
|
+
// B-14#4: the compact projection for x402_search_services. Keeps the decision-useful scalars
|
|
102
|
+
// (identity, price, status, uptime, response time, verification, networks, endpoint count) plus the
|
|
103
|
+
// two ranking-relevant assessment scalars (compliance grade, risk level), and DROPS the long
|
|
104
|
+
// description and the heavy nested assessment block. Callers that need the full assessment pass
|
|
105
|
+
// fields='full' here or call x402_get_service for one service. USD fields stay pass-through (no rescale).
|
|
106
|
+
function toCompactService(s) {
|
|
107
|
+
return {
|
|
108
|
+
slug: s.slug,
|
|
109
|
+
name: s.name,
|
|
110
|
+
category: s.category,
|
|
111
|
+
status: s.status,
|
|
112
|
+
verified: s.verified,
|
|
113
|
+
endpoint_count: s.endpoint_count,
|
|
114
|
+
min_price_usd: s.min_price_usd, // decimal USD, verbatim
|
|
115
|
+
networks: s.networks,
|
|
116
|
+
uptime_24h: s.uptime_24h,
|
|
117
|
+
avg_response_time_ms: s.avg_response_time_ms,
|
|
118
|
+
base_url: s.base_url,
|
|
119
|
+
website_url: s.website_url,
|
|
120
|
+
created_at: s.created_at,
|
|
121
|
+
compliance_grade: s.assessment?.compliance_grade ?? null,
|
|
122
|
+
risk_level: s.assessment?.risk_level ?? null,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
74
125
|
// Pull a human message out of an API error/control body ({error:{code,message}}, {error, message},
|
|
75
|
-
// or {message}). Used by
|
|
126
|
+
// or {message}). Used by x402_assess_services to surface a 400/503 answer to the agent.
|
|
76
127
|
function extractApiMessage(body) {
|
|
77
128
|
if (!body || typeof body !== "object")
|
|
78
129
|
return null;
|
|
@@ -89,16 +140,44 @@ function extractApiMessage(body) {
|
|
|
89
140
|
return err;
|
|
90
141
|
return null;
|
|
91
142
|
}
|
|
92
|
-
// ──
|
|
93
|
-
|
|
143
|
+
// ── x402_assess_services copy (user-facing; census in docs/COPY-REVIEW-t1c-t2.md and COPY-REVIEW-T5) ──
|
|
144
|
+
// A-17#5: the instruction is DERIVED from accepts[0] of the live challenge, never a hardcoded
|
|
145
|
+
// "$0.25". When a live probe is armed the server quotes $0.25 + the endpoint price X, so a fixed
|
|
146
|
+
// dollar figure in the instruction contradicts the amount the caller must actually sign, on a
|
|
147
|
+
// non-refundable spend. We surface accepts[0].amount (the authoritative atomic amount) verbatim and
|
|
148
|
+
// point the caller at it. No atomic->USD math here (USD PASS-THROUGH rule, top of file).
|
|
149
|
+
function firstAccept(body) {
|
|
150
|
+
if (!body || typeof body !== "object")
|
|
151
|
+
return null;
|
|
152
|
+
const accepts = body.accepts;
|
|
153
|
+
if (!Array.isArray(accepts) || accepts.length === 0)
|
|
154
|
+
return null;
|
|
155
|
+
const a = accepts[0];
|
|
156
|
+
return a && typeof a === "object" ? a : null;
|
|
157
|
+
}
|
|
158
|
+
function buildAssessInstruction(body) {
|
|
159
|
+
const a = firstAccept(body);
|
|
160
|
+
const amount = a && typeof a.amount === "string" ? a.amount : null;
|
|
161
|
+
const asset = a && typeof a.asset === "string" ? a.asset : null;
|
|
162
|
+
const network = a && typeof a.network === "string" ? a.network : null;
|
|
163
|
+
const quoted = amount
|
|
164
|
+
? `This challenge quotes accepts[0].amount = ${amount} atomic units${asset ? ` of asset ${asset}` : ""}${network ? ` on ${network}` : ""}, which is the authoritative amount to sign and, when a live probe is requested, already includes the probe endpoint price X. `
|
|
165
|
+
: "";
|
|
166
|
+
return `Payment required. ${quoted}Sign the single accepts[0] option in THIS challenge client-side with your own x402-capable wallet, then call x402_assess_services again with the same question and services and set payment_signature_b64 to the base64 PAYMENT-SIGNATURE you produced. Read the amount from accepts[0].amount, not from any fixed price. This server never holds keys and never signs: it only relays the challenge. There is no refund.`;
|
|
167
|
+
}
|
|
94
168
|
const ASSESS_SIGNATURE_REJECTED_NOTE = "A payment_signature_b64 was supplied but the server did not settle (the signature did not verify, funds were insufficient, or the quoted price changed). Re-sign the accepts[0] option in this fresh challenge and retry.";
|
|
95
169
|
export function registerTools(server) {
|
|
96
170
|
// -------------------------------------------------------------------------
|
|
97
|
-
// 3.1
|
|
171
|
+
// 3.1 x402_search_services
|
|
98
172
|
// -------------------------------------------------------------------------
|
|
99
|
-
server.registerTool("
|
|
100
|
-
|
|
101
|
-
|
|
173
|
+
server.registerTool("x402_search_services", {
|
|
174
|
+
title: "Search x402 services",
|
|
175
|
+
description: "Your first call when you do not know which x402 service exists for a job: it narrows the directory of listed services to candidates. Filter by free-text query, category, network, live status, and whether the last observed 402 envelope is signable by a standard x402 client; sort by newest, uptime, cheapest, or endpoints. Returns up to 100 compact summaries a page: price in decimal USD, uptime, status, verification. Then x402_get_service for the full record.",
|
|
176
|
+
// B-14#1: inputSchema is a STRICT object, so an unknown top-level key (e.g. 'networks' for
|
|
177
|
+
// 'network') is rejected with a JSON-RPC -32602 instead of being silently dropped and the
|
|
178
|
+
// query answered as if the filter were honored. The advertised additionalProperties:false is
|
|
179
|
+
// now enforced at runtime, not just declared.
|
|
180
|
+
inputSchema: z.object({
|
|
102
181
|
q: z
|
|
103
182
|
.string()
|
|
104
183
|
.trim()
|
|
@@ -136,11 +215,31 @@ export function registerTools(server) {
|
|
|
136
215
|
.enum(["newest", "uptime", "cheapest", "endpoints"])
|
|
137
216
|
.default("newest")
|
|
138
217
|
.describe("Server-side sort order."),
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
218
|
+
// B-14#4: response weight. `compact` (default) returns lean per-service summaries and drops
|
|
219
|
+
// the heavy per-service assessment block (a full page could exceed 87k tokens and be
|
|
220
|
+
// truncated mid-JSON by the client); `full` restores every field verbatim, matching
|
|
221
|
+
// x402_get_service. Use compact to survey, then x402_get_service for one service's full detail.
|
|
222
|
+
fields: z
|
|
223
|
+
.enum(["compact", "full"])
|
|
224
|
+
.default("compact")
|
|
225
|
+
.describe("Response detail: 'compact' (default) = lean summaries (identity, price, status, uptime, verification, networks, compliance grade), 'full' = every field including the per-service assessment block. Compact keeps a directory sweep small enough to not truncate."),
|
|
226
|
+
page: z
|
|
227
|
+
.number()
|
|
228
|
+
.int()
|
|
229
|
+
.min(1)
|
|
230
|
+
.default(1)
|
|
231
|
+
.describe("1-based page index into the filtered result set (see meta.total_pages)."),
|
|
232
|
+
per_page: z
|
|
233
|
+
.number()
|
|
234
|
+
.int()
|
|
235
|
+
.min(1)
|
|
236
|
+
.max(100)
|
|
237
|
+
.default(25)
|
|
238
|
+
.describe("Services per page, 1 to 100 (default 25). Higher values return larger results; with fields='full' a large page can be very heavy, so prefer compact when raising it."),
|
|
239
|
+
}).strict(),
|
|
240
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
142
241
|
}, async (args) => {
|
|
143
|
-
trackTool("
|
|
242
|
+
trackTool("x402_search_services", {
|
|
144
243
|
category: args.category ?? null,
|
|
145
244
|
network: args.network ?? null,
|
|
146
245
|
status: args.status,
|
|
@@ -148,6 +247,7 @@ export function registerTools(server) {
|
|
|
148
247
|
verified_only: args.verified_only,
|
|
149
248
|
signable: args.signable ?? null,
|
|
150
249
|
has_query: Boolean(args.q),
|
|
250
|
+
fields: args.fields ?? "compact",
|
|
151
251
|
});
|
|
152
252
|
try {
|
|
153
253
|
const status = args.status === "all" ? undefined : args.status;
|
|
@@ -174,14 +274,27 @@ export function registerTools(server) {
|
|
|
174
274
|
// unknown value, so never let an unfiltered list pass as filtered.
|
|
175
275
|
if (net)
|
|
176
276
|
services = services.filter((s) => s.networks.includes(net.abbrev));
|
|
277
|
+
const fields = args.fields ?? "compact";
|
|
177
278
|
const notes = ["min_price_usd values are decimal US dollars."];
|
|
178
|
-
if (
|
|
279
|
+
if (fields === "compact") {
|
|
280
|
+
notes.push("fields='compact': per-service assessment block omitted; call with fields='full' or use x402_get_service for the full assessment.");
|
|
281
|
+
}
|
|
282
|
+
// A-17#4: only claim "no services match it" when the list is ACTUALLY empty. An unrecognized
|
|
283
|
+
// network name can still coincide with a raw abbreviation the API filtered on server-side
|
|
284
|
+
// (or the /networks map was momentarily unavailable), leaving services non-empty. Guarding
|
|
285
|
+
// on services.length keeps the note from contradicting a populated list.
|
|
286
|
+
if (net && !net.recognized && services.length === 0) {
|
|
179
287
|
notes.push(`network '${args.network}' did not match any known network (${await knownNetworksHint()}); no services match it.`);
|
|
180
288
|
}
|
|
289
|
+
else if (net && !net.recognized) {
|
|
290
|
+
notes.push(`network '${args.network}' was not in the known network set (${await knownNetworksHint()}); results were filtered server-side on the raw value.`);
|
|
291
|
+
}
|
|
292
|
+
const servicesOut = fields === "compact" ? services.map(toCompactService) : services;
|
|
181
293
|
return ok({
|
|
182
|
-
services, // fields verbatim
|
|
294
|
+
services: servicesOut, // compact projection or full fields verbatim; min_price_usd in decimal USD
|
|
295
|
+
fields,
|
|
183
296
|
meta: resp.meta,
|
|
184
|
-
returned:
|
|
297
|
+
returned: servicesOut.length,
|
|
185
298
|
filters_applied: {
|
|
186
299
|
q: args.q ?? null,
|
|
187
300
|
category: args.category ?? null,
|
|
@@ -196,23 +309,26 @@ export function registerTools(server) {
|
|
|
196
309
|
});
|
|
197
310
|
}
|
|
198
311
|
catch (e) {
|
|
199
|
-
return fail(`
|
|
312
|
+
return fail(`x402_search_services failed: ${describeError(e)}`);
|
|
200
313
|
}
|
|
201
314
|
});
|
|
202
315
|
// -------------------------------------------------------------------------
|
|
203
|
-
// 3.2
|
|
316
|
+
// 3.2 x402_get_service
|
|
204
317
|
// -------------------------------------------------------------------------
|
|
205
|
-
server.registerTool("
|
|
206
|
-
|
|
207
|
-
|
|
318
|
+
server.registerTool("x402_get_service", {
|
|
319
|
+
title: "Get x402 service",
|
|
320
|
+
description: "Call this once you hold a slug and are deciding whether to commit to that service: the full record behind a directory row. Live status, uptime over 24h/7d/30d/90d, average response time, networks and settlement asset, every priced endpoint, and the assessment block. include_series=true adds 90 daily points of on-chain volume and distinct buyers. Read the units map in the response: the per-endpoint price field is atomic token units, not dollars.",
|
|
321
|
+
// B-14#1: STRICT object - an unknown top-level key is rejected (-32602), not silently dropped.
|
|
322
|
+
inputSchema: z.object({
|
|
208
323
|
slug: z.string().trim().min(1).max(200).describe("Service slug, e.g. 'my-api'."),
|
|
209
324
|
include_series: z
|
|
210
325
|
.boolean()
|
|
211
326
|
.default(false)
|
|
212
327
|
.describe("If true, also attach this service's daily on-chain series under `series` (settlement volume and distinct buyers, one point per UTC day over the most recent 90 days, oldest first). Off by default to keep the response small."),
|
|
213
|
-
},
|
|
328
|
+
}).strict(),
|
|
329
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
214
330
|
}, async (args) => {
|
|
215
|
-
trackTool("
|
|
331
|
+
trackTool("x402_get_service", {
|
|
216
332
|
slug: String(args.slug).slice(0, 128),
|
|
217
333
|
include_series: args.include_series,
|
|
218
334
|
});
|
|
@@ -226,7 +342,7 @@ export function registerTools(server) {
|
|
|
226
342
|
assessment: "per-service evidence-backed assessment (reliability, x402 compliance, site/docs, domain, economics, risk, plus an AI synthesis); null until the service is first assessed. Measured fields are plain values; 'unknown'/null are honest, not zero.",
|
|
227
343
|
"assessment.economics": "price_usd/category_percentile are the ENTRY (min) price and its in-category rank; price_max_usd/category_percentile_max carry the highest tier and its rank; endpoint_count and distinct_price_count (1 = flat, >1 = tiered) describe the price spread. All decimal USD; new fields are null on rows assessed before they existed.",
|
|
228
344
|
"assessment.synthesis.*": "AI-derived (family 10): each field is {value, confidence 0-1, source:'ai'}; value may be 'unknown' when the model could not ground it in the measured signals. An AI-derived field NEVER overrides a measured value.",
|
|
229
|
-
"assessment.traction": "Fase 2 (family 6): on-chain settlement traction measured over this service's known payTo addresses via recognized settlers. All *_usd/count fields are a CONSERVATIVE UNDERCOUNT (unattributed settlements are not counted, never estimated up). volume_usd_30d = decimal USD over the last 30 UTC days; tx_count_30d/unique_buyers_30d = counts over 30d; last_settlement_at = ISO 8601 of the most recent settlement; top_buyer_share_30d = 0-1 concentration of the largest buyer; trend_7d_vs_30d = last-7d daily rate over the 30d daily rate; measured_networks = canonical CAIP-2 chains that contributed. status: 'measured' = real numbers where 0 is an HONEST zero; 'no-payto'/'unmeasured-network' = null, never a fake zero; 'unresponsive' = a shared-payout member whose probe has been failing for 7 days, so its share is suppressed (null). shared_payout=true means the payTo is shared across N services; volume_usd_30d
|
|
345
|
+
"assessment.traction": "Fase 2 (family 6): on-chain settlement traction measured over this service's known payTo addresses via recognized settlers. All *_usd/count fields are a CONSERVATIVE UNDERCOUNT (unattributed settlements are not counted, never estimated up). volume_usd_30d = decimal USD over the last 30 UTC days; tx_count_30d/unique_buyers_30d = counts over 30d; last_settlement_at = ISO 8601 of the most recent settlement; top_buyer_share_30d = 0-1 concentration of the largest buyer; trend_7d_vs_30d = last-7d daily rate over the 30d daily rate; measured_networks = canonical CAIP-2 chains that contributed. status: 'measured' = real numbers where 0 is an HONEST zero; 'no-payto'/'unmeasured-network' = null, never a fake zero; 'unresponsive' = a shared-payout member whose probe has been failing for 7 days, so its share is suppressed (null). shared_payout=true means the payTo is shared across N services; only volume_usd_30d is then attributed PRO-QUOTA (the operator-level volume over the shared address, divided across the services sharing it) - a declared convention, not an individually observed measure - while tx_count_30d and unique_buyers_30d stay WHOLE operator-level counts (never fractional), and pro_quota_share carries the cluster fraction (1/(shared_with+1)) a consumer can apply to those counts for a per-service split. top_buyer_share_30d and trend_7d_vs_30d are ratios, invariant under the split. Beyond the 30d figures the traction block carries `first_settlement_at`, all-time `volume_usd_all_time` (pro-quota on a shared payout, like the 30d volume) and `tx_count_all_time` (a whole operator-level count), the per-settlement `median_settlement_usd_30d` / `max_settlement_usd_30d` (invariant amounts, never divided), the `settled_via` facilitator list (volume first), and `shared_with_services` (the sibling listed services on a shared payout address).",
|
|
230
346
|
};
|
|
231
347
|
const payload = {
|
|
232
348
|
service: resp.data, // full ServiceDetail verbatim (includes `assessment` when present)
|
|
@@ -254,16 +370,22 @@ export function registerTools(server) {
|
|
|
254
370
|
if (e instanceof ApiError && e.status === 404) {
|
|
255
371
|
return fail(`Service '${args.slug}' not found.`);
|
|
256
372
|
}
|
|
257
|
-
return fail(`
|
|
373
|
+
return fail(`x402_get_service failed: ${describeError(e)}`);
|
|
258
374
|
}
|
|
259
375
|
});
|
|
260
376
|
// -------------------------------------------------------------------------
|
|
261
|
-
// 3.3
|
|
377
|
+
// 3.3 x402_find_best_service (reliability/compliance/price primary; on-chain traction weighs ~10%,
|
|
262
378
|
// shared-payout traction is attributed pro-quota; unmeasured/suppressed carry no term)
|
|
263
379
|
// -------------------------------------------------------------------------
|
|
264
|
-
server.registerTool("
|
|
265
|
-
|
|
266
|
-
|
|
380
|
+
server.registerTool("x402_find_best_service", {
|
|
381
|
+
title: "Find best x402 service",
|
|
382
|
+
description: "Call this when you have a need in words and want one service to call rather than a list to read: it is the free ranking step between searching and paying. Pass the need as q, plus any category, network, price cap or verification requirement, and get up to 20 ranked recommendations with the basis each one placed on. Ranking is mostly per-service reliability (live status, verification, uptime, response time), x402 compliance, and price in USD, with a small (about 10%) weight on measured on-chain settlement traction that can never dominate those three. The response carries ranking_version (currently 3), need_blind_ranking (true when no q was given, so the order is global quality rather than your need), and a units map holding every scoring caveat in full: the compliance cap, the pro-quota rule for shared payout addresses, renormalization, the $10 volume floor, and the single-buyer discount. Read units before comparing scores across generations.",
|
|
383
|
+
// B-16#0 + B-14#1: STRICT object. A wrong arg NAME (e.g. 'query' for 'q') is now rejected with
|
|
384
|
+
// -32602 instead of being dropped and answered as a need-blind global ranking that scored
|
|
385
|
+
// HIGHER than the correct relevance-matched answer. The strict boundary closes the silent
|
|
386
|
+
// arg-name mismatch; the response also carries need_blind_ranking (below) for the legitimate
|
|
387
|
+
// no-'q' case.
|
|
388
|
+
inputSchema: z.object({
|
|
267
389
|
category: z
|
|
268
390
|
.string()
|
|
269
391
|
.trim()
|
|
@@ -309,9 +431,10 @@ export function registerTools(server) {
|
|
|
309
431
|
.boolean()
|
|
310
432
|
.default(false)
|
|
311
433
|
.describe("If true, also return top facilitators by 7d settlement volume as separate ecosystem context (NOT per-service)."),
|
|
312
|
-
},
|
|
434
|
+
}).strict(),
|
|
435
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
313
436
|
}, async (args) => {
|
|
314
|
-
trackTool("
|
|
437
|
+
trackTool("x402_find_best_service", {
|
|
315
438
|
category: args.category ?? null,
|
|
316
439
|
network: args.network ?? null,
|
|
317
440
|
prefer: args.prefer,
|
|
@@ -321,7 +444,7 @@ export function registerTools(server) {
|
|
|
321
444
|
});
|
|
322
445
|
try {
|
|
323
446
|
// Network name/abbreviation -> canonical abbreviation. This is shared input normalization
|
|
324
|
-
// (
|
|
447
|
+
// (x402_search_services uses the same resolver), NOT ranking: the /best route validates the
|
|
325
448
|
// abbreviation and returns 400 on an unknown one. An unrecognized input is forwarded raw so
|
|
326
449
|
// the server is the single authority on the answer (decision 27/7: API-first).
|
|
327
450
|
const net = args.network ? await resolveNetwork(args.network) : null;
|
|
@@ -344,6 +467,20 @@ export function registerTools(server) {
|
|
|
344
467
|
// tool used to build client-side), lifting meta.ranking_version so a consumer can pin the
|
|
345
468
|
// scoring generation. `note` is present only when nothing matched the filters.
|
|
346
469
|
const d = resp.data;
|
|
470
|
+
// B3: the scoring caveats live HERE, in the response, not in the tool description.
|
|
471
|
+
// A caveat in the description is paid in context by every client that merely MOUNTS this
|
|
472
|
+
// server; a caveat in `units` is paid only by the caller that actually ranked something.
|
|
473
|
+
// Same mechanism x402_get_service already uses. Keep these two in sync with the API.
|
|
474
|
+
const units = {
|
|
475
|
+
ranking_version: "The scoring generation this answer was produced under, currently 3. Generation 2 introduced the compliance signability cap; generation 3 added the anti-wash traction rules below (the $10 volume floor, the single-buyer discount, whole-integer buyer counts). Scores you stored under an earlier generation are NOT comparable with these.",
|
|
476
|
+
"recommendations[].score": "0 to 1 composite. Reliability (live status, verification, uptime, response time), x402 compliance and price carry the weight; measured on-chain traction carries a SMALL term of about 10% and can never dominate the other three.",
|
|
477
|
+
compliance: "The share of deterministic x402 conformance checks the service passes, 0 to 1. CAPPED at 0.6, the floor of the C band, when at least one of its EVM routes was observed missing the EIP-712 domain parameters (extra.name and extra.version) that a standard x402 client needs in order to sign a payment. That is a fact about the payment envelope on the wire, not a judgement on the merit of the service.",
|
|
478
|
+
traction: "Measured per service over its known payTo addresses via recognized settlers: a conservative undercount, never an estimate. The term is 0 with no on-chain settlement in the last 30 UTC days, and 0 when 30d volume is under a $10 floor (sub-floor volume is indistinguishable from dust and must not move rank). A service on a network not yet measured, or a shared-payout member whose probe has been failing, carries NO traction term at all and the remaining weights are RENORMALIZED over it, so an unmeasured service is not scored as if it had measured zero.",
|
|
479
|
+
"traction.shared_payout": "When a payTo address is shared across services, only settlement VOLUME is attributed PRO-QUOTA: the operator-level volume over that address divided across the services sharing it, a declared convention rather than an individually observed measure. Transaction count and unique buyers stay WHOLE operator-level integers, never fractional. Sharing a payout therefore neither rewards a service nor lets clones multiply the same volume.",
|
|
480
|
+
"recommendations[].top_buyer_share_30d": "0 to 1 share of the 30d settlement volume taken by the single largest buyer. A concentrated payout is DISCOUNTED, up to half the traction term when one buyer accounts for all of it: one buyer is one relationship, not broad demand.",
|
|
481
|
+
need_blind_ranking: "true when no free-text q was supplied, so this order is global quality and NOT relevance to a need, whatever the ranking_basis prose asserts. A need-blind answer is not comparable with a q-driven one: they answer different questions.",
|
|
482
|
+
facilitator_context: "Present only with include_facilitator_context=true: top facilitators by 7d settlement volume, as ECOSYSTEM context. It is per-facilitator, never per-service, and carries no meaning for any single recommendation.",
|
|
483
|
+
};
|
|
347
484
|
return ok({
|
|
348
485
|
recommendations: d.recommendations,
|
|
349
486
|
ranking_basis: d.ranking_basis,
|
|
@@ -351,18 +488,27 @@ export function registerTools(server) {
|
|
|
351
488
|
facilitator_context: d.facilitator_context,
|
|
352
489
|
...(d.note !== undefined ? { note: d.note } : {}),
|
|
353
490
|
ranking_version: resp.meta?.ranking_version ?? null,
|
|
491
|
+
// B-16#0: honest signal that no free-text need ('q') was supplied, so the ranking is
|
|
492
|
+
// need-blind (global quality order), NOT relevance-matched to a need - regardless of what
|
|
493
|
+
// ranking_basis prose asserts. True when q is absent/empty. A caller comparing this answer
|
|
494
|
+
// against a q-driven one can see the two are not the same question.
|
|
495
|
+
need_blind_ranking: !args.q,
|
|
496
|
+
// Paid only by the caller that ranked: the full scoring caveats, out of the description.
|
|
497
|
+
units,
|
|
354
498
|
});
|
|
355
499
|
}
|
|
356
500
|
catch (e) {
|
|
357
|
-
return fail(`
|
|
501
|
+
return fail(`x402_find_best_service failed: ${describeError(e)}`);
|
|
358
502
|
}
|
|
359
503
|
});
|
|
360
504
|
// -------------------------------------------------------------------------
|
|
361
|
-
// 3.4
|
|
505
|
+
// 3.4 x402_check_health
|
|
362
506
|
// -------------------------------------------------------------------------
|
|
363
|
-
server.registerTool("
|
|
364
|
-
|
|
365
|
-
|
|
507
|
+
server.registerTool("x402_check_health", {
|
|
508
|
+
title: "Check x402 service health",
|
|
509
|
+
description: "Call this before you send a payment, or right after a call unexpectedly failed: is this service up right now. With no slug, the directory snapshot: five status counts across the directory (include_services=true attaches every row). With a slug: that service's status, its 24h/7d/30d/90d uptime windows, response time, consecutive failures, daily snapshots. No money fields.",
|
|
510
|
+
// B-14#1: STRICT object - an unknown top-level key is rejected (-32602), not silently dropped.
|
|
511
|
+
inputSchema: z.object({
|
|
366
512
|
slug: z
|
|
367
513
|
.string()
|
|
368
514
|
.trim()
|
|
@@ -374,18 +520,27 @@ export function registerTools(server) {
|
|
|
374
520
|
.enum(["24h", "7d", "30d", "90d"])
|
|
375
521
|
.default("30d")
|
|
376
522
|
.describe("Daily uptime snapshot window for single-service mode."),
|
|
377
|
-
|
|
523
|
+
// A-17#3: directory mode returns just the five status counts by default. The full per-service
|
|
524
|
+
// list (453 rows, ~55k tokens, duplicated across content+structuredContent before the compact
|
|
525
|
+
// mirror) is attached ONLY when include_services=true. Ignored in single-service mode.
|
|
526
|
+
include_services: z
|
|
527
|
+
.boolean()
|
|
528
|
+
.default(false)
|
|
529
|
+
.describe("Directory mode only (no slug): if true, also attach the full per-service status array. Off by default so a directory health check returns just the five status counts, not every service."),
|
|
530
|
+
}).strict(),
|
|
531
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
378
532
|
}, async (args) => {
|
|
379
|
-
trackTool("
|
|
533
|
+
trackTool("x402_check_health", {
|
|
380
534
|
mode: args.slug ? "service" : "directory",
|
|
381
535
|
slug: args.slug ? String(args.slug).slice(0, 128) : null,
|
|
382
536
|
uptime_period: args.uptime_period,
|
|
537
|
+
include_services: args.slug ? null : (args.include_services ?? false),
|
|
383
538
|
});
|
|
384
539
|
try {
|
|
385
540
|
if (!args.slug) {
|
|
386
541
|
const resp = await getStatus();
|
|
387
542
|
const d = resp.data;
|
|
388
|
-
|
|
543
|
+
const directory = {
|
|
389
544
|
mode: "directory",
|
|
390
545
|
summary: {
|
|
391
546
|
total: d.total,
|
|
@@ -394,8 +549,11 @@ export function registerTools(server) {
|
|
|
394
549
|
offline: d.offline,
|
|
395
550
|
unknown: d.unknown,
|
|
396
551
|
},
|
|
397
|
-
|
|
398
|
-
|
|
552
|
+
};
|
|
553
|
+
// A-17#3: attach the full per-service list only on request (default: counts only).
|
|
554
|
+
if (args.include_services)
|
|
555
|
+
directory.services = d.services; // StatusServiceItem[] verbatim
|
|
556
|
+
return ok(directory);
|
|
399
557
|
}
|
|
400
558
|
const detail = await getService(args.slug);
|
|
401
559
|
const s = detail.data;
|
|
@@ -428,15 +586,17 @@ export function registerTools(server) {
|
|
|
428
586
|
if (e instanceof ApiError && e.status === 404) {
|
|
429
587
|
return fail(`Service '${args.slug}' not found.`);
|
|
430
588
|
}
|
|
431
|
-
return fail(`
|
|
589
|
+
return fail(`x402_check_health failed: ${describeError(e)}`);
|
|
432
590
|
}
|
|
433
591
|
});
|
|
434
592
|
// -------------------------------------------------------------------------
|
|
435
|
-
// 3.5
|
|
593
|
+
// 3.5 x402_facilitator_volumes (the core per-facilitator on-chain metric)
|
|
436
594
|
// -------------------------------------------------------------------------
|
|
437
|
-
server.registerTool("
|
|
438
|
-
|
|
439
|
-
|
|
595
|
+
server.registerTool("x402_facilitator_volumes", {
|
|
596
|
+
title: "x402 facilitator volumes",
|
|
597
|
+
description: "Call this when the question is about the rail rather than the service: which x402 facilitator actually settles money, and how much. Returns on-chain-verified settlement volume and transaction counts per facilitator for today (UTC), 7d, 30d and all-time, plus a verification flag ('on-chain' once volume has been observed on-chain, else 'listed'), across more than 30 facilitators. Optional daily timeseries (up to 90 days) and per-chain breakdown. Volume is decimal USD. Caveats: PER-FACILITATOR, never per-service; the *_24h fields cover today (UTC) so far, not a trailing 24 hours, and reset at 00:00 UTC, so prefer 7d.",
|
|
598
|
+
// B-14#1: STRICT object - an unknown top-level key is rejected (-32602), not silently dropped.
|
|
599
|
+
inputSchema: z.object({
|
|
440
600
|
timeframe: z
|
|
441
601
|
.enum(["24h", "7d", "30d", "all"])
|
|
442
602
|
.default("7d")
|
|
@@ -458,9 +618,10 @@ export function registerTools(server) {
|
|
|
458
618
|
.describe("Length of the timeseries in days (only used when include_timeseries is true)."),
|
|
459
619
|
page: z.number().int().min(1).default(1),
|
|
460
620
|
per_page: z.number().int().min(1).max(100).default(25),
|
|
461
|
-
},
|
|
621
|
+
}).strict(),
|
|
622
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
462
623
|
}, async (args) => {
|
|
463
|
-
trackTool("
|
|
624
|
+
trackTool("x402_facilitator_volumes", {
|
|
464
625
|
timeframe: args.timeframe,
|
|
465
626
|
include_timeseries: args.include_timeseries,
|
|
466
627
|
include_chains: args.include_chains,
|
|
@@ -483,22 +644,25 @@ export function registerTools(server) {
|
|
|
483
644
|
facilitators: resp.data, // Facilitator[] verbatim, USD passed through
|
|
484
645
|
meta: resp.meta,
|
|
485
646
|
units: {
|
|
486
|
-
"volume_usd_24h/7d/30d/all": "decimal US dollars",
|
|
647
|
+
"volume_usd_24h/7d/30d/all": "decimal US dollars; the *_24h fields cover today (UTC) so far, not a trailing 24-hour window, and reset at 00:00 UTC",
|
|
487
648
|
"tx_count_*": "integer transaction counts",
|
|
488
649
|
verification: "'on-chain' iff observed on-chain volume > 0, else 'listed'",
|
|
489
650
|
},
|
|
490
651
|
});
|
|
491
652
|
}
|
|
492
653
|
catch (e) {
|
|
493
|
-
return fail(`
|
|
654
|
+
return fail(`x402_facilitator_volumes failed: ${describeError(e)}`);
|
|
494
655
|
}
|
|
495
656
|
});
|
|
496
657
|
// -------------------------------------------------------------------------
|
|
497
|
-
// 3.6
|
|
658
|
+
// 3.6 x402_assess_services (PAID pass-through; the package holds NO keys and NEVER signs/settles)
|
|
498
659
|
// -------------------------------------------------------------------------
|
|
499
|
-
server.registerTool("
|
|
500
|
-
|
|
501
|
-
|
|
660
|
+
server.registerTool("x402_assess_services", {
|
|
661
|
+
title: "Assess x402 services (paid)",
|
|
662
|
+
description: "Call this when the free signals have run out: you hold 2 to 8 finalists from x402_search_services or x402_find_best_service, their stored fields do not separate them for YOUR stated need, and choosing wrong costs more than a quarter. It buys one fresh AI assessment reasoned against your question, not a cached grade; reading an already-computed assessment stays free via x402_get_service. Price: a one-time $0.25 USDC on Base, over two calls. Call once WITHOUT payment_signature_b64 to receive the x402 payment challenge verbatim (accepts[], amount, payTo, and a base64 PAYMENT-REQUIRED header); sign accepts[0] client-side with your own wallet; call again with the SAME question and services plus payment_signature_b64 to receive the report and a base64 PAYMENT-RESPONSE settlement receipt. This server holds no keys, never signs and never settles: it only relays the challenge. Optionally add probe { slug, endpoint_path? } to have one listed service paid and called for real and its answer analyzed: the challenge is then priced at $0.25 plus that endpoint price X, and the report gains a probe_report block with a verdict and truncated extracts, never the verbatim third-party body. When live probing is not armed the probe is ignored. Caveats: read the amount to sign from accepts[0].amount, never from a fixed figure, since a probe changes it; probe fees are non-refundable whatever the verdict; if the fresh run cannot be produced the server answers before settling, so you are never charged for nothing; there is no refund. Prices are US dollars.",
|
|
663
|
+
// B-14#1: STRICT object - an unknown top-level key is rejected (-32602), not silently dropped.
|
|
664
|
+
// Matters most on a PAID tool: a misnamed key can no longer change what is charged for.
|
|
665
|
+
inputSchema: z.object({
|
|
502
666
|
question: z
|
|
503
667
|
.string()
|
|
504
668
|
.trim()
|
|
@@ -509,7 +673,7 @@ export function registerTools(server) {
|
|
|
509
673
|
.array(z.string().trim().min(1).max(200))
|
|
510
674
|
.min(1)
|
|
511
675
|
.max(8)
|
|
512
|
-
.describe("Service slugs to compare for the need (1 to 8; find them with
|
|
676
|
+
.describe("Service slugs to compare for the need (1 to 8; find them with x402_search_services or x402_find_best_service)."),
|
|
513
677
|
payment_signature_b64: z
|
|
514
678
|
.string()
|
|
515
679
|
.trim()
|
|
@@ -537,9 +701,10 @@ export function registerTools(server) {
|
|
|
537
701
|
})
|
|
538
702
|
.optional()
|
|
539
703
|
.describe("Optional live-probe request: pay one listed service for real and analyze what it returns. When the server has probing armed the price becomes $0.25 plus that endpoint price X (non-refundable); the report gains a probe_report block with a verdict and truncated extracts, never the verbatim third-party body. Ignored when probing is not armed."),
|
|
540
|
-
},
|
|
704
|
+
}).strict(),
|
|
705
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true },
|
|
541
706
|
}, async (args) => {
|
|
542
|
-
trackTool("
|
|
707
|
+
trackTool("x402_assess_services", {
|
|
543
708
|
service_count: args.services.length,
|
|
544
709
|
has_signature: Boolean(args.payment_signature_b64),
|
|
545
710
|
has_probe: Boolean(args.probe),
|
|
@@ -567,17 +732,121 @@ export function registerTools(server) {
|
|
|
567
732
|
status: 402,
|
|
568
733
|
payment_required: result.body,
|
|
569
734
|
payment_required_header_b64: result.paymentRequiredHeaderB64,
|
|
570
|
-
instruction:
|
|
735
|
+
instruction: buildAssessInstruction(result.body),
|
|
571
736
|
...(args.payment_signature_b64 ? { note: ASSESS_SIGNATURE_REJECTED_NOTE } : {}),
|
|
572
737
|
});
|
|
573
738
|
}
|
|
574
739
|
// 400 (validation), 503 (dark or an uncharged fail-soft miss), or anything else: surface the
|
|
575
740
|
// server's message as a tool error.
|
|
576
|
-
const msg = extractApiMessage(result.body) ?? `
|
|
741
|
+
const msg = extractApiMessage(result.body) ?? `x402_assess_services failed: HTTP ${result.status}`;
|
|
577
742
|
return fail(msg);
|
|
578
743
|
}
|
|
579
744
|
catch (e) {
|
|
580
|
-
return fail(`
|
|
745
|
+
return fail(`x402_assess_services failed: ${describeError(e)}`);
|
|
746
|
+
}
|
|
747
|
+
});
|
|
748
|
+
// -------------------------------------------------------------------------
|
|
749
|
+
// 3.7 x402_change_events (T1a drift feed; read-only, free)
|
|
750
|
+
//
|
|
751
|
+
// WIRE-NAME TRAP: the per-service filter is `service`, NOT `slug`. The API ignores an unknown
|
|
752
|
+
// query param rather than rejecting it, so a `slug=` would return the whole unfiltered feed and
|
|
753
|
+
// be reported here as filtered. Pinned by a test in tools.test.ts.
|
|
754
|
+
// NO USD ANYWHERE: the prices in this feed (summary.priceChanges[].oldPrice/newPrice and the
|
|
755
|
+
// `price` inside the snapshots) are ATOMIC token amounts, never dollars. Passed through verbatim
|
|
756
|
+
// per the USD PASS-THROUGH rule at the top of this file: no rescale, no conversion.
|
|
757
|
+
// -------------------------------------------------------------------------
|
|
758
|
+
server.registerTool("x402_change_events", {
|
|
759
|
+
title: "x402 service change events",
|
|
760
|
+
description: "Call this before you trust anything you cached about a service, and right after a payment failed for no obvious reason: the monitor's log of what moved under you. Returns payTo, price and 402-schema changes observed on listed services, most recent first, in exactly three event types (payto_changed, price_changed, schema_changed). Filter with service (the slug), type, and days (1 to 365, default 90). Caveats: prices here are atomic token amounts, never dollars, and every payTo is masked by design, so the feed reports THAT the payout address changed, never the address. Free and read-only.",
|
|
761
|
+
// STRICT object, like every other tool: an unknown top-level key is rejected with -32602
|
|
762
|
+
// instead of being dropped and the query answered as if the filter had been honored.
|
|
763
|
+
inputSchema: z.object({
|
|
764
|
+
service: z
|
|
765
|
+
.string()
|
|
766
|
+
.trim()
|
|
767
|
+
.min(1)
|
|
768
|
+
.max(200)
|
|
769
|
+
.optional()
|
|
770
|
+
.describe("Service slug to restrict the feed to, e.g. 'exa' (the same slug x402_get_service takes). Omit for changes across every listed service."),
|
|
771
|
+
type: z
|
|
772
|
+
.enum(["payto_changed", "price_changed", "schema_changed"])
|
|
773
|
+
.optional()
|
|
774
|
+
.describe("Restrict to one kind of change: 'payto_changed' (the payout address set changed), 'price_changed' (at least one endpoint's price changed), 'schema_changed' (the 402 envelope gained or lost accepts entries or priced endpoints). Omit for all three."),
|
|
775
|
+
days: z
|
|
776
|
+
.number()
|
|
777
|
+
.int()
|
|
778
|
+
.min(1)
|
|
779
|
+
.max(365)
|
|
780
|
+
.default(90)
|
|
781
|
+
.describe("Lookback window in days, 1 to 365 (default 90). Events older than the window are not in the feed."),
|
|
782
|
+
page: z
|
|
783
|
+
.number()
|
|
784
|
+
.int()
|
|
785
|
+
.min(1)
|
|
786
|
+
.default(1)
|
|
787
|
+
.describe("1-based page index into the filtered event set (see total_pages)."),
|
|
788
|
+
per_page: z
|
|
789
|
+
.number()
|
|
790
|
+
.int()
|
|
791
|
+
.min(1)
|
|
792
|
+
.max(100)
|
|
793
|
+
.default(25)
|
|
794
|
+
.describe("Events per page, 1 to 100 (default 25). Each event carries the full before/after envelope snapshots, so a large page is heavy."),
|
|
795
|
+
}).strict(),
|
|
796
|
+
annotations: { readOnlyHint: true, openWorldHint: true },
|
|
797
|
+
}, async (args) => {
|
|
798
|
+
trackTool("x402_change_events", {
|
|
799
|
+
service: args.service ? String(args.service).slice(0, 128) : null,
|
|
800
|
+
type: args.type ?? null,
|
|
801
|
+
days: args.days ?? null,
|
|
802
|
+
page: args.page ?? null,
|
|
803
|
+
per_page: args.per_page ?? null,
|
|
804
|
+
});
|
|
805
|
+
try {
|
|
806
|
+
const resp = await getChanges({
|
|
807
|
+
// `service` is the wire name. Do NOT rename this to `slug`: the API would ignore it and
|
|
808
|
+
// answer with the whole unfiltered feed, silently.
|
|
809
|
+
service: args.service,
|
|
810
|
+
type: args.type,
|
|
811
|
+
days: args.days,
|
|
812
|
+
page: args.page,
|
|
813
|
+
per_page: args.per_page,
|
|
814
|
+
});
|
|
815
|
+
return ok({
|
|
816
|
+
changes: resp.data, // ChangeEvent[] verbatim, summaries and snapshots untouched
|
|
817
|
+
// Explicitly the SERVER's total for the filtered window, not this page's length. The two
|
|
818
|
+
// differ by design (a filtered feed can hold thousands of events across many pages), so
|
|
819
|
+
// `returned` carries the page length separately and neither is ever inferred from the other.
|
|
820
|
+
total: resp.meta.total,
|
|
821
|
+
returned: resp.data.length,
|
|
822
|
+
page: resp.meta.page,
|
|
823
|
+
per_page: resp.meta.per_page,
|
|
824
|
+
total_pages: resp.meta.total_pages,
|
|
825
|
+
days: resp.meta.days,
|
|
826
|
+
filters_applied: {
|
|
827
|
+
service: args.service ?? null,
|
|
828
|
+
type: args.type ?? null,
|
|
829
|
+
},
|
|
830
|
+
units: {
|
|
831
|
+
observed_at: "ISO 8601 UTC timestamp of when the monitor observed the change, not when the operator made it. Events are returned most recent first; the order is fixed and cannot be configured.",
|
|
832
|
+
type: "'payto_changed' = the set of payout addresses the service asks to be paid at changed (one added, one dropped, or both); 'price_changed' = at least one endpoint changed price; 'schema_changed' = the 402 envelope itself changed, with accepts entries or priced endpoints added or removed. Every event is exactly one of these three.",
|
|
833
|
+
summary: "Per-type diff digest, passed through verbatim: payto_changed carries payToAdded/payToRemoved, price_changed carries priceChanges[{network, endpoint, oldPrice, newPrice, assetName}], schema_changed carries schemaAdded/schemaRemoved/endpointsAdded/endpointsRemoved.",
|
|
834
|
+
"summary.priceChanges[].oldPrice/newPrice": "ATOMIC on-chain token units (uint256 strings) in that route's own asset, NOT dollars. Do not rescale them and do not read them as USD; a change of asset can move the number without moving the real price.",
|
|
835
|
+
"old_snapshot/new_snapshot": "The service's full accepts array before and after the change, verbatim. The `price` field inside is an ATOMIC token amount too, not dollars.",
|
|
836
|
+
payTo: "Every payTo address in this feed is MASKED by the API (leading and trailing characters only), deliberately: the feed reports THAT the payout address changed, never the address in full. Do not present a masked value as a full address and do not try to reconstruct one.",
|
|
837
|
+
total: "The server's count of events matching the filter over the whole window, NOT the number of events on this page. `returned` is the page length; page through with page/per_page up to total_pages.",
|
|
838
|
+
days: "The lookback window actually applied, in days; the server clamps the request to 1 to 365 (default 90).",
|
|
839
|
+
},
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
catch (e) {
|
|
843
|
+
// zod blocks an out-of-set `type` before the wire, so this 400 branch should be
|
|
844
|
+
// unreachable; keep it so an API-side validation change surfaces as a readable message
|
|
845
|
+
// instead of a bare HTTP status.
|
|
846
|
+
if (e instanceof ApiError && e.status === 400) {
|
|
847
|
+
return fail(`x402_change_events: the API rejected the query: ${describeError(e)}`);
|
|
848
|
+
}
|
|
849
|
+
return fail(`x402_change_events failed: ${describeError(e)}`);
|
|
581
850
|
}
|
|
582
851
|
});
|
|
583
852
|
}
|