Stock Analysis MCP Server
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
Stock Analysis MCP Server
A comprehensive Model Context Protocol (MCP) server for stock analysis, portfolio optimization, and technical analysis focused on Indian stock markets (NSE/BSE). Built with configurable JSON files for easy customization and deployment.
π Features
π Portfolio Optimization: Modern Portfolio Theory with Sharpe ratio optimization
π° Real-time Stock Prices: Current prices for NSE/BSE listed companies
π Historical Data Analysis: Fetch and analyze historical stock data
π Technical Analysis: Generate detailed technical analysis reports
π Predefined Watchlists: Nifty50, BankNifty, IT stocks, Pharma stocks, and more
βοΈ JSON Configuration: Easy customization via config files
π€ MCP Integration: Seamless integration with AI assistants like Claude
π Caching: LRU caching for improved performance
Related MCP server: Tapetide - Indian Stock Market MCP
π¦ Quick Start
Installation
git clone <your-repo-url>
cd stock-analysis-mcp
pip install -e .[dev]MCP Client Setup (Claude Desktop)
Add to your claude_desktop_config.json:
{
"mcpServers": {
"stock-analysis": {
"command": "python",
"args": ["-m", "main"],
"cwd": "/path/to/stock-analysis-mcp"
}
}
}Basic Usage
# Get stock price
get_stock_price("RELIANCE")
# Analyze portfolio
analyze_portfolio(["RELIANCE", "TCS", "HDFCBANK"])
# Use predefined watchlist
get_watchlist("nifty50")
# Technical analysis
technical_analysis(["RELIANCE", "TCS"], "3mo")βοΈ Configuration
The server uses JSON files for easy configuration:
config.json - Server Settings
{
"server": {
"name": "Stock_Analysis_MCP",
"description": "Stock analysis server"
},
"market": {
"default_exchange": "NS",
"currency": "INR"
},
"analysis": {
"default_period": "1y",
"cache_size": 32
}
}portfolios.json - Watchlists & Portfolios
{
"watchlists": {
"nifty50": ["RELIANCE", "TCS", "HDFCBANK", "..."],
"custom_tech": ["TCS", "INFY", "WIPRO"]
},
"custom_portfolios": {
"conservative": {
"description": "Low risk portfolio",
"stocks": ["HDFCBANK", "TCS", "RELIANCE"],
"target_allocation": "optimized"
}
}
}π οΈ Available Tools
Tool | Description |
| Get current stock price |
| Get historical data |
| Optimize portfolio allocation |
| Get predefined watchlist |
| Technical analysis |
| Compare two stocks |
| Server capabilities |
π Predefined Watchlists
nifty50: Top 50 NSE stocks
banknifty: Banking sector stocks
it_stocks: IT/Technology companies
pharma_stocks: Pharmaceutical companies
π― Example Use Cases
With Claude Desktop
"Analyze my portfolio with Reliance, TCS, and HDFC Bank"
"What's the current price of Infosys?"
"Compare Reliance and TCS stocks"
"Show me the Nifty50 watchlist"
Portfolio Optimization
# Custom portfolio
analyze_portfolio(["RELIANCE", "TCS", "HDFCBANK", "INFY", "HINDUNILVR"])
# Predefined portfolio
analyze_predefined_portfolio("conservative")Technical Analysis
# Multi-stock analysis
technical_analysis(["RELIANCE", "TCS"], "3mo")
# Comparison analysis
compare_stocks_prompt("RELIANCE", "TCS")Installation
Prerequisites
Python 3.10 or higher
Setup
Clone the repository:
git clone https://github.com/yourusername/stock-analysis.git
cd stock-analysisCreate and activate a virtual environment:
# Windows
python -m venv .venv
.venv\Scripts\activate
# Linux/macOS
python -m venv .venv
source .venv/bin/activateInstall the package in development mode:
pip install -e .[dev]Usage
Running the MCP Server
python main.pyUsing as a Library
import main
# Get current stock price
price_data = main.get_stock_price("RELIANCE")
# Analyze portfolio
portfolio_result = main.analyze_portfolio(["RELIANCE", "TCS", "INFY"])
# Get historical data
historical_data = main.get_stock_history("RELIANCE", period="1y")Development
Running Tests
This project uses pytest for testing:
# Run tests
uv pip run pytest
# Run tests with coverage report
uv pip run pytest --cov=main --cov-report=term-missingCode Formatting and Linting
# Format code with black
uv pip run black .
# Sort imports with isort
uv pip run isort .
# Lint with flake8
uv pip run flake8 .
# Type check with mypy
uv pip run mypy main.pyGitHub Workflow
This project includes a GitHub Actions workflow that automatically:
Runs tests on multiple Python versions (3.9, 3.10, 3.11)
Checks code formatting with Black
Sorts imports with isort
Performs linting with flake8
Runs type checking with mypy
Generates test coverage reports
The workflow runs on every push to the main branch, on pull requests, and weekly for regular checks.
Installation
This project uses uv for dependency management.
Prerequisites
Python 3.9 or higher
uv package manager
Setup
Clone the repository:
git clone https://github.com/yourusername/stock-analysis.git
cd stock-analysisCreate and activate a virtual environment with uv:
uv venv
# On Windows
.venv\Scripts\activate
# On Unix/MacOS
source .venv/bin/activateInstall dependencies:
uv syncInstall development dependencies:
uv sync --extra devUsage
Running the MCP Server
python -m stock_analysis.mainUsing the Analysis Functions
from stock_analysis.core import StockAnalyzer
analyzer = StockAnalyzer()
# Get current stock price
price_data = analyzer.get_stock_price("RELIANCE")
# Analyze portfolio
portfolio_result = analyzer.analyze_portfolio(["RELIANCE", "TCS", "INFY"])
# Get historical data
historical_data = analyzer.get_stock_history("RELIANCE", period="1y")API Reference
Main Functions
get_stock_price(symbol: str)- Get current stock priceanalyze_portfolio(symbols: list)- Optimize portfolio allocationget_stock_history(symbol: str, period: str)- Get historical datacompare_stocks(symbol1: str, symbol2: str)- Compare two stockstechnical_analysis(symbols: list, period: str)- Generate technical analysis
Stock Symbol Format
All stock symbols are automatically normalized to NSE format (e.g., "RELIANCE" becomes "RELIANCE.NS").
Development
Running Tests
# Run all tests
uv run pytest
# Run with coverage
uv run pytest --cov=stock_analysis
# Run specific test file
uv run pytest tests/test_core.pyCode Formatting
# Format code with black
uv run black stock_analysis tests
# Sort imports with isort
uv run isort stock_analysis tests
# Run linting
uv run flake8 stock_analysis tests
# Type checking
uv run mypy stock_analysisPre-commit Hooks
Install pre-commit hooks to ensure code quality:
uv run pre-commit installProject Structure
stock-analysis/
βββ stock_analysis/ # Main package
β βββ __init__.py
β βββ main.py # MCP server entry point
β βββ core.py # Core analysis functions
β βββ utils.py # Utility functions
βββ tests/ # Test files
β βββ __init__.py
β βββ test_core.py
β βββ test_utils.py
βββ .github/workflows/ # GitHub Actions
β βββ ci.yml
βββ pyproject.toml # Project configuration
βββ README.md
βββ LICENSEContributing
Fork the repository
Create a feature branch (
git checkout -b feature/amazing-feature)Commit your changes (
git commit -m 'Add some amazing feature')Push to the branch (
git push origin feature/amazing-feature)Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Disclaimer
This tool is for educational and research purposes only. Always consult with a qualified financial advisor before making investment decisions. The authors are not responsible for any financial losses incurred using this tool.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelogβ¦
This server cannot be deployed
Maintenance
Related MCP Connectors
Live stock quotes, a stock screener, crypto prices and FX rates as agent tools.
Hosted MCP server for Indian NSE/BSE stock research: 59 tools for quotes, financials and ratios, peers, shareholding and pledge, filings with extracted facts, screens, F&O and FII/DII context. Source and freshness on every answer; no buy/sell calls.
Connect brokerage accounts to AI assistants: holdings, orders, asset lookup, and approved trading.
Live crypto + IDX stock market intelligence for AI agents β 19 tools, no API key.
Related MCP Servers
- AlicenseAqualityDmaintenanceProvides AI agents with real-time financial market intelligence including stock quotes, crypto data, technical analysis, and portfolio insights. Enables natural language queries for current prices, technical indicators, asset comparisons, and portfolio analysis.1710MIT
- AlicenseAqualityBmaintenanceIndian stock market (NSE & BSE) MCP server with 55 tools: live quotes, financials, technicals, a 326-ratio screener, FII/DII flows, option chains with IV, parsed annual reports and concall transcripts, IPOs and portfolio tracking for ~8,200 stocks.55143 npm151MIT
- AlicenseAqualityCmaintenanceEnables AI assistants to query live NSE & BSE stock market data, with 55 tools covering quotes, financials, screeners, FII/DII flows, option chains, and company filings.55MIT
- FlicenseNot gradedqualityAmaintenanceEnables AI assistants to search, screen, and analyze 8,200+ NSE and BSE listed securities through 55 tools covering live quotes, financials, technical indicators, FII/DII flows, option chains, filings, IPOs, bulk deals, and portfolio P&L.-