Upstox MCP Server
About
A Model Context Protocol (MCP) server that integrates with the Upstox Trading API, enabling AI agents like Claude to securely access Indian stock market data, perform technical analysis, and view account information in read-only mode.
Details
- Author
- ravikant1918
- Categories
- Other, Finance, API
Jump to
2️⃣ Create Virtual Environment (Recommended)
python -m venv venv # On macOS/Linux source venv/bin/activate # On Windows venv\Scripts\activate
- Visit:[https://api.upstox.com/
- Login with your Upstox account
- Go to "My Apps"
- Click "Create App"
- Fill in details:
- App Name: "MCP Server"
- Redirect URL:http://localhost:8000/callback
- Select read-only permissions
- Follow Upstox OAuth flow
- Or use Upstox's token generation tool
- Token is valid for 24 hours (needs daily refresh)
# Required UPSTOX_ACCESS_TOKEN=your_access_token_here # Optional (for token auto-refresh) UPSTOX_API_KEY=your_api_key UPSTOX_API_SECRET=your_api_secret
- Never commit.envfile to version control
- Add.envto.gitignore
- Rotate tokens regularly
- Use read-only API scopes only
Upstox MCP Server: Global Model Context Protocol for Indian Equity Markets 📈
TheOfficial-style Upstox MCP Serverprovides a high-performanceModel Context Protocol (MCP)integration for theUpstox Trading API. It enables AI agents likeClaude Desktop,Cursor IDE, and custom LLM applications to securely access real-timeIndian stock market data (NSE, BSE, MCX), perform advancedtechnical analysis (RSI, MACD, Bollinger Bands), and manage portfolio information in astrictly read-only mode.
Optimized foralgorithmic trading,market analysis, andautomated researchonNifty 50,Bank Nifty, and thousands of Indian equities.
📖Featured on Modern AI Day:The USB Port for AI: Connecting Claude to Real-Time Market Data
🌐Live Demo Instance:https://mcp-server-upstox.onrender.com/mcp
- Framework:FastMCP(MCP Python SDK)
- API Engine:FastAPI&Uvicorn
- Data Science:Pandas,NumPy
- Technical Analysis:Pandas-TA
- Client Integration:Httpx,Upstox Python SDK
- Deployment:Docker,Render
Connect Claude Desktop to your remote instance in seconds usingBring Your Own Key (BYOK)support:
{ "mcpServers": { "Upstox-Remote": { "command": "npx", "args": [ "-y", "mcp-remote", "https://mcp-server-upstox.onrender.com/mcp", "--header", "X-Upstox-API-Key:YOUR_API_KEY", "--header", "X-Upstox-API-Secret:YOUR_API_SECRET", "--header", "X-Upstox-Access-Token:YOUR_ACCESS_TOKEN" ] } } }
- Live quotes-market_get_live_quote
- Search Instruments-market_search_instruments
- Historical data-market_get_historical_data(Custom ranges)
- Intraday candles-market_get_intraday_candles
- Granular Indicators- Individual tools for RSI, MACD, ADX, Bollinger Bands, etc.
- Fibonacci Levels-analysis_calculate_fibonacci_levels
- Candlestick Patterns-analysis_analyze_candlestick_patterns
- Smart Context-analysis_get_technical_analysis(Super Tool)
- Margin Details-account_get_user_margin
- Order Book-account_get_order_book
- Trade History-account_get_trade_history
- Portfolio- Holdings and Positions lists
- AI-First Design- Built specifically for AI agents
- Tool-Based Architecture- Natural language to API calls
- Multi-User Support- Secure "Bring Your Own Key" (BYOK) architecture
- Conversational Interface- No complex API knowledge needed
This MCP server is STRICTLY READ-ONLY
❌ No order placement
❌ No order modification
❌ No fund transfers
❌ No trading actions
Trading endpoints are intentionally excluded for your safety and security.
- Python 3.10 or higher
- Upstox Trading Account
- Upstox API credentials
git clone https://github.com/ravikant1918/mcp-server-upstox.git cd mcp-server-upstox
2️⃣ Create Virtual Environment (Recommended)
python -m venv venv # On macOS/Linux source venv/bin/activate # On Windows venv\Scripts\activate
- Visit:https://api.upstox.com/
- Login with your Upstox account
- Go to "My Apps"
- Click "Create App"
- Fill in details:
- App Name: "MCP Server"
- Redirect URL:http://localhost:8000/callback
- Select read-only permissions
- Follow Upstox OAuth flow
- Or use Upstox's token generation tool
- Token is valid for 24 hours (needs daily refresh)
# Required UPSTOX_ACCESS_TOKEN=your_access_token_here # Optional (for token auto-refresh) UPSTOX_API_KEY=your_api_key UPSTOX_API_SECRET=your_api_secret
- Never commit.envfile to version control
- Add.envto.gitignore
- Rotate tokens regularly
- Use read-only API scopes only
Option A — Standard IO (for Claude Desktop)
upstox-mcp # or upstox-mcp --transport stdio
Option B — HTTP Mode (for Cursor or Remote Access)
upstox-mcp --transport http # Server will start on http://localhost:8000
# Build and run docker-compose up -d # View logs docker-compose logs -f # Stop docker-compose down
# Build image docker build -t upstox-mcp . # Run container docker run -d \ -p 8000:8000 \ --env-file .env \ --name upstox-mcp \ upstox-mcp # View logs docker logs -f upstox-mcp # Stop container docker stop upstox-mcp
Server will be available at:http://localhost:8000/mcp
- macOS:~/Library/Application Support/Claude/claude_desktop_config.json
- Windows:%APPDATA%\Claude\claude_desktop_config.json
- Linux:~/.config/Claude/claude_desktop_config.json
{ "mcpServers": { "Upstox": { "command": "/absolute/path/to/venv/bin/upstox-mcp", "args": ["--transport", "stdio"], "env": { "UPSTOX_ACCESS_TOKEN": "YOUR_ACCESS_TOKEN" } } } }
# On macOS/Linux which upstox-mcp # On Windows (PowerShell) (Get-Command upstox-mcp).Path
- Open Cursor Settings
- Go toFeatures→MCP
- Add new server:
- Name: Upstox
- Type: HTTP
- URL:http://localhost:8000/mcp
Remote MCP (via mcp-remote) — BYOK Support
For running the server remotely or in a multi-user environment (e.g., Render), you can pass your credentials via headers. This is known asBring Your Own Key (BYOK).
{ "mcpServers": { "Upstox-Remote": { "command": "npx", "args": [ "-y", "mcp-remote", "https://mcp-server-upstox.onrender.com/mcp", "--header", "X-Upstox-API-Key:YOUR_API_KEY", "--header", "X-Upstox-API-Secret:YOUR_API_SECRET", "--header", "X-Upstox-Access-Token:YOUR_ACCESS_TOKEN" ] } } }
[!TIP] This allows multiple users to use the same server instance securely without sharing credentials on the server side.
"What's the current price of RELIANCE?" "Show me OHLC data for INFY" "Get live quote for TATAMOTORS on NSE" "What's the volume on SBIN today?"
"Run technical analysis on BHARTIARTL" "Show RSI and MACD for HDFCBANK" "Is TCS in a bullish or bearish trend?" "Find support and resistance levels for WIPRO" "Analyze ICICIBANK with EMA-20 and EMA-50"
"Show me 5-minute candles for RELIANCE" "Get 1-minute chart data for INFY" "Display 15-minute intraday data for SBIN"
"Show my Upstox account summary" "What's my available margin?" "List all my holdings" "Show my current positions and P&L" "What's my total portfolio value?" "How much profit/loss do I have in TRIDENT?"
"Analyze all my holdings technically and rank them by strength" "Compare HDFC Bank vs ICICI Bank - which is better?" "Find oversold stocks in my watchlist (RSI < 30)" "Which of my holdings are above their 50-day EMA?" "Show me stocks breaking resistance levels today"
[!NOTE] All tools return a standardized JSON response:{ "success": true, "data": ..., "error": null, "metadata": ... }.
{ "symbol": "RELIANCE", # Stock symbol "exchange": "NSE_EQ" # NSE_EQ or BSE_EQ (default: NSE_EQ) }
{ "symbol": "INFY", "interval": "5minute", # 1minute, 3minute, 5minute, 10minute, 15minute, 30minute "exchange": "NSE_EQ" }
{ "symbol": "SBIN", "interval": "1day", # 1minute, 5minute, 15minute, 30minute, 1day, 1week "indicators": [ # Array of indicators "RSI", # Relative Strength Index "MACD", # Moving Average Convergence Divergence "EMA_20", # Exponential Moving Average (20 period) "EMA_50", "SMA_200", # Simple Moving Average (200 period) "BBANDS", # Bollinger Bands "VWAP", # Volume Weighted Average Price "ATR" # Average True Range ], "exchange": "NSE_EQ" }
- RSI- Momentum oscillator (14 period default)
- MACD- Trend-following indicator
- EMA_x- Exponential Moving Average (e.g., EMA_20, EMA_50, EMA_200)
- SMA_x- Simple Moving Average (e.g., SMA_50, SMA_200)
- BBANDS- Bollinger Bands (volatility)
- VWAP- Volume Weighted Average Price
- ATR- Average True Range (volatility)
- Price data
- Calculated indicators
- Detected candlestick patterns
- Trend context (Bullish/Bearish/Sideways)
- Support and resistance levels
┌─────────────────┐ │ AI Agent │ (Claude Desktop, Cursor, etc.) │ (Claude/GPT) │ └────────┬────────┘ │ │ MCP Protocol │ ┌────────▼────────┐ │ FastMCP │ (MCP Server Framework) │ Server │ └────────┬────────┘ │ │ Python Functions │ ┌────────▼────────┐ │ Upstox API │ (Read-Only Access) │ Client │ └────────┬────────┘ │ │ HTTPS │ ┌────────▼────────┐ │ Upstox │ (Live Market Data) │ Backend │ └─────────────────┘
- Framework: FastMCP (Model Context Protocol)
- API Client: Upstox Python SDK
- Technical Analysis: pandas-ta
- Web Server: Uvicorn (for HTTP mode)
- Containerization: Docker, Docker Compose
Problem: Access token expired (tokens are valid for 24 hours)
# Generate new token from Upstox # Update .env file with new token # Restart the MCP server
2. "Command not found: upstox-mcp"
Problem: Package not installed or not in PATH
# Activate virtual environment source venv/bin/activate # macOS/Linux venv\Scripts\activate # Windows # Reinstall package pip install -e .
Problem: Configuration file path or format issue
- Verify config file location
- Check JSON syntax (use a JSON validator)
- Ensure absolute path to executable
- Restart Claude Desktop
4. "No data returned" for Intraday Candles
Problem: Market closed or no recent trading activity
- Check if market is open (9:15 AM - 3:30 PM IST, Mon-Fri)
- Try a different interval
- Verify symbol is correct
Problem: Too many API calls in short time
- Add delays between requests
- Implement caching (future enhancement)
- Use batch queries when possible
- Token Expiry: Access tokens expire every 24 hours and need manual refresh
- Read-Only: Cannot place trades (by design for safety)
- API Rate Limits: Subject to Upstox API rate limiting
- Market Hours: Live data only available during trading hours
- Historical Data: Limited by Upstox API data retention policies
- Caching layer for improved performance
- Basic candlestick pattern detection
- Granular Technical Indicators: 10+ new specialized TA tools
- Namespaced Tools: Logical grouping (market_,analysis_,account_)
- Historical Data: Custom timeframe retrieval
- Instrument Search: Find symbols by name
- JSON-Safe Response Schema: Robust serialization for all agents
- Order & Trade Tracking: Real-time access to daily activity
- BYOK Support: Pass credentials via HTTP headers
- Multi-User Support: Secure architecture for shared deployments
- Dynamic Instructions: Interactive landing page with setup guides
- Automatic token refresh mechanism
- Database integration for long-term historical tracking
- Portfolio performance analytics
- Alert system
- Machine learning predictions
- Machine learning predictions
- Strategy builder
- Social trading features
- Mobile app integration
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (git checkout -b feature/AmazingFeature)
- Commit your changes (git commit -m 'Add some AmazingFeature')
- Push to the branch (git push origin feature/AmazingFeature)
- Open a Pull Request
# Clone your fork git clone https://github.com/ravikant1918/mcp-server-upstox.git # Install dev dependencies pip install -e ".[dev]" # Run tests pytest # Format code black . flake8 .
Q1 2026: Foundation & Core Analysis (Current)
- Initial MCP implementation for Upstox
- Comprehensive technical indicator tools
- Bring Your Own Key (BYOK) support for remote deployments
- Dynamic JSON configuration generator
- Sector-wise market analysis tools
- Option Chain analysis (Greeks calculation)
- Corporate actions tracking (Dividends, Splits)
- Multi-instrument correlation analysis
- Integrated Backtesting engine wrapper
- Webhook support for real-time alerts
- Native support for more MCP clients (e.g., Goose, Windsurf)
This project is licensed under the MIT License - see theLICENSEfile for details.
- FastMCP- MCP server framework
- Upstox- Trading API and market data
- pandas-ta- Technical analysis indicators
- Anthropic- Claude AI and MCP protocol
IMPORTANT: This project is not affiliated with, endorsed by, or sponsored by Upstox.
Sign in to leave a review
Use Google, GitHub, or an email account so ratings stay tied to real people.
No reviews posted yet.




