get_price
Retrieve the current price of any Solana token in SOL. Checks Jupiter first, then falls back to DexScreener for accuracy.
Instructions
Get the current price of any Solana token in SOL. Checks Jupiter first, falls back to DexScreener.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| mint | Yes | Solana token mint address |
Implementation Reference
- src/tools.js:261-271 (handler)The handler function for the 'get_price' tool. Calls fetchPrice(mint) and returns the result as JSON text, or a 'no price data' message if null.
async ({ mint }) => { try { const result = await fetchPrice(mint); if (!result.price) { return text(`No price data found for ${mint.slice(0, 8)}...`); } return text(JSON.stringify(result, null, 2)); } catch (err) { return error(err.message); } } - src/tools.js:250-253 (schema)Input schema for the 'get_price' tool: requires a 'mint' parameter validated by MINT_REGEX regex.
{ mint: z.string().regex(MINT_REGEX) .describe('Solana token mint address'), }, - src/tools.js:247-272 (registration)Registration of the 'get_price' tool via server.tool(), with description, input schema, and handler.
server.tool( 'get_price', 'Get the current price of any Solana token in SOL. Checks Jupiter first, falls back to DexScreener.', { mint: z.string().regex(MINT_REGEX) .describe('Solana token mint address'), }, { title: 'Get Price', readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false, }, async ({ mint }) => { try { const result = await fetchPrice(mint); if (!result.price) { return text(`No price data found for ${mint.slice(0, 8)}...`); } return text(JSON.stringify(result, null, 2)); } catch (err) { return error(err.message); } } ); - src/tools.js:9-35 (helper)The fetchPrice() helper function that queries Jupiter API first, then falls back to DexScreener API.
async function fetchPrice(mint) { try { const res = await fetch( `https://api.jup.ag/price/v2?ids=${encodeURIComponent(mint)}&vsToken=${SOL_MINT}`, { signal: AbortSignal.timeout(PRICE_TIMEOUT_MS) } ); if (res.ok) { const data = await res.json(); const p = data.data?.[mint]?.price; if (p) return { mint, price: parseFloat(p), source: 'jupiter' }; } } catch {} try { const res = await fetch( `https://api.dexscreener.com/latest/dex/tokens/${encodeURIComponent(mint)}`, { signal: AbortSignal.timeout(PRICE_TIMEOUT_MS) } ); if (res.ok) { const data = await res.json(); const pair = data.pairs?.find(p => p.chainId === 'solana' && p.quoteToken?.symbol === 'SOL'); if (pair?.priceNative) return { mint, price: parseFloat(pair.priceNative), source: 'dexscreener' }; const any = data.pairs?.[0]; if (any?.priceNative) return { mint, price: parseFloat(any.priceNative), source: 'dexscreener' }; } } catch {} return { mint, price: null, source: null }; } - src/tools.js:74-74 (helper)MINT_REGEX constant used for validating Solana mint addresses in the input schema.
const MINT_REGEX = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;