@moonpay/cli 0.3.9 → 0.3.11

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/index.js CHANGED
@@ -312,7 +312,7 @@ program.command("logout").description("Log out and clear stored credentials").ac
312
312
  console.log("Logged out.");
313
313
  });
314
314
  program.command("mcp").description("Start MCP server over stdio (for Claude Desktop, Claude Code, etc.)").action(async () => {
315
- const { startMcpServer } = await import("./mcp-J2ARFIOB.js");
315
+ const { startMcpServer } = await import("./mcp-NSLQO3QO.js");
316
316
  await startMcpServer();
317
317
  });
318
318
  function getOrCreateGroup(parent, segments) {
@@ -16,8 +16,13 @@ import {
16
16
  } from "./chunk-ZJ3XMP4N.js";
17
17
 
18
18
  // src/mcp.ts
19
- import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
19
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
20
20
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
21
+ import {
22
+ CallToolRequestSchema,
23
+ ListToolsRequestSchema
24
+ } from "@modelcontextprotocol/sdk/types.js";
25
+ import { zodToJsonSchema } from "zod-to-json-schema";
21
26
 
22
27
  // src/tools/x402/request/tool.ts
23
28
  import { Keypair, VersionedTransaction, VersionedMessage } from "@solana/web3.js";
@@ -141,60 +146,86 @@ function resolveRemoteSchema(schema) {
141
146
  return input;
142
147
  }
143
148
  async function startMcpServer() {
144
- const server = new McpServer({
145
- name: "moonpay",
146
- version: "1.0.0"
147
- });
148
- for (const tool of LOCAL_TOOLS) {
149
- server.registerTool(
150
- tool.schema.name,
151
- { description: tool.schema.description, inputSchema: tool.schema.input },
152
- async (params) => {
153
- const result = await tool.handler(params);
154
- return {
155
- content: [
156
- { type: "text", text: JSON.stringify(result, null, 2) }
157
- ]
158
- };
159
- }
160
- );
161
- }
149
+ const server = new Server(
150
+ { name: "moonpay", version: "1.0.0" },
151
+ { capabilities: { tools: { listChanged: true } } }
152
+ );
153
+ const toolDefs = LOCAL_TOOLS.map((tool) => ({
154
+ name: tool.schema.name,
155
+ description: tool.schema.description,
156
+ inputSchema: zodToJsonSchema(tool.schema.input)
157
+ }));
158
+ const remotePropsMap = /* @__PURE__ */ new Map();
162
159
  for (const schema of schemas_default) {
163
160
  if (localToolMap.has(schema.name)) continue;
164
161
  const resolved = resolveRemoteSchema(schema);
165
- const props = resolved.properties ?? {};
166
- server.registerTool(
162
+ remotePropsMap.set(
167
163
  schema.name,
168
- { description: schema.description },
169
- async (params) => {
170
- for (const [key, prop] of Object.entries(props)) {
171
- if (params[key] === void 0) {
172
- const nullable = Array.isArray(prop.type) ? prop.type.includes("null") : prop.anyOf?.some((t) => t.type === "null");
173
- if (nullable) params[key] = null;
174
- }
175
- const isNum = prop.type === "number" || prop.type === "integer" || Array.isArray(prop.type) && prop.type.some(
176
- (t) => t === "number" || t === "integer"
177
- ) || prop.anyOf?.some(
178
- (t) => t.type === "number" || t.type === "integer"
179
- );
180
- if (isNum && typeof params[key] === "string") {
181
- params[key] = Number(params[key]);
182
- }
183
- }
184
- const baseUrl = resolveBaseUrl();
185
- const result = await callTool(baseUrl, schema.name, params);
186
- return {
187
- content: [
188
- { type: "text", text: JSON.stringify(result, null, 2) }
189
- ]
190
- };
191
- }
164
+ resolved.properties ?? {}
192
165
  );
166
+ toolDefs.push({
167
+ name: schema.name,
168
+ description: schema.description,
169
+ inputSchema: {
170
+ type: "object",
171
+ properties: resolved.properties ?? {},
172
+ ...resolved.required ? { required: resolved.required } : {},
173
+ ...resolved.additionalProperties !== void 0 ? { additionalProperties: resolved.additionalProperties } : {}
174
+ }
175
+ });
193
176
  }
177
+ const toolDefMap = new Map(toolDefs.map((t) => [t.name, t]));
178
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({
179
+ tools: toolDefs.map((t) => ({
180
+ name: t.name,
181
+ description: t.description,
182
+ inputSchema: t.inputSchema
183
+ }))
184
+ }));
185
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
186
+ const { name, arguments: params = {} } = request.params;
187
+ if (!toolDefMap.has(name)) {
188
+ return {
189
+ content: [{ type: "text", text: `Unknown tool: ${name}` }],
190
+ isError: true
191
+ };
192
+ }
193
+ const localTool = localToolMap.get(name);
194
+ if (localTool) {
195
+ const result2 = await localTool.handler(params);
196
+ return {
197
+ content: [
198
+ { type: "text", text: JSON.stringify(result2, null, 2) }
199
+ ]
200
+ };
201
+ }
202
+ const props = remotePropsMap.get(name) ?? {};
203
+ for (const [key, prop] of Object.entries(props)) {
204
+ if (params[key] === void 0) {
205
+ const nullable = Array.isArray(prop.type) ? prop.type.includes("null") : prop.anyOf?.some((t) => t.type === "null");
206
+ if (nullable) params[key] = null;
207
+ }
208
+ const isNum = prop.type === "number" || prop.type === "integer" || Array.isArray(prop.type) && prop.type.some(
209
+ (t) => t === "number" || t === "integer"
210
+ ) || prop.anyOf?.some(
211
+ (t) => t.type === "number" || t.type === "integer"
212
+ );
213
+ if (isNum && typeof params[key] === "string") {
214
+ params[key] = Number(params[key]);
215
+ }
216
+ }
217
+ const baseUrl = resolveBaseUrl();
218
+ const result = await callTool(baseUrl, name, params);
219
+ return {
220
+ content: [
221
+ { type: "text", text: JSON.stringify(result, null, 2) }
222
+ ]
223
+ };
224
+ });
194
225
  const transport = new StdioServerTransport();
