Skip to main content
Glama
mektigboy

Hyperliquid MCP Server

by mektigboy

get_l2_book

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

Instructions

Get the L2 book of a token on Hyperliquid

Input Schema

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

Implementation Reference

  • The main handler function that validates the input arguments using l2BookSchema and fetches the L2 book data from the Hyperliquid client, returning it as JSON text.
    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, }; }
  • Zod schema used for input validation in the getL2Book handler, transforming 'symbol' to 'coin' and handling optional nSigFigs and mantissa parameters.
    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, }));
  • MCP Tool object definition for get_l2_book, including the JSON inputSchema advertised to clients.
    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)
    Registration of the get_l2_book tool in the switch statement of the CallToolRequest handler, dispatching to the getL2Book function.
    case "get_l2_book": { return await getL2Book(hyperliquidClient, args); }
  • src/index.ts:75-80 (registration)
    Registration in the ListToolsRequest handler, including L2_BOOK_TOOL in the list of available tools.
    server.setRequestHandler(ListToolsRequestSchema, async () => { console.error("Received ListToolsRequest"); return { tools: [ALL_MIDS_TOOL, CANDLE_SNAPSHOT_TOOL, L2_BOOK_TOOL], }; });

Other Tools

Related 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