@one-source/api-mcp 5.5.0 → 5.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/mpp.d.ts +23 -14
- package/dist/mpp.d.ts.map +1 -1
- package/dist/mpp.js +119 -38
- package/dist/mpp.js.map +1 -1
- package/dist/tools/chain/refund.d.ts +5 -1
- package/dist/tools/chain/refund.d.ts.map +1 -1
- package/dist/tools/chain/refund.js +20 -13
- package/dist/tools/chain/refund.js.map +1 -1
- package/package.json +1 -1
package/dist/mpp.d.ts
CHANGED
|
@@ -13,6 +13,11 @@ export interface MppSetupResult {
|
|
|
13
13
|
/** Voucher-channel session handle. */
|
|
14
14
|
session?: MppSessionHandle;
|
|
15
15
|
}
|
|
16
|
+
export interface MppReclaimResult {
|
|
17
|
+
ok: boolean;
|
|
18
|
+
/** Human-readable outcome, safe to surface directly to the user. */
|
|
19
|
+
message: string;
|
|
20
|
+
}
|
|
16
21
|
export declare function setupMpp(): MppSetupResult;
|
|
17
22
|
/** Whether MPP payment is active (MPP_PRIVATE_KEY set). */
|
|
18
23
|
export declare function isMppEnabled(): boolean;
|
|
@@ -20,21 +25,25 @@ export declare function isMppEnabled(): boolean;
|
|
|
20
25
|
export declare function getMppAddress(): string | undefined;
|
|
21
26
|
/** Whether the session channel scheme initialised and can be selected. */
|
|
22
27
|
export declare function isMppSessionAvailable(): boolean;
|
|
28
|
+
/** Whether an MPP voucher channel is currently open on-chain. */
|
|
29
|
+
export declare function isMppSessionOpen(): boolean;
|
|
23
30
|
/**
|
|
24
|
-
* Cooperatively close the active MPP voucher channel
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* We do NOT use `manager.close()`: mppx's legacy manager signs the close at its
|
|
30
|
-
* locally-tracked `spent`, which it derives from the receipt `spent` field. The
|
|
31
|
-
* gateway (mpp-go) reports `spent` as the per-call delta and the running total
|
|
32
|
-
* in `acceptedCumulative`, so mppx's `spent` never advances past the first
|
|
33
|
-
* voucher and the close is rejected ("close cumulativeAmount … below the last
|
|
34
|
-
* accepted voucher"). Instead we sign our own close credential at the manager's
|
|
35
|
-
* `cumulative` (the total we authorized and the gateway accepted) and POST it —
|
|
36
|
-
* validated end-to-end against the live gateway. Track the upstream fix at
|
|
37
|
-
* wevm/mppx; switch back to `manager.close()` once it uses `acceptedCumulative`.
|
|
31
|
+
* Cooperatively close the active MPP voucher channel on shutdown. Safe to call
|
|
32
|
+
* when no channel was ever opened (no-op) and idempotent. Swallows errors so a
|
|
33
|
+
* stuck settle can't hang shutdown. Terminal — does not re-open the channel
|
|
34
|
+
* (use {@link reclaimMppSession} for the in-session reclaim that re-opens).
|
|
38
35
|
*/
|
|
39
36
|
export declare function closeMppSession(): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* Reclaim the unspent deposit of the open MPP voucher channel back to the payer
|
|
39
|
+
* wallet, then re-arm the session so the next mpp-session call opens a fresh
|
|
40
|
+
* channel. This is the MPP analog of x402's `refundBatchChannel` and backs the
|
|
41
|
+
* `1s_refund` tool's MPP branch.
|
|
42
|
+
*
|
|
43
|
+
* Unlike {@link closeMppSession} (terminal, shutdown-only), this rebuilds the
|
|
44
|
+
* legacy session manager after settling so the rail stays usable in-session.
|
|
45
|
+
* Returns a structured result rather than throwing, so the calling tool can
|
|
46
|
+
* surface a clear message for the "nothing to reclaim" / failure cases.
|
|
47
|
+
*/
|
|
48
|
+
export declare function reclaimMppSession(): Promise<MppReclaimResult>;
|
|
40
49
|
//# sourceMappingURL=mpp.d.ts.map
|
package/dist/mpp.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mpp.d.ts","sourceRoot":"","sources":["../src/mpp.ts"],"names":[],"mappings":"AA4BA,MAAM,MAAM,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE3C,MAAM,WAAW,gBAAgB;IAC/B,qEAAqE;IACrE,KAAK,EAAE,OAAO,U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AI,CAAC,CAWrD;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,gBAAgB,CAAC,CAiCnE"}
|
package/dist/mpp.js
CHANGED
|
@@ -44,6 +44,11 @@ let _sessionFetchImpl;
|
|
|
44
44
|
let _lastSessionUrl;
|
|
45
45
|
let _lastSessionChallenge;
|
|
46
46
|
let _sessionClosed = false;
|
|
47
|
+
// (Re)builds the legacy session manager + method under a fresh channel, so a
|
|
48
|
+
// reclaim (1s_refund) can settle the current channel and immediately make a new
|
|
49
|
+
// one openable on the next mpp-session call — mirrors x402's salt-rotation
|
|
50
|
+
// rebuild. Undefined when the session scheme failed to initialise.
|
|
51
|
+
let _rebuildSession;
|
|
47
52
|
function maxDeposit() {
|
|
48
53
|
return process.env.MPP_MAX_DEPOSIT?.trim() || DEFAULT_MAX_DEPOSIT;
|
|
49
54
|
}
|
|
@@ -100,22 +105,36 @@ export function setupMpp() {
|
|
|
100
105
|
chain: tempoChain,
|
|
101
106
|
transport: http(process.env.MPP_RPC_URL?.trim() || undefined),
|
|
102
107
|
});
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
108
|
+
// (Re)construct the manager + standalone close method for a brand-new
|
|
109
|
+
// channel. Called once here and again by reclaimMppSession after a close,
|
|
110
|
+
// so the next mpp-session call opens a fresh channel rather than reusing the
|
|
111
|
+
// closed one (the legacy manager has no reset). maxDeposit() is read live so
|
|
112
|
+
// a cap changed via 1s_batch_config applies to the next channel.
|
|
113
|
+
_rebuildSession = () => {
|
|
114
|
+
_sessionManager = sessionLegacyManager({
|
|
115
|
+
account,
|
|
116
|
+
client: sessionClient,
|
|
117
|
+
maxDeposit: maxDeposit(),
|
|
118
|
+
fetch: stripX402Fetch,
|
|
119
|
+
});
|
|
120
|
+
// A standalone legacy session method (same account/client) used to sign
|
|
121
|
+
// our own close credential — see closeMppSession for why. The method
|
|
122
|
+
// factory takes `getClient` (the `client` shorthand is manager-only).
|
|
123
|
+
_sessionMethod = sessionLegacy({ account, getClient: () => sessionClient });
|
|
124
|
+
_sessionFetchImpl = stripX402Fetch;
|
|
125
|
+
// A rebuilt channel has no captured request yet.
|
|
126
|
+
_lastSessionUrl = undefined;
|
|
127
|
+
_lastSessionChallenge = undefined;
|
|
128
|
+
};
|
|
129
|
+
_rebuildSession();
|
|
130
|
+
// Reads `_sessionManager` live (not a captured const) so a post-reclaim
|
|
131
|
+
// rebuild routes through the new manager. Captures the last session
|
|
132
|
+
// request's URL + parsed challenge so a close can target the right endpoint
|
|
133
|
+
// and bind to a valid challenge.
|
|
118
134
|
const sessionFetch = async (input, init) => {
|
|
135
|
+
const mgr = _sessionManager;
|
|
136
|
+
if (!mgr)
|
|
137
|
+
throw new Error('MPP session manager not initialised');
|
|
119
138
|
const res = await mgr.fetch(input, init);
|
|
120
139
|
_lastSessionUrl = typeof input === 'string' ? input : input instanceof URL ? input.href : input.url;
|
|
121
140
|
const challenge = res.challenge;
|
|
@@ -129,6 +148,7 @@ export function setupMpp() {
|
|
|
129
148
|
catch (err) {
|
|
130
149
|
_sessionAvailable = false;
|
|
131
150
|
_sessionManager = undefined;
|
|
151
|
+
_rebuildSession = undefined;
|
|
132
152
|
console.error(`[onesource-api] warning: MPP session channel unavailable (${err instanceof Error ? err.message : String(err)}); falling back to charge-only`);
|
|
133
153
|
}
|
|
134
154
|
_enabled = true;
|
|
@@ -154,11 +174,19 @@ export function getMppAddress() {
|
|
|
154
174
|
export function isMppSessionAvailable() {
|
|
155
175
|
return _sessionAvailable;
|
|
156
176
|
}
|
|
177
|
+
/** Whether an MPP voucher channel is currently open on-chain. */
|
|
178
|
+
export function isMppSessionOpen() {
|
|
179
|
+
return Boolean(_sessionManager?.opened);
|
|
180
|
+
}
|
|
181
|
+
/** Whether an open channel is ready to be settled (open + close machinery captured). */
|
|
182
|
+
function closeReady() {
|
|
183
|
+
return Boolean(_sessionManager?.opened && _sessionMethod && _sessionFetchImpl && _lastSessionUrl && _lastSessionChallenge);
|
|
184
|
+
}
|
|
157
185
|
/**
|
|
158
|
-
*
|
|
159
|
-
* authorized spend on-chain and reclaiming the unspent
|
|
160
|
-
*
|
|
161
|
-
*
|
|
186
|
+
* Sign and POST our own close credential for the currently-open channel,
|
|
187
|
+
* settling the latest authorized spend on-chain and reclaiming the unspent
|
|
188
|
+
* deposit to the payer wallet. Caller must ensure {@link closeReady}; throws on
|
|
189
|
+
* gateway rejection.
|
|
162
190
|
*
|
|
163
191
|
* We do NOT use `manager.close()`: mppx's legacy manager signs the close at its
|
|
164
192
|
* locally-tracked `spent`, which it derives from the receipt `spent` field. The
|
|
@@ -170,36 +198,88 @@ export function isMppSessionAvailable() {
|
|
|
170
198
|
* validated end-to-end against the live gateway. Track the upstream fix at
|
|
171
199
|
* wevm/mppx; switch back to `manager.close()` once it uses `acceptedCumulative`.
|
|
172
200
|
*/
|
|
201
|
+
async function postCloseCredential() {
|
|
202
|
+
const mgr = _sessionManager;
|
|
203
|
+
const credential = await _sessionMethod.createCredential({
|
|
204
|
+
challenge: _lastSessionChallenge,
|
|
205
|
+
context: {
|
|
206
|
+
action: 'close',
|
|
207
|
+
channelId: mgr.channelId,
|
|
208
|
+
cumulativeAmountRaw: mgr.cumulative.toString(),
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
const res = await _sessionFetchImpl(_lastSessionUrl, {
|
|
212
|
+
method: 'POST',
|
|
213
|
+
headers: { Authorization: credential },
|
|
214
|
+
});
|
|
215
|
+
if (!res.ok) {
|
|
216
|
+
const body = await res.text().catch(() => '');
|
|
217
|
+
throw new Error(`gateway returned ${res.status}${body ? `: ${body.slice(0, 160)}` : ''}`);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Cooperatively close the active MPP voucher channel on shutdown. Safe to call
|
|
222
|
+
* when no channel was ever opened (no-op) and idempotent. Swallows errors so a
|
|
223
|
+
* stuck settle can't hang shutdown. Terminal — does not re-open the channel
|
|
224
|
+
* (use {@link reclaimMppSession} for the in-session reclaim that re-opens).
|
|
225
|
+
*/
|
|
173
226
|
export async function closeMppSession() {
|
|
174
227
|
if (_sessionClosed)
|
|
175
228
|
return;
|
|
176
229
|
_sessionClosed = true;
|
|
177
|
-
|
|
178
|
-
if (!mgr?.opened || !_sessionMethod || !_sessionFetchImpl || !_lastSessionUrl || !_lastSessionChallenge) {
|
|
230
|
+
if (!closeReady())
|
|
179
231
|
return;
|
|
180
|
-
}
|
|
181
232
|
try {
|
|
182
|
-
|
|
183
|
-
challenge: _lastSessionChallenge,
|
|
184
|
-
context: {
|
|
185
|
-
action: 'close',
|
|
186
|
-
channelId: mgr.channelId,
|
|
187
|
-
cumulativeAmountRaw: mgr.cumulative.toString(),
|
|
188
|
-
},
|
|
189
|
-
});
|
|
190
|
-
const res = await _sessionFetchImpl(_lastSessionUrl, {
|
|
191
|
-
method: 'POST',
|
|
192
|
-
headers: { Authorization: credential },
|
|
193
|
-
});
|
|
194
|
-
if (!res.ok) {
|
|
195
|
-
const body = await res.text().catch(() => '');
|
|
196
|
-
throw new Error(`gateway returned ${res.status}${body ? `: ${body.slice(0, 160)}` : ''}`);
|
|
197
|
-
}
|
|
233
|
+
await postCloseCredential();
|
|
198
234
|
}
|
|
199
235
|
catch (err) {
|
|
200
236
|
console.error(`[onesource-api] warning: MPP session close failed (${err instanceof Error ? err.message : String(err)}); unspent deposit is reclaimable later on-chain`);
|
|
201
237
|
}
|
|
202
238
|
}
|
|
239
|
+
/**
|
|
240
|
+
* Reclaim the unspent deposit of the open MPP voucher channel back to the payer
|
|
241
|
+
* wallet, then re-arm the session so the next mpp-session call opens a fresh
|
|
242
|
+
* channel. This is the MPP analog of x402's `refundBatchChannel` and backs the
|
|
243
|
+
* `1s_refund` tool's MPP branch.
|
|
244
|
+
*
|
|
245
|
+
* Unlike {@link closeMppSession} (terminal, shutdown-only), this rebuilds the
|
|
246
|
+
* legacy session manager after settling so the rail stays usable in-session.
|
|
247
|
+
* Returns a structured result rather than throwing, so the calling tool can
|
|
248
|
+
* surface a clear message for the "nothing to reclaim" / failure cases.
|
|
249
|
+
*/
|
|
250
|
+
export async function reclaimMppSession() {
|
|
251
|
+
if (!_enabled) {
|
|
252
|
+
return { ok: false, message: 'MPP payment is not active in this session (set MPP_PRIVATE_KEY to a funded Tempo wallet).' };
|
|
253
|
+
}
|
|
254
|
+
if (!_sessionAvailable) {
|
|
255
|
+
return { ok: false, message: 'MPP session channels are unavailable in this session, so there is nothing to reclaim.' };
|
|
256
|
+
}
|
|
257
|
+
if (!closeReady()) {
|
|
258
|
+
return {
|
|
259
|
+
ok: false,
|
|
260
|
+
message: 'No open MPP voucher channel — nothing to reclaim. A channel opens on your first call in mpp-session mode (1s_payment_mode → mpp-session).',
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
try {
|
|
264
|
+
await postCloseCredential();
|
|
265
|
+
}
|
|
266
|
+
catch (err) {
|
|
267
|
+
const raw = err instanceof Error ? err.message : String(err);
|
|
268
|
+
return {
|
|
269
|
+
ok: false,
|
|
270
|
+
message: `Reclaim failed: ${raw}. The unspent deposit remains reclaimable later on-chain.`,
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
// Re-arm: rebuild the manager so a later mpp-session call opens a new channel,
|
|
274
|
+
// and clear the shutdown latch so closeMppSession can still settle that one.
|
|
275
|
+
_rebuildSession?.();
|
|
276
|
+
_sessionClosed = false;
|
|
277
|
+
return {
|
|
278
|
+
ok: true,
|
|
279
|
+
message: `MPP voucher channel closed and settled. Unspent deposit is being returned to ${_address ?? 'your wallet'} on Tempo. ` +
|
|
280
|
+
'A fresh channel will open on your next mpp-session call.',
|
|
281
|
+
};
|
|
282
|
+
}
|
|
203
283
|
/** @internal -- for test teardown only */
|
|
204
284
|
export function resetMpp() {
|
|
205
285
|
_applied = false;
|
|
@@ -213,5 +293,6 @@ export function resetMpp() {
|
|
|
213
293
|
_lastSessionUrl = undefined;
|
|
214
294
|
_lastSessionChallenge = undefined;
|
|
215
295
|
_sessionClosed = false;
|
|
296
|
+
_rebuildSession = undefined;
|
|
216
297
|
}
|
|
217
298
|
//# sourceMappingURL=mpp.js.map
|
package/dist/mpp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mpp.js","sourceRoot":"","sources":["../src/mpp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAChD,OAAO,EAAE,KAAK,IAAI,UAAU,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"mpp.js","sourceRoot":"","sources":["../src/mpp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,EAAE,mBAAmB,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAChD,OAAO,EAAE,KAAK,IAAI,UAAU,EAAE,MAAM,aAAa,CAAC;AA0BlD,+EAA+E;AAC/E,yEAAyE;AACzE,MAAM,mBAAmB,GAAG,GAAG,CAAC;AAEhC,IAAI,QAAQ,GAAG,KAAK,CAAC;AACrB,IAAI,aAAyC,CAAC;AAE9C,IAAI,QAAQ,GAAG,KAAK,CAAC;AACrB,IAAI,QAA4B,CAAC;AACjC,IAAI,iBAAiB,G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,SAAS,CAAC;AAC9B,CAAC"}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 1s_refund — reclaim unused
|
|
2
|
+
* 1s_refund — reclaim unused payment-channel deposit back to the payer wallet.
|
|
3
|
+
*
|
|
4
|
+
* Rail-neutral: covers x402 batch channels (USDC on Base) and MPP session
|
|
5
|
+
* channels (USDC.e / pathUSD on Tempo). Routes to whichever channel is live for
|
|
6
|
+
* this session, so the same tool reclaims either deposit.
|
|
3
7
|
*/
|
|
4
8
|
import type { ToolDef } from '../../types.js';
|
|
5
9
|
export declare const tool: ToolDef;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refund.d.ts","sourceRoot":"","sources":["../../../src/tools/chain/refund.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"refund.d.ts","sourceRoot":"","sources":["../../../src/tools/chain/refund.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAK9C,eAAO,MAAM,IAAI,EAAE,OAiClB,CAAC"}
|
|
@@ -1,25 +1,32 @@
|
|
|
1
1
|
import { getPaymentModeInfo } from '../../payment.js';
|
|
2
2
|
import { refundBatchChannel } from '../../x402.js';
|
|
3
|
+
import { reclaimMppSession, isMppSessionOpen } from '../../mpp.js';
|
|
3
4
|
export const tool = {
|
|
4
5
|
name: '1s_refund',
|
|
5
|
-
description: '
|
|
6
|
-
'
|
|
7
|
-
'whatever you do not spend stays locked
|
|
8
|
-
'
|
|
9
|
-
'
|
|
10
|
-
'
|
|
11
|
-
'MPP session (Tempo) deposits are reclaimed automatically when the server shuts down, not via this tool.',
|
|
6
|
+
description: 'Reclaim the unused deposit from an open payment channel back to your wallet right away, ' +
|
|
7
|
+
'instead of waiting for the channel to be closed or auto-refunded. ' +
|
|
8
|
+
'Channel modes deposit funds up front to cover many calls; whatever you do not spend stays locked until reclaimed. ' +
|
|
9
|
+
'Works for whichever channel is active this session: x402 batch (USDC on Base) or MPP session (USDC.e/pathUSD on Tempo). ' +
|
|
10
|
+
'Call this when you are done making channel-mode calls. ' +
|
|
11
|
+
'Not needed for per-call modes (x402-exact / mpp-charge) or API-key auth — there is no channel deposit to reclaim.',
|
|
12
12
|
category: 'chain',
|
|
13
13
|
schema: {},
|
|
14
14
|
handler: async () => {
|
|
15
15
|
const info = getPaymentModeInfo();
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
// MPP session channel: reclaim when on the MPP rail, or whenever a Tempo
|
|
17
|
+
// channel is open (e.g. opened in mpp-session, then switched to mpp-charge).
|
|
18
|
+
if (info.mode.startsWith('mpp-') || isMppSessionOpen()) {
|
|
19
|
+
const res = await reclaimMppSession();
|
|
20
|
+
return res.message;
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
// x402 batch channel.
|
|
23
|
+
if (info.x402.enabled) {
|
|
24
|
+
const res = await refundBatchChannel();
|
|
25
|
+
return res.message;
|
|
26
|
+
}
|
|
27
|
+
return ('No payment channel is active in this session, so there is nothing to reclaim. ' +
|
|
28
|
+
'Channel deposits exist only in x402 batch mode (set X402_PRIVATE_KEY on Base) or MPP session mode (set MPP_PRIVATE_KEY on Tempo). ' +
|
|
29
|
+
'With an API key, calls are covered by your plan — no channel deposit to reclaim.');
|
|
23
30
|
},
|
|
24
31
|
};
|
|
25
32
|
//# sourceMappingURL=refund.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refund.js","sourceRoot":"","sources":["../../../src/tools/chain/refund.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"refund.js","sourceRoot":"","sources":["../../../src/tools/chain/refund.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEnE,MAAM,CAAC,MAAM,IAAI,GAAY;IAC3B,IAAI,EAAE,WAAW;IACjB,WAAW,EACT,0FAA0F;QAC1F,oEAAoE;QACpE,oHAAoH;QACpH,0HAA0H;QAC1H,yDAAyD;QACzD,mHAAmH;IACrH,QAAQ,EAAE,OAAO;IACjB,MAAM,EAAE,EAAE;IACV,OAAO,EAAE,KAAK,IAAI,EAAE;QAClB,MAAM,IAAI,GAAG,kBAAkB,EAAE,CAAC;QAElC,yEAAyE;QACzE,6EAA6E;QAC7E,IAAI,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,gBAAgB,EAAE,EAAE,CAAC;YACvD,MAAM,GAAG,GAAG,MAAM,iBAAiB,EAAE,CAAC;YACtC,OAAO,GAAG,CAAC,OAAO,CAAC;QACrB,CAAC;QAED,sBAAsB;QACtB,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YACtB,MAAM,GAAG,GAAG,MAAM,kBAAkB,EAAE,CAAC;YACvC,OAAO,GAAG,CAAC,OAAO,CAAC;QACrB,CAAC;QAED,OAAO,CACL,gFAAgF;YAChF,oIAAoI;YACpI,kFAAkF,CACnF,CAAC;IACJ,CAAC;CACF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@one-source/api-mcp",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.6.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "MCP server for OneSource blockchain data — named tools for balances, NFTs, transactions, events, live chain queries, with x402 (USDC on Base) and MPP (Tempo) pay-per-call payment rails",
|
|
6
6
|
"bin": {
|