Skip to main content
Glama
kukapay

hyperliquid-info-mcp

get_user_state

Retrieve user trading positions, margin details, and withdrawable balance from Hyperliquid to monitor account status and manage risk.

Instructions

Query user state including trading positions, margin, and withdrawable balance.

Parameters:
    account_address (str): The Hyperliquid account address (e.g., '0xcd5051944f780a621ee62e39e493c489668acf4d').
    check_spot (bool, optional): If True, queries spot user state; otherwise, queries perpetuals state. Defaults to False.
    ctx (Context, optional): The MCP context object for accessing server state.

Returns:
    str: A JSON string containing the user state, including a list of positions (with symbol, size, entry_price,
        current_price, unrealized_pnl), margin_summary, and withdrawable balance. Returns a JSON string with an
        error message if the query fails.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
account_addressYes
check_spotNo

Implementation Reference

  • main.py:23-42 (handler)
    The handler function implementing the 'get_user_state' tool logic. It conditionally queries spot or perpetuals user state via the Hyperliquid Info API, serializes to JSON, and handles exceptions.
    @mcp.tool()
    async def get_user_state(account_address: str, check_spot: bool=False, ctx: Context=None) -> str:
        """
        Query user state including trading positions, margin, and withdrawable balance.
    
        Parameters:
            account_address (str): The Hyperliquid account address (e.g., '0xcd5051944f780a621ee62e39e493c489668acf4d').
            check_spot (bool, optional): If True, queries spot user state; otherwise, queries perpetuals state. Defaults to False.
            ctx (Context, optional): The MCP context object for accessing server state.
    
        Returns:
            str: A JSON string containing the user state, including a list of positions (with symbol, size, entry_price,
                current_price, unrealized_pnl), margin_summary, and withdrawable balance. Returns a JSON string with an
                error message if the query fails.
        """
        try:
            user_state = info.spot_user_state(account_address) if check_spot else info.user_state(account_address)
            return json.dumps(user_state)
        except Exception as e:
            return json.dumps({"error": f"Failed to fetch user state: {str(e)}"})
Behavior4/5

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

With no annotations provided, the description carries the full burden. It discloses that this is a query operation (non-destructive), describes the return format (JSON string with positions, margin, etc.), and mentions error handling ('Returns a JSON string with an error message if the query fails'). It lacks details on rate limits, authentication needs, or data freshness, but covers core behavioral aspects adequately.

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

Conciseness4/5

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

The description is appropriately sized and front-loaded: the first sentence states the purpose clearly, followed by structured sections for parameters and returns. Every sentence adds value, though the 'ctx' parameter explanation could be more specific. No redundant information is present.

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?

Given the complexity (querying financial state with 2 parameters), no annotations, and no output schema, the description is fairly complete. It explains the tool's purpose, parameters, and return format in detail. It could improve by specifying data sources or update frequency, but it covers the essentials for an AI agent to use the tool effectively.

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?

Schema description coverage is 0%, so the description must compensate. It adds meaningful semantics: 'account_address' is explained as 'The Hyperliquid account address' with an example, and 'check_spot' clarifies it queries spot vs. perpetuals state with a default. The 'ctx' parameter is noted as optional for server state access, though its purpose is vague. This compensates well for the lack of schema descriptions.

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 tool's purpose: 'Query user state including trading positions, margin, and withdrawable balance.' It specifies the verb 'query' and the resource 'user state' with key components listed. However, it doesn't explicitly differentiate from siblings like 'get_user_fees' or 'get_user_trade_history' beyond the general scope of user state.

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

Usage Guidelines3/5

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

The description implies usage through the parameter details (e.g., 'check_spot' for spot vs. perpetuals state), but it doesn't provide explicit guidance on when to use this tool versus alternatives like 'get_user_open_orders' or 'get_user_trade_history'. No when-not-to-use or prerequisite information is included.

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/kukapay/hyperliquid-info-mcp'

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