zerodha
Zerodha MCP Server & Client - AI Agent (w/Agno & w/Google ADK)
claude mcp add --transport stdio mtwn105-zerodha-mcp python server.py \ --env PORT="8001" \ --env MCP_HOST="localhost" \ --env MCP_PORT="8001" \ --env SERVER_MODE="sse" \ --env GOOGLE_API_KEY="your_google_api_key" \ --env OPENAI_API_KEY="your_openai_api_key" \ --env ZERODHA_API_KEY="your_api_key" \ --env ZERODHA_API_SECRET="your_api_secret"
How to use
This Zerodha MCP Server provides a Python-based backend that connects to Zerodha's trading platform and exposes trading operations via the Model Context Protocol (MCP). It supports account management, placing and modifying orders, retrieving holdings, margins, positions, and order histories, as well as generating login URLs and access tokens through the MCP-enabled endpoints. The server can be interacted with through multiple clients (Agno-based, Google ADK-based, or Gradio) to provide an interactive, natural-language interface for trading operations. To start, ensure your environment variables contain your Zerodha API credentials and OpenAI/Google keys as needed. Once running, you can use the built-in tools like get_login_url, get_access_token, get_user_profile, get_margins, get_holdings, get_positions, get_orders, get_order_history, get_order_trades, place_order, modify_order, and cancel_order to manage your Zerodha account via MCP-compatible clients. The included clients (Agno, Gradio, and Google ADK) connect to the MCP server and present an accessible UI or chat-based interface for executing these actions.
To interact using the server directly, connect a client to the MCP host/port you started the server on, then issue commands through the MCP interface. The Agno client provides a conversational interface, the Gradio client offers a web UI, and the Google ADK client enables integration with Google ADK workflows. Each client authenticates with the MCP server and forwards user intents to Zerodha through the server.
How to install
Prerequisites:
- Python 3.8+ installed
- Git installed
- Zerodha account with Personal API access and API key/secret
- Optional: OpenAI API key (for Agno/AI-assisted chat) and Google API key (for Google ADK)
Install steps:
-
Clone the repository: git clone https://github.com/mtwn105/zerodha-mcp-server-client.git cd zerodha-mcp-server-client
-
Create and activate a virtual environment: python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies: pip install -r requirements.txt
-
Configure environment variables:
- Copy the example env file and edit values
cp .env.example .env
Edit .env with your credentials and settings
- Copy the example env file and edit values
cp .env.example .env
-
Run the server (example): python server.py
-
Optional: Run a client (Agno, Gradio, or Google ADK) to connect to the MCP server using host/port from the .env file or CLI arguments.
Additional notes
Tips and notes:
- Ensure ZERODHA_API_KEY and ZERODHA_API_SECRET are kept secret and not committed to version control.
- The SERVER_MODE can be 'sse' (Server-Sent Events) or 'stdio' depending on your client integration; adjust in .env accordingly.
- If you encounter authentication issues, re-authenticate with Zerodha and refresh tokens as required by Zerodha's API workflow.
- The MCP_HOST and MCP_PORT settings determine where clients connect; keep them consistent across server and clients.
- The Gradio client requires OPENAI_API_KEY for AI-assisted features; ensure the key is valid and has access.
- For Google ADK integration, ensure GOOGLE_API_KEY or appropriate Application Default Credentials are configured.
- Review the tools list (get_login_url, get_access_token, get_user_profile, get_margins, get_holdings, get_positions, get_orders, get_order_history, get_order_trades, place_order, modify_order, cancel_order) to plan automation flows and natural language commands.
- If running multiple MCP servers, use distinct host/port pairs and environment configurations to avoid conflicts.
Related MCP Servers
pgmcp
An MCP server to query any Postgres database in natural language.
okta
The Okta MCP Server is a groundbreaking tool built by the team at Fctr that enables AI models to interact directly with your Okta environment using the Model Context Protocol (MCP). Built specifically for IAM engineers, security teams, and Okta administrators, it implements the MCP specification to help work with Okta enitities
openai -agent-dotnet
Sample to create an AI Agent using OpenAI models with any MCP server running on Azure Container Apps
fast -telegram
Telegram MCP Server and HTTP-MTProto bridge | Multi-user auth, intelligent search, file sending, web setup | Docker & PyPI ready
mcp-framework
Rust MCP framework for building AI agents
mcp-agent-proxy
An MCP server that exposes local and remote agents across different servers as MCP tools.