check_auth_status
Verify authentication status and retrieve active access token details for DhanHQ trading API access.
Instructions
Checks the current authentication status and returns details about the active access token if available.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Input Schema (JSON Schema)
{
"properties": {},
"required": [],
"type": "object"
}
Implementation Reference
- src/index.ts:433-469 (handler)The handler function for the 'check_auth_status' tool. It fetches the current authentication state, access token, and validity check, then constructs and returns a formatted status object as MCP tool response.case 'check_auth_status': { console.error('[Tool] Executing: check_auth_status'); const authState = getAuthState(); const accessToken = getAccessToken(); const tokenValid = isTokenValid(); const status = { authenticated: !!authState.authToken, hasValidToken: tokenValid, accessToken: accessToken ? '***REDACTED***' : null, authState: { consentAppId: authState.consentAppId || null, consentAppStatus: authState.consentAppStatus || null, tokenId: authState.tokenId ? '***REDACTED***' : null, clientInfo: authState.authToken ? { dhanClientId: authState.authToken.dhanClientId, dhanClientName: authState.authToken.dhanClientName, dhanClientUcc: authState.authToken.dhanClientUcc, expiryTime: authState.authToken.expiryTime, givenPowerOfAttorney: authState.authToken.givenPowerOfAttorney, generatedAt: authState.authToken.generatedAt, } : null, }, }; return { content: [ { type: 'text' as const, text: JSON.stringify(status, null, 2), }, ], }; }
- src/index.ts:87-96 (schema)The schema definition for the 'check_auth_status' tool, including name, description, and empty input schema (no parameters required). This is part of the tools array used for MCP listTools response.{ 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: [], }, },
- src/authentication.ts:171-173 (helper)Helper function to retrieve the current in-memory authentication state object.export function getAuthState(): AuthState { return authState; }
- src/authentication.ts:178-190 (helper)Helper function that returns the current access token if it exists and is not expired.export function getAccessToken(): string | null { if (!authState.authToken) { return null; } const expiryTime = new Date(authState.authToken.expiryTime); if (new Date() > expiryTime) { log('Access token has expired'); return null; } return authState.authToken.accessToken; }
- src/authentication.ts:203-210 (helper)Helper function that checks if the stored auth token is still valid (not expired).export function isTokenValid(): boolean { if (!authState.authToken) { return false; } const expiryTime = new Date(authState.authToken.expiryTime); return new Date() < expiryTime; }