home / mcp / zerodha mcp server
๐น This is the code for Zerodha MCP โ you can use it to trade live on the Indian Stock Market ๐ฎ๐ณ๐๐ฐ
Configuration
View docs{
"mcpServers": {
"kshitij-21-mcp-server": {
"command": "/opt/homebrew/bin/bun",
"args": [
"/path/to/your/zerodha-mcp/main.ts"
],
"env": {
"API_KEY": "your_zerodha_api_key",
"API_SECRET": "your_zerodha_api_secret"
}
}
}
}You deploy this MCP server to interact with Zerodha trading through an AI assistant. It provides tools to place stock orders, view holdings, and manage mutual fund investments via Zerodhaโs API, all with OAuth-based authentication, token management, and robust error handling.
Start the MCP server locally and connect it to your MCP client. Your client can request actions such as placing stock orders, checking your current holdings, viewing active mutual fund SIPs, and checking mutual fund holdings. The server handles authentication flows, token storage, and session persistence so you can focus on trading tasks without re-authenticating each time.
Prerequisites you need before installing:
# Prerequisites
- Bun runtime installed
- Zerodha trading account
- Zerodha API credentials (API_KEY and API_SECRET)Configure environment variables and start the MCP server locally. Use the environment variables shown in the setup to authorize requests to Zerodha.
API_KEY=your_zerodha_api_key
API_SECRET=your_zerodha_api_secretRun the MCP server using Bun as the runtime and point it to the main entry file.
bun main.tsIf you are configuring an MCP client like Claude to talk to this server, use the following example configuration. It runs the MCP server locally and passes the necessary authentication tokens via environment variables.
{
"mcpServers": {
"kite": {
"command": "/opt/homebrew/bin/bun",
"env": {
"API_KEY": "your_zerodha_api_key",
"API_SECRET": "your_zerodha_api_secret"
},
"args": ["/path/to/your/zerodha-mcp/main.ts"]
}
}
}This MCP server supports a local stdio connection. The complete command to run is provided in the example above. You can customize the server name and path to your project as needed.
- The server stores tokens in a local file and automatically refreshes them as needed. - Authentication is OAuth-based, with a login flow initiated by your MCP client. - The server provides structured error handling and detailed operation logging to help diagnose issues.
- Environment variables contain credentials and are kept on your local machine. - Sensitive data is not included in error messages. - Token management auto-refreshes, reducing the risk of session expiry during trades.
Common issues you might encounter include authentication failures, API errors, network issues, or MCP connection problems. Check that the environment variables are set, tokens are valid, and the server is running with the expected path to main.ts. Review error logs for detailed information.
# Example checks
cat config/tokens.json
# If tokens are invalid, re-authenticate via the login flow in your MCP clientTool to initiate the OAuth login flow and obtain user authorization for Zerodha access.
Tool to complete authentication by providing the request token obtained after login.
Tool to place buy or sell orders for specified stocks on NSE or BSE with given quantity and order type.
Tool to fetch current stock portfolio holdings.
Tool to retrieve active mutual fund SIPs.
Tool to view mutual fund holdings (experimental).