read.asset.prices
Fetch current USD prices for single or multiple asset addresses. Pass addresses as comma-separated string to get a price map keyed by each address.
Instructions
Get USD prices for one or more asset addresses. Pass a single address or comma-separated addresses. Returns a price map keyed by address.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| asset_addresses | Yes | Single address or comma-separated addresses for price lookup | |
| chain_id | No | Chain ID: 8453 (Base), 130 (Unichain), or 10 (Optimism) |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| prices | Yes |
Implementation Reference
- src/tools/read/assets.ts:66-113 (handler)The core handler function for the 'read.asset.prices' tool. Splits the comma-separated asset_addresses input, calls api.getPrice (single) or api.getPrices (multi), wraps the result into a {prices: {...}} structure, and returns it as text and structured content. On error, returns an isError response.
server.registerTool( "read.asset.prices", { annotations: { title: "Get Asset Prices", readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true, }, description: "Get USD prices for one or more asset addresses. Pass a single address or comma-separated addresses. Returns a price map keyed by address.", inputSchema: { asset_addresses: z .string() .describe("Single address or comma-separated addresses for price lookup"), chain_id: z.number().default(8453).describe(CHAIN_ID_DESCRIPTION), }, outputSchema: AssetPricesOutput, }, async ({ asset_addresses, chain_id }) => { try { const addresses = asset_addresses.split(",").map((a) => a.trim()); const result = addresses.length === 1 ? await api.getPrice(chain_id, addresses[0]) : await api.getPrices(chain_id, addresses); const wrapped = typeof result === "number" ? { prices: { [addresses[0]]: result } } : { prices: result as Record<string, number> }; return { content: [{ type: "text" as const, text: JSON.stringify(wrapped, null, 2) }], structuredContent: wrapped, }; } catch (err) { return { content: [ { type: "text" as const, text: `Error: ${err instanceof Error ? err.message : String(err)}`, }, ], isError: true, }; } }, ); - src/tools/output-schemas.ts:114-116 (schema)Output schema for the tool: AssetPricesOutput is a Zod object with a single field 'prices' which is a Record<string, number> mapping asset addresses to their USD prices.
export const AssetPricesOutput = z.object({ prices: z.record(z.number()), }); - src/tools/read/assets.ts:66-85 (schema)Tool registration metadata for 'read.asset.prices' including annotations (title: 'Get Asset Prices', readOnlyHint, idempotentHint), description, input schema (asset_addresses: string, chain_id: number with default 8453), and output schema (AssetPricesOutput).
server.registerTool( "read.asset.prices", { annotations: { title: "Get Asset Prices", readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true, }, description: "Get USD prices for one or more asset addresses. Pass a single address or comma-separated addresses. Returns a price map keyed by address.", inputSchema: { asset_addresses: z .string() .describe("Single address or comma-separated addresses for price lookup"), chain_id: z.number().default(8453).describe(CHAIN_ID_DESCRIPTION), }, outputSchema: AssetPricesOutput, }, - src/clients/api.ts:130-132 (helper)API client method getPrice() - fetches a single asset price via GET /assets/price with chain_id and asset params.
async getPrice(chainId: number, asset: string) { return this.get("/assets/price", { chain_id: chainId, asset }); } - src/clients/api.ts:134-146 (helper)API client method getPrices() - fetches multiple asset prices via GET /assets/prices with chain_id and multiple 'assets' query params. Returns a Record<string, number> mapping addresses to USD prices.
async getPrices(chainId: number, assets: string[]) { const url = new URL(`${this.baseUrl}${API_PREFIX}/assets/prices`); url.searchParams.set("chain_id", String(chainId)); for (const a of assets) { url.searchParams.append("assets", a); } const resp = await fetch(url.toString(), { headers: DEFAULT_HEADERS, signal: AbortSignal.timeout(this.timeout), }); if (!resp.ok) await this.throwApiError(resp, "/assets/prices"); return resp.json() as Promise<Record<string, number>>; }