run402-mcp 2.9.0 → 2.10.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/package.json +1 -1
- package/sdk/dist/node/_paid-stack.d.ts +49 -0
- package/sdk/dist/node/_paid-stack.d.ts.map +1 -0
- package/sdk/dist/node/_paid-stack.js +89 -0
- package/sdk/dist/node/_paid-stack.js.map +1 -0
- package/sdk/dist/node/paid-fetch.d.ts +4 -0
- package/sdk/dist/node/paid-fetch.d.ts.map +1 -1
- package/sdk/dist/node/paid-fetch.js +27 -20
- package/sdk/dist/node/paid-fetch.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "run402-mcp",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.0",
|
|
4
4
|
"description": "MCP server for Run402 — AI-native Postgres databases with REST API, auth, storage, and row-level security. Pay with x402 USDC micropayments.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single audit surface for the optional paid-fetch dependency stack.
|
|
3
|
+
*
|
|
4
|
+
* Every `viem` / `@x402/*` / `mppx` import the SDK performs flows through
|
|
5
|
+
* this file. Concentrating the imports here lets a reviewer enumerate the
|
|
6
|
+
* SDK's direct attack surface to those packages from one place, and lets
|
|
7
|
+
* the package.json declare them as `optionalPeerDependencies` — consumers
|
|
8
|
+
* who never make on-chain paid requests do not need to install them.
|
|
9
|
+
*
|
|
10
|
+
* Adding a new import here is the only way to grow the surface; doing so
|
|
11
|
+
* also widens what consumers must install to enable paid fetch. Keep this
|
|
12
|
+
* list minimal. When a symbol is small enough to inline (e.g. the
|
|
13
|
+
* `viem/chains` constants are ~5-line objects), prefer inlining over
|
|
14
|
+
* adding a new dependency edge.
|
|
15
|
+
*/
|
|
16
|
+
type FetchFn = typeof globalThis.fetch;
|
|
17
|
+
export declare class PaidStackUnavailable extends Error {
|
|
18
|
+
readonly missingPackages: readonly string[];
|
|
19
|
+
constructor(missing: readonly string[]);
|
|
20
|
+
}
|
|
21
|
+
export interface X402Stack {
|
|
22
|
+
privateKeyToAccount: (pk: `0x${string}`) => unknown;
|
|
23
|
+
createPublicClient: (opts: unknown) => {
|
|
24
|
+
readContract: (args: unknown) => Promise<bigint>;
|
|
25
|
+
};
|
|
26
|
+
http: () => unknown;
|
|
27
|
+
base: unknown;
|
|
28
|
+
baseSepolia: unknown;
|
|
29
|
+
x402Client: new () => {
|
|
30
|
+
register: (network: string, scheme: unknown) => void;
|
|
31
|
+
registerPolicy: (fn: (version: number, reqs: unknown[]) => unknown[]) => void;
|
|
32
|
+
};
|
|
33
|
+
wrapFetchWithPayment: (fetch: FetchFn, client: unknown) => FetchFn;
|
|
34
|
+
ExactEvmScheme: new (signer: unknown) => unknown;
|
|
35
|
+
toClientEvmSigner: (account: unknown, client: unknown) => unknown;
|
|
36
|
+
}
|
|
37
|
+
export interface MppStack {
|
|
38
|
+
privateKeyToAccount: (pk: `0x${string}`) => unknown;
|
|
39
|
+
Mppx: {
|
|
40
|
+
create: (opts: unknown) => {
|
|
41
|
+
fetch: FetchFn;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
tempo: (opts: unknown) => unknown;
|
|
45
|
+
}
|
|
46
|
+
export declare function loadX402Stack(): Promise<X402Stack>;
|
|
47
|
+
export declare function loadMppStack(): Promise<MppStack>;
|
|
48
|
+
export {};
|
|
49
|
+
//# sourceMappingURL=_paid-stack.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_paid-stack.d.ts","sourceRoot":"","sources":["../../src/node/_paid-stack.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,KAAK,OAAO,GAAG,OAAO,UAAU,CAAC,KAAK,CAAC;AAEvC,qBAAa,oBAAqB,SAAQ,KAAK;IAC7C,QAAQ,CAAC,eAAe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C,CAoBxD;AAED,wBAAsB,YAAY,IAAI,OAAO,CAAC,QAAQ,CAAC,CAgBtD"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Single audit surface for the optional paid-fetch dependency stack.
|
|
3
|
+
*
|
|
4
|
+
* Every `viem` / `@x402/*` / `mppx` import the SDK performs flows through
|
|
5
|
+
* this file. Concentrating the imports here lets a reviewer enumerate the
|
|
6
|
+
* SDK's direct attack surface to those packages from one place, and lets
|
|
7
|
+
* the package.json declare them as `optionalPeerDependencies` — consumers
|
|
8
|
+
* who never make on-chain paid requests do not need to install them.
|
|
9
|
+
*
|
|
10
|
+
* Adding a new import here is the only way to grow the surface; doing so
|
|
11
|
+
* also widens what consumers must install to enable paid fetch. Keep this
|
|
12
|
+
* list minimal. When a symbol is small enough to inline (e.g. the
|
|
13
|
+
* `viem/chains` constants are ~5-line objects), prefer inlining over
|
|
14
|
+
* adding a new dependency edge.
|
|
15
|
+
*/
|
|
16
|
+
export class PaidStackUnavailable extends Error {
|
|
17
|
+
missingPackages;
|
|
18
|
+
constructor(missing) {
|
|
19
|
+
super(`run402: paid requests require optional peer dependencies that are not installed: ${missing.join(", ")}. ` +
|
|
20
|
+
`Install them with: npm install ${missing.join(" ")}`);
|
|
21
|
+
this.name = "PaidStackUnavailable";
|
|
22
|
+
this.missingPackages = missing;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function isModuleNotFound(err) {
|
|
26
|
+
if (!(err instanceof Error))
|
|
27
|
+
return false;
|
|
28
|
+
const code = err.code;
|
|
29
|
+
if (code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND")
|
|
30
|
+
return true;
|
|
31
|
+
return /Cannot find (package|module)/.test(err.message);
|
|
32
|
+
}
|
|
33
|
+
class LoadCollector {
|
|
34
|
+
missing = new Set();
|
|
35
|
+
firstOtherError = null;
|
|
36
|
+
async load(pkg, load) {
|
|
37
|
+
try {
|
|
38
|
+
return await load();
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
if (isModuleNotFound(err))
|
|
42
|
+
this.missing.add(pkg);
|
|
43
|
+
else if (this.firstOtherError === null)
|
|
44
|
+
this.firstOtherError = err;
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
throwIfFailed() {
|
|
49
|
+
if (this.missing.size > 0) {
|
|
50
|
+
throw new PaidStackUnavailable([...this.missing].sort());
|
|
51
|
+
}
|
|
52
|
+
if (this.firstOtherError !== null)
|
|
53
|
+
throw this.firstOtherError;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
export async function loadX402Stack() {
|
|
57
|
+
const c = new LoadCollector();
|
|
58
|
+
const accounts = await c.load("viem", () => import("viem/accounts"));
|
|
59
|
+
const viemMod = await c.load("viem", () => import("viem"));
|
|
60
|
+
const chains = await c.load("viem", () => import("viem/chains"));
|
|
61
|
+
const x402Fetch = await c.load("@x402/fetch", () => import("@x402/fetch"));
|
|
62
|
+
const x402EvmClient = await c.load("@x402/evm", () => import("@x402/evm/exact/client"));
|
|
63
|
+
const x402Evm = await c.load("@x402/evm", () => import("@x402/evm"));
|
|
64
|
+
c.throwIfFailed();
|
|
65
|
+
return {
|
|
66
|
+
privateKeyToAccount: accounts.privateKeyToAccount,
|
|
67
|
+
createPublicClient: viemMod.createPublicClient,
|
|
68
|
+
http: viemMod.http,
|
|
69
|
+
base: chains.base,
|
|
70
|
+
baseSepolia: chains.baseSepolia,
|
|
71
|
+
x402Client: x402Fetch.x402Client,
|
|
72
|
+
wrapFetchWithPayment: x402Fetch.wrapFetchWithPayment,
|
|
73
|
+
ExactEvmScheme: x402EvmClient.ExactEvmScheme,
|
|
74
|
+
toClientEvmSigner: x402Evm.toClientEvmSigner,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
export async function loadMppStack() {
|
|
78
|
+
const c = new LoadCollector();
|
|
79
|
+
const mppxSpecifier = "mppx/client";
|
|
80
|
+
const mppx = await c.load("mppx", () => import(/* webpackIgnore: true */ mppxSpecifier));
|
|
81
|
+
const accounts = await c.load("viem", () => import("viem/accounts"));
|
|
82
|
+
c.throwIfFailed();
|
|
83
|
+
return {
|
|
84
|
+
privateKeyToAccount: accounts.privateKeyToAccount,
|
|
85
|
+
Mppx: mppx.Mppx,
|
|
86
|
+
tempo: mppx.tempo,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=_paid-stack.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_paid-stack.js","sourceRoot":"","sources":["../../src/node/_paid-stack.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IACpC,eAAe,CAAoB;IAC5C,YAAY,OAA0B;QACpC,KAAK,CACH,oFAAoF,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;YACxG,kCAAkC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CACxD,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;QACnC,IAAI,CAAC,eAAe,GAAG,OAAO,CAAC;IACjC,CAAC;CACF;AAED,SAAS,gBAAgB,CAAC,GAAY;IACpC,IAAI,CAAC,CAAC,GAAG,YAAY,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC1C,MAAM,IAAI,GAAI,GAA0B,CAAC,IAAI,CAAC;IAC9C,IAAI,IAAI,KAAK,sBAAsB,IAAI,IAAI,KAAK,kBAAkB;QAAE,OAAO,IAAI,CAAC;IAChF,OAAO,8BAA8B,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;AAC1D,CAAC;AAED,MAAM,aAAa;IACR,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IACrC,eAAe,GAAY,IAAI,CAAC;IAEhC,KAAK,CAAC,IAAI,CAAI,GAAW,EAAE,IAAsB;QAC/C,IAAI,CAAC;YACH,O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|
* unwrapped fetch and let 402s surface as `PaymentRequired` errors.
|
|
9
9
|
*
|
|
10
|
+
* The viem / @x402/* / mppx imports live behind `./_paid-stack.ts` so the
|
|
11
|
+
* SDK's direct surface to those packages is auditable from one file and the
|
|
12
|
+
* packages can be declared as optional peer dependencies in package.json.
|
|
13
|
+
*
|
|
10
14
|
* Never calls `process.exit` — the SDK leaves exit-code decisions to the
|
|
11
15
|
* CLI edge.
|
|
12
16
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paid-fetch.d.ts","sourceRoot":"","sources":["../../src/node/paid-fetch.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"paid-fetch.d.ts","sourceRoot":"","sources":["../../src/node/paid-fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH,KAAK,OAAO,GAAG,OAAO,UAAU,CAAC,KAAK,CAAC;AAkCvC,wBAAsB,cAAc,IAAI,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAuE9D;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,OAAO,CAW7C"}
|
|
@@ -7,10 +7,15 @@
|
|
|
7
7
|
* optional payment libraries fail to load. Callers can fall back to an
|
|
8
8
|
* unwrapped fetch and let 402s surface as `PaymentRequired` errors.
|
|
9
9
|
*
|
|
10
|
+
* The viem / @x402/* / mppx imports live behind `./_paid-stack.ts` so the
|
|
11
|
+
* SDK's direct surface to those packages is auditable from one file and the
|
|
12
|
+
* packages can be declared as optional peer dependencies in package.json.
|
|
13
|
+
*
|
|
10
14
|
* Never calls `process.exit` — the SDK leaves exit-code decisions to the
|
|
11
15
|
* CLI edge.
|
|
12
16
|
*/
|
|
13
17
|
import { readAllowance } from "../../core-dist/allowance.js";
|
|
18
|
+
import { PaidStackUnavailable, loadMppStack, loadX402Stack } from "./_paid-stack.js";
|
|
14
19
|
const USDC_ABI = [
|
|
15
20
|
{
|
|
16
21
|
name: "balanceOf",
|
|
@@ -22,6 +27,7 @@ const USDC_ABI = [
|
|
|
22
27
|
];
|
|
23
28
|
const USDC_MAINNET = "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913";
|
|
24
29
|
const USDC_SEPOLIA = "0x036CbD53842c5426634e7929541eC2318f3dCF7e";
|
|
30
|
+
let warnedMissingDeps = false;
|
|
25
31
|
async function checkBalance(publicClient, tokenAddress, walletAddress) {
|
|
26
32
|
try {
|
|
27
33
|
const raw = await publicClient.readContract({
|
|
@@ -53,33 +59,26 @@ export async function setupPaidFetch() {
|
|
|
53
59
|
return null;
|
|
54
60
|
try {
|
|
55
61
|
if (allowance.rail === "mpp") {
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
const account = privateKeyToAccount(allowance.privateKey);
|
|
60
|
-
const mppx = Mppx.create({
|
|
62
|
+
const stack = await loadMppStack();
|
|
63
|
+
const account = stack.privateKeyToAccount(allowance.privateKey);
|
|
64
|
+
const mppx = stack.Mppx.create({
|
|
61
65
|
polyfill: false,
|
|
62
|
-
methods: [tempo({ account })],
|
|
66
|
+
methods: [stack.tempo({ account })],
|
|
63
67
|
});
|
|
64
68
|
return mppx.fetch;
|
|
65
69
|
}
|
|
66
70
|
// Default: x402 on Base + Base Sepolia
|
|
67
|
-
const
|
|
68
|
-
const
|
|
69
|
-
const { base,
|
|
70
|
-
const
|
|
71
|
-
const { ExactEvmScheme } = await import("@x402/evm/exact/client");
|
|
72
|
-
const { toClientEvmSigner } = await import("@x402/evm");
|
|
73
|
-
const account = privateKeyToAccount(allowance.privateKey);
|
|
74
|
-
const mainnetClient = createPublicClient({ chain: base, transport: http() });
|
|
75
|
-
const sepoliaClient = createPublicClient({ chain: baseSepolia, transport: http() });
|
|
71
|
+
const stack = await loadX402Stack();
|
|
72
|
+
const account = stack.privateKeyToAccount(allowance.privateKey);
|
|
73
|
+
const mainnetClient = stack.createPublicClient({ chain: stack.base, transport: stack.http() });
|
|
74
|
+
const sepoliaClient = stack.createPublicClient({ chain: stack.baseSepolia, transport: stack.http() });
|
|
76
75
|
const [mainnetBalance, sepoliaBalance] = await Promise.all([
|
|
77
76
|
checkBalance(mainnetClient, USDC_MAINNET, allowance.address),
|
|
78
77
|
checkBalance(sepoliaClient, USDC_SEPOLIA, allowance.address),
|
|
79
78
|
]);
|
|
80
|
-
const client = new x402Client();
|
|
81
|
-
client.register("eip155:8453", new ExactEvmScheme(toClientEvmSigner(account, mainnetClient)));
|
|
82
|
-
client.register("eip155:84532", new ExactEvmScheme(toClientEvmSigner(account, sepoliaClient)));
|
|
79
|
+
const client = new stack.x402Client();
|
|
80
|
+
client.register("eip155:8453", new stack.ExactEvmScheme(stack.toClientEvmSigner(account, mainnetClient)));
|
|
81
|
+
client.register("eip155:84532", new stack.ExactEvmScheme(stack.toClientEvmSigner(account, sepoliaClient)));
|
|
83
82
|
if (mainnetBalance > 0 || sepoliaBalance > 0) {
|
|
84
83
|
// Compare against the requested amount, not > 0. A chain with dust below
|
|
85
84
|
// the request amount would otherwise be picked by x402Client and fail
|
|
@@ -100,9 +99,17 @@ export async function setupPaidFetch() {
|
|
|
100
99
|
// Read `globalThis.fetch` fresh each call so test suites that swap the
|
|
101
100
|
// global fetch after setupPaidFetch has already run still see their mocks.
|
|
102
101
|
const dynamicFetch = (input, init) => globalThis.fetch(input, init);
|
|
103
|
-
return wrapFetchWithPayment(dynamicFetch, client);
|
|
102
|
+
return stack.wrapFetchWithPayment(dynamicFetch, client);
|
|
104
103
|
}
|
|
105
|
-
catch {
|
|
104
|
+
catch (err) {
|
|
105
|
+
// Emit a clear one-time warning when the failure is "optional peer deps
|
|
106
|
+
// not installed" — otherwise the caller silently falls back to unwrapped
|
|
107
|
+
// fetch and the user has no way to know they need to `npm install viem`.
|
|
108
|
+
// Other errors stay silent to preserve the graceful-degradation contract.
|
|
109
|
+
if (err instanceof PaidStackUnavailable && !warnedMissingDeps) {
|
|
110
|
+
warnedMissingDeps = true;
|
|
111
|
+
console.warn(`[run402] ${err.message}`);
|
|
112
|
+
}
|
|
106
113
|
return null;
|
|
107
114
|
}
|
|
108
115
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paid-fetch.js","sourceRoot":"","sources":["../../src/node/paid-fetch.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"paid-fetch.js","sourceRoot":"","sources":["../../src/node/paid-fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAIrF,MAAM,QAAQ,GAAG;IACf;QACE,IAAI,EAAE,WAAW;QACjB,IAAI,EAAE,UAAU;QAChB,eAAe,EAAE,MAAM;QACvB,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QAC9C,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;KACzC;CACO,CAAC;AACX,MAAM,YAAY,GAAG,4CAA4C,CAAC;AAClE,MAAM,YAAY,GAAG,4CAA4C,CAAC;AAElE,IAAI,iBAAiB,GAAG,KAAK,CAAC;AAE9B,KAAK,UAAU,YAAY,CACzB,YAAkE,EAClE,YAAoB,EACpB,aAAqB;IAErB,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,MAAM,YAAY,CAAC,YAAY,CAAC;YAC1C,OAAO,EAAE,YAAY;YACrB,GAAG,EAAE,QAAQ;YACb,YAAY,EAAE,WAAW;YACzB,IAAI,EAAE,CAAC,aAAa,CAAC;SACtB,CAAC,CAAC;QACH,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;IACrB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,CAAC,CAAC;IACX,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cA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