195
226
  await server.connect(transport);
196
227
  }
197
228
  export {
198
229
  startMcpServer
199
230
  };
200
- //# sourceMappingURL=mcp-J2ARFIOB.js.map
231
+ //# sourceMappingURL=mcp-NSLQO3QO.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/mcp.ts","../src/tools/x402/request/tool.ts","../src/tools/x402/request/schema.ts"],"sourcesContent":["import { Server } from \"@modelcontextprotocol/sdk/server/index.js\";\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\nimport {\n CallToolRequestSchema,\n ListToolsRequestSchema,\n} from \"@modelcontextprotocol/sdk/types.js\";\nimport { zodToJsonSchema } from \"zod-to-json-schema\";\nimport { callTool } from \"./client\";\nimport { resolveBaseUrl } from \"./auth\";\nimport type { Tool } from \"./tools/shared\";\nimport { walletCreate } from \"./tools/wallet/create/tool\";\nimport { walletImport } from \"./tools/wallet/import/tool\";\nimport { walletList } from \"./tools/wallet/list/tool\";\nimport { walletRetrieve } from \"./tools/wallet/retrieve/tool\";\nimport { walletDelete } from \"./tools/wallet/delete/tool\";\nimport { transactionSign } from \"./tools/transaction/sign/tool\";\nimport { messageSign } from \"./tools/message/sign/tool\";\nimport { x402Request } from \"./tools/x402/request/tool\";\nimport schemas from \"./generated/schemas.json\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst LOCAL_TOOLS: Tool<any>[] = [\n walletCreate,\n walletImport,\n walletList,\n walletRetrieve,\n walletDelete,\n transactionSign,\n messageSign,\n x402Request,\n];\n\nconst localToolMap = new Map(LOCAL_TOOLS.map((t) => [t.schema.name, t]));\n\n/**\n * Resolve a remote schema's $ref to the actual properties object.\n */\nfunction resolveRemoteSchema(schema: (typeof schemas)[number]) {\n const input = schema.inputSchema as any;\n if (input.$ref && input.definitions) {\n const defName = input.$ref.replace(\"#/definitions/\", \"\");\n return input.definitions[defName] ?? input;\n }\n return input;\n}\n\nexport async function startMcpServer() {\n const server = new Server(\n { name: \"moonpay\", version: \"1.0.0\" },\n { capabilities: { tools: { listChanged: true } } },\n );\n\n // Build tool definitions — local tools use Zod→JSON, remote use JSON directly\n const toolDefs: Array<{\n name: string;\n description: string;\n inputSchema: Record<string, unknown>;\n }> = LOCAL_TOOLS.map((tool) => ({\n name: tool.schema.name,\n description: tool.schema.description,\n inputSchema: zodToJsonSchema(tool.schema.input) as Record<string, unknown>,\n }));\n\n const remotePropsMap = new Map<string, Record<string, any>>();\n for (const schema of schemas) {\n if (localToolMap.has(schema.name)) continue;\n const resolved = resolveRemoteSchema(schema);\n remotePropsMap.set(\n schema.name,\n (resolved.properties ?? {}) as Record<string, any>,\n );\n toolDefs.push({\n name: schema.name,\n description: schema.description,\n inputSchema: {\n type: \"object\",\n properties: resolved.properties ?? {},\n ...(resolved.required ? { required: resolved.required } : {}),\n ...(resolved.additionalProperties !== undefined\n ? { additionalProperties: resolved.additionalProperties }\n : {}),\n },\n });\n }\n\n const toolDefMap = new Map(toolDefs.map((t) => [t.name, t]));\n\n // tools/list — return raw JSON schemas directly\n server.setRequestHandler(ListToolsRequestSchema, async () => ({\n tools: toolDefs.map((t) => ({\n name: t.name,\n description: t.description,\n inputSchema: t.inputSchema,\n })),\n }));\n\n // tools/call\n server.setRequestHandler(CallToolRequestSchema, async (request) => {\n const { name, arguments: params = {} } = request.params;\n\n if (!toolDefMap.has(name)) {\n return {\n content: [{ type: \"text\" as const, text: `Unknown tool: ${name}` }],\n isError: true,\n };\n }\n\n // Local tool — run handler directly\n const localTool = localToolMap.get(name);\n if (localTool) {\n const result = await localTool.handler(params);\n return {\n content: [\n { type: \"text\" as const, text: JSON.stringify(result, null, 2) },\n ],\n };\n }\n\n // Remote tool — coerce types then call API\n const props = remotePropsMap.get(name) ?? {};\n for (const [key, prop] of Object.entries(props)) {\n if (params[key] === undefined) {\n const nullable = Array.isArray(prop.type)\n ? prop.type.includes(\"null\")\n : prop.anyOf?.some((t: any) => t.type === \"null\");\n if (nullable) params[key] = null;\n }\n const isNum =\n prop.type === \"number\" ||\n prop.type === \"integer\" ||\n (Array.isArray(prop.type) &&\n prop.type.some(\n (t: string) => t === \"number\" || t === \"integer\",\n )) ||\n prop.anyOf?.some(\n (t: any) => t.type === \"number\" || t.type === \"integer\",\n );\n if (isNum && typeof params[key] === \"string\") {\n params[key] = Number(params[key]);\n }\n }\n\n const baseUrl = resolveBaseUrl();\n const result = await callTool(baseUrl, name, params);\n return {\n content: [\n { type: \"text\" as const, text: JSON.stringify(result, null, 2) },\n ],\n };\n });\n\n const transport = new StdioServerTransport();\n await server.connect(transport);\n}\n","import { Keypair, VersionedTransaction, VersionedMessage } from \"@solana/web3.js\";\nimport bs58 from \"bs58\";\nimport axios from \"axios\";\nimport { wrapAxiosWithPayment } from \"@x402/axios\";\nimport { x402Client } from \"@x402/core/client\";\nimport { ExactSvmScheme } from \"@x402/svm\";\nimport type { Address } from \"@solana/addresses\";\nimport type { SignatureDictionary } from \"@solana/signers\";\nimport type { Transaction } from \"@solana/transactions\";\nimport { createTool } from \"../../shared\";\nimport { loadWallet } from \"../../wallet/server\";\nimport { x402RequestSchema } from \"./schema\";\n\nconst SOLANA_NETWORK = \"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp\" as const;\n\nfunction createLocalX402Client(walletAddress: string, secretKey: string) {\n const keypair = Keypair.fromSecretKey(bs58.decode(secretKey));\n\n const signer = {\n address: walletAddress as Address,\n signTransactions: async (\n transactions: readonly Transaction[],\n ): Promise<readonly SignatureDictionary[]> => {\n return transactions.map((transaction) => {\n const messageBytes = new Uint8Array(transaction.messageBytes);\n const message = VersionedMessage.deserialize(messageBytes);\n const numSigs = Object.keys(transaction.signatures).length;\n const tx = new VersionedTransaction(\n message,\n new Array(numSigs).fill(new Uint8Array(64)),\n );\n\n tx.sign([keypair]);\n\n const signerIndex = message.staticAccountKeys.findIndex(\n (key) => key.toBase58() === walletAddress,\n );\n if (signerIndex === -1) {\n throw new Error(\n `Wallet ${walletAddress} is not a signer for this transaction`,\n );\n }\n\n return {\n [walletAddress]: tx.signatures[signerIndex],\n } as SignatureDictionary;\n });\n },\n };\n\n const client = new x402Client();\n const svmScheme = new ExactSvmScheme(signer);\n client.register(SOLANA_NETWORK, svmScheme);\n client.registerV1(\"solana\", svmScheme);\n\n return wrapAxiosWithPayment(axios.create(), client);\n}\n\nexport const x402Request = createTool(\n x402RequestSchema,\n async ({ method, url, body, params, wallet: walletNameOrAddress }) => {\n const storedWallet = loadWallet(walletNameOrAddress);\n const client = createLocalX402Client(\n storedWallet.address,\n storedWallet.secretKey,\n );\n\n let response;\n switch (method) {\n case \"GET\":\n response = await client.get(url, { params });\n break;\n case \"POST\":\n response = await client.post(url, body || {}, { params });\n break;\n case \"PUT\":\n response = await client.put(url, body || {}, { params });\n break;\n case \"PATCH\":\n response = await client.patch(url, body || {}, { params });\n break;\n case \"DELETE\":\n response = await client.delete(url, { params });\n break;\n default:\n throw new Error(`Unsupported HTTP method: ${method}`);\n }\n\n return {\n status: response.status,\n data: response.data,\n headers: response.headers as Record<string, string>,\n };\n },\n);\n","import { z } from \"zod\";\nimport { defineToolSchema } from \"../../shared\";\n\nexport const x402RequestSchema = defineToolSchema({\n name: \"x402_request\",\n description:\n \"Make an HTTP request to an x402-protected endpoint. Automatically handles payment when a 402 Payment Required response is received, signing the payment transaction with the local wallet.\",\n input: z.object({\n method: z\n .enum([\"GET\", \"POST\", \"PUT\", \"PATCH\", \"DELETE\"])\n .describe(\"HTTP method\"),\n url: z\n .string()\n .url()\n .describe(\n \"Full URL of the x402-protected endpoint (e.g., 'https://agents.moonpay.com/api/x402/tools/market_digest_retrieve')\",\n ),\n body: z\n .record(z.any())\n .nullable()\n .describe(\"Request body (for POST, PUT, PATCH)\"),\n params: z.record(z.any()).nullable().describe(\"Query parameters\"),\n wallet: z.string().describe(\"Wallet name or address to pay with\"),\n }),\n output: z.object({\n status: z.number().describe(\"HTTP status code\"),\n data: z.any().describe(\"Response data\"),\n headers: z.record(z.string()).describe(\"Response headers\"),\n }),\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,SAAS,cAAc;AACvB,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;;;ACNhC,SAAS,SAAS,sBAAsB,wBAAwB;AAChE,OAAO,UAAU;AACjB,OAAO,WAAW;AAClB,SAAS,4BAA4B;AACrC,SAAS,kBAAkB;AAC3B,SAAS,sBAAsB;;;ACL/B,SAAS,SAAS;AAGX,IAAM,oBAAoB,iBAAiB;AAAA,EAChD,MAAM;AAAA,EACN,aACE;AAAA,EACF,OAAO,EAAE,OAAO;AAAA,IACd,QAAQ,EACL,KAAK,CAAC,OAAO,QAAQ,OAAO,SAAS,QAAQ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AK,OAAO;AAAA,QACV,CAAC,MAAW,EAAE,SAAS,YAAY,EAAE,SAAS;AAAA,MAChD;AACF,UAAI,SAAS,OAAO,OAAO,GAAG,MAAM,UAAU;AAC5C,eAAO,GAAG,IAAI,OAAO,OAAO,GAAG,CAAC;AAAA,MAClC;AAAA,IACF;AAEA,UAAM,UAAU,eAAe;AAC/B,UAAM,SAAS,MAAM,SAAS,SAAS,MAAM,MAAM;AACnD,WAAO;AAAA,MACL,SAAS;AAAA,QACP,EAAE,MAAM,QAAiB,MAAM,KAAK,UAAU,QAAQ,MAAM,CAAC,EAAE;AAAA,MACjE;AAAA,IACF;AAAA,EACF,CAAC;AAED,QAAM,YAAY,IAAI,qBAAqB;AAC3C,QAAM,OAAO,QAAQ,SAAS;AAChC;","names":["result"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moonpay/cli",
3
- "version": "0.3.9",
3
+ "version": "0.3.11",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -29,7 +29,8 @@
29
29
  "bs58": "^6.0.0",
