Skip to main content
Glama
esshka

OKX MCP Server

by esshka

get_price

Retrieve current cryptocurrency prices from OKX exchange for any trading instrument to monitor market values and inform trading decisions.

Instructions

Get latest price for an OKX instrument

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
instrumentYesInstrument ID (e.g. BTC-USDT)

Implementation Reference

  • The main execution logic for the 'get_price' tool. It queries the OKX /market/ticker API, handles errors, extracts the ticker data, and returns a formatted JSON response with instrument details, prices, and timestamp.
    if (request.params.name === 'get_price') {
      console.error(`[API] Fetching price for instrument: ${args.instrument}`);
      const response = await this.axiosInstance.get<OKXTickerResponse>(
        '/market/ticker',
        {
          params: { instId: args.instrument },
        }
      );
    
      if (response.data.code !== '0') {
        throw new Error(`OKX API error: ${response.data.msg}`);
      }
    
      if (!response.data.data || response.data.data.length === 0) {
        throw new Error('No data returned from OKX API');
      }
    
      const ticker = response.data.data[0];
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify({
              instrument: ticker.instId,
              lastPrice: ticker.last,
              bid: ticker.bidPx,
              ask: ticker.askPx,
              high24h: ticker.high24h,
              low24h: ticker.low24h,
              volume24h: ticker.vol24h,
              timestamp: new Date(parseInt(ticker.ts)).toISOString(),
            }, null, 2),
          },
        ],
      };
    } else {
  • src/index.ts:84-97 (registration)
    Registers the 'get_price' tool in the MCP listTools handler, specifying its name, description, and input schema requiring an 'instrument' parameter.
    {
      name: 'get_price',
      description: 'Get latest price for an OKX instrument',
      inputSchema: {
        type: 'object',
        properties: {
          instrument: {
            type: 'string',
            description: 'Instrument ID (e.g. BTC-USDT)',
          },
        },
        required: ['instrument'],
      },
    },
  • Type definition for the OKX ticker API response, providing type safety for the data parsed in the get_price handler.
    interface OKXTickerResponse {
      code: string;
      msg: string;
      data: Array<{
        instId: string;
        last: string;
        askPx: string;
        bidPx: string;
        open24h: string;
        high24h: string;
        low24h: string;
        volCcy24h: string;
        vol24h: string;
        ts: string;
      }>;
    }
  • src/index.ts:127-127 (registration)
    Validates that the requested tool name is either 'get_price' or 'get_candlesticks' in the callTool handler, effectively registering the allowed tools.
    if (!['get_price', 'get_candlesticks'].includes(request.params.name)) {

Schema Changelog

Changes observed during successful MCP inspections.

  1. Addedv1.0.0

TDQS

C2.9/5.0
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states what the tool does but lacks details on traits like rate limits, authentication needs, error handling, or response format. This is a significant gap for a tool with no annotation coverage.

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 with zero waste. It is appropriately sized and front-loaded, clearly stating the tool's purpose without unnecessary elaboration.

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

Completeness2/5

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

Given the lack of annotations and output schema, the description is incomplete. It doesn't explain behavioral traits, return values, or usage context, which are essential for a tool that fetches financial data. This leaves clear gaps in understanding.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents the 'instrument' parameter. The description adds no additional meaning beyond what the schema provides, such as examples or constraints, meeting the baseline for high schema coverage.

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 verb 'Get' and resource 'latest price for an OKX instrument', making the purpose specific and understandable. It doesn't explicitly distinguish from the sibling 'get_candlesticks', which provides historical price data, so it misses full 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_candlesticks'. There is no mention of prerequisites, context, or exclusions, leaving usage unclear.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Deploy Server

Other Tools