Skip to main content
Glama

start_authentication

Initiates OAuth authentication for DhanHQ trading APIs by generating a browser login URL to access trading operations and market data.

Instructions

Initiates the DhanHQ authentication flow (Step 1). Returns a login URL that you must open in your browser to authenticate.

Input Schema

NameRequiredDescriptionDefault

No arguments

Input Schema (JSON Schema)

{ "properties": {}, "required": [], "type": "object" }

Implementation Reference

  • src/index.ts:45-54 (registration)
    Tool definition and registration in the tools array used by ListToolsRequest handler, including name, description, and input schema.
    { 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: [], }, },
  • MCP CallToolRequest handler case for 'start_authentication' that invokes generateConsent() and returns the formatted result.
    case 'start_authentication': { console.error('[Tool] Executing: start_authentication'); const result = await generateConsent(); return { content: [ { type: 'text' as const, text: JSON.stringify(result, null, 2), }, ], }; }
  • Core helper function that executes the authentication initiation logic: POST to Dhan auth API to generate consentAppId and login URL.
    export async function generateConsent(): Promise<{ consentAppId: string; loginUrl: string; message: string; }> { try { log('Generating consent...'); const response = await axios.post<AuthStep1Response>( `${AUTH_BASE_URL}/app/generate-consent?client_id=${dhanConfig.clientId}`, {}, { headers: { app_id: dhanConfig.apiKey, app_secret: dhanConfig.apiSecret, }, } ); if (response.data.status !== 'success') { throw new Error(`Failed to generate consent: ${response.data.status}`); } authState.consentAppId = response.data.consentAppId; authState.consentAppStatus = response.data.consentAppStatus; const loginUrl = `${AUTH_BASE_URL}/login/consentApp-login?consentAppId=${response.data.consentAppId}`; log('✓ Consent generated successfully'); log(`Consent App ID: ${response.data.consentAppId}`); return { consentAppId: response.data.consentAppId, loginUrl, message: `Please open this URL in your browser to authenticate:\n${loginUrl}\n\nAfter login, you will be redirected and the tokenId will be passed as a query parameter.`, }; } catch (error) { const errorMessage = error instanceof axios.AxiosError ? `API Error: ${error.response?.status} - ${error.response?.data}` : error instanceof Error ? error.message : 'Unknown error'; log(`✗ Failed: ${errorMessage}`); throw new Error(`Step 1 Failed: ${errorMessage}`); } }
  • Input schema definition for the start_authentication tool (no required parameters).
    inputSchema: { type: 'object' as const, properties: {}, required: [], },

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