Skip to main content
Glama
mektigboy

Hyperliquid MCP Server

by mektigboy

get_l2_book

Retrieve the Level 2 order book for a specific token on Hyperliquid to analyze market depth and liquidity.

Instructions

Get the L2 book of a token on Hyperliquid

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
symbolNoThe symbol of the token to get the price of
requiredNo

Implementation Reference

  • The handler function that executes the get_l2_book tool: parses args with l2BookSchema, fetches L2 book data from Hyperliquid client, stringifies to JSON, and returns as MCP content block.
    export async function getL2Book(
      hyperliquidClient: PublicClient,
      args: unknown
    ) {
      const validatedArgs = l2BookSchema.parse(args);
    
      let l2Book = await hyperliquidClient.l2Book(validatedArgs);
      return {
        content: [{ type: "text", text: JSON.stringify(l2Book) }],
        isError: false,
      };
    }
  • Defines the MCP Tool schema for get_l2_book, including name, description, and inputSchema requiring a 'symbol' string.
    export const L2_BOOK_TOOL: Tool = {
      name: "get_l2_book",
      description: "Get the L2 book of a token on Hyperliquid",
      inputSchema: {
        type: "object",
        properties: {
          symbol: {
            type: "string",
            description: "The symbol of the token to get the price of",
          },
          required: ["symbol"],
        },
      },
    };
  • src/index.ts:43-45 (registration)
    Registers the getL2Book handler for the 'get_l2_book' tool name in the CallToolRequest switch statement.
    case "get_l2_book": {
      return await getL2Book(hyperliquidClient, args);
    }
  • Zod schema used in the handler for input validation and transformation (symbol to coin, optional nSigFigs and mantissa).
    export const l2BookSchema = z
      .object({
        symbol: z.string(),
        nSigFigs: z
          .union([z.literal(2), z.literal(3), z.literal(4), z.literal(5), z.null()])
          .optional(),
        mantissa: z.union([z.literal(2), z.literal(5), z.null()]).optional(),
      })
      .strict()
      .transform((data) => ({
        coin: data.symbol,
        nSigFigs: data.nSigFigs,
        mantissa: data.mantissa,
      }));
  • src/index.ts:78-79 (registration)
    The get_l2_book tool (as L2_BOOK_TOOL) is registered/returned in the ListToolsRequest handler.
      tools: [ALL_MIDS_TOOL, CANDLE_SNAPSHOT_TOOL, L2_BOOK_TOOL],
    };
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool retrieves data ('Get'), implying a read-only operation, but doesn't specify whether it's real-time or historical, rate limits, authentication needs, or what an L2 book entails (e.g., bid/ask levels). This leaves significant gaps for a tool with no annotation coverage.

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 a single, efficient sentence with zero wasted words. It front-loads the core purpose and includes essential context ('on Hyperliquid'), making it highly concise and well-structured for quick understanding.

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

Completeness2/5

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

Given the tool's complexity (financial data retrieval), lack of annotations, no output schema, and incomplete parameter documentation, the description is insufficient. It doesn't explain what an L2 book contains, the response format, or behavioral traits like latency or data freshness, leaving the agent with critical gaps for effective use.

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

Parameters3/5

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

Schema description coverage is 50% (one parameter documented, one not). The description adds no parameter details beyond the schema, which already documents 'symbol' as 'The symbol of the token to get the price of'. Since the schema handles half the parameters adequately, the baseline score of 3 applies, as the description doesn't compensate for the undocumented parameter.

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

Purpose4/5

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

The description clearly states the action ('Get') and the resource ('L2 book of a token'), specifying the domain ('on Hyperliquid'). It distinguishes from siblings by focusing on order book data rather than mid prices or candle snapshots. However, it doesn't explicitly differentiate from potential similar tools beyond the given siblings.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives like get_all_mids or get_candle_snapshot. It lacks context about use cases, prerequisites, or exclusions, leaving the agent to infer usage based solely on tool names.

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/mektigboy/server-hyperliquid'

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