get_login_instructions
Retrieve browser-based login URL and instructions for DhanHQ trading API authentication. Complete the OAuth login manually by opening the provided URL.
Instructions
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.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| consentAppId | No | The consentAppId from Step 1 (start_authentication). If not provided, the latest one from the current session will be used. |
Input Schema (JSON Schema)
{
"properties": {
"consentAppId": {
"description": "The consentAppId from Step 1 (start_authentication). If not provided, the latest one from the current session will be used.",
"type": "string"
}
},
"required": [],
"type": "object"
}
Implementation Reference
- src/index.ts:382-404 (handler)MCP CallToolRequest handler case that implements the get_login_instructions tool. Handles input arguments, retrieves consentAppId from state if not provided, calls the helper function, and formats the response.case 'get_login_instructions': { console.error('[Tool] Executing: get_login_instructions'); const authState = getAuthState(); const consentAppId = (args as Record<string, unknown>).consentAppId || authState.consentAppId; if (!consentAppId) { throw new Error( 'No consentAppId available. Please run start_authentication first.' ); } const instructions = getStep2Instructions(consentAppId as string); return { content: [ { type: 'text' as const, text: JSON.stringify(instructions, null, 2), }, ], }; }
- src/index.ts:55-70 (schema)Tool metadata including name, description, and input schema definition used for tool discovery and validation.{ 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: [], }, },
- src/index.ts:359-361 (registration)Registers the tool list (including get_login_instructions) with the MCP server via ListToolsRequestSchema handler.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools, }));
- src/authentication.ts:101-114 (helper)Helper function that constructs the login URL and multi-step instructions for browser-based authentication step 2.export function getStep2Instructions( consentAppId: string ): { loginUrl: string; instruction: string } { const loginUrl = `${AUTH_BASE_URL}/login/consentApp-login?consentAppId=${consentAppId}`; return { loginUrl, instruction: `1. Open this URL in your browser: ${loginUrl} 2. Log in with your Dhan credentials 3. Complete 2FA verification (OTP/PIN/Password) 4. You will be redirected to: ${dhanConfig.redirectUrl}?tokenId=<TOKEN_ID> 5. Copy the tokenId from the URL and use it in the 'consumeConsent' tool`, }; }