Skip to main content
Glama
MF MCP Server

MF MCP Server

by ronyv89
README.md
# MF MCP Server

A production-ready Model Context Protocol (MCP) server for Indian mutual funds, providing comprehensive NAV history, technical indicators, and screening capabilities.

## Features

### šŸ” Fund Discovery & Information
- **Search mutual funds** by name, AMC, or category
- **List all available funds** with pagination
- **Get detailed fund information** including metadata and performance summaries
- **Retrieve latest NAV** with change calculations

### šŸ“ˆ Technical Analysis
- **Complete indicator suite**: SMA, EMA, RSI, MACD, Bollinger Bands, ROC, Volatility, Drawdown
- **Rolling returns** over configurable periods (30d, 90d, 180d, 365d)
- **Signal generation** with bullish/bearish/neutral classifications
- **Trend and momentum analysis**

### šŸ“Š Advanced Features
- **Fund comparison** across multiple performance and technical metrics
- **Custom screening** with flexible rule-based filtering
- **Historical NAV data** with date range filtering
- **Performance analytics** with risk-adjusted metrics

### šŸš€ Enterprise Ready
- **Robust error handling** with user-friendly messages
- **In-memory caching** with configurable TTL
- **Request timeouts** and retry logic
- **TypeScript** with comprehensive type safety
- **Zod validation** for all inputs

## Supported Tools

| Tool | Description |
|------|-------------|
| `search_mutual_funds` | Search schemes by name, AMC, category |
| `list_mutual_funds` | Paginated listing of all available funds |
| `get_mutual_fund_details` | Detailed fund information and metadata |
| `get_latest_nav` | Current NAV with change calculations |
| `get_nav_history` | Historical NAV data with filtering |
| `compute_indicators` | Technical indicators and signals |
| `compare_mutual_funds` | Side-by-side fund comparison |
| `screen_mutual_funds` | Rule-based fund screening |

## Architecture

```
src/
ā”œā”€ā”€ index.ts                 # Application entry point
ā”œā”€ā”€ server.ts               # MCP server setup and tool registration
ā”œā”€ā”€ config/
│   └── env.ts             # Environment configuration
ā”œā”€ā”€ tools/                 # MCP tool implementations
ā”œā”€ā”€ services/              # Business logic layer
ā”œā”€ā”€ providers/             # Data provider integrations
ā”œā”€ā”€ analytics/             # Technical indicator calculations
ā”œā”€ā”€ utils/                 # Utility functions
└── types/                 # TypeScript type definitions
```

## Quick Start

### Installation

```bash
git clone <repository-url>
cd mf-mcp-server
npm install
```

### Environment Setup

```bash
cp .env.example .env
# Edit .env file with your configuration
```

### Development

```bash
npm run dev
```

### Production Build

```bash
npm run build
npm start
```

## Environment Variables

```bash
# MCP Server Configuration
NODE_ENV=development
LOG_LEVEL=info

# API Configuration
MFAPI_BASE_URL=https://api.mfapi.in
MFAPI_TIMEOUT=10000
CACHE_TTL_SECONDS=300

# Rate limiting
REQUESTS_PER_MINUTE=60
```

## Claude Desktop Configuration

Add this to your Claude Desktop configuration:

```json
{
  "mcpServers": {
    "mf-mcp-server": {
      "command": "node",
      "args": ["/path/to/mf-mcp-server/dist/index.js"],
      "env": {
        "NODE_ENV": "production"
      }
    }
  }
}
```

For development with TypeScript:

```json
{
  "mcpServers": {
    "mf-mcp-server": {
      "command": "npx",
      "args": ["tsx", "/path/to/mf-mcp-server/src/index.ts"],
      "cwd": "/path/to/mf-mcp-server"
    }
  }
}
```

## Usage Examples

### Search for Funds

```
Search for HDFC equity funds with a limit of 5 results
```

### Get Technical Indicators

```
Compute RSI, MACD, and Bollinger Bands for scheme code 119551
```

