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], };

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