Skip to main content
Glama
harshitdynamite

DhanHQ MCP Server

get_order_by_correlation_id

Retrieve order status in DhanHQ trading by entering the correlation ID used during order placement. This tool provides order tracking through the DhanHQ MCP Server.

Instructions

Retrieves order status using the user-specified correlation ID. Requires authentication.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
correlationIdYesCorrelation ID used when placing the order

Implementation Reference

  • Core implementation of the tool handler that performs an API GET request to retrieve the order details using the correlation ID.
    export async function getOrderByCorrelationID(
      correlationId: string
    ): Promise<OrderBook> {
      try {
        log(`Fetching order by correlation ID: ${correlationId}`);
    
        const response = await axios.get<OrderBook>(
          `https://api.dhan.co/v2/orders/external/${correlationId}`,
          {
            headers: getApiHeaders(),
          }
        );
    
        log(`✓ Order retrieved. Order ID: ${response.data.orderId}`);
        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 by correlation ID: ${errorMessage}`);
        throw new Error(
          `Failed to get order by correlation ID: ${errorMessage}`
        );
      }
    }
  • MCP tool schema defining the name, description, and input parameters (correlationId) for the get_order_by_correlation_id tool.
    {
      name: 'get_order_by_correlation_id',
      description:
        'Retrieves order status using the user-specified correlation ID. Requires authentication.',
      inputSchema: {
        type: 'object' as const,
        properties: {
          correlationId: { type: 'string', description: 'Correlation ID used when placing the order' },
        },
        required: ['correlationId'],
      },
    },
  • src/index.ts:599-611 (registration)
    Registration and dispatching logic in the MCP call tool handler that invokes the getOrderByCorrelationID function upon tool invocation.
    case 'get_order_by_correlation_id': {
      console.error('[Tool] Executing: get_order_by_correlation_id');
      const { correlationId } = args as Record<string, unknown>;
      const order = await getOrderByCorrelationID(correlationId as string);
      return {
        content: [
          {
            type: 'text' as const,
            text: JSON.stringify(order, null, 2),
          },
        ],
      };
    }
  • TypeScript interface defining the structure of the OrderBook response returned by the handler.
    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;
    }
Behavior3/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 adds value by stating the authentication requirement, which is useful context beyond the input schema. However, it lacks details on rate limits, error handling, or response format, leaving gaps in behavioral understanding for a retrieval tool.

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 concise with two short sentences that are front-loaded with the core purpose. It avoids unnecessary details, but the second sentence about authentication could be integrated more smoothly, slightly affecting structure.

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 moderate complexity (single parameter retrieval), no annotations, and no output schema, the description is minimally adequate. It covers the basic purpose and authentication need but lacks details on return values, error cases, or usage context, which would enhance completeness for an agent.

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?

The input schema has 100% description coverage, with the parameter 'correlationId' well-documented. The description adds no additional parameter information beyond what the schema provides, so it meets the baseline of 3 where the schema does the heavy lifting without compensating for any gaps.

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 ('order status'), making the purpose understandable. However, it doesn't explicitly differentiate from sibling tools like 'get_order_by_id' or 'get_order_book', which likely retrieve orders by different identifiers or in bulk, so it doesn't achieve full 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. It mentions authentication as a requirement, but doesn't specify scenarios where a correlation ID is preferred over other order identifiers or when to choose this over other order-related tools in the sibling list.

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