Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(pump-fun-mcp worker): fail over between Solana RPCs and read Token-2022 metadata

nirholas87ed8bafce2f
diff --git a/data/changelog.json b/data/changelog.json
index e6e3129d8..a3fc1156e 100644
--- a/data/changelog.json
+++ b/data/changelog.json
@@ -1,6 +1,35 @@
{
"$comment": "Curated changelog entries for three.ws, the editorial layer of the public changelog. New PAGE launches are tracked automatically via the `added` field in data/pages.json; this file is for everything else holders care about: improvements, fixes, SDK releases, trading/payments capabilities, security work. scripts/build-page-index.mjs merges both sources into CHANGELOG.md, public/changelog.json, and public/changelog.xml. Newest first. Allowed tags: feature, improvement, fix, sdk, infra, docs, security. `link` is optional and must be a live three.ws path.",
"entries": [
+ {
+ "date": "2026-08-11",
+ "title": "Stylizing a model no longer throws away the finished result over a momentary network hiccup, and plain models keep their intended color",
+ "summary": "The stylize filters (voxel, brick, voronoi shell, low-poly) rebuild your model and then upload the result to storage. A brief interruption on that last upload step was not retried, so roughly once a week a job that had already done all its work was reported to you as failed. That upload now retries by itself. Two more repairs ride along: a model that carries no colors of its own now comes back in the soft neutral tone the filters were designed around, instead of the flat gray the geometry library hands out by default, and a model with no size at all is refused with a clear reason rather than returning a file with nothing visible in it.",
+ "tags": [
+ "fix",
+ "improvement"
+ ],
+ "link": "/forge"
+ },
+ {
+ "date": "2026-08-11",
+ "title": "Motion Swap's guide now describes the hand and finger capture it has been doing all along",
+ "summary": "The Motion Swap guide described body tracking only, so a reader had no way to know the capture also follows both hands, takes wrist rotation from the palm itself, and solves every finger joint, or that it holds your last handshape when your hands leave the frame. The guide and the capture worker's README now cover all of that, plus the exact files a capture produces, every setting the worker reads, and how to run a real capture on your own machine to check a change before it ships. The worker also gained a second test suite covering the parts around the motion solver: the authentication and input rules on its API, the video normalization step, the person-mask video, and the guard that refuses to fetch a video address pointing at our own internal infrastructure.",
+ "tags": [
+ "docs",
+ "improvement"
+ ],
+ "link": "/motion-swap"
+ },
+ {
+ "date": "2026-08-11",
+ "title": "The pump.fun MCP server now returns the real name and symbol for tokens launched today",
+ "summary": "Ask the pump.fun MCP server for a token's details and it reported no name, no symbol, and no image link for essentially every coin launched recently, including $THREE. The reason: pump.fun now mints Token-2022 tokens, which carry their name and symbol inside the mint itself rather than in the separate metadata account the server was reading. It now reads both places, so a request for a current token returns its actual name, symbol, and metadata link alongside supply and decimals. Older tokens are unaffected.",
+ "tags": [
+ "fix"
+ ],
+ "link": "/docs/mcp"
+ },
{
"date": "2026-08-11",
"title": "A watched agent card no longer promises a live browser that is never coming",
diff --git a/prompts/swarm-100/worker-pump-fun-mcp.md b/prompts/swarm-100/worker-pump-fun-mcp.md
deleted file mode 100644
index a448b34d0..000000000
--- a/prompts/swarm-100/worker-pump-fun-mcp.md
+++ /dev/null
@@ -1,98 +0,0 @@
-# Worker audit: workers/pump-fun-mcp
-
-How to run: paste this file's repo path into a fresh Claude Code chat in this
-repository and say "run this work order". This file is fully self-contained:
-it depends on no other prompt file anywhere. If neighboring files in
-prompts/swarm-100/ are gone, that work is done; if present, ignore them.
-Every claim below rots; step 0 re-measures, and what you measure wins.
-
-## Operating clause (binding)
-
-- Read CLAUDE.md first. Its rules override everything, including this file.
-- Finish 100% in this session. Never end the turn with a question, an option
- list, or an unexecuted plan. A judgment call goes in one line of the final
- report; it never becomes a question that halts work.
-- The only permitted stops are the CLAUDE.md stop-and-ask gates: spending real
- funds or any irreversible on-chain write, git push or a production deploy,
- committing content that references a crypto project other than $THREE, and
- destroying unrecoverable data.
-- No mocks, no fake data, no placeholder stubs, no unfinished-work markers, no
- commented-out code. Real APIs and real integrations only.
-- The em-dash and en-dash characters are banned in everything you write.
-- Concurrent agents share this worktree: stage explicit paths only (never a
- bare add-everything), and commit finished work promptly.
-- Before committing, run: npm run check:rules -- --paths <files you touched>.
- It must exit 0.
-
-## Step 0: re-derive the current state
-
-1. Read workers/pump-fun-mcp/README.md and its build config (cloudbuild.yaml,
- Dockerfile, package.json; whichever exist).
-2. Is it deployed?
-
- export PATH="$HOME/google-cloud-sdk/bin:$PATH"
- gcloud run services list --project aerial-vehicle-466722-p5 --region us-central1 | grep -i "pump-fun-mcp" || echo "not deployed as its own service"
-
-3. If deployed: which commit is the running revision built from, and does main
- contain fixes it has not picked up? A fix in main can sit undeployed for
- days; never call a bug unfixed without checking the running revision.
-4. Logs, last 24h, if deployed:
-
- gcloud logging read 'resource.type="cloud_run_revision" resource.labels.service_name="<service name from step 2>"' --freshness=24h --limit 100 --project aerial-vehicle-466722-p5
-
-## Task: bring this worker to verified-healthy
-
-1. README accuracy: what it does, how to run it, its inputs and outputs. Fix
- every stale claim; a README that lies fails the audit.
-2. Build it the way its own config says. The build must succeed from a clean
- checkout of this worktree. Model workers that need weights stage them from
- gs://three-ws-model-weights (staging weights is part of the job, not a
- blocker).
-3. Run its tests; add a smoke test if it has none that proves its core path.
-4. If deployed: last 24h of logs free of unhandled errors; fix root causes in
- code and commit. Redeploying is owner-gated: prepare everything so the
- deploy is one command and say so in the report.
-5. If not deployed by design: its README must state how and where it runs, and
- that path must be verified locally.
-
-## Definition of done
-
-- [ ] Build succeeds from this worktree with the worker's own config.
-- [ ] Tests pass, including at least one core-path smoke test.
-- [ ] README verified accurate against the code.
-- [ ] If deployed: running revision identified, 24h logs clean or root causes
- fixed and committed (deploy itself flagged for the owner).
-- [ ] npm run check:rules -- --paths <touched files> exits 0.
-
-## Never blocked
-
-| Blocker | Resolution (act, do not ask) |
-|---|---|
-| Missing env var or credential | Check .env and .env.local, then the Cloud Run service env, then Secret Manager (the CLAUDE.md self-unblock playbook has the exact commands). If it truly exists nowhere, wire the code fully behind the env var, prove the wiring with a dry run, and name the single missing var in the report. |
-| gcloud not on PATH | Run: export PATH="$HOME/google-cloud-sdk/bin:$PATH" |
-| Dev server port 3000 busy | Another agent may be serving this repo; probe it and reuse if so. Otherwise start your own on a free port: npx vite --port 3101 |
-| Playwright browser missing | npx playwright install chromium |
-| A surface needs a signed-in user | Register a fresh account through the real /register flow against the real API and use it. Never mock the session. |
-| A defect sits in code you did not touch | Fix it if it blocks a Definition of done line (root cause it, never mask it). Otherwise note it in the report and continue. |
-| An unrelated test is red | Same rule. Never pipe npm test through tail; it masks exit codes. |
-
-## Close out (required)
-
-1. Verify every Definition of done line with the actual command output in
- front of you. Never claim a line you did not verify.
-2. Commit with explicit paths and a subject that describes the diff (house
- style: type(scope): what changed and why a reader cares).
-3. Delete this prompt file in that same commit:
-
- git rm prompts/swarm-100/worker-pump-fun-mcp.md
-
- The shrinking directory is this campaign's only progress ledger; there is
- no progress log to update.
-4. Final report: what step 0 measured, what changed (file list), evidence per
- Definition of done line, and any one-line judgment calls. No trailing
- questions, no unexecuted plans.
-
-If a line genuinely cannot pass inside this session (an external party must
-respond, or an owner-gated action is the final step), finish everything else,
-leave this file in place, and state exactly which line remains and who owns
-it. Never delete this file on a partial.
diff --git a/workers/pump-fun-mcp/README.md b/workers/pump-fun-mcp/README.md
index 1e81af0f4..9188ff5ad 100644
--- a/workers/pump-fun-mcp/README.md
+++ b/workers/pump-fun-mcp/README.md
@@ -1,54 +1,164 @@
# pump-fun-mcp (Cloudflare Workers mirror)
-Mirror of the canonical pump.fun MCP server at `https://three.ws/api/pump-fun-mcp`
-(`api/pump-fun-mcp.js`). Deploy: `wrangler deploy`
+A remote MCP server exposing free, read-only pump.fun and Solana data. It mirrors
+the canonical server at `https://three.ws/api/pump-fun-mcp` ([api/pump-fun-mcp.js](../../api/pump-fun-mcp.js))
+so the same tools can be served from Cloudflare's edge, and shares its tool
+catalog with that handler through [src/pump/mcp-tools.js](../../src/pump/mcp-tools.js).
+
+Point any MCP client at the worker URL. No API key, no account, no auth header.
+
+## Where it runs
+
+This worker is **not deployed today**: there is no Cloudflare account wired up in
+this repo, and no `pump-fun-mcp` service exists on the project's Cloud Run fleet
+(the canonical server there is the three.ws API route, not this file). The
+production endpoint agents should use is `https://three.ws/api/pump-fun-mcp`.
+
+The worker exists so the read-only surface can be run anywhere, by anyone, on
+their own Cloudflare account. Both paths below are the ones verified against this
+code; `wrangler` is not a repo dependency, so it is invoked through `npx`.
+
+```bash
+cd workers/pump-fun-mcp
+
+# Run it locally (workerd, the real Workers runtime) on http://127.0.0.1:8787
+npx wrangler@4 dev --var "SOLANA_RPC_URL:https://your-rpc.example"
+
+# Type-free build check: bundles exactly what a deploy would upload
+npx wrangler@4 deploy --dry-run --outdir /tmp/pump-fun-mcp-build
+
+# Deploy to your own Cloudflare account (prompts for login on first run)
+npx wrangler@4 deploy
+```
+
+Dependencies (`@solana/web3.js`, `@solana/spl-token`, `@pump-fun/pump-sdk`) resolve
+from the repo root `node_modules`, so run `npm install` at the repo root first.
+The worker has no `package.json` of its own by design: it is bundled from this
+worktree, not published.
+
+Tests: `npx vitest run tests/workers/pump-fun-mcp-worker.test.js` exercises the
+transport, the dispatch table, the tools/list filtering, and the RPC failover
+boundary against the real module.
## Transport
Full MCP Streamable HTTP (protocol `2025-06-18`), identical to the three.ws handler:
-- `POST` — JSON-RPC 2.0, single requests and batches (max 16). Notification-only
+- `POST`: JSON-RPC 2.0, single requests and batches (max 16). Notification-only
requests return `202 Accepted` with no body.
-- `GET` / `HEAD` — SSE handshake (`content-type: text/event-stream`). The worker is
- stateless and never initiates server→client messages, so the stream closes
- immediately after opening — permitted by the spec.
-- `DELETE` — session terminate (`204`; nothing to tear down).
-- `OPTIONS` — CORS preflight. CORS is open (`*`), matching the read-only surface.
+- `GET` / `HEAD`: SSE handshake (`content-type: text/event-stream`). The worker is
+ stateless and never initiates server-to-client messages, so the stream closes
+ immediately after opening, which the spec permits.
+- `DELETE`: session terminate (`204`; nothing to tear down).
+- `OPTIONS`: CORS preflight. CORS is open (`*`), matching the read-only surface.
Every JSON-RPC response carries the `mcp-protocol-version` header.
-## Tool names
+## Tools
+
+Canonical names are snake_case. `tools/list` advertises only canonical names;
+`tools/call` also accepts the legacy camelCase names (`searchTokens`,
+`getBondingCurve`, and so on) forever, via `TOOL_NAME_ALIASES` in
+[src/pump/mcp-tools.js](../../src/pump/mcp-tools.js), the shared single source of
+truth for both this worker and the three.ws handler.
-Canonical names are snake_case (`search_tokens`, `get_bonding_curve`, …).
-`tools/list` advertises only canonical names; `tools/call` accepts the legacy
-camelCase names (`searchTokens`, `getBondingCurve`, …) forever via
-`TOOL_NAME_ALIASES` in `src/pump/mcp-tools.js` — the shared single source of truth.
+| Tool | Source | Listed when |
+| --- | --- | --- |
+| `get_bonding_curve` | on-chain (pump SDK) | always |
+| `get_token_details` | on-chain (mint + metadata) | always |
+| `get_token_holders` | on-chain (largest accounts) | always |
+| `pumpfun_bot_status` | worker self-report | always |
+| `search_tokens` | indexer | `PUMPFUN_BOT_URL` set |
+| `get_token_trades` | indexer | `PUMPFUN_BOT_URL` set |
+| `get_trending_tokens` | indexer | `PUMPFUN_BOT_URL` set |
+| `get_new_tokens` | indexer | `PUMPFUN_BOT_URL` set |
+| `get_graduated_tokens` | indexer | `PUMPFUN_BOT_URL` set |
+| `get_king_of_the_hill` | indexer | `PUMPFUN_BOT_URL` set |
+| `get_creator_profile` | indexer | `PUMPFUN_BOT_URL` set |
-## Documented divergences from the three.ws handler
+Indexer-backed tools are hidden from `tools/list` until `PUMPFUN_BOT_URL` is
+configured, so a client never sees a tool whose only possible answer is an error.
+`pumpfun_bot_status` is always listed and always callable: it reports whether the
+indexer is configured and, if so, whether it is currently answering.
+`initialize` carries the same signal as `serverInfo.indexerEnabled`.
-These are deliberate scope decisions, not platform constraints — CF Workers
-support SSE/streams fine:
+`get_token_details` reads Token-2022 mints (what pump.fun launches today) from the
+mint's own TokenMetadata extension, and legacy SPL mints from the Metaplex
+metadata PDA. Metadata is best effort: a mint with neither returns `null` name,
+symbol, and uri alongside its real supply and decimals.
-1. **Tool subset.** The worker serves only the on-chain + indexer data tools
- (`get_bonding_curve`, `get_token_details`, `get_token_holders`, `search_tokens`,
- `get_token_trades`, `get_trending_tokens`, `get_new_tokens`,
- `get_graduated_tokens`, `get_king_of_the_hill`, `get_creator_profile`), and its
- `tools/list` honestly advertises exactly that subset. The kol/sns/social/claims
- and auth-gated tools depend on three.ws backend modules (x402 settlement,
- bearer auth, the radar/leaderboard stores) that live in the three.ws
- (Cloud Run) deployment.
-2. **No auth / x402 gating.** None of the gated tools (`pumpfun_vanity_mint`,
+## RPC failover
+
+On-chain tools try each endpoint in order until one answers:
+`SOLANA_RPC_URL`, then every comma-separated entry in `SOLANA_RPC_FALLBACKS`
+(devnet uses `SOLANA_RPC_URL_DEVNET` and `SOLANA_RPC_FALLBACKS_DEVNET`). When
+none of those are set, the chain is the public Solana endpoint alone. Configuring
+any endpoint replaces the public default rather than prepending to it, so a
+pinned paid RPC never silently downgrades to a shared one.
+
+A tool-level verdict (invalid mint, account genuinely absent) stops the chain
+immediately; only transport failures advance it. When every endpoint fails, the
+caller gets JSON-RPC error `-32004` naming the upstream cause, never a `-32603`.
+Public endpoints IP-block and rate-limit routinely, so a single-endpoint
+deployment will go dark on every on-chain tool sooner or later. Set at least one
+fallback.
+
+## Divergences from the three.ws handler
+
+Deliberate scope decisions, not platform constraints (Workers support SSE and
+streams fine):
+
+1. **Tool subset.** The worker serves the on-chain and indexer data tools listed
+ above, and its `tools/list` advertises exactly that subset. The kol, sns,
+ social, claims, and auth-gated tools depend on three.ws backend modules (x402
+ settlement, bearer auth, the radar and leaderboard stores) that live in the
+ Cloud Run deployment.
+2. **No auth or x402 gating.** None of the gated tools (`pumpfun_vanity_mint`,
`pumpfun_watch_whales`, `pumpfun_watch_claims`) are served here, so the worker
carries no bearer or payment plumbing.
-3. **No rate limiting in-process.** Handled at the Cloudflare edge layer.
-4. **`get_token_trades` is indexer-only here.** The three.ws handler falls back to
- decoding trades from chain; the worker requires `PUMPFUN_BOT_URL`.
-
-## Secrets (`wrangler secret put <NAME>`)
-
-| Secret | Purpose |
-| ----------------------- | ---------------------------------------- |
-| `SOLANA_RPC_URL` | mainnet RPC endpoint (default: public) |
-| `SOLANA_RPC_URL_DEVNET` | devnet RPC endpoint (default: public) |
-| `PUMPFUN_BOT_URL` | upstream indexer endpoint (optional) |
-| `PUMPFUN_BOT_TOKEN` | bearer token for the indexer (optional) |
+3. **No in-process rate limiting.** Handled at the Cloudflare edge layer.
+4. **`get_token_trades` is indexer-only here.** The three.ws handler also decodes
+ trades from chain; this worker requires `PUMPFUN_BOT_URL`.
+
+## Configuration
+
+Set with `npx wrangler@4 secret put <NAME>` for a deployment, or `--var NAME:VALUE`
+for a local `wrangler dev` run. Everything is optional: with no configuration at
+all, the on-chain tools work against the public Solana endpoint and the
+indexer-backed tools stay unlisted.
+
+| Variable | Purpose |
+| --- | --- |
+| `SOLANA_RPC_URL` | primary mainnet RPC endpoint |
+| `SOLANA_RPC_FALLBACKS` | comma-separated mainnet failover endpoints |
+| `SOLANA_RPC_URL_DEVNET` | primary devnet RPC endpoint |
+| `SOLANA_RPC_FALLBACKS_DEVNET` | comma-separated devnet failover endpoints |
+| `PUMPFUN_BOT_URL` | upstream indexer MCP endpoint |
+| `PUMPFUN_BOT_TOKEN` | bearer token for the indexer |
+
+## Example
+
+```bash
+curl -s -X POST http://127.0.0.1:8787/ \
+ -H 'content-type: application/json' \
+ -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"get_token_details","arguments":{"mint":"FeMbDoX7R1Psc4GEcvJdsbNbZA3bfztcyDCatJVJpump"}}}'
+```
+
+```json
+{
+ "jsonrpc": "2.0",
+ "id": 1,
+ "result": {
+ "structuredContent": {
+ "mint": "FeMbDoX7R1Psc4GEcvJdsbNbZA3bfztcyDCatJVJpump",
+ "name": "three.ws",
+ "symbol": "three",
+ "uri": "https://ipfs.io/ipfs/bafkreiftorgs5knoqr3z53unjpdmgyhp4abjnqjkast3iq3tfofetm2oom",
+ "decimals": 6,
+ "supply": "999668768738714",
+ "mintAuthority": null,
+ "freezeAuthority": null
+ }
+ }
+}
+```
diff --git a/workers/pump-fun-mcp/worker.js b/workers/pump-fun-mcp/worker.js
index 9b42dd1cc..e9ca100c0 100644
--- a/workers/pump-fun-mcp/worker.js
+++ b/workers/pump-fun-mcp/worker.js
@@ -1,19 +1,20 @@
-// Cloudflare Workers mirror of /api/pump-fun-mcp (Vercel).
+// Cloudflare Workers mirror of the canonical pump.fun MCP server, which runs at
+// https://three.ws/api/pump-fun-mcp (api/pump-fun-mcp.js, on Cloud Run).
//
-// Implements the MCP Streamable HTTP transport: POST — JSON-RPC 2.0 (single +
-// batch), GET/HEAD — SSE handshake, DELETE — session terminate. Tool
-// definitions (and the snake_case ↔ camelCase alias map) are shared with the
-// Vercel handler via src/pump/mcp-tools.js. Handler logic is adapted from
-// api/pump-fun-mcp.js — see README.md for the documented divergences (no
-// auth/x402-gated tools, on-chain + indexer subset only).
+// Implements the MCP Streamable HTTP transport: POST for JSON-RPC 2.0 (single +
+// batch), GET/HEAD for the SSE handshake, DELETE for session terminate. Tool
+// definitions (and the snake_case to camelCase alias map) are shared with the
+// three.ws handler via src/pump/mcp-tools.js. Handler logic is adapted from
+// api/pump-fun-mcp.js. See README.md for the documented divergences (no
+// auth/x402-gated tools, on-chain + indexer subset only), the full config table,
+// and the verified run/build/deploy commands.
//
-// Secrets (wrangler secret put <NAME>):
-// SOLANA_RPC_URL mainnet RPC endpoint (default: public)
-// SOLANA_RPC_URL_DEVNET devnet RPC endpoint (default: public)
-// PUMPFUN_BOT_URL upstream indexer endpoint (optional)
-// PUMPFUN_BOT_TOKEN bearer token for indexer (optional)
+// Config, all optional (npx wrangler@4 secret put <NAME>, or --var NAME:VALUE
+// under `wrangler dev`): SOLANA_RPC_URL, SOLANA_RPC_FALLBACKS,
+// SOLANA_RPC_URL_DEVNET, SOLANA_RPC_FALLBACKS_DEVNET, PUMPFUN_BOT_URL,
+// PUMPFUN_BOT_TOKEN.
//
-// Deploy: wrangler deploy
+// Tests: npx vitest run tests/workers/pump-fun-mcp-worker.test.js
import { TOOLS, resolveToolName, rpcError, rpcEnvelope } from '../../src/pump/mcp-tools.js';
@@ -45,11 +46,43 @@ const CORS_HEADERS = {
// ── Solana helpers (adapted for CF Workers env bindings) ─────────────────────
-function getRpcUrl(env, network = 'mainnet') {
- if (network === 'devnet') {
- return env.SOLANA_RPC_URL_DEVNET || 'https://api.devnet.solana.com';
+// Ordered failover chain: the configured endpoint first, then any comma-separated
+// SOLANA_RPC_FALLBACKS (the same var name the three.ws deployment uses). Public
+// and free-tier RPCs rate-limit and IP-block routinely, so a single-endpoint
+// worker goes dark on every on-chain tool the moment one provider says no.
+// The public endpoint is the chain only when nothing is configured: an operator
+// who pinned their own RPCs gets exactly those, in order, and never a silent
+// downgrade to a shared endpoint.
+function getRpcUrls(env, network = 'mainnet') {
+ const isDevnet = network === 'devnet';
+ const configured = [
+ isDevnet ? env.SOLANA_RPC_URL_DEVNET : env.SOLANA_RPC_URL,
+ ...String((isDevnet ? env.SOLANA_RPC_FALLBACKS_DEVNET : env.SOLANA_RPC_FALLBACKS) || '')
+ .split(',')
+ .map((u) => u.trim()),
+ ].filter((u) => typeof u === 'string' && /^https?:\/\//.test(u));
+ if (configured.length === 0) {
+ return [isDevnet ? 'https://api.devnet.solana.com' : 'https://api.mainnet-beta.solana.com'];
}
- return env.SOLANA_RPC_URL || 'https://api.mainnet-beta.solana.com';
+ return [...new Set(configured)];
+}
+
+// Run `fn` against each endpoint in the chain until one answers. A tool-level
+// rpcError (invalid mint, account genuinely absent) is a verdict, not a
+// transport failure, so it propagates immediately instead of burning the chain.
+async function withRpc(env, network, fn) {
+ const { Connection } = await import('@solana/web3.js');
+ const urls = getRpcUrls(env, network);
+ let lastError = null;
+ for (const url of urls) {
+ try {
+ return await fn(new Connection(url, 'confirmed'));
+ } catch (err) {
+ if (err?.rpcCode) throw err;
+ lastError = err;
+ }
+ }
+ throw lastError || new Error('no Solana RPC endpoint configured');
}
// ── On-chain handlers ────────────────────────────────────────────────────────
@@ -63,22 +96,25 @@ async function handleGetBondingCurve({ mint, network = 'mainnet' }, env) {
throw rpcError(-32602, 'invalid mint');
}
- const conn = new Connection(getRpcUrl(env, network), 'confirmed');
const { OnlinePumpSdk, PumpSdk } = await import('@pump-fun/pump-sdk');
let curve;
try {
- const sdk = new OnlinePumpSdk(conn);
- if (sdk.fetchBuyState) {
- const state = await sdk.fetchBuyState(pk, pk);
- curve = state.bondingCurve;
- } else if (sdk.fetchBondingCurve) {
- curve = await sdk.fetchBondingCurve(pk);
- }
- if (!curve) {
- const sdk2 = new PumpSdk(conn);
- if (sdk2.fetchBondingCurve) curve = await sdk2.fetchBondingCurve(pk);
- }
+ curve = await withRpc(env, network, async (conn) => {
+ const sdk = new OnlinePumpSdk(conn);
+ let found;
+ if (sdk.fetchBuyState) {
+ const state = await sdk.fetchBuyState(pk, pk);
+ found = state.bondingCurve;
+ } else if (sdk.fetchBondingCurve) {
+ found = await sdk.fetchBondingCurve(pk);
+ }
+ if (!found) {
+ const sdk2 = new PumpSdk(conn);
+ if (sdk2.fetchBondingCurve) found = await sdk2.fetchBondingCurve(pk);
+ }
+ return found;
+ });
} catch (e) {
throw rpcError(-32004, `bonding curve unavailable: ${e?.message || 'unknown'}`);
}
@@ -106,8 +142,8 @@ async function handleGetBondingCurve({ mint, network = 'mainnet' }, env) {
}
async function handleGetTokenDetails({ mint, network = 'mainnet' }, env) {
- const { Connection, PublicKey } = await import('@solana/web3.js');
- const { MintLayout } = await import('@solana/spl-token');
+ const { PublicKey } = await import('@solana/web3.js');
+ const { MintLayout, getTokenMetadata, TOKEN_2022_PROGRAM_ID } = await import('@solana/spl-token');
let pk;
try {
@@ -116,29 +152,64 @@ async function handleGetTokenDetails({ mint, network = 'mainnet' }, env) {
throw rpcError(-32602, 'invalid mint');
}
- const conn = new Connection(getRpcUrl(env, network), 'confirmed');
- const info = await conn.getAccountInfo(pk);
- if (!info) throw rpcError(-32004, 'mint account not found');
- const mintAccount = MintLayout.decode(info.data);
-
const METADATA_PROGRAM = new PublicKey('metaqbxxUerdq28cj1RbAWkYQm3ybzjb6a8bt518x1s');
const [metadataPda] = PublicKey.findProgramAddressSync(
[Buffer.from('metadata'), METADATA_PROGRAM.toBuffer(), pk.toBuffer()],
METADATA_PROGRAM,
);
- let name = null;
- let symbol = null;
- let uri = null;
+
+ // Both reads share the endpoint that answered, so metadata never lands on a
+ // provider the mint read already failed over from.
+ let read;
try {
- const metaInfo = await conn.getAccountInfo(metadataPda);
+ read = await withRpc(env, network, async (conn) => {
+ const info = await conn.getAccountInfo(pk);
+ if (!info) throw rpcError(-32004, 'mint account not found');
+ // Token-2022 mints (what pump.fun launches today) carry name/symbol/uri
+ // in the mint's own TokenMetadata extension, not at the legacy Metaplex
+ // PDA, which for them does not exist at all. Read whichever applies.
+ const isToken2022 = info.owner?.equals?.(TOKEN_2022_PROGRAM_ID);
+ const extensionMetadata = isToken2022
+ ? await getTokenMetadata(conn, pk, 'confirmed', TOKEN_2022_PROGRAM_ID).catch(() => null)
+ : null;
+ return {
+ info,
+ extensionMetadata,
+ metaInfo: extensionMetadata
+ ? null
+ : await conn.getAccountInfo(metadataPda).catch(() => null),
+ };
+ });
+ } catch (e) {
+ // An RPC that is down, rate-limiting, or blocking this egress IP is an
+ // upstream-data failure, not a bug in this worker: report it with the same
+ // -32004 the sibling on-chain tools use rather than leaking a raw provider
+ // body through the generic -32603 catch-all.
+ if (e?.rpcCode) throw e;
+ throw rpcError(-32004, `mint account unavailable: ${e?.message || 'rpc error'}`);
+ }
+ const mintAccount = MintLayout.decode(read.info.data);
+
+ let name = read.extensionMetadata?.name?.trim() || null;
+ let symbol = read.extensionMetadata?.symbol?.trim() || null;
+ let uri = read.extensionMetadata?.uri?.trim() || null;
+ try {
+ const metaInfo = read.metaInfo;
if (metaInfo) {
+ // Metaplex Token Metadata v1: 1 key + 32 updateAuthority + 32 mint, then
+ // three borsh strings (name/symbol/uri), each a u32 byte length followed
+ // by that many bytes. Pre-1.3 accounts pad to the field maximum and
+ // report the padded length; 1.3+ accounts store the exact length. So the
+ // cursor must advance by the length ON THE WIRE, while the value we
+ // return is clamped to the field maximum.
const buf = Buffer.from(metaInfo.data);
let cursor = 1 + 32 + 32;
const readStr = (max) => {
- const len = Math.min(buf.readUInt32LE(cursor), max);
+ const len = buf.readUInt32LE(cursor);
cursor += 4;
- const slice = buf.slice(cursor, cursor + len);
- cursor += len;
+ const end = Math.min(cursor + len, buf.length);
+ const slice = buf.subarray(cursor, Math.min(cursor + max, end));
+ cursor = end;
return slice.toString('utf8').replace(/\0+$/g, '').trim();
};
name = readStr(32);
@@ -164,7 +235,7 @@ async function handleGetTokenDetails({ mint, network = 'mainnet' }, env) {
}
async function handleGetTokenHolders({ mint, limit = 10, network = 'mainnet' }, env) {
- const { Connection, PublicKey } = await import('@solana/web3.js');
+ const { PublicKey } = await import('@solana/web3.js');
let pk;
try {
@@ -173,10 +244,9 @@ async function handleGetTokenHolders({ mint, limit = 10, network = 'mainnet' },
throw rpcError(-32602, 'invalid mint');
}
- const conn = new Connection(getRpcUrl(env, network), 'confirmed');
let largest;
try {
- largest = await conn.getTokenLargestAccounts(pk);
+ largest = await withRpc(env, network, (conn) => conn.getTokenLargestAccounts(pk));
} catch (e) {
throw rpcError(-32004, `holders unavailable: ${e?.message || 'rpc error'}`);
}
diff --git a/workers/pump-fun-mcp/wrangler.toml b/workers/pump-fun-mcp/wrangler.toml
index 402adc09c..8126509f5 100644
--- a/workers/pump-fun-mcp/wrangler.toml
+++ b/workers/pump-fun-mcp/wrangler.toml
@@ -3,8 +3,12 @@ main = "worker.js"
compatibility_date = "2025-01-15"
compatibility_flags = ["nodejs_compat"]
-# Secrets — set with: wrangler secret put <NAME>
-# SOLANA_RPC_URL mainnet RPC (default: public endpoint)
-# SOLANA_RPC_URL_DEVNET devnet RPC (default: public endpoint)
-# PUMPFUN_BOT_URL upstream indexer MCP endpoint (optional)
-# PUMPFUN_BOT_TOKEN bearer token for indexer (optional)
+# All configuration is optional. Set with: npx wrangler@4 secret put <NAME>
+# (or --var NAME:VALUE for a local `wrangler dev` run). See README.md.
+#
+# SOLANA_RPC_URL primary mainnet RPC endpoint
+# SOLANA_RPC_FALLBACKS comma-separated mainnet failover endpoints
+# SOLANA_RPC_URL_DEVNET primary devnet RPC endpoint
+# SOLANA_RPC_FALLBACKS_DEVNET comma-separated devnet failover endpoints
+# PUMPFUN_BOT_URL upstream indexer MCP endpoint
+# PUMPFUN_BOT_TOKEN bearer token for the indexer