Fyers MCP Server
Enables Claude to interact with the Fyers trading platform for portfolio management, order placement, market data retrieval, and automated OAuth authentication for Indian stock markets.
README
Fyers MCP Server
MCP (Model Context Protocol) server for Fyers API v3 with automated OAuth authentication
A comprehensive MCP server that enables Claude Desktop to interact with Fyers trading platform through a secure, automated authentication flow. Supports all major trading operations including portfolio management, order placement, and real-time market data.
🎬 Demo
<video src="https://github.com/quantabox/fyers-mcp-server/assets/fyers-mcp.mp4" width ="300"/>
✨ Features
🔐 Smart Authentication
- One-click OAuth flow with automatic browser handling
- Persistent token storage in
.envfile - Auto-refresh capabilities with session management
📊 Complete Trading Toolkit
- Portfolio Management: Holdings, positions, funds, profile
- Order Management: Place, modify, cancel orders
- Market Data: Real-time quotes for multiple symbols
- Order History: Complete order and trade book
🚀 Production Ready
- Full error handling with detailed error messages
- Type safety with parameter validation
- Comprehensive logging for debugging
- Claude Desktop integration with simple configuration
🚀 Quick Start
Prerequisites
- Python 3.10 or higher
- Claude Desktop installed
- Fyers Trading Account with API access
1. Installation
# Clone the repository
git clone https://github.com/quantabox/fyers-mcp-server.git
cd fyers-mcp-server
# Install dependencies using uv (recommended)
curl -LsSf https://astral.sh/uv/install.sh | sh
uv sync
# Or install with pip
pip install .
2. Get Fyers API Credentials
-
Create Fyers API App:
- Visit Fyers API Dashboard
- Create a new app with redirect URI:
http://localhost:8080/ - Note down your
App IDandSecret Key
-
Configure Environment:
cp .env.example .envEdit
.envfile:FYERS_CLIENT_ID=YOUR_APP_ID-100 # e.g., ABC123XYZ-100 FYERS_SECRET_KEY=YOUR_SECRET_KEY # Secret from Fyers app FYERS_REDIRECT_URI=http://localhost:8080/
3. Configure Claude Desktop
Add to your Claude Desktop configuration file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"fyers-mcp-server": {
"command": "uv",
"args": [
"run",
"--directory",
"/path/to/fyers-mcp-server",
"python",
"fyers_mcp_complete.py"
],
"env": {
"PYTHONWARNINGS": "ignore"
}
}
}
}
4. First Run
- Restart Claude Desktop
- Authenticate: In Claude, type:
authenticate - Browser will open → Login to Fyers → Automatic token capture
- Start trading: All 11 tools are now available!
🛠️ Available Tools
Authentication & Profile
authenticate()- One-click OAuth authenticationcheck_auth_status()- Verify current authenticationget_profile()- User profile information
Portfolio & Funds
get_funds()- Account balance and margin detailsget_holdings()- Portfolio holdings with P&Lget_positions()- Current trading positions
Orders & Trading
place_order(symbol, quantity, order_type, side, ...)- Place new ordersmodify_order(order_id, quantity, limit_price, ...)- Modify existing orderscancel_order(order_id)- Cancel pending ordersget_orders()- Order history and status
Market Data
get_quotes(symbols)- Real-time quotes for multiple symbols
📖 Usage Examples
Portfolio Analysis
# Check account balance
get_funds()
# View all holdings with P&L
get_holdings()
# Check current positions
get_positions()
Order Management
# Place a market order
place_order("NSE:SBIN-EQ", 10, "MARKET", "BUY")
# Place a limit order
place_order("NSE:RELIANCE-EQ", 5, "LIMIT", "BUY", limit_price=2500)
# Modify an order
modify_order("ORDER_ID", quantity=15, limit_price=2550)
# Cancel an order
cancel_order("ORDER_ID")
Market Data
# Get live quotes
get_quotes("NSE:SBIN-EQ,NSE:RELIANCE-EQ,NSE:TCS-EQ")
🔧 Configuration Options
Order Types
MARKET- Market order (immediate execution)LIMIT- Limit order (execute at specific price)STOP- Stop loss orderSTOPLIMIT- Stop limit order
Product Types
MARGIN- Margin trading (intraday with leverage)CNC- Cash and Carry (delivery)INTRADAY- Intraday tradingBO- Bracket OrderCO- Cover Order
Validity Options
DAY- Valid for current trading dayIOC- Immediate or CancelGTD- Good Till Date
🐛 Troubleshooting
Common Issues
1. Authentication Failed
# Check credentials in .env file
cat .env | grep FYERS
# Verify app configuration at https://myapi.fyers.in/dashboard/
2. Claude Desktop Connection Issues
# Test MCP server directly
cd /path/to/fyers-mcp-server
uv run python fyers_mcp_complete.py
# Check Claude Desktop logs (macOS)
tail -f ~/Library/Logs/Claude/mcp.log
3. Order Placement Errors
- Verify symbol format:
NSE:SYMBOL-EQfor equity - Check market hours (9:15 AM - 3:30 PM IST)
- Ensure sufficient funds/margin
Debug Mode
Enable detailed logging:
export LOG_LEVEL=DEBUG
uv run python fyers_mcp_complete.py
🚧 Development
Project Structure
fyers-mcp-server/
├── fyers_mcp_complete.py # Main MCP server
├── pyproject.toml # Dependencies
├── .env.example # Environment template
├── claude_config.json # Claude Desktop config
└── README.md # This file
Adding New Features
- Fork the repository
- Create feature branch:
git checkout -b feature/new-tool - Add MCP tool: Use
@mcp.tool()decorator - Test with Claude Desktop
- Submit pull request
Testing
# Install development dependencies
uv sync --dev
# Run tests
uv run pytest
# Type checking
uv run mypy fyers_mcp_complete.py
📋 API Reference
Authentication Flow
graph TD
A[Claude: authenticate] --> B[Generate Auth URL]
B --> C[Open Browser]
C --> D[User Login]
D --> E[Auth Code Capture]
E --> F[Exchange for Token]
F --> G[Store in .env]
G --> H[Ready for Trading]
Error Handling
All functions return standardized responses:
- ✅ Success: Clear confirmation with relevant data
- ❌ Error: Detailed error message with troubleshooting hints
🤝 Contributing
We welcome contributions! Please see our Contributing Guidelines for details.
Areas for Contribution
- WebSocket real-time data streaming
- Advanced order types (OCO, Iceberg)
- Portfolio analytics and reporting
- Options chain analysis tools
- Risk management features
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
⚠️ Disclaimer
This software is for educational and development purposes. Trading involves financial risk. Users are responsible for their trading decisions and should thoroughly test in demo environments before live trading.
🔗 Links
📊 Status
- Current Version: 1.0.0
- API Compatibility: Fyers API v3.1.7
- Python Support: 3.10+
- Tools Available: 11/11 ✅
- Production Ready: Yes ✅
<p align="center"> <strong>Made with ❤️ for the trading community</strong><br> <sub>Enable algorithmic trading with Claude's intelligence</sub> </p>
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。