Skip to main content
Glama

bitcoin_price

Retrieve current Bitcoin price data to monitor cryptocurrency market values and track real-time price changes for investment decisions.

Instructions

Get realtime bitcoin price

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The toolCall method, which is the core handler executing the bitcoin_price tool logic: fetches Bitcoin price data from Coincap API and formats response.
    toolCall = async () => {
      try {
        const response = await fetch(BITCOIN_PRICE_URL);
        if (!response.ok) {
          throw new Error("Error fetching coincap data");
        }
    
        const body = await response.json();
    
        return {
          content: [{ type: "text", text: `${JSON.stringify(body.data)}` }],
        };
      } catch (error) {
        return {
          content: [
            { type: "error", text: JSON.stringify((error as any).message) },
          ],
        };
      }
    };
  • Tool definition schema specifying name, description, and empty input schema (no parameters).
    toolDefinition: Tool = {
      name: this.name,
      description: "Get realtime bitcoin price",
      inputSchema: {
        type: "object",
      },
    };
  • loadTools dynamically scans src/tools for tool JS files, imports and instantiates them (including BitcoinPriceTool), and createToolsMap indexes by name for dispatch.
    export async function loadTools(): Promise<BaseTool[]> {
      try {
        const toolsPath = await findToolsPath();
        const files = await fs.readdir(toolsPath);
        const tools: BaseTool[] = [];
    
        for (const file of files) {
          if (!isToolFile(file)) {
            continue;
          }
    
          try {
            const modulePath = `file://${join(toolsPath, file)}`;
            const { default: ToolClass } = await import(modulePath);
    
            if (!ToolClass) {
              continue;
            }
    
            const tool = new ToolClass();
    
            if (
              tool.name &&
              tool.toolDefinition &&
              typeof tool.toolCall === "function"
            ) {
              tools.push(tool);
            }
          } catch (error) {
            console.error(`Error loading tool from ${file}:`, error);
          }
        }
    
        return tools;
      } catch (error) {
        console.error(`Failed to load tools:`, error);
        return [];
      }
    }
    
    export function createToolsMap(tools: BaseTool[]): Map<string, BaseTool> {
      return new Map(tools.map((tool) => [tool.name, tool]));
    }
  • src/index.ts:40-54 (registration)
    MCP server request handler for CallTool that retrieves the tool instance from map by name and invokes its toolCall method.
    server.setRequestHandler(CallToolRequestSchema, async (request) => {
      if (!toolsMap) {
        throw new Error("Tools not initialized");
      }
    
      const tool = toolsMap.get(request.params.name);
      if (!tool) {
        throw new Error(
          `Unknown tool: ${request.params.name}. Available tools: ${Array.from(
            toolsMap.keys()
          ).join(", ")}`
        );
      }
      return tool.toolCall(request);
    });
  • API URL constant used in the bitcoin_price tool handler to fetch Bitcoin data.
    export const BITCOIN_PRICE_URL = "https://api.coincap.io/v2/assets/bitcoin";
Install Server

Other Tools

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/QuantGeekDev/coincap-mcp'

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