Skip to main content
Glama
harshitdynamite

DhanHQ MCP Server

cancel_super_order_leg

Cancel a specific leg (ENTRY_LEG, TARGET_LEG, or STOP_LOSS_LEG) of a super order in DhanHQ trading by providing the order ID and leg type.

Instructions

Cancels a specific leg of a super order (ENTRY_LEG, TARGET_LEG, or STOP_LOSS_LEG). Requires authentication.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
orderIdYesSuper order ID
orderLegYesWhich leg to cancel

Implementation Reference

  • The core handler function that performs the API call to cancel a specific leg of a super order using the Dhan API.
    export async function cancelSuperOrderLeg(
      orderId: string,
      orderLeg: string
    ): Promise<OrderResponse> {
      try {
        log(
          `Cancelling super order leg: ${orderId}, leg: ${orderLeg}`
        );
    
        const response = await axios.delete<OrderResponse>(
          `https://api.dhan.co/v2/super/orders/${orderId}/${orderLeg}`,
          {
            headers: getApiHeaders(),
          }
        );
    
        log(
          `✓ Super order leg cancelled successfully. 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 cancel super order leg: ${errorMessage}`);
        throw new Error(`Failed to cancel super order leg: ${errorMessage}`);
      }
  • Defines the tool schema including name, description, and input validation schema for parameters orderId and orderLeg.
    {
      name: 'cancel_super_order_leg',
      description:
        'Cancels a specific leg of a super order (ENTRY_LEG, TARGET_LEG, or STOP_LOSS_LEG). Requires authentication.',
      inputSchema: {
        type: 'object' as const,
        properties: {
          orderId: { type: 'string', description: 'Super order ID' },
          orderLeg: {
            type: 'string',
            enum: ['ENTRY_LEG', 'TARGET_LEG', 'STOP_LOSS_LEG'],
            description: 'Which leg to cancel',
          },
        },
        required: ['orderId', 'orderLeg'],
      },
  • src/index.ts:686-701 (registration)
    Registers the tool handler in the MCP server's request handler switch statement, extracting arguments and calling the cancelSuperOrderLeg function.
    case 'cancel_super_order_leg': {
      console.error('[Tool] Executing: cancel_super_order_leg');
      const { orderId, orderLeg } = args as Record<string, unknown>;
      const result = await cancelSuperOrderLeg(
        orderId as string,
        orderLeg as string
      );
      return {
        content: [
          {
            type: 'text' as const,
            text: JSON.stringify(result, null, 2),
          },
        ],
      };
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It mentions authentication requirements, which is useful, but lacks details on behavioral traits such as whether the cancellation is immediate or pending, if it's reversible, what happens to other legs, error conditions, or rate limits. For a mutation tool with zero annotation coverage, this is a significant gap.

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 sentences: one for the purpose and one for authentication. It's front-loaded with the core action, but could be slightly more structured by separating usage notes. There's no wasted text, though it's brief.

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 a mutation tool (canceling part of a financial order) with no annotations and no output schema, the description is incomplete. It lacks details on behavior, error handling, or what the tool returns, which are critical for an AI agent to use it correctly in a trading context.

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 fully documents both parameters (orderId and orderLeg with enum values). The description adds no additional meaning beyond what the schema provides, such as explaining the super order ID format or the implications of canceling each leg type. Baseline 3 is appropriate when the schema does the heavy lifting.

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 ('Cancels') and the target ('a specific leg of a super order'), with examples of leg types provided. It distinguishes from sibling tools like 'cancel_order' by specifying it's for a leg of a super order, though it doesn't explicitly contrast with 'modify_super_order' which might be an alternative for adjustments.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage by stating it's for canceling a leg of a super order, but it doesn't explicitly guide when to use this vs. alternatives like 'cancel_order' (for entire orders) or 'modify_super_order' (for changes other than cancellation). The mention of 'Requires authentication' is a prerequisite, not a usage context.

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