Skip to main content
Glama
harshitdynamite

DhanHQ MCP Server

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

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

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: [],
    },
Behavior4/5

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

With no annotations provided, the description carries full burden and does well by disclosing key behavioral traits: it's an initiation action that returns a login URL for browser-based authentication. It doesn't mention rate limits, error conditions, or what happens if authentication is already in progress, but covers the core behavior adequately.

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?

Two sentences that are perfectly front-loaded: the first states the purpose and step position, the second explains the return value and required next action. Every word earns its place with zero waste or redundancy.

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

Completeness4/5

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

For a 0-parameter tool with no output schema, the description provides complete context about what the tool does and how to use its output. It could mention what happens after browser authentication or error cases, but covers the essential workflow adequately given the tool's simplicity.

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?

With 0 parameters and 100% schema description coverage, the baseline would be 4. The description appropriately doesn't discuss parameters since none exist, focusing instead on the tool's purpose and output behavior.

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 specific action ('Initiates the DhanHQ authentication flow') and resource ('authentication flow'), distinguishing it from siblings like 'check_auth_status' or 'complete_authentication'. It explicitly identifies this as 'Step 1' in a multi-step process, providing clear differentiation.

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

Usage Guidelines5/5

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

The description provides explicit guidance on when to use this tool ('Step 1' of authentication) and what to do with its output ('open in your browser to authenticate'). It distinguishes this from other authentication-related tools by positioning it as the initial step in the flow.

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