Skip to main content
Glama
harshitdynamite

DhanHQ MCP Server

modify_order

Update pending trading orders by changing price, quantity, order type, or other parameters through the DhanHQ trading platform.

Instructions

Modifies a pending order. Can change price, quantity, order type, and other parameters. Requires authentication.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
orderIdYesOrder ID to modify
dhanClientIdYesYour Dhan client ID
orderTypeYes
quantityNoNew quantity
priceNoNew price (for LIMIT/STOP_LOSS)
triggerPriceNoNew trigger price (for STOP_LOSS/STOP_LOSS_MARKET)
disclosedQuantityNoNew disclosed quantity

Implementation Reference

  • Core handler function that executes the HTTP PUT request to the Dhan API to modify a pending order.
    export async function modifyOrder(
      orderId: string,
      request: ModifyOrderRequest
    ): Promise<OrderResponse> {
      try {
        log(`Modifying order: ${orderId}`);
    
        const response = await axios.put<OrderResponse>(
          `https://api.dhan.co/v2/orders/${orderId}`,
          request,
          {
            headers: getApiHeaders(),
          }
        );
    
        log(`✓ Order modified 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 modify order: ${errorMessage}`);
        throw new Error(`Failed to modify order: ${errorMessage}`);
      }
    }
  • src/index.ts:167-187 (registration)
    MCP tool registration defining the 'modify_order' tool name, description, and input schema.
    {
      name: 'modify_order',
      description:
        'Modifies a pending order. Can change price, quantity, order type, and other parameters. Requires authentication.',
      inputSchema: {
        type: 'object' as const,
        properties: {
          orderId: { type: 'string', description: 'Order ID to modify' },
          dhanClientId: { type: 'string', description: 'Your Dhan client ID' },
          orderType: {
            type: 'string',
            enum: ['MARKET', 'LIMIT', 'STOP_LOSS', 'STOP_LOSS_MARKET'],
          },
          quantity: { type: 'number', description: 'New quantity' },
          price: { type: 'number', description: 'New price (for LIMIT/STOP_LOSS)' },
          triggerPrice: { type: 'number', description: 'New trigger price (for STOP_LOSS/STOP_LOSS_MARKET)' },
          disclosedQuantity: { type: 'number', description: 'New disclosed quantity' },
        },
        required: ['orderId', 'dhanClientId', 'orderType'],
      },
    },
  • TypeScript interface defining the structure of the ModifyOrderRequest used by the handler.
    export interface ModifyOrderRequest {
      dhanClientId: string;
      orderId: string;
      orderType: 'LIMIT' | 'MARKET' | 'STOP_LOSS' | 'STOP_LOSS_MARKET';
      quantity?: number;
      price?: number;
      triggerPrice?: number;
      disclosedQuantity?: number;
    }
  • MCP server request handler that processes 'modify_order' tool calls and delegates to the core modifyOrder function.
    case 'modify_order': {
      console.error('[Tool] Executing: modify_order');
      const modifyArgs = args as Record<string, unknown>;
      const result = await modifyOrder(modifyArgs.orderId as string, {
        dhanClientId: modifyArgs.dhanClientId as string,
        orderId: modifyArgs.orderId as string,
        orderType: modifyArgs.orderType as 'LIMIT' | 'MARKET' | 'STOP_LOSS' | 'STOP_LOSS_MARKET',
        quantity: modifyArgs.quantity as number | undefined,
        price: modifyArgs.price as number | undefined,
        triggerPrice: modifyArgs.triggerPrice as number | undefined,
        disclosedQuantity: modifyArgs.disclosedQuantity as number | undefined,
      });
      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?

With no annotations provided, the description carries full burden for behavioral disclosure. It states 'Requires authentication', which is useful, but lacks details on permissions, rate limits, side effects (e.g., order state changes), error handling, or response format. For a mutation 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 concise with two sentences that efficiently cover purpose and authentication requirement. It's front-loaded with the core action and avoids unnecessary details, though it could be slightly more structured by explicitly separating usage conditions from parameter info.

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?

For a mutation tool with 7 parameters, no annotations, and no output schema, the description is incomplete. It lacks details on behavioral traits (e.g., idempotency, error cases), output expectations, and sibling differentiation. The high schema coverage helps, but the description doesn't compensate for missing context in other areas.

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 high at 86%, with most parameters well-documented in the schema. The description adds minimal value by listing 'price, quantity, order type, and other parameters', but doesn't clarify dependencies (e.g., price relevance to order types) or semantics beyond what the schema provides. Baseline 3 is appropriate given the schema does 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 ('modifies') and target ('a pending order'), specifying it can change price, quantity, order type, and other parameters. It distinguishes from siblings like 'cancel_order' by focusing on modification rather than cancellation, though it doesn't explicitly contrast with 'modify_super_order'.

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 mentions 'Requires authentication' but provides no guidance on when to use this tool versus alternatives like 'modify_super_order' or 'cancel_order'. It doesn't specify prerequisites (e.g., order must be pending) or contextual constraints, leaving the agent with minimal 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/harshitdynamite/DhanMCP'

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