deepsearch-x402-mcp 1.0.0 → 1.0.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/dist/index.js CHANGED
@@ -19,33 +19,23 @@ import { privateKeyToAccount } from "viem/accounts";
19
19
  // ── 환경 변수 ───────────────────────────────────────────────
20
20
  const PRIVATE_KEY = (process.env.MCP_WALLET_PRIVATE_KEY ?? "");
21
21
  const RESOURCE_URL = (process.env.RESOURCE_SERVER_URL ?? "https://x402.deepsearch.com").replace(/\/$/, "");
22
- if (!PRIVATE_KEY?.startsWith("0x")) {
23
- process.stderr.write([
24
- "❌ MCP_WALLET_PRIVATE_KEY is not set.",
25
- "",
26
- "Set it to an EVM private key (0x...) for a wallet holding USDC on Base Mainnet.",
27
- "",
28
- "Claude Desktop config example:",
29
- JSON.stringify({
30
- mcpServers: {
31
- "deepsearch-stocks": {
32
- command: "npx",
33
- args: ["deepsearch-x402-mcp"],
34
- env: { MCP_WALLET_PRIVATE_KEY: "0x..." },
35
- },
36
- },
37
- }, null, 2),
38
- "",
39
- "Get testnet USDC: https://faucet.circle.com",
40
- ].join("\n") + "\n");
41
- process.exit(1);
22
+ const hasWallet = PRIVATE_KEY?.startsWith("0x");
23
+ // ── x402 클라이언트 (지갑 있을 때만 초기화) ─────────────────
24
+ let fetchWithPayment = null;
25
+ let walletAddress = "(not configured)";
26
+ if (hasWallet) {
27
+ const account = privateKeyToAccount(PRIVATE_KEY);
28
+ walletAddress = account.address;
29
+ const x402 = new x402Client();
30
+ registerExactEvmScheme(x402, { signer: account });
31
+ fetchWithPayment = wrapFetchWithPayment(fetch, x402);
42
32
  }
43
- // ── x402 클라이언트 ──────────────────────────────────────────
44
- const account = privateKeyToAccount(PRIVATE_KEY);
45
- const x402 = new x402Client();
46
- registerExactEvmScheme(x402, { signer: account });
47
- const fetchWithPayment = wrapFetchWithPayment(fetch, x402);
48
33
  async function callAPI(path, params = {}) {
34
+ if (!fetchWithPayment) {
35
+ throw new Error("MCP_WALLET_PRIVATE_KEY is not set. " +
36
+ "Please configure a wallet holding USDC on Base Mainnet. " +
37
+ "See: https://smithery.ai/server/deepsearch/korean-stocks");
38
+ }
49
39
  const url = new URL(`${RESOURCE_URL}${path}`);
50
40
  for (const [k, v] of Object.entries(params))
51
41
  url.searchParams.set(k, v);
@@ -179,7 +169,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
179
169
  return {
180
170
  content: [{
181
171
  type: "text",
182
- text: `Insufficient USDC balance.\nWallet: ${account.address}\nGet Base Mainnet USDC: https://coinbase.com or bridge from other chains.`,
172
+ text: `Insufficient USDC balance.\nWallet: ${walletAddress}\nGet Base Mainnet USDC: https://coinbase.com or bridge from other chains.`,
183
173
  }],
184
174
  isError: true,
185
175
  };
@@ -189,5 +179,5 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
189
179
  });
190
180
  // ── 시작 ────────────────────────────────────────────────────
191
181
  const transport = new StdioServerTransport();
192
- process.stderr.write(`DeepSearch Korean Stock MCP — wallet: ${account.address} | server: ${RESOURCE_URL}\n`);
182
+ process.stderr.write(`DeepSearch Korean Stock MCP — wallet: ${walletAddress} | server: ${RESOURCE_URL}\n`);
193
183
  await server.connect(transport);