### Screen High-Performing Funds

```
Find funds with RSI < 30, 1-year returns > 15%, and volatility < 20%
```

### Compare Fund Performance

```
Compare schemes 119551, 120503, and 118989 across returns, volatility, and signals
```

## Technical Indicators

### Moving Averages
- **Simple Moving Average (SMA)**: Trend identification
- **Exponential Moving Average (EMA)**: Responsive trend analysis

### Momentum Oscillators
- **RSI (Relative Strength Index)**: Overbought/oversold conditions
- **Rate of Change (ROC)**: Momentum measurement

### Trend Analysis
- **MACD**: Moving average convergence divergence
- **Bollinger Bands**: Volatility-based support/resistance

### Risk Metrics
- **Standard Deviation**: Volatility measurement
- **Maximum Drawdown**: Downside risk assessment
- **Rolling Returns**: Performance over multiple timeframes

## Data Sources

### Primary: MFAPI (api.mfapi.in)
- Real-time NAV data
- Historical price series
- Scheme metadata
- Free public API with good coverage

### Planned: AMFI Integration
- Enhanced fund metadata
- Category classifications
- Regulatory information
- Fallback data source

## Performance & Limitations

### Caching Strategy
- **Default TTL**: 5 minutes for most data
- **Latest NAV**: 1 minute TTL
- **Historical data**: 10 minute TTL
- **Fund listings**: 30 minute TTL

### API Rate Limits
- **Default**: 60 requests per minute
- **Retry logic**: 3 attempts with exponential backoff
- **Timeout**: 10 seconds per request

### Data Limitations
- NAV-based analysis (not suitable for intraday trading)
- Limited fundamental data (P/E ratios, holdings not available)
- Historical data availability varies by fund
- Technical analysis requires minimum 50 data points

## Development

### Scripts

```bash
npm run dev          # Development with hot reload
npm run build        # Production build
npm start            # Run production build
npm run lint         # ESLint checks
npm run lint:fix     # Fix linting issues
npm run type-check   # TypeScript type checking
```

### Testing

```bash
# Manual testing with Claude Desktop or MCP inspector
npx @modelcontextprotocol/inspector build/index.js
```

### Code Quality

- **TypeScript**: Strict mode enabled
- **ESLint**: Code quality and consistency
- **Zod**: Runtime type validation
- **Error handling**: Comprehensive error boundaries

## Roadmap

### Phase 1 (Current)
- āœ… Core MCP tools implementation
- āœ… Technical indicators
- āœ… Fund screening
- āœ… MFAPI integration

### Phase 2 (Planned)
- [ ] AMFI data integration
- [ ] Portfolio analysis tools
- [ ] Expense ratio comparisons
- [ ] Fund manager analytics

### Phase 3 (Future)
- [ ] Real-time market data
- [ ] Holdings analysis
- [ ] Sector allocation tools
- [ ] Risk-adjusted metrics (Sharpe, Sortino)

## Important Disclaimers

āš ļø **Investment Advisory Warning**: This tool is for informational purposes only and does not constitute investment advice. Technical analysis of mutual funds based solely on NAV data has limitations:

- **NAV vs Market Price**: Mutual funds trade at NAV, not market prices
- **Daily Frequency**: Most indicators designed for higher-frequency data
- **Fundamental Focus**: Long-term mutual fund performance depends more on underlying holdings than technical patterns
- **Market Context**: Technical signals should be considered alongside fundamental analysis and market conditions

Always consult with qualified financial advisors before making investment decisions.

## Contributing

1. Fork the repository
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

## Support

- šŸ“š [MCP Documentation](https://modelcontextprotocol.io)
- šŸ› [Report Issues](https://github.com/your-username/mf-mcp-server/issues)
- šŸ’¬ [Discussions](https://github.com/your-username/mf-mcp-server/discussions)

---

**šŸ”„ Generated with [Claude Code](https://claude.ai/code)**