The DhanHQ Trading Assistant is an AI-powered solution that enables natural language interaction with the DhanHQ trading platform. This tool allows you to place orders, check your portfolio, and manage trading activities through simple conversational commands, making trading more accessible and efficient.
Clone the repository:
git clone https://github.com/yourusername/dhan-broker-mcp-trades.git
cd dhan-broker-mcp-trades
Install dependencies:
pip install -r requirements.txt
Configure your DhanHQ credentials:
Edit the config.py
file:
DHAN_CLIENT_ID = "your_client_id_here"
DHAN_ACCESS_TOKEN = "your_access_token_here"
DHAN_API_BASE_URL = "https://api.dhan.co/v2"
Ensure your stocks.json
file contains the stocks you want to trade:
{
"companies": [
{
"stock_code": "1333",
"company_name": "HDFC Bank Ltd.",
"stock_name": "HDFCBANK",
"description": "Description of the company..."
}
]
}
Each tool can be operated independently using the MCP CLI:
# For order placement
python -m mcp.server.cli dev order_placement_tool.py
# For portfolio management
python -m mcp.server.cli dev portfolio_server.py
# For other specific tools
python -m mcp.server.cli dev <tool_filename>.py
Handles regular market and limit orders for buying and selling stocks.
Creates advanced orders with target and stop-loss limits that can be specified in absolute values or percentages.
Enables order placement outside trading hours for execution on the next trading day.
Retrieves account fund information and available margin.
Provides portfolio information and allows position conversion between product types.
Calculates margin requirements before placing trades.
Accesses order history, trade book, and facilitates order cancellation.
Serves as the main interface for portfolio management functions.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.