Skip to main content
Glama
harshitdynamite

DhanHQ MCP Server

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

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • 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),
          },
        ],
      };
    }
  • 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: [],
      },
    },
  • Helper function to retrieve the current in-memory authentication state object.
    export function getAuthState(): AuthState {
      return authState;
    }
  • 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;
    }
  • 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;
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It discloses that the tool checks status and returns token details, which implies it's a read-only operation without side effects. However, it lacks details on error conditions (e.g., what happens if no token is available), rate limits, or specific permissions required, leaving behavioral gaps for a tool that interacts with authentication systems.

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, well-structured sentence that front-loads the core action ('Checks the current authentication status') and adds essential detail ('returns details about the active access token if available'). There is no wasted wording, and every part contributes to understanding the tool's function.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (authentication-related with potential security implications), no annotations, and no output schema, the description is minimally adequate. It covers the basic purpose and return intent but lacks details on output format, error handling, or dependencies (e.g., whether authentication must be started first). For a tool in this context, more completeness would be beneficial.

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 no parameter documentation is needed. The description does not discuss parameters, which is appropriate. A baseline of 4 is applied for zero parameters, as it efficiently avoids unnecessary information while matching the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/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 a specific verb ('Checks') and resource ('authentication status'), and distinguishes it from siblings by focusing on authentication status rather than order/trade operations or authentication initiation/reset. It explicitly mentions what it returns ('details about the active access token if available'), making the purpose unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context by mentioning 'current authentication status' and 'active access token', suggesting it should be used to verify authentication state, likely before performing operations that require authentication. However, it does not explicitly state when not to use it or name alternatives (e.g., compared to 'start_authentication' or 'reset_authentication'), which prevents a score of 5.

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