Skip to main content
Glama

bsv_getPrice

Fetch the current Bitcoin SV (BSV) price in USD to calculate transaction values, monitor market conditions, or convert between BSV and fiat currencies using real-time data from a reliable exchange API.

Instructions

Retrieves the current price of Bitcoin SV (BSV) in USD from a reliable exchange API. This tool provides real-time market data that can be used for calculating transaction values, monitoring market conditions, or converting between BSV and fiat currencies.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
argsNoNo parameters required - simply returns the current BSV price in USD

Implementation Reference

  • The handler function for the 'bsv_getPrice' tool. It calls getBsvPriceWithCache to fetch the price, formats it, and returns it as text content, handling errors appropriately.
    async () => { try { const price = await getBsvPriceWithCache(); return { content: [ { type: "text", text: `Current BSV price: $${price.toFixed(2)} USD`, }, ], }; } catch (err) { return { content: [{ type: "text", text: "Error fetching BSV price." }], isError: true, }; } }, );
  • Zod schema for tool input arguments. Defines an optional empty object, indicating no parameters are required.
    args: z .object({}) .optional() .describe( "No parameters required - simply returns the current BSV price in USD", ),
  • The registration function 'registerGetPriceTool' that registers the 'bsv_getPrice' tool on the MCP server, including name, description, schema, and handler.
    export function registerGetPriceTool(server: McpServer): void { server.tool( "bsv_getPrice", "Retrieves the current price of Bitcoin SV (BSV) in USD from a reliable exchange API. This tool provides real-time market data that can be used for calculating transaction values, monitoring market conditions, or converting between BSV and fiat currencies.", { args: z .object({}) .optional() .describe( "No parameters required - simply returns the current BSV price in USD", ), }, async () => { try { const price = await getBsvPriceWithCache(); return { content: [ { type: "text", text: `Current BSV price: $${price.toFixed(2)} USD`, }, ], }; } catch (err) { return { content: [{ type: "text", text: "Error fetching BSV price." }], isError: true, }; } }, ); }
  • Helper function that fetches the BSV price from Whatsonchain API with a 5-minute caching mechanism to avoid excessive API calls.
    async function getBsvPriceWithCache(): Promise<number> { // Return cached price if it's still valid if ( cachedPrice && Date.now() - cachedPrice.timestamp < PRICE_CACHE_DURATION ) { return cachedPrice.value; } // If no valid cache, fetch new price const res = await fetch( "https://api.whatsonchain.com/v1/bsv/main/exchangerate", ); if (!res.ok) throw new Error("Failed to fetch price"); const data = (await res.json()) as { currency: string; rate: string; time: number; }; const price = Number(data.rate); if (Number.isNaN(price) || price <= 0) throw new Error("Invalid price received"); // Update cache cachedPrice = { value: price, timestamp: Date.now(), }; return price; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/b-open-io/bsv-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server