Skip to main content
Glama
vibeoski

Dhan MCP Server

Official
by vibeoski
README.md
# Dhan MCP Server

An MCP (Model Context Protocol) server that exposes [Dhan](https://dhanhq.co) trading APIs as tools, enabling AI assistants to manage orders, view portfolios, fetch market data, and more.

## Prerequisites

- Node.js 18+
- A [Dhan](https://dhanhq.co) account with API access
- Access token from Dhan's developer portal

## Setup

### 1. Get your Dhan API credentials

1. Log in to [Dhan Web](https://web.dhan.co)
2. Go to **Profile → DhanHQ Trading APIs**
3. Generate an **Access Token** and note your **Client ID**

### 2. Install and build

```bash
npm install
npm run build
```

### 3. Configure environment

Copy `.env.example` to `.env` and fill in your credentials:

```bash
cp .env.example .env
```

```
DHAN_ACCESS_TOKEN=your_jwt_access_token_here
DHAN_CLIENT_ID=your_dhan_client_id_here
```

## Usage

### Run directly

```bash
DHAN_ACCESS_TOKEN=<token> DHAN_CLIENT_ID=<clientId> node dist/index.js
```

### Configure with Claude Desktop

Add to your Claude Desktop `config.json`:

```json
{
  "mcpServers": {
    "dhan": {
      "command": "node",
      "args": ["/path/to/dhan-mcp-server/dist/index.js"],
      "env": {
        "DHAN_ACCESS_TOKEN": "your_access_token",
        "DHAN_CLIENT_ID": "your_client_id"
      }
    }
  }
}
```

## Available Tools

### Orders
| Tool | Description |
|------|-------------|
| `place_order` | Place a new order (equity, F&O, currency, commodity) |
| `place_slice_order` | Place a large order split into smaller chunks automatically |
| `get_orders` | Get all orders for today |
| `get_order_by_id` | Get a specific order by ID |
| `get_order_by_correlation_id` | Get order by client correlation ID |
| `modify_order` | Modify a pending order |
| `cancel_order` | Cancel a pending order |

### Trades
| Tool | Description |
|------|-------------|
| `get_trades` | Get all executed trades for today |
| `get_trades_by_order_id` | Get trades for a specific order |

### Portfolio
| Tool | Description |
|------|-------------|
| `get_holdings` | View equity holdings from previous sessions |
| `get_positions` | View open positions for today |
| `convert_position` | Convert position between product types (e.g. INTRADAY → CNC) |

### Funds & Margin
| Tool | Description |
|------|-------------|
| `get_fund_limits` | View available margin, used margin, collateral |
| `calculate_margin` | Calculate margin required for a potential order |

### Market Data
| Tool | Description |
|------|-------------|
| `get_market_quote_ticker` | Real-time LTP for given securities |
| `get_market_quote_ohlc` | OHLC data for given securities |
| `get_market_quote_full` | Full market depth (bid/ask, volume, OI) |
| `get_option_chain` | Complete option chain for an underlying |
| `get_expiry_list` | Available expiry dates for an underlying |
| `get_historical_candle` | Historical daily OHLCV candles |
| `get_intraday_candle` | Intraday OHLCV candles (1/5/15/25/60 min) |

### Statements
| Tool | Description |
|------|-------------|
| `get_ledger_report` | Account ledger for a date range |
| `get_trade_history` | Historical trade records |

### Profile & Auth
| Tool | Description |
|------|-------------|
| `get_profile` | User profile information |
| `renew_token` | Renew the access token |

### EDIS
| Tool | Description |
|------|-------------|
| `generate_edis_form` | Generate EDIS slip for selling holdings |
| `get_edis_inquiry` | Check EDIS status for an ISIN |

## Exchange Segments

| Segment | Description |
|---------|-------------|
| `NSE_EQ` | NSE Equity |
| `NSE_FNO` | NSE Futures & Options |
| `NSE_CURRENCY` | NSE Currency Derivatives |
| `BSE_EQ` | BSE Equity |
| `BSE_FNO` | BSE Futures & Options |
| `BSE_CURRENCY` | BSE Currency Derivatives |
| `MCX_COMM` | MCX Commodity |

## Product Types

| Type | Description |
|------|-------------|
| `CNC` | Cash and Carry (delivery) |
| `INTRADAY` | Intraday MIS |
| `MARGIN` | Margin |
| `MTF` | Margin Trading Facility |
| `CO` | Cover Order |
| `BO` | Bracket Order |