Skip to main content
Glama
CryptoQuantOfficial

CryptoQuant MCP Server

Official

query_data

Retrieve raw cryptocurrency on-chain data from CryptoQuant API. Use endpoint paths discovered earlier, with optional parameters like window, limit, date range, exchange, and symbol.

Instructions

Query raw data from CryptoQuant API. Workflow: initialize() → discover_endpoints(asset, category) → query_data(endpoint, params). Use endpoint paths and parameter values from discover_endpoints response.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
endpointYesAPI endpoint path (e.g., /v1/btc/market-data/mvrv)
paramsNoQuery parameters

Implementation Reference

  • The main handler function for the query_data tool. Validates auth, endpoint, params, and plan limits, then fetches data from the CryptoQuant API and returns the response.
    server.tool(
      "query_data",
      "Query raw data from CryptoQuant API. Workflow: initialize() → discover_endpoints(asset, category) → query_data(endpoint, params). Use endpoint paths and parameter values from discover_endpoints response.",
      queryDataSchema,
      async (params: QueryDataParams) => {
        logger.debug("[query_data] called with endpoint:", params.endpoint);
        logger.debug("[query_data] params:", params.params);
    
        const authError = requireAuth();
        if (authError) return authError;
    
        const state = getPermissionState();
        const endpoint = getEndpointByPath(params.endpoint);
        if (!endpoint) {
          return errorResponse(`Unknown endpoint: ${params.endpoint}`, {
            action: "Use discover_endpoints() to find valid endpoints",
          });
        }
    
        const queryParams = params.params || {};
        const validation = validateEndpointParams(endpoint, queryParams);
        if (!validation.valid) {
          const paramOptions = getParameterOptions(params.endpoint);
          return errorResponse("Invalid parameters", {
            details: validation.errors,
            endpoint: params.endpoint,
            available_parameters: paramOptions?.parameters,
            required_parameters: paramOptions?.required,
          });
        }
    
        const planState = getPlanLimitsState();
    
        if (planState.loaded) {
          if (!hasEndpointAccess(params.endpoint)) {
            const requiredPlan = getRequiredPlan(params.endpoint);
            return errorResponse("Endpoint not accessible on your plan", {
              your_plan: planState.plan,
              required_plan: requiredPlan,
              upgrade_url: "https://cryptoquant.com/pricing",
              suggestion: `Upgrade to ${capitalizeFirst(requiredPlan)} plan for access to this endpoint`,
            });
          }
    
          const fromDate = queryParams.from as string | undefined;
          const windowParam = queryParams.window as string | undefined;
          if (fromDate) {
            const dateValidation = validateDateRange(
              params.endpoint,
              fromDate,
              windowParam,
            );
            if (!dateValidation.valid) {
              return errorResponse(
                dateValidation.error || "Date range exceeds plan limit",
                {
                  your_plan: planState.plan,
                  ...(dateValidation.limit && { limit: dateValidation.limit }),
                  ...(dateValidation.earliest_allowed && {
                    earliest_allowed: dateValidation.earliest_allowed,
                  }),
                  upgrade_url: "https://cryptoquant.com/pricing",
                  suggestion:
                    "Upgrade to Premium for unlimited historical data access",
                },
              );
            }
          }
        }
    
        const apiKey = state.api_key;
        if (!apiKey) {
          return errorResponse("API key not available", {
            action: "Re-initialize with your API key",
          });
        }
    
        try {
          const urlParams = new URLSearchParams();
          for (const [key, value] of Object.entries(queryParams)) {
            if (value !== undefined && value !== null) {
              urlParams.set(key, String(value));
            }
          }
          if (!urlParams.has("limit")) {
            urlParams.set("limit", "100");
          }
          urlParams.set("source", "mcp");
    
          const apiUrl = getApiBaseUrl();
          const fullUrl = `${apiUrl}${params.endpoint}?${urlParams.toString()}`;
    
          logger.debug("[query_data] API request:", fullUrl);
    
          const response = await fetch(fullUrl, {
            method: "GET",
            headers: { Authorization: `Bearer ${apiKey}` },
          });
    
          logger.debug("[query_data] API response status:", response.status, response.statusText);
    
          if (!response.ok) {
            const errorBody = await response.text();
            return errorResponse(
              `API request failed: ${response.status} ${response.statusText}`,
              {
                details: errorBody,
                endpoint: params.endpoint,
              },
            );
          }
    
          let data: Record<string, unknown>;
          try {
            data = (await response.json()) as Record<string, unknown>;
          } catch {
            return errorResponse("Failed to parse API response", {
              endpoint: params.endpoint,
            });
          }
    
          const rateLimitInfo = buildRateLimitInfo(response);
    
          return jsonResponse({
            success: true,
            endpoint: params.endpoint,
            params: queryParams,
            ...(rateLimitInfo && { rate_limit: rateLimitInfo }),
            ...data,
          });
        } catch (error) {
          return errorResponse(`Network error: ${error}`, {
            endpoint: params.endpoint,
          });
        }
      },
    );
  • Zod schema defining input parameters for query_data: endpoint (required string) and optional params object with window, limit, from, to, exchange, symbol, market, token, miner, type.
    const queryDataSchema = {
      endpoint: z
        .string()
        .describe("API endpoint path (e.g., /v1/btc/market-data/mvrv)"),
      params: z
        .object({
          window: z
            .string()
            .optional()
            .describe("Time window granularity (hour, day, block, etc.)"),
          limit: z
            .number()
            .optional()
            .describe("Number of data points to return (max 1000)"),
          from: z.string().optional().describe("Start date (ISO 8601 format)"),
          to: z.string().optional().describe("End date (ISO 8601 format)"),
          exchange: z
            .string()
            .optional()
            .describe("Exchange filter (for exchange-specific data)"),
          symbol: z
            .string()
            .optional()
            .describe("Trading symbol (e.g., btc_usd, btc_usdt)"),
          market: z.string().optional().describe("Market type (spot, perpetual)"),
          token: z
            .string()
            .optional()
            .describe("Token filter (for alt/erc20 data)"),
          miner: z.string().optional().describe("Miner filter (for miner data)"),
          type: z
            .string()
            .optional()
            .describe("Entity type filter (e.g., exchange, entity, miner, bank)"),
        })
        .optional()
        .describe("Query parameters"),
    };
  • Registration of the query_data tool on the MCP server via server.tool() within registerCoreTools().
    server.tool(
      "query_data",
      "Query raw data from CryptoQuant API. Workflow: initialize() → discover_endpoints(asset, category) → query_data(endpoint, params). Use endpoint paths and parameter values from discover_endpoints response.",
      queryDataSchema,
      async (params: QueryDataParams) => {
        logger.debug("[query_data] called with endpoint:", params.endpoint);
        logger.debug("[query_data] params:", params.params);
    
        const authError = requireAuth();
        if (authError) return authError;
    
        const state = getPermissionState();
        const endpoint = getEndpointByPath(params.endpoint);
        if (!endpoint) {
          return errorResponse(`Unknown endpoint: ${params.endpoint}`, {
            action: "Use discover_endpoints() to find valid endpoints",
          });
        }
    
        const queryParams = params.params || {};
        const validation = validateEndpointParams(endpoint, queryParams);
        if (!validation.valid) {
          const paramOptions = getParameterOptions(params.endpoint);
          return errorResponse("Invalid parameters", {
            details: validation.errors,
            endpoint: params.endpoint,
            available_parameters: paramOptions?.parameters,
            required_parameters: paramOptions?.required,
          });
        }
    
        const planState = getPlanLimitsState();
    
        if (planState.loaded) {
          if (!hasEndpointAccess(params.endpoint)) {
            const requiredPlan = getRequiredPlan(params.endpoint);
            return errorResponse("Endpoint not accessible on your plan", {
              your_plan: planState.plan,
              required_plan: requiredPlan,
              upgrade_url: "https://cryptoquant.com/pricing",
              suggestion: `Upgrade to ${capitalizeFirst(requiredPlan)} plan for access to this endpoint`,
            });
          }
    
          const fromDate = queryParams.from as string | undefined;
          const windowParam = queryParams.window as string | undefined;
          if (fromDate) {
            const dateValidation = validateDateRange(
              params.endpoint,
              fromDate,
              windowParam,
            );
            if (!dateValidation.valid) {
              return errorResponse(
                dateValidation.error || "Date range exceeds plan limit",
                {
                  your_plan: planState.plan,
                  ...(dateValidation.limit && { limit: dateValidation.limit }),
                  ...(dateValidation.earliest_allowed && {
                    earliest_allowed: dateValidation.earliest_allowed,
                  }),
                  upgrade_url: "https://cryptoquant.com/pricing",
                  suggestion:
                    "Upgrade to Premium for unlimited historical data access",
                },
              );
            }
          }
        }
    
        const apiKey = state.api_key;
        if (!apiKey) {
          return errorResponse("API key not available", {
            action: "Re-initialize with your API key",
          });
        }
    
        try {
          const urlParams = new URLSearchParams();
          for (const [key, value] of Object.entries(queryParams)) {
            if (value !== undefined && value !== null) {
              urlParams.set(key, String(value));
            }
          }
          if (!urlParams.has("limit")) {
            urlParams.set("limit", "100");
          }
          urlParams.set("source", "mcp");
    
          const apiUrl = getApiBaseUrl();
          const fullUrl = `${apiUrl}${params.endpoint}?${urlParams.toString()}`;
    
          logger.debug("[query_data] API request:", fullUrl);
    
          const response = await fetch(fullUrl, {
            method: "GET",
            headers: { Authorization: `Bearer ${apiKey}` },
          });
    
          logger.debug("[query_data] API response status:", response.status, response.statusText);
    
          if (!response.ok) {
            const errorBody = await response.text();
            return errorResponse(
              `API request failed: ${response.status} ${response.statusText}`,
              {
                details: errorBody,
                endpoint: params.endpoint,
              },
            );
          }
    
          let data: Record<string, unknown>;
          try {
            data = (await response.json()) as Record<string, unknown>;
          } catch {
            return errorResponse("Failed to parse API response", {
              endpoint: params.endpoint,
            });
          }
    
          const rateLimitInfo = buildRateLimitInfo(response);
    
          return jsonResponse({
            success: true,
            endpoint: params.endpoint,
            params: queryParams,
            ...(rateLimitInfo && { rate_limit: rateLimitInfo }),
            ...data,
          });
        } catch (error) {
          return errorResponse(`Network error: ${error}`, {
            endpoint: params.endpoint,
          });
        }
      },
    );
  • Helper function that builds an example query_data() call string for a given endpoint, used to display usage examples.
    function buildExampleQuery(endpoint: ParsedEndpoint): string {
      const params: string[] = [];
    
      for (const required of endpoint.required_parameters) {
        const values = endpoint.parameters[required];
        if (values && values.length > 0) {
          params.push(`${required}=${values[0]}`);
        }
      }
    
      if (
        endpoint.parameters.window &&
        !endpoint.required_parameters.includes("window")
      ) {
        params.push(`window=${endpoint.parameters.window[0]}`);
      }
    
      params.push("limit=100");
    
      const paramStr = params
        .map((p) => {
          const [key, val] = p.split("=");
          return `"${key}": "${val}"`;
        })
        .join(", ");
    
      return `query_data(endpoint="${endpoint.path}", params={${paramStr}})`;
    }
  • src/index.ts:157-157 (registration)
    Top-level registration call in main() that registers all core tools including query_data on the MCP server.
    registerCoreTools(server);
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, and the description does not disclose behavioral traits such as rate limits, authentication requirements, or read-only safety. The agent needs more insight into side effects or constraints.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is very concise with two sentences, front-loading the purpose and then the workflow. Every sentence earns its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description provides the necessary workflow context and schema covers parameters, but it lacks any mention of return format or output behavior, which would help completeness given no output schema.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Though schema coverage is 100%, the description adds value by instructing the agent to use values from discover_endpoints response, which helps in correctly populating endpoint and params parameters.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool queries raw data from CryptoQuant API and provides a specific workflow (initialize → discover_endpoints → query_data), distinguishing it from siblings like discover_endpoints or describe_metric.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description gives explicit workflow instructions and tells the agent to use endpoint paths and parameter values from discover_endpoints response, providing clear context for when to use this tool.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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/CryptoQuantOfficial/cryptoquant-mcp'

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