30
30
  "commander": "^12.1.0",
31
31
  "tweetnacl": "^1.0.3",
32
- "zod": "^3.25.76"
32
+ "zod": "^3.25.76",
33
+ "zod-to-json-schema": "^3.25.1"
33
34
  },
34
35
  "devDependencies": {
35
36
  "@types/jest": "^29",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/mcp.ts","../src/tools/x402/request/tool.ts","../src/tools/x402/request/schema.ts"],"sourcesContent":["import { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\nimport { callTool } from \"./client\";\nimport { resolveBaseUrl } from \"./auth\";\nimport type { Tool } from \"./tools/shared\";\nimport { walletCreate } from \"./tools/wallet/create/tool\";\nimport { walletImport } from \"./tools/wallet/import/tool\";\nimport { walletList } from \"./tools/wallet/list/tool\";\nimport { walletRetrieve } from \"./tools/wallet/retrieve/tool\";\nimport { walletDelete } from \"./tools/wallet/delete/tool\";\nimport { transactionSign } from \"./tools/transaction/sign/tool\";\nimport { messageSign } from \"./tools/message/sign/tool\";\nimport { x402Request } from \"./tools/x402/request/tool\";\nimport schemas from \"./generated/schemas.json\";\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst LOCAL_TOOLS: Tool<any>[] = [\n walletCreate,\n walletImport,\n walletList,\n walletRetrieve,\n walletDelete,\n transactionSign,\n messageSign,\n x402Request,\n];\n\nconst localToolMap = new Map(LOCAL_TOOLS.map((t) => [t.schema.name, t]));\n\n/**\n * Resolve a remote schema's $ref to the actual properties object.\n */\nfunction resolveRemoteSchema(schema: (typeof schemas)[number]) {\n const input = schema.inputSchema as any;\n if (input.$ref && input.definitions) {\n const defName = input.$ref.replace(\"#/definitions/\", \"\");\n return input.definitions[defName] ?? input;\n }\n return input;\n}\n\nexport async function startMcpServer() {\n const server = new McpServer({\n name: \"moonpay\",\n version: \"1.0.0\",\n });\n\n // Register local tools — pass Zod input schema directly\n for (const tool of LOCAL_TOOLS) {\n server.registerTool(\n tool.schema.name,\n { description: tool.schema.description, inputSchema: tool.schema.input },\n async (params: Record<string, unknown>) => {\n const result = await tool.handler(params);\n return {\n content: [\n { type: \"text\" as const, text: JSON.stringify(result, null, 2) },\n ],\n };\n },\n );\n }\n\n // Register remote tools (skip if already registered as local)\n for (const schema of schemas) {\n if (localToolMap.has(schema.name)) continue;\n\n const resolved = resolveRemoteSchema(schema);\n const props = (resolved.properties ?? {}) as Record<string, any>;\n\n server.registerTool(\n schema.name,\n { description: schema.description },\n async (params: Record<string, unknown>) => {\n // Coerce types for remote tools\n for (const [key, prop] of Object.entries(props)) {\n if (params[key] === undefined) {\n const nullable = Array.isArray(prop.type)\n ? prop.type.includes(\"null\")\n : prop.anyOf?.some((t: any) => t.type === \"null\");\n if (nullable) params[key] = null;\n }\n const isNum =\n prop.type === \"number\" ||\n prop.type === \"integer\" ||\n (Array.isArray(prop.type) &&\n prop.type.some(\n (t: string) => t === \"number\" || t === \"integer\",\n )) ||\n prop.anyOf?.some(\n (t: any) => t.type === \"number\" || t.type === \"integer\",\n );\n if (isNum && typeof params[key] === \"string\") {\n params[key] = Number(params[key]);\n }\n }\n\n const baseUrl = resolveBaseUrl();\n const result = await callTool(baseUrl, schema.name, params);\n return {\n content: [\n { type: \"text\" as const, text: JSON.stringify(result, null, 2) },\n ],\n };\n },\n );\n }\n\n const transport = new StdioServerTransport();\n await server.connect(transport);\n}\n","import { Keypair, VersionedTransaction, VersionedMessage } from \"@solana/web3.js\";\nimport bs58 from \"bs58\";\nimport axios from \"axios\";\nimport { wrapAxiosWithPayment } from \"@x402/axios\";\nimport { x402Client } from \"@x402/core/client\";\nimport { ExactSvmScheme } from \"@x402/svm\";\nimport type { Address } from \"@solana/addresses\";\nimport type { SignatureDictionary } from \"@solana/signers\";\nimport type { Transaction } from \"@solana/transactions\";\nimport { createTool } from \"../../shared\";\nimport { loadWallet } from \"../../wallet/server\";\nimport { x402RequestSchema } from \"./schema\";\n\nconst SOLANA_NETWORK = \"solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp\" as const;\n\nfunction createLocalX402Client(walletAddress: string, secretKey: string) {\n const keypair = Keypair.fromSecretKey(bs58.decode(secretKey));\n\n const signer = {\n address: walletAddress as Address,\n signTransactions: async (\n transactions: readonly Transaction[],\n ): Promise<readonly SignatureDictionary[]> => {\n return transactions.map((transaction) => {\n const messageBytes = new Uint8Array(transaction.messageBytes);\n const message = VersionedMessage.deserialize(messageBytes);\n const numSigs = Object.keys(transaction.signatures).length;\n const tx = new VersionedTransaction(\n message,\n new Array(numSigs).fill(new Uint8Array(64)),\n );\n\n tx.sign([keypair]);\n\n const signerIndex = message.staticAccountKeys.findIndex(\n (key) => key.toBase58() === walletAddress,\n );\n if (signerIndex === -1) {\n throw new Error(\n `Wallet ${walletAddress} is not a signer for this transaction`,\n );\n }\n\n return {\n [walletAddress]: tx.signatures[signerIndex],\n } as SignatureDictionary;\n });\n },\n };\n\n const client = new x402Client();\n const svmScheme = new ExactSvmScheme(signer);\n client.register(SOLANA_NETWORK, svmScheme);\n client.registerV1(\"solana\", svmScheme);\n\n return wrapAxiosWithPayment(axios.create(), client);\n}\n\nexport const x402Request = createTool(\n x402RequestSchema,\n async ({ method, url, body, params, wallet: walletNameOrAddress }) => {\n const storedWallet = loadWallet(walletNameOrAddress);\n const client = createLocalX402Client(\n storedWallet.address,\n storedWallet.secretKey,\n );\n\n let response;\n switch (method) {\n case \"GET\":\n response = await client.get(url, { params });\n break;\n case \"POST\":\n response = await client.post(url, body || {}, { params });\n break;\n case \"PUT\":\n response = await client.put(url, body || {}, { params });\n break;\n case \"PATCH\":\n response = await client.patch(url, body || {}, { params });\n break;\n case \"DELETE\":\n response = await client.delete(url, { params });\n break;\n default:\n throw new Error(`Unsupported HTTP method: ${method}`);\n }\n\n return {\n status: response.status,\n data: response.data,\n headers: response.headers as Record<string, string>,\n };\n },\n);\n","import { z } from \"zod\";\nimport { defineToolSchema } from \"../../shared\";\n\nexport const x402RequestSchema = defineToolSchema({\n name: \"x402_request\",\n description:\n \"Make an HTTP request to an x402-protected endpoint. Automatically handles payment when a 402 Payment Required response is received, signing the payment transaction with the local wallet.\",\n input: z.object({\n method: z\n .enum([\"GET\", \"POST\", \"PUT\", \"PATCH\", \"DELETE\"])\n .describe(\"HTTP method\"),\n url: z\n .string()\n .url()\n .describe(\n \"Full URL of the x402-protected endpoint (e.g., 'https://agents.moonpay.com/api/x402/tools/market_digest_retrieve')\",\n ),\n body: z\n .record(z.any())\n .nullable()\n .describe(\"Request body (for POST, PUT, PATCH)\"),\n params: z.record(z.any()).nullable().describe(\"Query parameters\"),\n wallet: z.string().describe(\"Wallet name or address to pay with\"),\n }),\n output: z.object({\n status: z.number().describe(\"HTTP status code\"),\n data: z.any().describe(\"Response data\"),\n headers: z.record(z.string()).describe(\"Response headers\"),\n }),\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA,SAAS,iBAAiB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