trackmcp
Back to directory
quantabox

fyers-mcp-server

View on GitHub

MCP server for FYERS API v3 with auto Oauth

2 stars PythonServers & Infrastructure Updated Aug 30, 2025

Documentation

Fyers MCP Server

> MCP (Model Context Protocol) server for Fyers API v3 with automated OAuth authentication

Python 3.10+
Fyers API v3
License: MIT

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

[](https://github.com/user-attachments/assets/d0aba24d-4471-442a-9120-983b413f5154)

โœจ Features

๐Ÿ” Smart Authentication

  • One-click OAuth flow with automatic browser handling
  • Persistent token storage in `.env` file
  • 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

1. Installation

bash
# 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

1. Create Fyers API App:

    2. Configure Environment:

    bash
    cp .env.example .env

    Edit `.env` file:

    env
    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`

    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

    1. Restart Claude Desktop

    2. Authenticate: In Claude, type: `authenticate`

    3. Browser will open โ†’ Login to Fyers โ†’ Automatic token capture

    4. Start trading: All 11 tools are now available!

    ๐Ÿ› ๏ธ Available Tools

    Authentication & Profile

    • `authenticate()` - One-click OAuth authentication
    • `check_auth_status()` - Verify current authentication
    • `get_profile()` - User profile information

    Portfolio & Funds

    • `get_funds()` - Account balance and margin details
    • `get_holdings()` - Portfolio holdings with P&L
    • `get_positions()` - Current trading positions

    Orders & Trading

    • `place_order(symbol, quantity, order_type, side, ...)` - Place new orders
    • `modify_order(order_id, quantity, limit_price, ...)` - Modify existing orders
    • `cancel_order(order_id)` - Cancel pending orders
    • `get_orders()` - Order history and status

    Market Data

    • `get_quotes(symbols)` - Real-time quotes for multiple symbols

    ๐Ÿ“– Usage Examples

    Portfolio Analysis

    code
    # Check account balance
    get_funds()
    
    # View all holdings with P&L
    get_holdings()
    
    # Check current positions
    get_positions()

    Order Management

    code
    # 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

    code
    # 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 order
    • `STOPLIMIT` - Stop limit order

    Product Types

    • `MARGIN` - Margin trading (intraday with leverage)
    • `CNC` - Cash and Carry (delivery)
    • `INTRADAY` - Intraday trading
    • `BO` - Bracket Order
    • `CO` - Cover Order

    Validity Options

    • `DAY` - Valid for current trading day
    • `IOC` - Immediate or Cancel
    • `GTD` - Good Till Date

    ๐Ÿ› Troubleshooting

    Common Issues

    1. Authentication Failed

    bash
    # Check credentials in .env file
    cat .env | grep FYERS
    
    # Verify app configuration at https://myapi.fyers.in/dashboard/

    2. Claude Desktop Connection Issues

    bash
    # 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-EQ` for equity
    • Check market hours (9:15 AM - 3:30 PM IST)
    • Ensure sufficient funds/margin

    Debug Mode

    Enable detailed logging:

    bash
    export LOG_LEVEL=DEBUG
    uv run python fyers_mcp_complete.py

    ๐Ÿšง Development

    Project Structure

    code
    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

    1. Fork the repository

    2. Create feature branch: `git checkout -b feature/new-tool`

    3. Add MCP tool: Use `@mcp.tool()` decorator

    4. Test with Claude Desktop

    5. Submit pull request

    Testing

    bash
    # Install development dependencies
    uv sync --dev
    
    # Run tests
    uv run pytest
    
    # Type checking
    uv run mypy fyers_mcp_complete.py

    ๐Ÿ“‹ API Reference

    Authentication Flow

    mermaid
    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.

    ๐Ÿ“Š Status

    • Current Version: 1.0.0
    • API Compatibility: Fyers API v3.1.7
    • Python Support: 3.10+
    • Tools Available: 11/11 โœ…
    • Production Ready: Yes โœ…

    Made with โค๏ธ for the trading community

    Enable algorithmic trading with Claude's intelligence

    Frequently asked questions

    What is fyers-mcp-server?

    fyers-mcp-server is MCP server for FYERS API v3 with auto Oauth

    How do I install fyers-mcp-server?

    Open the GitHub repository and follow its README. Most MCP servers are added to your client's MCP config, then called by your agent.

    Is fyers-mcp-server open source?

    Yes โ€” it is hosted on GitHub at https://github.com/quantabox/fyers-mcp-server and has 2 stars.

    Related MCP tools

    Run your own MCP server? See who uses it and what to fix.

    Measure it with TrackMCP