Skip to main content
Glama
harshitdynamite

DhanHQ MCP Server

reset_authentication

Clear authentication state and reset session for DhanHQ trading APIs when encountering login issues or needing fresh authorization.

Instructions

Clears the current authentication state and resets the session.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • MCP tool handler for 'reset_authentication': logs execution, calls resetAuthState(), and returns a success response.
    case 'reset_authentication': {
      console.error('[Tool] Executing: reset_authentication');
      resetAuthState();
      return {
        content: [
          {
            type: 'text' as const,
            text: JSON.stringify(
              {
                success: true,
                message: 'Authentication state has been reset',
              },
              null,
              2
            ),
          },
        ],
      };
    }
  • Input schema definition for the 'reset_authentication' tool (no parameters required).
    {
      name: 'reset_authentication',
      description: 'Clears the current authentication state and resets the session.',
      inputSchema: {
        type: 'object' as const,
        properties: {},
        required: [],
      },
    },
  • src/index.ts:44-356 (registration)
    The 'reset_authentication' tool is registered in the tools array used for ListToolsRequestHandler.
    const tools = [
      {
        name: 'start_authentication',
        description:
          'Initiates the DhanHQ authentication flow (Step 1). Returns a login URL that you must open in your browser to authenticate.',
        inputSchema: {
          type: 'object' as const,
          properties: {},
          required: [],
        },
      },
      {
        name: 'get_login_instructions',
        description:
          'Gets the login instructions and URL for Step 2 (browser-based login). You must complete this step manually by opening the URL in your browser.',
        inputSchema: {
          type: 'object' as const,
          properties: {
            consentAppId: {
              type: 'string' as const,
              description:
                'The consentAppId from Step 1 (start_authentication). If not provided, the latest one from the current session will be used.',
            },
          },
          required: [],
        },
      },
      {
        name: 'complete_authentication',
        description:
          'Completes the authentication flow (Step 3). Takes the tokenId from the redirect URL after browser login and exchanges it for an access token.',
        inputSchema: {
          type: 'object' as const,
          properties: {
            tokenId: {
              type: 'string' as const,
              description:
                'The tokenId received in the redirect URL after browser login (Step 2).',
            },
          },
          required: ['tokenId'],
        },
      },
      {
        name: 'check_auth_status',
        description:
          'Checks the current authentication status and returns details about the active access token if available.',
        inputSchema: {
          type: 'object' as const,
          properties: {},
          required: [],
        },
      },
      {
        name: 'reset_authentication',
        description: 'Clears the current authentication state and resets the session.',
        inputSchema: {
          type: 'object' as const,
          properties: {},
          required: [],
        },
      },
      {
        name: 'get_fund_limit',
        description:
          'Retrieves account fund limit information including available balance, margins, collateral, and withdrawable balance. Requires authentication.',
        inputSchema: {
          type: 'object' as const,
          properties: {},
          required: [],
        },
      },
    
      // ===== ORDER MANAGEMENT TOOLS =====
      {
        name: 'place_order',
        description:
          'Places a new order on DhanHQ. Requires authentication. Supports MARKET, LIMIT, STOP_LOSS, and STOP_LOSS_MARKET orders.',
        inputSchema: {
          type: 'object' as const,
          properties: {
            dhanClientId: { type: 'string', description: 'Your Dhan client ID' },
            correlationId: { type: 'string', description: 'Unique correlation ID for order tracking' },
            transactionType: { type: 'string', enum: ['BUY', 'SELL'] },
            exchangeSegment: { type: 'string', description: 'e.g., NSE_EQ, BSE_EQ, NFO_FUT' },
            productType: {
              type: 'string',
              enum: ['CNC', 'INTRADAY', 'MARGIN', 'MTF', 'CO', 'BO'],
              description: 'CNC=Delivery, INTRADAY=Intraday, MARGIN=Margin, CO=Cover Order, BO=Bracket Order',
            },
            orderType: {
              type: 'string',
              enum: ['MARKET', 'LIMIT', 'STOP_LOSS', 'STOP_LOSS_MARKET'],
            },
            validity: {
              type: 'string',
              enum: ['DAY', 'IOC'],
              description: 'DAY=Valid for today, IOC=Immediate or Cancel',
            },
            securityId: { type: 'string', description: 'Security ID for the instrument' },
            quantity: { type: 'number', description: 'Quantity to order' },
            price: { type: 'number', description: 'Price per share (required for LIMIT/STOP_LOSS)' },
            triggerPrice: { type: 'number', description: 'Trigger price (required for STOP_LOSS/STOP_LOSS_MARKET)' },
            disclosedQuantity: { type: 'number', description: 'Quantity visible in order book (min 30% of quantity)' },
            afterMarketOrder: { type: 'boolean', description: 'Flag for after-market orders' },
            amoTime: { type: 'string', enum: ['PRE_OPEN', 'OPEN', 'OPEN_30', 'OPEN_60'], description: 'AMO timing' },
            boProfitValue: { type: 'number', description: 'BO target price change' },
            boStopLossValue: { type: 'number', description: 'BO stop loss price change' },
          },
          required: [
            'dhanClientId',
            'correlationId',
            'transactionType',
            'exchangeSegment',
            'productType',
            'orderType',
            'validity',
            'securityId',
            'quantity',
            'price',
          ],
        },
      },
      {
        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'],
        },
      },
      {
        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'],
        },
      },
      {
        name: 'get_order_book',
        description:
          'Retrieves all orders placed during the day with their current status. Requires authentication.',
        inputSchema: {
          type: 'object' as const,
          properties: {},
          required: [],
        },
      },
      {
        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'],
        },
      },
      {
        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'],
        },
      },
      {
        name: 'get_trade_book',
        description:
          'Retrieves all trades executed during the day. Useful for tracking fills and execution prices. Requires authentication.',
        inputSchema: {
          type: 'object' as const,
          properties: {},
          required: [],
        },
      },
      {
        name: 'get_order_trades',
        description:
          'Retrieves all trades for a specific order. Useful for partial fills or bracket/cover orders. Requires authentication.',
        inputSchema: {
          type: 'object' as const,
          properties: {
            orderId: { type: 'string', description: 'Order ID to get trades for' },
          },
          required: ['orderId'],
        },
      },
    
      // ===== SUPER ORDER MANAGEMENT TOOLS =====
      {
        name: 'place_super_order',
        description:
          'Places a smart super order combining entry, target, and stop-loss legs. Supports trailing stop loss. Requires authentication.',
        inputSchema: {
          type: 'object' as const,
          properties: {
            dhanClientId: { type: 'string', description: 'Your Dhan client ID' },
            correlationId: { type: 'string', description: 'Unique correlation ID for order tracking' },
            transactionType: { type: 'string', enum: ['BUY', 'SELL'] },
            exchangeSegment: { type: 'string', description: 'e.g., NSE_EQ, BSE_EQ' },
            productType: {
              type: 'string',
              enum: ['CNC', 'INTRADAY', 'MARGIN', 'MTF', 'CO', 'BO'],
            },
            orderType: {
              type: 'string',
              enum: ['MARKET', 'LIMIT', 'STOP_LOSS', 'STOP_LOSS_MARKET'],
            },
            securityId: { type: 'string', description: 'Security ID for the instrument' },
            quantity: { type: 'number', description: 'Quantity for entry leg' },
            price: { type: 'number', description: 'Entry price' },
            targetPrice: { type: 'number', description: 'Target price for profit booking' },
            stopLossPrice: { type: 'number', description: 'Stop loss price' },
            trailingJump: {
              type: 'number',
              description: 'Trailing stop loss jump amount (optional)',
            },
          },
          required: [
            'dhanClientId',
            'correlationId',
            'transactionType',
            'exchangeSegment',
            'productType',
            'orderType',
            'securityId',
            'quantity',
            'price',
            'targetPrice',
            'stopLossPrice',
          ],
        },
      },
      {
        name: 'modify_super_order',
        description:
          'Modifies any leg of a pending or part-traded super order. Requires authentication.',
        inputSchema: {
          type: 'object' as const,
          properties: {
            orderId: { type: 'string', description: 'Super order ID to modify' },
            dhanClientId: { type: 'string', description: 'Your Dhan client ID' },
            legName: {
              type: 'string',
              enum: ['ENTRY_LEG', 'TARGET_LEG', 'STOP_LOSS_LEG'],
              description: 'Which leg to modify',
            },
            orderType: {
              type: 'string',
              enum: ['MARKET', 'LIMIT', 'STOP', 'STOP_LIMIT'],
            },
            quantity: { type: 'number', description: 'New quantity' },
            price: { type: 'number', description: 'New price' },
            targetPrice: { type: 'number', description: 'New target price (for entry leg)' },
            stopLossPrice: { type: 'number', description: 'New stop loss price' },
            trailingJump: { type: 'number', description: 'New trailing jump amount' },
          },
          required: ['orderId', 'dhanClientId', 'legName', 'orderType'],
        },
      },
      {
        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'],
        },
      },
      {
        name: 'get_super_order_book',
        description:
          'Retrieves all super orders placed during the day with nested leg details. Requires authentication.',
        inputSchema: {
          type: 'object' as const,
          properties: {},
          required: [],
        },
      },
    ];
  • Core helper function that implements the reset logic by clearing the in-memory authState object.
    export function resetAuthState(): void {
      authState = {};
      log('State reset');
    }
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 states the tool 'clears' and 'resets', implying a destructive action, but doesn't specify consequences (e.g., loss of access, need to re-authenticate) or requirements (e.g., permissions, side effects like logging out). This is inadequate for a mutation tool with zero annotation coverage.

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 a single, efficient sentence that directly states the tool's function without unnecessary words. It is front-loaded with the core action ('clears'), making it easy to parse. Every part of the sentence contributes meaning, earning its place.

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 an authentication reset tool (a mutation with potential side effects), no annotations, and no output schema, the description is insufficient. It lacks details on behavioral outcomes (e.g., what 'resets the session' entails), error conditions, or return values, leaving significant gaps for agent understanding.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool has 0 parameters, and schema description coverage is 100%, so there's no need for parameter details in the description. The baseline for this scenario is 4, as the description appropriately avoids redundant information while focusing on the tool's purpose.

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 tool's purpose with specific verbs ('clears', 'resets') and identifies the target resource ('authentication state', 'session'). It distinguishes itself from sibling tools like 'check_auth_status' or 'complete_authentication' by focusing on resetting rather than checking or completing. However, it doesn't explicitly contrast with all siblings, keeping it from a perfect score.

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 doesn't mention prerequisites (e.g., needing an active session), exclusions (e.g., not for initial setup), or compare to siblings like 'start_authentication' or 'complete_authentication'. This leaves the agent without context for appropriate invocation.

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