Skip to main content
Glama
mbarinov

OKX MCP Server

by mbarinov

get_positions

Read-onlyIdempotent

Retrieve all derivative positions from OKX trading accounts to monitor portfolio exposure and track trading performance.

Instructions

Get all derivative positions

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main handler function for the 'get_positions' tool. It fetches positions from the OKX API client and returns them as formatted JSON, with error handling.
    export default async function get_positions({}: InferSchema<typeof schema>) {
      try {
        const positions = await okxApiClient.getPositions();
        return {
          content: [{ type: 'text', text: JSON.stringify(positions, 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) }],
        };
      }
    }
  • The input schema for the 'get_positions' tool, which is empty indicating no parameters are required.
    export const schema = {};
  • Metadata for registering the 'get_positions' tool, including name, description, and annotations for UI hints.
    export const metadata = {
      name: 'get_positions',
      description: 'Get all derivative positions',
      annotations: {
        title: 'Get Positions',
        readOnlyHint: true,
        destructiveHint: false,
        idempotentHint: true,
      },
    };
  • Helper method in OkxApiClient that retrieves positions from the OKX API and maps the response to a simplified format.
    async getPositions() {
      try {
        const response = await client.getPositions();
        return response.map((position) => ({
          symbol: position.instId,
          size: parseFloat(position.pos),
          entryPrice: parseFloat(position.avgPx),
          unrealizedPnl: parseFloat(position.upl),
          margin: parseFloat(position.margin),
        }));
      } catch (error) {
        console.error("Error fetching positions:", error);
        throw error;
      }
    }
Behavior3/5

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

Annotations already indicate read-only, idempotent, and non-destructive behavior, so the description doesn't need to repeat this. It adds no additional behavioral context (e.g., rate limits, auth needs, or return format), but doesn't contradict annotations, resulting in a baseline score for minimal added value.

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 directly states the tool's function without any wasted words. It's appropriately sized and front-loaded, making it easy to parse quickly.

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 minimal. It covers the basic purpose but lacks details on output format or when to use it, leaving some contextual gaps for the agent.

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 implies no filtering or arguments are needed ('all derivative positions'), which aligns with the schema, earning a high baseline score for consistency.

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 ('all derivative positions'), making the purpose understandable. However, it doesn't differentiate from sibling tools like 'get_portfolio' or 'get_account_summary', which might also retrieve position-related data, so it doesn't fully distinguish its specific scope.

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. It doesn't mention context, prerequisites, or comparisons to sibling tools like 'get_portfolio', leaving the agent without usage direction.

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