Zerodha MCP Server
Enables trading operations on Zerodha platform through natural language, supporting account management, order placement/modification, portfolio holdings, positions, margins, and stock news retrieval.
README
Zerodha MCP Server & Client
A Python-based trading assistant that connects to a Zerodha MCP server to help users manage their trading account.
Features
- Account Management: Manage Zerodha trading account, orders, and positions
- Interactive Chat Interface: Natural language interface for trading operations
- MCP Integration: Built on the Model Context Protocol for standardized communication
- Zerodha API Integration: Uses Zerodha's API to interact with the trading platform
- Google ADK Agent: Uses Google ADK Agent to interact with the trading platform
Tech Stack
- Protocol: Model Context Protocol (MCP)
- Agent Framework:
Tools
- Place Orders: Place orders in the trading platform
- Modify Orders: Modify orders in the trading platform
- Cancel Orders: Cancel orders in the trading platform
- Get Orders: Get orders in the trading platform
- Get Order History: Get order history in the trading platform
- Get Order Trades: Get order trades in the trading platform
- Get Margins: Get margins in the trading platform
- Get Holdings: Get holdings in the trading platform
- Get Positions: Get positions in the trading platform
- Get User Profile: Get user profile in the trading platform
- Get Stock News & Fundamentals: Gets news about a specific stock
Prerequisites
- Python
- Zerodha trading account with Personal API access from here
- Zerodha API key and secret
- Gemini API key or Application Default Credentials (for Google ADK Agent)
Installation
- Clone the repository:
git clone https://github.com/jainsourabh2/zerodha-mcp.git
cd zerodha-mcp
- Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
- Install dependencies:
pip3 install -r requirements.txt
- Set up environment variables:
# Copy the example environment file
cp .env.example .env
# Edit the .env file with your credentials
- Create a
.envfile with your configuration:
# Server Configuration
ZERODHA_API_KEY=your_api_key
ZERODHA_API_SECRET=your_api_secret
PORT=8001
SERVER_MODE=sse # or stdio
# Client Configuration
MCP_HOST=localhost
MCP_PORT=8001
GOOGLE_API_KEY=your_google_api_key
Server Usage
The server provides a set of tools for interacting with the Zerodha trading platform. To start the server:
-
Make sure your
.envfile is properly configured with your Zerodha API credentials. -
Start the server using one of the following methods:
# Using environment variables
python server.py
# Or using command line arguments
python server.py --api-key your_api_key --api-secret your_api_secret --port 8001 --mode sse
The server provides the following tools:
get_login_url: Get the login URL for user authenticationget_access_token: Generate access token using request tokenget_user_profile: Get user's Zerodha profile informationget_margins: Get available margins and fund detailsget_holdings: Get portfolio holdingsget_positions: Get current positionsget_orders: Get all orders for the dayget_order_history: Get history of a specific orderget_order_trades: Get trades generated by an orderplace_order: Place a new ordermodify_order: Modify an existing ordercancel_order: Cancel an order
Client Usage
This project provides three client implementations:
- Using Google ADK (
client/google_adk_client.py)
All clients connect to the MCP server and provide an interactive interface for trading operations.
### Running the Google ADK Client
1. Ensure you have authenticated with Google AI, either by setting the `GOOGLE_API_KEY` environment variable (and uncommenting it in `.env`) or by using Application Default Credentials (run `gcloud auth application-default login`).
2. Start the client using one of the following methods:
```bash
# Using environment variables from .env file
python client/google_adk_client.py
# Using command line arguments
python client/google_adk_client.py --host localhost --port 8001
# Using a combination (command line arguments take precedence)
MCP_HOST=localhost MCP_PORT=8001 python client/google_adk_client.py --host otherhost --port 9000
Client Configuration
Both clients support configuration through multiple sources, with the following precedence:
- Command-line arguments (highest precedence)
- Environment variables
.envfile variables
Configuration options:
- Environment variables:
MCP_HOSTandMCP_PORT - Command-line arguments:
--hostand--port .envfile variables:MCP_HOST,MCP_PORT,OPENAI_API_KEY, andGOOGLE_API_KEY
Default values (if no configuration is provided):
- Host: localhost
- Port: 8001
The client automatically loads environment variables from the .env file in the project root directory. Make sure your .env file contains the necessary configuration:
# Client Configuration
MCP_HOST=localhost
MCP_PORT=8001
OPENAI_API_KEY=your_openai_api_key
# GOOGLE_API_KEY=your_google_api_key
-
The client will automatically connect to the MCP server using the provided configuration.
-
Once connected, you can interact with the assistant using natural language commands. For example:
- "Show me my portfolio holdings"
- "What are my current positions?"
- "Place a market order for 10 shares of RELIANCE"
- "Cancel order ID 123456"
-
To exit the client, type 'quit' when prompted.
Development
Project Structure
client/google_adk_client.py: MCP client implementation using Google ADKserver.py: MCP server implementation with Zerodha API integrationgenerate_token.py: Utility for generating access tokensrequirements.txt: Project dependencies.env: Environment configuration
Contributing
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Acknowledgments
- Built using Google ADK
- Uses MCP for standardized communication
- Powered by KiteConnect for Zerodha API integration
zerodha-mcp
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。