Kite---MCP
A Spring Boot application that integrates with Zerodha's Kite Connect API to provide trading capabilities through Model Context Protocol (MCP).
GitHub Stars
1
User Rating
Not Rated
Forks
0
Issues
0
Views
0
Favorites
0

&
Kite Trading MCP Server
A Spring Boot application that integrates with Zerodha's Kite Connect API to provide trading capabilities through Model Context Protocol (MCP). This allows AI assistants like Claude/Cursor to interact with your trading account through a standardized interface.
Features
Trading Operations
- Place buy/sell orders with limit price // to do : check this properly
- Get current positions with P&L analysis
- View portfolio holdings
- Get account margins
- Order history analysis
Portfolio Management
- Track P&L (realized and unrealized)
- Monitor portfolio value
- Risk analysis with sector exposure
Authentication
- Secure login through Kite Connect
- Session management with expiry handling
- Token-based authentication
Prerequisites
- Java 17 or higher
- Maven
- Zerodha Kite Connect API credentials
- Claude Desktop or compatible MCP client
Setup
- Clone the repository:
git clone https://github.com/mayur1377/Kite---MCP.git
cd Kite---MCP
Get your Kite Connect API credentials:
- Visit Kite Connect Developer Portal
- Sign in with your Zerodha account
- Click "New App" to create a new application
- Fill in the following details:
- App Name:
Kite Trading MCP
(or any name you prefer) - Website:
https://example.com
(use any dummy website for testing) - Redirect URL:
https://example.com/callback
(must match your website domain) - Description:
MCP server for trading automation
- App Name:
- After creating the app, you'll get:
- API Key
- API Secret
- Save these credentials securely
Configure your Kite API credentials in
src/main/resources/application.properties
:
kite.api.key=your_api_key
kite.api.secret=your_api_secret
- Build the project:
./mvnw clean package
The JAR file will be created at target/demo-0.0.1-SNAPSHOT.jar
Running the Application
Standalone Mode
java -jar target/demo-0.0.1-SNAPSHOT.jar
MCP Integration
To integrate with Claude Desktop or other MCP clients, create a configuration file (e.g., claude_desktop_config.json
):
{
"mcpServers": {
"kite-trading-mcp": {
"command": "/usr/bin/java",
"args": [
"-jar",
"/path/to/your/target/demo-0.0.1-SNAPSHOT.jar"
]
}
}
}
Replace /path/to/your/
with the actual path to your JAR file.
Authentication Flow
Each time you start a new session with Claude Desktop, you need to authenticate with Kite Connect:
- Ask Claude to use the
get_login_url
tool to get the Kite login URL - Open the URL in your browser and log in to your Zerodha account
- After successful login, you'll be redirected to your configured redirect URL (e.g.,
https://example.com/callback
) - In the URL, you'll find a
request_token
parameter, for example:https://example.com/callback?request_token=AbCdEfGhIjKlMnOpQrStUvWxYz123456
- Copy the
request_token
value (in this case:AbCdEfGhIjKlMnOpQrStUvWxYz123456
) - Ask Claude to use the
generate_session
tool with your request token - Once the session is generated, you can use all other trading tools
Note: The access token is valid for the current session only. You'll need to repeat this process each time you start a new session with Claude Desktop.
Available MCP Tools
The server provides the following tools that can be used by AI assistants:
get_login_url
: Get the Kite login URL for authorizationgenerate_session
: Generate a Kite session using request tokenplace_order
: Place trading orders with specified parameters (symbol, type, quantity, price)get_margins
: Get account margins and available cashget_holdings
: View current portfolio holdings with quantity and average priceget_positions
: Get current positions with P&L analysis (net and day positions)get_risk_analysis
: Analyze portfolio risk metrics and sector exposureget_order_analysis
: Get order history analysis with symbol-wise statistics