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
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Input Schema (JSON Schema)
{
"properties": {},
"required": [],
"type": "object"
}
Implementation Reference
- src/index.ts:471-489 (handler)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 ), }, ], }; }
- src/index.ts:97-105 (schema)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: [], }, }, ];
- src/authentication.ts:195-198 (helper)Core helper function that implements the reset logic by clearing the in-memory authState object.export function resetAuthState(): void { authState = {}; log('State reset'); }