Skip to main content
Glama
harshitdynamite

DhanHQ MCP Server

cancel_order

Cancel pending trading orders on DhanHQ by providing the order ID. This tool requires authentication to execute order cancellations.

Instructions

Cancels a pending order. Requires authentication and a valid order ID.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
orderIdYesOrder ID to cancel

Implementation Reference

  • Core handler function that executes the cancel order logic by sending a DELETE request to the Dhan API endpoint.
    export async function cancelOrder(orderId: string): Promise<OrderResponse> {
      try {
        log(`Cancelling order: ${orderId}`);
    
        const response = await axios.delete<OrderResponse>(
          `https://api.dhan.co/v2/orders/${orderId}`,
          {
            headers: getApiHeaders(),
          }
        );
    
        log(`✓ Order 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 order: ${errorMessage}`);
        throw new Error(`Failed to cancel order: ${errorMessage}`);
      }
  • MCP tool dispatcher handler that extracts the orderId argument and invokes the cancelOrder function, returning the result as MCP content.
    case 'cancel_order': {
      console.error('[Tool] Executing: cancel_order');
      const { orderId } = args as Record<string, unknown>;
      const result = await cancelOrder(orderId as string);
      return {
        content: [
          {
            type: 'text' as const,
            text: JSON.stringify(result, null, 2),
          },
        ],
      };
    }
  • Tool schema definition including name, description, and input schema requiring a string orderId.
    {
      name: 'cancel_order',
      description:
        'Cancels a pending order. Requires authentication and a valid order ID.',
      inputSchema: {
        type: 'object' as const,
        properties: {
          orderId: { type: 'string', description: 'Order ID to cancel' },
        },
        required: ['orderId'],
      },
    },
  • src/index.ts:359-361 (registration)
    Registration of the tools list handler, which includes the cancel_order tool schema for MCP listTools requests.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools,
    }));
Behavior3/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 discloses authentication requirements and that the order must be 'pending,' which adds useful behavioral context beyond the input schema. However, it doesn't cover other traits like whether the cancellation is reversible, rate limits, error conditions, or what happens post-cancellation, leaving gaps for a mutation tool.

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 two sentences, front-loaded with the core purpose and followed by prerequisites. Every word earns its place with zero waste, making it highly efficient and well-structured for quick understanding.

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 no annotations and no output schema, the description is moderately complete. It covers the purpose and prerequisites but lacks details on behavioral traits (e.g., side effects, response format) and doesn't fully compensate for the absence of structured data, making it adequate but with clear gaps for a cancellation tool.

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%, with the parameter 'orderId' fully documented in the schema. The description adds no additional meaning beyond what the schema provides (e.g., no format details or examples). Baseline 3 is appropriate as the schema handles parameter documentation adequately.

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 target ('a pending order'), providing a specific verb+resource combination. However, it doesn't differentiate from sibling tools like 'modify_order' or explicitly mention what makes this tool distinct for cancellation versus modification.

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 context by stating 'Requires authentication and a valid order ID,' which suggests prerequisites but doesn't explicitly guide when to use this tool versus alternatives like 'modify_order' or specify exclusions (e.g., cannot cancel completed orders). It provides some implied guidance but lacks explicit alternatives or when-not scenarios.

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