wickedapi-mcp 0.2.0 → 0.3.1
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/LICENSE +1 -1
- package/README.md +114 -98
- package/dist/clientIp.js +67 -0
- package/dist/http.js +82 -0
- package/dist/index.js +5 -318
- package/dist/rateLimit.js +22 -0
- package/dist/server.js +332 -0
- package/dist/suite.js +395 -0
- package/package.json +62 -49
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -1,98 +1,114 @@
|
|
|
1
|
-
# WickedAPI MCP Server
|
|
2
|
-
|
|
3
|
-
MCP server for the whole [
|
|
4
|
-
|
|
5
|
-
**
|
|
6
|
-
|
|
7
|
-
| Service | Tools | Auth |
|
|
8
|
-
| --- | --- | --- |
|
|
9
|
-
| [Trading Data API](https://api.wickedapi.com) | 22 (unprefixed: `price`, `ohlcv`, `fvg`, `momentum_score`, `sentiment`, `macro_calendar`, …) | API key or x402, 5 free |
|
|
10
|
-
| [Protocol Health Oracle](https://protocol-health-oracle.wickedapi.com) | 6 (`protocol_health_*`) | API key or x402, scoreboard free |
|
|
11
|
-
| [Token Risk Oracle](https://token-risk-oracle.wickedapi.com) | 1 (`token_risk`) | 100% free, no key |
|
|
12
|
-
| [Broker Sync API](https://broker-sync-api.wickedapi.com) | 6 (`broker_sync_*`) | API key or x402 |
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
##
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
1
|
+
# WickedAPI MCP Server
|
|
2
|
+
|
|
3
|
+
MCP server for the whole [Wicked](https://wickedapi.com) suite — trading data, DeFi protocol health, token safety, brokerage sync, agent identity, reputation, a tool-reliability registry, hallucination checks, persistent agent memory, and x402 paywalls, in one server.
|
|
4
|
+
|
|
5
|
+
**70 tools** across 10 live services. The first four are generated automatically from each service's own live `openapi.json`, so the list always matches what's deployed; the rest are hand-written because they use wallet signatures and non-`/v1` routes:
|
|
6
|
+
|
|
7
|
+
| Service | Tools | Auth |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| [Trading Data API](https://api.wickedapi.com) | 22 (unprefixed: `price`, `ohlcv`, `fvg`, `momentum_score`, `sentiment`, `macro_calendar`, …) | API key or x402, 5 free |
|
|
10
|
+
| [Protocol Health Oracle](https://protocol-health-oracle.wickedapi.com) | 6 (`protocol_health_*`) | API key or x402, scoreboard free |
|
|
11
|
+
| [Token Risk Oracle](https://token-risk-oracle.wickedapi.com) | 1 (`token_risk`) | 100% free, no key |
|
|
12
|
+
| [Broker Sync API](https://broker-sync-api.wickedapi.com) | 6 (`broker_sync_*`) | API key or x402 |
|
|
13
|
+
| [Wicked Reputation](https://stake.wickedapi.com) | 5 (`reputation_*`) | free, no key |
|
|
14
|
+
| [Wicked Registry](https://registry.wickedapi.com) | 6 (`registry_*`) | search/detail: key or x402; featured/badge/report free; register needs your signature |
|
|
15
|
+
| [Wicked Identity](https://verify.wickedapi.com) | 6 (`identity_*`) | status: key or x402; the rest need your wallet signature over a nonce |
|
|
16
|
+
| [Wicked Sanity](https://sanity.wickedapi.com) | 2 (`sanity_check`, `sanity_check_batch`) | key or x402 |
|
|
17
|
+
| [Wicked Memory](https://memory.wickedapi.com) | 8 (`memory_prepare`, `memory_store`, `memory_search`, …) | wallet signature on every call; only search is metered |
|
|
18
|
+
| [x402 Paywall](https://paywall.wickedapi.com) | 8 (`paywall_*`) | `paywall_signup` is open; the rest need the tenant key |
|
|
19
|
+
|
|
20
|
+
Plus **6 resources** (the platform directory, `llms.txt`, and each service's live endpoint catalog) and **3 prompts** (`rug_check`, `vet_dependency`, `morning_briefing`) that chain tools together the way the [cookbook](../cookbooks/wickedapi-cookbook.md) does.
|
|
21
|
+
|
|
22
|
+
These tools never sign anything or hold a key. Identity, Registry registration and Memory take a signature you produce with your own wallet (`identity_get_nonce` / `memory_prepare` return the exact message to sign). Calls that need x402 payment return the real `402` challenge (decoded under `payment_required` for x402 v2) rather than auto-paying — `WICKEDAPI_PAYER_PRIVATE_KEY` auto-pay applies to the Trading, Protocol Health, Token Risk and Broker Sync tools.
|
|
23
|
+
|
|
24
|
+
## Remote endpoint (no install)
|
|
25
|
+
|
|
26
|
+
The same 70 tools are served over streamable HTTP at **`https://mcp.wickedapi.com/mcp`** (stateless, rate-limited per IP; the public deployment carries no personal keys, so paid calls return the x402 challenge). Point any streamable-HTTP MCP client at it. To self-host, build the `Dockerfile` (or `npm run build && npm run start:http`); see `.env.example` for `RATE_LIMIT_PER_MINUTE`, `ALLOWED_HOSTS` and `TRUSTED_CLIENT_IP_HEADER`.
|
|
27
|
+
|
|
28
|
+
## No signup required
|
|
29
|
+
|
|
30
|
+
Every tool hits a real endpoint gated by [x402](https://x402.org) (HTTP-native pay-per-call, USDC on Base) with an API-key fallback — and the Token Risk Oracle tool is free no matter what:
|
|
31
|
+
|
|
32
|
+
- **Zero config** — calls without credentials still work; paid endpoints return the real `402` payment challenge (price, network, `payTo`) as the tool result.
|
|
33
|
+
- **Autonomous pay-per-call** — set `WICKEDAPI_PAYER_PRIVATE_KEY` to a funded Base-mainnet wallet's private key, and every call auto-pays ~$0.001 in USDC and returns real data. No account, no subscription.
|
|
34
|
+
- **Partner API key** — set `WICKEDAPI_API_KEY` for free, rate-limited access across all four services (same key works everywhere).
|
|
35
|
+
|
|
36
|
+
## Install
|
|
37
|
+
|
|
38
|
+
```json
|
|
39
|
+
{
|
|
40
|
+
"mcpServers": {
|
|
41
|
+
"wickedapi": {
|
|
42
|
+
"command": "npx",
|
|
43
|
+
"args": ["-y", "wickedapi-mcp"],
|
|
44
|
+
"env": {
|
|
45
|
+
"WICKEDAPI_API_KEY": "your-key-here"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Or for autonomous pay-per-call instead of a key:
|
|
53
|
+
|
|
54
|
+
```json
|
|
55
|
+
{
|
|
56
|
+
"mcpServers": {
|
|
57
|
+
"wickedapi": {
|
|
58
|
+
"command": "npx",
|
|
59
|
+
"args": ["-y", "wickedapi-mcp"],
|
|
60
|
+
"env": {
|
|
61
|
+
"WICKEDAPI_PAYER_PRIVATE_KEY": "0xyour-base-wallet-private-key"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Nothing configured? The Token Risk Oracle tool and the 5 free Trading Data API endpoints (`sentiment`, `macro_calendar`, `market_overview`, `gas`, `kalshi_probability`) still work with zero setup.
|
|
69
|
+
|
|
70
|
+
## Resources
|
|
71
|
+
|
|
72
|
+
Read without calling a tool — useful for a client that surfaces resources in its UI:
|
|
73
|
+
|
|
74
|
+
- `wickedapi://platform/services` — the full service directory (JSON)
|
|
75
|
+
- `wickedapi://platform/llms` — the platform's `llms.txt`
|
|
76
|
+
- `wickedapi://trading/status`, `wickedapi://protocol_health/status`, `wickedapi://token_risk/status`, `wickedapi://broker_sync/status` — each service's live endpoint catalog
|
|
77
|
+
|
|
78
|
+
## Prompts
|
|
79
|
+
|
|
80
|
+
One-click workflows that chain real tool calls (Claude Desktop and other prompt-aware clients surface these directly):
|
|
81
|
+
|
|
82
|
+
- **`rug_check`** (`address`, `chain`, optional `symbol`) — token risk check + market sentiment + optional momentum read, before buying.
|
|
83
|
+
- **`vet_dependency`** (`slug`, optional `token_address`, `chain`) — protocol health + optional contract-level risk check, before building on a DeFi protocol.
|
|
84
|
+
- **`morning_briefing`** (optional `symbol`) — macro calendar + earnings calendar + sentiment + momentum verdict, as one digest.
|
|
85
|
+
|
|
86
|
+
## Environment variables
|
|
87
|
+
|
|
88
|
+
| Var | Required | Notes |
|
|
89
|
+
| --- | --- | --- |
|
|
90
|
+
| `WICKEDAPI_API_KEY` | no | Free, rate-limited access across all four services (same key works everywhere). |
|
|
91
|
+
| `WICKEDAPI_PAYER_PRIVATE_KEY` | no | Base-mainnet wallet private key. If set, every call auto-pays the x402 challenge in USDC — no key needed. |
|
|
92
|
+
| `WICKEDAPI_BASE_URL` | no | Override the Trading Data API base (default `https://api.wickedapi.com`). |
|
|
93
|
+
| `WICKEDAPI_PROTOCOL_HEALTH_URL` | no | Override the Protocol Health Oracle base (default `https://protocol-health-oracle.wickedapi.com`). |
|
|
94
|
+
| `WICKEDAPI_TOKEN_RISK_URL` | no | Override the Token Risk Oracle base (default `https://token-risk-oracle.wickedapi.com`). |
|
|
95
|
+
| `WICKEDAPI_BROKER_SYNC_URL` | no | Override the Broker Sync API base (default `https://broker-sync-api.wickedapi.com`). |
|
|
96
|
+
| `REGISTRY_API_KEY` / `IDENTITY_API_KEY` / `SANITY_API_KEY` / `MEMORY_API_KEY` | no | Free-tier keys for the paid calls of Registry, Identity, Sanity and Memory search. Omit to get the x402 challenge instead. |
|
|
97
|
+
| `PAYWALL_API_KEY` | for `paywall_*` | Tenant Bearer key returned once by `paywall_signup`. |
|
|
98
|
+
| `REPUTATION_BASE_URL` / `REGISTRY_BASE_URL` / `IDENTITY_BASE_URL` / `SANITY_BASE_URL` / `MEMORY_BASE_URL` / `PAYWALL_BASE_URL` | no | Override the matching service base (defaults are the `*.wickedapi.com` hosts). |
|
|
99
|
+
| `WICKEDAPI_SHOWCASE_URL` | no | Override the platform directory base used by resources (default `https://wickedapi.com`). |
|
|
100
|
+
|
|
101
|
+
If neither `WICKEDAPI_API_KEY` nor `WICKEDAPI_PAYER_PRIVATE_KEY` is set, paid calls still succeed at the protocol level — you'll get the real `402` challenge back as the tool result instead of data. If one service's spec fails to load (network hiccup, that service is down), its tools are simply skipped for the session — the rest still register normally.
|
|
102
|
+
|
|
103
|
+
## Local development
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
npm install
|
|
107
|
+
npm test # builds, then unit + end-to-end tests (e2e needs network)
|
|
108
|
+
node dist/index.js # stdio
|
|
109
|
+
node dist/http.js # streamable HTTP on $PORT (default 8080)
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## What this is not
|
|
113
|
+
|
|
114
|
+
This server doesn't reimplement any data logic — it's a thin bridge from MCP tool calls to the live Wicked HTTP endpoints across all ten services. All the actual market data, indicators, scoring, and risk signals live in the APIs themselves.
|
package/dist/clientIp.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Who is calling, for rate limiting. Ported from the Python http_app.py so
|
|
2
|
+
// behaviour is unchanged after the cutover.
|
|
3
|
+
//
|
|
4
|
+
// Behind Railway's edge proxy the TCP peer is always an internal address, so
|
|
5
|
+
// the limiter keys on the proxy-set X-Real-IP header instead. That is only
|
|
6
|
+
// safe because the proxy sets the header itself; set TRUSTED_CLIENT_IP_HEADER
|
|
7
|
+
// to empty to fall back to the TCP peer when running without a proxy, or to
|
|
8
|
+
// cf-connecting-ip if the domain is ever proxied through Cloudflare.
|
|
9
|
+
import { isIP } from "node:net";
|
|
10
|
+
const TRUSTED_HEADER = (process.env.TRUSTED_CLIENT_IP_HEADER ?? "x-real-ip").trim().toLowerCase();
|
|
11
|
+
function expandIPv6(ip) {
|
|
12
|
+
let s = ip.split("%")[0];
|
|
13
|
+
let tail = [];
|
|
14
|
+
const v4 = s.match(/(\d+\.\d+\.\d+\.\d+)$/);
|
|
15
|
+
if (v4) {
|
|
16
|
+
const o = v4[1].split(".").map(Number);
|
|
17
|
+
tail = [(o[0] << 8) | o[1], (o[2] << 8) | o[3]];
|
|
18
|
+
s = s.slice(0, -v4[1].length) + "0:0";
|
|
19
|
+
}
|
|
20
|
+
const halves = s.split("::");
|
|
21
|
+
if (halves.length > 2)
|
|
22
|
+
return null;
|
|
23
|
+
const head = halves[0] ? halves[0].split(":") : [];
|
|
24
|
+
const rest = halves.length === 2 && halves[1] ? halves[1].split(":") : [];
|
|
25
|
+
const fill = 8 - head.length - rest.length;
|
|
26
|
+
if ((halves.length === 1 && fill !== 0) || fill < 0)
|
|
27
|
+
return null;
|
|
28
|
+
const groups = [...head, ...Array(halves.length === 2 ? fill : 0).fill("0"), ...rest].map((g) => parseInt(g, 16));
|
|
29
|
+
if (groups.length !== 8 || groups.some((g) => Number.isNaN(g)))
|
|
30
|
+
return null;
|
|
31
|
+
if (tail.length) {
|
|
32
|
+
groups[6] = tail[0];
|
|
33
|
+
groups[7] = tail[1];
|
|
34
|
+
}
|
|
35
|
+
return groups;
|
|
36
|
+
}
|
|
37
|
+
/** Canonical rate-limit key, or null if `raw` isn't an IP. IPv4-mapped IPv6
|
|
38
|
+
* collapses to the IPv4 address; IPv6 is grouped by /64 so rotating addresses
|
|
39
|
+
* inside one prefix can't dodge the limit. */
|
|
40
|
+
export function normalizeIp(raw) {
|
|
41
|
+
const s = raw.trim();
|
|
42
|
+
const kind = isIP(s);
|
|
43
|
+
if (kind === 4)
|
|
44
|
+
return s;
|
|
45
|
+
if (kind !== 6)
|
|
46
|
+
return null;
|
|
47
|
+
const g = expandIPv6(s);
|
|
48
|
+
if (!g)
|
|
49
|
+
return null;
|
|
50
|
+
if (g.slice(0, 5).every((x) => x === 0) && g[5] === 0xffff) {
|
|
51
|
+
return `${g[6] >> 8}.${g[6] & 255}.${g[7] >> 8}.${g[7] & 255}`;
|
|
52
|
+
}
|
|
53
|
+
return `${g.slice(0, 4).map((x) => x.toString(16)).join(":")}::/64`;
|
|
54
|
+
}
|
|
55
|
+
export function clientKey(req) {
|
|
56
|
+
if (TRUSTED_HEADER) {
|
|
57
|
+
const raw = req.headers[TRUSTED_HEADER];
|
|
58
|
+
const value = Array.isArray(raw) ? raw[0] : raw;
|
|
59
|
+
if (value) {
|
|
60
|
+
const key = normalizeIp(value);
|
|
61
|
+
if (key)
|
|
62
|
+
return key;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const peer = req.socket.remoteAddress ?? "unknown";
|
|
66
|
+
return normalizeIp(peer) ?? peer;
|
|
67
|
+
}
|
package/dist/http.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// Streamable-HTTP entry point for the public remote at https://mcp.wickedapi.com/mcp.
|
|
2
|
+
// Stateless: every request gets its own McpServer + transport (specs are
|
|
3
|
+
// loaded once at boot), so it scales and restarts without session loss.
|
|
4
|
+
// Public-endpoint additions over the stdio build: a per-IP rate limit and a
|
|
5
|
+
// Host allowlist (DNS-rebinding protection). Tools and upstream calls are
|
|
6
|
+
// identical.
|
|
7
|
+
import { createServer } from "node:http";
|
|
8
|
+
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
9
|
+
import { clientKey } from "./clientIp.js";
|
|
10
|
+
import { rateLimited } from "./rateLimit.js";
|
|
11
|
+
import { buildServer, loadWorld, SERVER_VERSION } from "./server.js";
|
|
12
|
+
const PORT = Number(process.env.PORT || 8080);
|
|
13
|
+
const RATE_LIMIT_PER_MINUTE = Number(process.env.RATE_LIMIT_PER_MINUTE || 30);
|
|
14
|
+
const MAX_BODY_BYTES = 1_000_000;
|
|
15
|
+
const ALLOWED_HOSTS = (process.env.ALLOWED_HOSTS || "mcp.wickedapi.com,wicked-mcp-production.up.railway.app,localhost:8080,127.0.0.1:8080")
|
|
16
|
+
.split(",")
|
|
17
|
+
.map((h) => h.trim().toLowerCase())
|
|
18
|
+
.filter(Boolean);
|
|
19
|
+
function send(res, status, body, headers = {}) {
|
|
20
|
+
res.writeHead(status, { "content-type": "application/json", ...headers });
|
|
21
|
+
res.end(JSON.stringify(body));
|
|
22
|
+
}
|
|
23
|
+
async function readJson(req) {
|
|
24
|
+
const chunks = [];
|
|
25
|
+
let size = 0;
|
|
26
|
+
for await (const chunk of req) {
|
|
27
|
+
size += chunk.length;
|
|
28
|
+
if (size > MAX_BODY_BYTES)
|
|
29
|
+
throw Object.assign(new Error("payload too large"), { status: 413 });
|
|
30
|
+
chunks.push(chunk);
|
|
31
|
+
}
|
|
32
|
+
if (!chunks.length)
|
|
33
|
+
return undefined;
|
|
34
|
+
try {
|
|
35
|
+
return JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
throw Object.assign(new Error("invalid JSON"), { status: 400 });
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async function main() {
|
|
42
|
+
const world = await loadWorld();
|
|
43
|
+
const { summary } = buildServer(world);
|
|
44
|
+
const http = createServer(async (req, res) => {
|
|
45
|
+
const url = new URL(req.url || "/", "http://x");
|
|
46
|
+
if (url.pathname === "/health")
|
|
47
|
+
return send(res, 200, { status: "ok", version: SERVER_VERSION });
|
|
48
|
+
const host = (req.headers.host || "").toLowerCase();
|
|
49
|
+
if (!ALLOWED_HOSTS.includes(host))
|
|
50
|
+
return send(res, 421, { error: "Invalid Host header" });
|
|
51
|
+
if (url.pathname !== "/mcp")
|
|
52
|
+
return send(res, 404, { error: "Not found. The MCP endpoint is /mcp." });
|
|
53
|
+
if (req.method !== "POST") {
|
|
54
|
+
return send(res, 405, { jsonrpc: "2.0", error: { code: -32000, message: "Method not allowed (stateless server: POST only)." }, id: null }, { allow: "POST" });
|
|
55
|
+
}
|
|
56
|
+
if (rateLimited(clientKey(req), RATE_LIMIT_PER_MINUTE)) {
|
|
57
|
+
return send(res, 429, { error: `Rate limit exceeded: ${RATE_LIMIT_PER_MINUTE} requests/minute per IP. Run this server locally (npx wickedapi-mcp) for unlimited use.` }, { "retry-after": "60" });
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
const body = await readJson(req);
|
|
61
|
+
const { server } = buildServer(world);
|
|
62
|
+
const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined });
|
|
63
|
+
res.on("close", () => {
|
|
64
|
+
void transport.close();
|
|
65
|
+
void server.close();
|
|
66
|
+
});
|
|
67
|
+
await server.connect(transport);
|
|
68
|
+
await transport.handleRequest(req, res, body);
|
|
69
|
+
}
|
|
70
|
+
catch (err) {
|
|
71
|
+
const status = err.status ?? 500;
|
|
72
|
+
if (!res.headersSent) {
|
|
73
|
+
send(res, status, { jsonrpc: "2.0", error: { code: -32603, message: err.message }, id: null });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
http.listen(PORT, "0.0.0.0", () => console.error(`[wickedapi-mcp] http on :${PORT}/mcp - ${summary}.`));
|
|
78
|
+
}
|
|
79
|
+
main().catch((err) => {
|
|
80
|
+
console.error("[wickedapi-mcp] fatal:", err);
|
|
81
|
+
process.exit(1);
|
|
82
|
+
});
|