Skip to main content
Glama
mbarinov

OKX MCP Server

by mbarinov

get_portfolio

Read-onlyIdempotent

Retrieve a complete list of all assets in your OKX trading account to monitor holdings and analyze portfolio composition.

Instructions

Get a list of all assets in the account

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The default exported async function implementing the core logic of the 'get_portfolio' MCP tool. It invokes the OKX API client to fetch portfolio data and formats it as JSON text response, with error handling.
    export default async function get_portfolio({}: InferSchema<typeof schema>) {
      try {
        const portfolio = await okxApiClient.getPortfolio();
        return {
          content: [{ type: 'text', text: JSON.stringify(portfolio, null, 2) }],
        };
      } catch (error) {
        const message = error instanceof Error ? error.message : 'An unknown error occurred';
        return {
          content: [{ type: 'text', text: JSON.stringify({ error: message }, null, 2) }],
        };
      }
    }
  • Empty Zod schema indicating the tool takes no input parameters.
    export const schema = {};
  • Metadata export defining the tool's name, description, and annotations for registration in the MCP server.
    export const metadata = {
      name: 'get_portfolio',
      description: 'Get a list of all assets in the account',
      annotations: {
        title: 'Get Portfolio',
        readOnlyHint: true,
        destructiveHint: false,
        idempotentHint: true,
      },
    };
  • Supporting method in OkxApiClient class that fetches account balances from OKX API, converts non-USDT balances to USDT equivalent using ticker prices, and returns formatted portfolio data.
    async getPortfolio() {
      try {
        const response = await client.getBalance();
        const details = response[0].details;
        const portfolio = [];
    
        for (const item of details) {
          const ccy = item.ccy;
          let usdtValue = 0;
          if (ccy !== "USDT") {
            try {
              const tickerResponse = await client.getTicker({
                instId: `${ccy}-USDT`,
              });
              if (tickerResponse.length > 0) {
                usdtValue = parseFloat(tickerResponse[0].last);
              }
            } catch (error) {
              // ignore errors for tickers that don't exist
            }
          }
    
          portfolio.push({
            currency: ccy,
            totalBalance: parseFloat(item.eq),
            frozenBalance: parseFloat(item.frozenBal),
            usdtValue:
              ccy === "USDT"
                ? parseFloat(item.eq)
                : parseFloat(item.eq) * usdtValue,
          });
        }
        return portfolio;
      } catch (error) {
        console.error("Error fetching portfolio:", error);
        throw error;
      }
    }
Behavior4/5

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

Annotations already declare readOnlyHint=true, idempotentHint=true, and destructiveHint=false, covering safety and idempotency. The description adds value by specifying the scope ('all assets') and that it returns a list, which isn't covered by annotations. No contradictions exist, and the description provides useful behavioral context beyond annotations.

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 that front-loads the core purpose with zero wasted words. It directly communicates the tool's function without unnecessary elaboration, making it easy to parse and understand immediately.

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

Completeness3/5

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

Given the tool's simplicity (0 parameters, no output schema) and rich annotations, the description is adequate but has gaps. It doesn't explain the return format (e.g., structure of the asset list) or potential limitations (e.g., pagination, real-time data), which could be important for an agent despite the annotations covering safety aspects.

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?

With 0 parameters and 100% schema description coverage, the schema fully documents the lack of inputs. The description adds semantic meaning by clarifying what is retrieved ('all assets in the account'), which compensates for the absence of parameters. This goes beyond the schema's structural information.

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 resource ('list of all assets in the account'), making the purpose immediately understandable. It doesn't explicitly differentiate from sibling tools like get_positions, but the scope ('all assets') provides some implicit distinction. This is clear but lacks explicit sibling differentiation.

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_positions or get_account_summary. It doesn't mention prerequisites, context, or exclusions. The agent must infer usage from the tool name and description alone, which is insufficient for optimal tool selection.

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/mbarinov/okx-mcp'

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