Skip to main content
Glama
harshitdynamite

DhanHQ MCP Server

get_trade_book

Retrieve all trades executed during the day to track fills and execution prices. Requires authentication with DhanHQ trading APIs.

Instructions

Retrieves all trades executed during the day. Useful for tracking fills and execution prices. Requires authentication.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Core handler function that executes the tool logic by fetching the day's trade book from the Dhan API endpoint 'https://api.dhan.co/v2/trades' using the authenticated access token.
    export async function getTradeBook(): Promise<TradeBook[]> {
      try {
        log('Fetching trade book...');
    
        const response = await axios.get<TradeBook[]>(
          'https://api.dhan.co/v2/trades',
          {
            headers: getApiHeaders(),
          }
        );
    
        log(`✓ Trade book retrieved. Total trades: ${response.data.length}`);
        return response.data;
      } catch (error) {
        const errorMessage =
          error instanceof axios.AxiosError
            ? `API Error: ${error.response?.status} - ${JSON.stringify(error.response?.data)}`
            : error instanceof Error
              ? error.message
              : 'Unknown error';
    
        log(`✗ Failed to get trade book: ${errorMessage}`);
        throw new Error(`Failed to get trade book: ${errorMessage}`);
      }
    }
  • Tool schema definition including name, description, and empty input schema (no parameters required). Output is implicitly TradeBook[].
    {
      name: 'get_trade_book',
      description:
        'Retrieves all trades executed during the day. Useful for tracking fills and execution prices. Requires authentication.',
      inputSchema: {
        type: 'object' as const,
        properties: {},
        required: [],
      },
    },
  • src/index.ts:613-624 (registration)
    MCP callTool request handler (switch case) that registers and dispatches the 'get_trade_book' tool call to the getTradeBook function and formats the response.
    case 'get_trade_book': {
      console.error('[Tool] Executing: get_trade_book');
      const trades = await getTradeBook();
      return {
        content: [
          {
            type: 'text' as const,
            text: JSON.stringify(trades, null, 2),
          },
        ],
      };
    }
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It adds value by specifying the scope ('all trades executed during the day') and stating 'Requires authentication', which are useful behavioral traits. However, it lacks details on rate limits, response format, or potential side effects, leaving gaps for a tool that retrieves data.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise and front-loaded, consisting of three short sentences that efficiently convey purpose, usage, and authentication requirement. Every sentence adds value without redundancy, making it easy to parse quickly. It could be slightly improved by integrating the information more seamlessly, but it's well-structured overall.

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 (a read operation with no parameters), no annotations, and no output schema, the description is moderately complete. It covers the core purpose and authentication need but lacks details on output format, pagination, or error handling. For a tool that retrieves all trades, more context on what 'all' entails (e.g., time range, limits) would enhance completeness.

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 input schema has 0 parameters with 100% coverage, so there are no parameters to document. The description doesn't need to add parameter semantics, and it appropriately avoids discussing any. This meets the baseline for tools with no parameters, as it doesn't mislead or omit necessary information.

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

Purpose4/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 ('Retrieves') and resource ('all trades executed during the day'), making it easy to understand what the tool does. However, it doesn't explicitly differentiate from sibling tools like 'get_order_trades' or 'get_order_book', which might have overlapping functionality, so it doesn't reach the highest score.

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

Usage Guidelines3/5

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

The description provides some usage context by stating it's 'useful for tracking fills and execution prices', which implies when to use it. However, it doesn't offer explicit guidance on when to choose this tool over alternatives like 'get_order_trades' or 'get_order_book', nor does it mention any exclusions or prerequisites beyond authentication.

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