deepsearch-x402-mcp 1.0.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/README.md ADDED
@@ -0,0 +1,80 @@
1
+ # deepsearch-x402-mcp
2
+
3
+ MCP server for [DeepSearch Korean Stock Intelligence API](https://x402.deepsearch.com).
4
+
5
+ Pay-per-query via x402 micropayments — USDC on Base Mainnet. No API key needed.
6
+
7
+ ## Setup
8
+
9
+ ### 1. Get a wallet with USDC
10
+
11
+ You need an EVM wallet with USDC on **Base Mainnet**.
12
+ - Buy USDC on [Coinbase](https://coinbase.com) and send to Base
13
+ - Or bridge from Ethereum via [bridge.base.org](https://bridge.base.org)
14
+
15
+ ### 2. Add to Claude Desktop
16
+
17
+ Edit `~/Library/Application Support/Claude/claude_desktop_config.json`:
18
+
19
+ ```json
20
+ {
21
+ "mcpServers": {
22
+ "deepsearch-stocks": {
23
+ "command": "npx",
24
+ "args": ["deepsearch-x402-mcp"],
25
+ "env": {
26
+ "MCP_WALLET_PRIVATE_KEY": "0xYOUR_PRIVATE_KEY"
27
+ }
28
+ }
29
+ }
30
+ }
31
+ ```
32
+
33
+ Restart Claude Desktop. You should see **13 tools** available.
34
+
35
+ ### 3. Try it
36
+
37
+ Ask Claude:
38
+ - *"What is Samsung Electronics' current PER and ROE?"*
39
+ - *"Show me SK Hynix stock performance over the last year"*
40
+ - *"Analyze the investment risks for NAVER (035420)"*
41
+
42
+ ## Tools & Pricing
43
+
44
+ | Tool | Description | Cost |
45
+ |------|-------------|------|
46
+ | `get_company` | Fundamentals: market cap, PER, PBR, ROE, financials | $0.01 |
47
+ | `get_financials` | Latest quarterly financial statements | $0.01 |
48
+ | `get_dividend` | Dividend schedule and amounts | $0.01 |
49
+ | `get_news` | Recent 30-day news with sentiment | $0.01 |
50
+ | `get_stock_1m` | 1-month daily price history | $0.01 |
51
+ | `get_stock_3m` | 3-month daily price history | $0.02 |
52
+ | `get_financials_2y` | 2-year quarterly financials | $0.02 |
53
+ | `get_stock_1y` | 1-year daily price history | $0.03 |
54
+ | `get_financials_5y` | 5-year quarterly financials | $0.03 |
55
+ | `get_issue` | News-driven issue analysis | $0.05 |
56
+ | `get_risk` | Investment risk assessment | $0.05 |
57
+ | `get_stock_3y` | 3-year daily price history | $0.05 |
58
+ | `get_financials_all` | All available quarterly data | $0.05 |
59
+
60
+ ## Environment Variables
61
+
62
+ | Variable | Required | Description |
63
+ |----------|----------|-------------|
64
+ | `MCP_WALLET_PRIVATE_KEY` | ✅ | EVM private key (0x...) — wallet must hold USDC on Base Mainnet |
65
+ | `RESOURCE_SERVER_URL` | ❌ | Override API server URL (default: https://x402.deepsearch.com) |
66
+
67
+ ## Ticker Format
68
+
69
+ Korean stocks use 6-digit KRX codes:
70
+ - `005930` — Samsung Electronics
71
+ - `000660` — SK Hynix
72
+ - `035420` — NAVER
73
+ - `005380` — Hyundai Motor
74
+ - `051910` — LG Chem
75
+
76
+ ## Links
77
+
78
+ - [API Server](https://x402.deepsearch.com)
79
+ - [x402scan listing](https://www.x402scan.com/server/2034f172-ed34-42dd-8aca-df9a0ab35027)
80
+ - [x402 Protocol](https://x402.org)
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/index.js ADDED
@@ -0,0 +1,193 @@
1
+ #!/usr/bin/env node
2
+ // ============================================================
3
+ // DeepSearch Korean Stock Intelligence — MCP Server
4
+ //
5
+ // Claude Desktop / Cursor / 기타 MCP 클라이언트용.
6
+ // tool 호출 시 x402 결제(USDC on Base Mainnet)를 자동 처리.
7
+ //
8
+ // 환경 변수:
9
+ // MCP_WALLET_PRIVATE_KEY 결제 지갑 private key (0x...)
10
+ // RESOURCE_SERVER_URL API 서버 URL (기본: https://x402.deepsearch.com)
11
+ // ============================================================
12
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
13
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
14
+ import { CallToolRequestSchema, ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
15
+ import { x402Client } from "@x402/core/client";
16
+ import { registerExactEvmScheme } from "@x402/evm/exact/client";
17
+ import { wrapFetchWithPayment } from "@x402/fetch";
18
+ import { privateKeyToAccount } from "viem/accounts";
19
+ // ── 환경 변수 ───────────────────────────────────────────────
20
+ const PRIVATE_KEY = (process.env.MCP_WALLET_PRIVATE_KEY ?? "");
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);
42
+ }
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
+ async function callAPI(path, params = {}) {
49
+ const url = new URL(`${RESOURCE_URL}${path}`);
50
+ for (const [k, v] of Object.entries(params))
51
+ url.searchParams.set(k, v);
52
+ const res = await fetchWithPayment(url.toString());
53
+ if (!res.ok)
54
+ throw new Error(`API ${res.status}: ${await res.text()}`);
55
+ return res.json();
56
+ }
57
+ // ── MCP 서버 ────────────────────────────────────────────────
58
+ const server = new Server({ name: "deepsearch-korean-stocks", version: "1.0.0" }, { capabilities: { tools: {} } });
59
+ // ── Tool 정의 ────────────────────────────────────────────────
60
+ const TICKER_PROP = {
61
+ type: "string",
62
+ description: "Stock ticker. Korean stocks: 6-digit KRX code (e.g. 005930 Samsung, 000660 SK Hynix, 035420 NAVER, 005380 Hyundai). US stocks: symbol (e.g. AAPL)",
63
+ };
64
+ const EXCHANGE_PROP = {
65
+ type: "string",
66
+ description: "Exchange code. Default: KRX (Korea). For US stocks: NASDAQ or NYSE",
67
+ };
68
+ server.setRequestHandler(ListToolsRequestSchema, async () => ({
69
+ tools: [
70
+ {
71
+ name: "get_company",
72
+ description: "Get company fundamentals for a Korean or global stock ($0.01 USDC). Returns market cap, PER, PBR, ROE, EPS, dividend yield, business overview, latest stock price with 52-week range, and most recent quarterly financials (revenue, operating profit, net income).",
73
+ inputSchema: { type: "object", properties: { ticker: TICKER_PROP, exchange: EXCHANGE_PROP }, required: ["ticker"] },
74
+ },
75
+ {
76
+ name: "get_financials",
77
+ description: "Get latest quarterly financial statements ($0.01 USDC). Returns revenue, gross profit, operating profit, net income, total assets, equity, fiscal end date, and currency.",
78
+ inputSchema: { type: "object", properties: { ticker: TICKER_PROP, exchange: EXCHANGE_PROP }, required: ["ticker"] },
79
+ },
80
+ {
81
+ name: "get_dividend",
82
+ description: "Get dividend schedule ($0.01 USDC). Returns ex-dividend date, payment date, dividend amount, and forecast flag. Use for dividend investing analysis.",
83
+ inputSchema: { type: "object", properties: { ticker: TICKER_PROP, exchange: EXCHANGE_PROP }, required: ["ticker"] },
84
+ },
85
+ {
86
+ name: "get_news",
87
+ description: "Get recent 30-day news articles ($0.01 USDC). Returns title, summary, published date, and per-company sentiment (positive/negative/neutral).",
88
+ inputSchema: { type: "object", properties: { ticker: TICKER_PROP, exchange: EXCHANGE_PROP }, required: ["ticker"] },
89
+ },
90
+ {
91
+ name: "get_stock_1m",
92
+ description: "Get 1-month daily stock price history ($0.01 USDC). Returns daily close, change %, market cap.",
93
+ inputSchema: { type: "object", properties: { ticker: TICKER_PROP, exchange: EXCHANGE_PROP }, required: ["ticker"] },
94
+ },
95
+ {
96
+ name: "get_stock_3m",
97
+ description: "Get 3-month daily stock price history ($0.02 USDC). Returns daily close, change %, market cap + period high/low/return.",
98
+ inputSchema: { type: "object", properties: { ticker: TICKER_PROP, exchange: EXCHANGE_PROP }, required: ["ticker"] },
99
+ },
100
+ {
101
+ name: "get_financials_2y",
102
+ description: "Get 2-year quarterly financials history ($0.02 USDC). Up to 8 quarters of revenue, operating profit, net income, assets, equity trends.",
103
+ inputSchema: { type: "object", properties: { ticker: TICKER_PROP, exchange: EXCHANGE_PROP }, required: ["ticker"] },
104
+ },
105
+ {
106
+ name: "get_stock_1y",
107
+ description: "Get 1-year daily stock price history ($0.03 USDC). Returns daily close + annual high/low/return. Use for medium-term trend analysis.",
108
+ inputSchema: { type: "object", properties: { ticker: TICKER_PROP, exchange: EXCHANGE_PROP }, required: ["ticker"] },
109
+ },
110
+ {
111
+ name: "get_financials_5y",
112
+ description: "Get 5-year quarterly financials history ($0.03 USDC). Up to 20 quarters of financial trends. Use for long-term growth analysis.",
113
+ inputSchema: { type: "object", properties: { ticker: TICKER_PROP, exchange: EXCHANGE_PROP }, required: ["ticker"] },
114
+ },
115
+ {
116
+ name: "get_issue",
117
+ description: "Get current news-driven issues analysis ($0.05 USDC). Based on 30 days of Korean financial news — returns key issues, sentiment labels, relevance scores. Use to understand what's happening with a company right now: earnings surprises, leadership changes, product launches, regulatory actions.",
118
+ inputSchema: { type: "object", properties: { ticker: TICKER_PROP, exchange: EXCHANGE_PROP }, required: ["ticker"] },
119
+ },
120
+ {
121
+ name: "get_risk",
122
+ description: "Get investment risk assessment ($0.05 USDC). Based on 60 days of news and regulatory filings — returns overall risk level (high/medium/low), risk items by category (financial, legal, operational, market), and mitigating factors. Use before recommending a stock or writing an investment memo.",
123
+ inputSchema: { type: "object", properties: { ticker: TICKER_PROP, exchange: EXCHANGE_PROP }, required: ["ticker"] },
124
+ },
125
+ {
126
+ name: "get_stock_3y",
127
+ description: "Get 3-year daily stock price history ($0.05 USDC). Returns daily close + 3-year high/low/cumulative return. Use for long-term performance analysis.",
128
+ inputSchema: { type: "object", properties: { ticker: TICKER_PROP, exchange: EXCHANGE_PROP }, required: ["ticker"] },
129
+ },
130
+ {
131
+ name: "get_financials_all",
132
+ description: "Get all available quarterly financials history ($0.05 USDC). Up to 10 years of quarterly financial data.",
133
+ inputSchema: { type: "object", properties: { ticker: TICKER_PROP, exchange: EXCHANGE_PROP }, required: ["ticker"] },
134
+ },
135
+ ],
136
+ }));
137
+ // ── Tool → 경로 매핑 ─────────────────────────────────────────
138
+ const TOOL_PATHS = {
139
+ get_company: "/v1/context/company",
140
+ get_financials: "/v1/context/financials",
141
+ get_dividend: "/v1/context/dividend",
142
+ get_news: "/v1/context/news",
143
+ get_stock_1m: "/v1/context/stock/1m",
144
+ get_stock_3m: "/v1/context/stock/3m",
145
+ get_stock_1y: "/v1/context/stock/1y",
146
+ get_stock_3y: "/v1/context/stock/3y",
147
+ get_issue: "/v1/context/issue",
148
+ get_risk: "/v1/context/risk",
149
+ get_financials_2y: "/v1/context/financials/2y",
150
+ get_financials_5y: "/v1/context/financials/5y",
151
+ get_financials_all: "/v1/context/financials/all",
152
+ };
153
+ // ── Tool 실행 ────────────────────────────────────────────────
154
+ server.setRequestHandler(CallToolRequestSchema, async (request) => {
155
+ const { name, arguments: args } = request.params;
156
+ const a = (args ?? {});
157
+ const ticker = String(a.ticker ?? "").trim();
158
+ const exchange = String(a.exchange ?? "KRX").trim();
159
+ if (!ticker) {
160
+ return { content: [{ type: "text", text: "Error: ticker parameter is required." }], isError: true };
161
+ }
162
+ const basePath = TOOL_PATHS[name];
163
+ if (!basePath) {
164
+ return { content: [{ type: "text", text: `Error: unknown tool ${name}` }], isError: true };
165
+ }
166
+ // period 히스토리 경로: /v1/context/stock/1m → /v1/context/stock/{ticker}/1m
167
+ const periodMatch = basePath.match(/\/(1m|3m|1y|3y|2y|5y|all)$/);
168
+ const path = periodMatch
169
+ ? basePath.replace(`/${periodMatch[1]}`, `/${ticker}/${periodMatch[1]}`)
170
+ : `${basePath}/${ticker}`;
171
+ const params = exchange !== "KRX" ? { exchange } : {};
172
+ try {
173
+ const data = await callAPI(path, params);
174
+ return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
175
+ }
176
+ catch (err) {
177
+ const msg = err instanceof Error ? err.message : String(err);
178
+ if (/insufficient|balance|usdc/i.test(msg)) {
179
+ return {
180
+ content: [{
181
+ type: "text",
182
+ text: `Insufficient USDC balance.\nWallet: ${account.address}\nGet Base Mainnet USDC: https://coinbase.com or bridge from other chains.`,
183
+ }],
184
+ isError: true,
185
+ };
186
+ }
187
+ return { content: [{ type: "text", text: `Error: ${msg}` }], isError: true };
188
+ }
189
+ });
190
+ // ── 시작 ────────────────────────────────────────────────────
191
+ const transport = new StdioServerTransport();
192
+ process.stderr.write(`DeepSearch Korean Stock MCP — wallet: ${account.address} | server: ${RESOURCE_URL}\n`);
193
+ await server.connect(transport);
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "deepsearch-x402-mcp",
3
+ "version": "1.0.0",
4
+ "description": "MCP server for DeepSearch Korean Stock Intelligence API — pay-per-query via x402 USDC micropayments on Base Mainnet",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "bin": {
8
+ "deepsearch-x402-mcp": "dist/index.js"
9
+ },
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "prepublishOnly": "npm run build"
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "README.md"
17
+ ],
18
+ "keywords": [
19
+ "mcp",
20
+ "model-context-protocol",
21
+ "korean-stocks",
22
+ "krx",
23
+ "x402",
24
+ "usdc",
25
+ "deepsearch",
26
+ "finance",
27
+ "stock-data"
28
+ ],
29
+ "author": "DeepSearch <huni@deepsearch.com>",
30
+ "license": "MIT",
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "https://github.com/deepsearch-hq/deepsearch-x402.git"
34
+ },
35
+ "homepage": "https://x402.deepsearch.com",
36
+ "engines": {
37
+ "node": ">=20"
38
+ },
39
+ "dependencies": {
40
+ "@modelcontextprotocol/sdk": "^1.29.0",
41
+ "@x402/core": "latest",
42
+ "@x402/evm": "latest",
43
+ "@x402/fetch": "latest",
44
+ "viem": "^2.21.0"
45
+ }
46
+ }