Skip to main content
Glama
harshitdynamite

DhanHQ MCP Server

get_order_by_id

Retrieve order details and status using the order ID for tracking trading operations on DhanHQ.

Instructions

Retrieves the details and status of a specific order by order ID. Requires authentication.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
orderIdYesOrder ID to retrieve

Implementation Reference

  • The MCP tool dispatcher handler for 'get_order_by_id'. Extracts orderId from input arguments, calls the getOrderByID helper function, and formats the response as MCP content.
    case 'get_order_by_id': {
      console.error('[Tool] Executing: get_order_by_id');
      const { orderId } = args as Record<string, unknown>;
      const order = await getOrderByID(orderId as string);
      return {
        content: [
          {
            type: 'text' as const,
            text: JSON.stringify(order, null, 2),
          },
        ],
      };
    }
  • Tool schema definition including name, description, and input schema that requires a single 'orderId' string parameter.
    {
      name: 'get_order_by_id',
      description:
        'Retrieves the details and status of a specific order by order ID. Requires authentication.',
      inputSchema: {
        type: 'object' as const,
        properties: {
          orderId: { type: 'string', description: 'Order ID to retrieve' },
        },
        required: ['orderId'],
      },
    },
  • Core helper function that performs the actual API call to DhanHQ to retrieve the specific order details by order ID, handles errors, and returns OrderBook.
    export async function getOrderByID(orderId: string): Promise<OrderBook> {
      try {
        log(`Fetching order: ${orderId}`);
    
        const response = await axios.get<OrderBook>(
          `https://api.dhan.co/v2/orders/${orderId}`,
          {
            headers: getApiHeaders(),
          }
        );
    
        log(`✓ Order retrieved. Status: ${response.data.orderStatus}`);
        return response.data;
      } catch (error) {
        const errorMessage =
          error instanceof axios.AxiosError
            ? `API Error: ${error.response?.status} - ${JSON.stringify(error.response?.data)}`
            : error instanceof Error
              ? error.message
              : 'Unknown error';
    
        log(`✗ Failed to get order: ${errorMessage}`);
        throw new Error(`Failed to get order: ${errorMessage}`);
      }
    }
  • TypeScript interface defining the structure of the OrderBook response object used as return type.
    export interface OrderBook {
      dhanClientId: string;
      orderId: string;
      correlationId: string;
      orderStatus: string;
      transactionType: string;
      exchangeSegment: string;
      productType: string;
      orderType: string;
      validity: string;
      securityId: string;
      quantity: number;
      price: number;
      triggerPrice?: number;
      disclosedQuantity?: number;
      createTime: string;
      algoId?: string;
      remainingQuantity: number;
      filledQty: number;
      updateTime?: string;
    }
  • src/index.ts:359-361 (registration)
    Registers the listTools handler which provides the full tools list including 'get_order_by_id'.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools,
    }));
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 mentions authentication requirements, which is useful, but lacks details on rate limits, error handling, response format, or whether it's a read-only operation. For a retrieval tool with zero annotation coverage, this leaves significant gaps in understanding its behavior.

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 brief and front-loaded with the core purpose, using only two sentences. It avoids unnecessary words, though it could be slightly more structured by separating the authentication note into a distinct guideline section.

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 complexity of order retrieval in a financial context with many sibling tools, no annotations, and no output schema, the description is incomplete. It fails to explain what details are returned, how to handle errors, or differentiate from similar tools, leaving the agent with insufficient context for optimal use.

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 input schema fully documents the 'orderId' parameter. The description does not add any meaning beyond what the schema provides, such as format examples or constraints. Baseline 3 is appropriate when the schema handles parameter documentation effectively.

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 ('retrieves') and resource ('details and status of a specific order'), making the purpose understandable. However, it does not explicitly distinguish this tool from similar siblings like 'get_order_by_correlation_id' or 'get_order_book', which slightly limits 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 includes a prerequisite ('Requires authentication') but provides no guidance on when to use this tool versus alternatives such as 'get_order_by_correlation_id' or 'get_order_book'. There is no mention of context, exclusions, or comparisons to sibling tools.

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/harshitdynamite/DhanMCP'

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