home / mcp / stock market analysis mcp server
A comprehensive Model Context Protocol (MCP) server for advanced stock market analysis, trend identification, portfolio management, dividend tracking, sector analysis, and risk metrics.
Configuration
View docs{
"mcpServers": {
"calvinliuu-stock_mcp_server": {
"command": "/absolute/path/to/stock_mcp_server/.venv/bin/python",
"args": [
"-m",
"mcp.server.fastmcp",
"run",
"/absolute/path/to/stock_mcp_server/stock.server.py"
],
"env": {
"STAKE_API_URL": "https://global-prd-api.stake.com",
"STAKE_ACCOUNT_ID": "acct_12345",
"STAKE_GRAPHQL_PATH": "/graphql"
}
}
}
}You have a practical, Python-based MCP server for stock market analysis that provides real-time pricing, historical data, portfolio management, technical indicators, risk metrics, sector and sentiment analysis, and even optional integration with Stake trading. It is designed to run locally, keep your data private, and expose a rich set of tools that you can access through an MCP-compatible client to analyze markets, manage portfolios, set alerts, and test strategies.
Launch the MCP server within a compatible client and begin by loading the stock analyzer MCP endpoint. Use the clientβs command palette or chat-based interface to request data or run analyses. Typical tasks you can perform include getting the latest price for a ticker, retrieving historical OHLC data, viewing your portfolio with real-time valuations, and running technical indicators like RSI and MACD. You can also set price or RSI alerts, track dividend income, analyze sector allocations, evaluate risk metrics such as Sharpe ratio and VaR, and monitor market sentiment signals. If you enable Stake integration, you can submit trades or manage orders through the same interface using the dedicated tooling. Start by querying simple data, then progressively combine tools to build dashboards, alerts, and automated signals.
Prerequisites you need before installing are Python 3.8 or higher and a MCP-compatible client. You should also have internet access to fetch market data.
Step 1: Prepare your environment. Create and activate a virtual environment to isolate dependencies.
Step 2: Install dependencies from the requirements file to ensure all needed packages are present.
Step 3: Run the MCP server using one of the provided configurations to enable a local stdio-based server that your MCP client can connect to.
Two stdio configurations are shown for running the MCP server locally. The first uses the Python module runner to start the server, and the second uses the FastMCP CLI. Each configuration uses an absolute path to the Python interpreter or the fastmcp launcher and passes the script that runs the stock server. Use one of these configurations in your MCP client setup.
You can also provide environment variables for the server, but the examples show an empty env block. You can fill in values as needed for your setup.
After the server starts, you can verify operation by querying common data points such as the latest price for a ticker or by requesting a portfolio view. The server exposes tools across data retrieval, portfolio management, technical analysis, alerts, dividends, sector analysis, risk metrics, and sentiment tracking. If you enable Stake integration, you can execute GraphQL-based trades with appropriate session tokens and API configuration.
If the MCP server does not start, ensure the paths in your configuration are absolute, confirm you are using the Python interpreter from your virtual environment, and verify all dependencies are installed (the environment should show yfinance, pandas, numpy, and fastmcp). If you encounter module not found errors, reactivate the virtual environment and reinstall dependencies. For data access issues, check your internet connection and ensure the ticker symbols are valid.
If you plan to forward trades to Stake, you must provide valid session tokens obtained from a manual login. Collect the access token and account ID from Stakeβs GraphQL requests, and supply optional extra headers as needed. Tokens expire, so you can provide a token_expiry timestamp to receive reminders for refreshing the session. The integration supports submitting market and limit orders, listing and canceling orders, and executing custom GraphQL operations.
RSI, MACD, and SMA crossover strategies are used to identify momentum and trend signals. For RSI, readings above 70 indicate overbought conditions, below 30 indicate oversold conditions. The SMA crossover strategy signals a potential buy when the short-term SMA crosses above the long-term SMA (e.g., 20-day vs 50-day). The MACD is used to detect momentum changes, with bullish crossovers suggesting upward momentum and bearish crossovers suggesting downward momentum.
The server follows a modular design with separate components for price data, portfolio management, analysis, alerts, dividends, sector analysis, risk metrics, and sentiment tracking. Each module is self-contained and can be updated independently, while a shared utility layer handles data persistence.
All data is stored locally on your machine to keep your information private. Portfolio holdings, transactions, alerts, and sentiment history reside in data/ files within your project directory. Market data requests may fetch data from external sources, but personal data remains local.
Follow a disciplined approach: diversify holdings, monitor risk metrics, and regularly rebalance. Use alerts to stay informed of price moves or RSI conditions. Maintain a clean data directory and back up the data/ folder periodically.
Core dependencies include yfinance for data, pandas for analysis, numpy for numerical computations, and fastmcp for the MCP server framework. Ensure your environment has compatible versions as specified in the installation flow.
Use one of the two stdio configurations to start the server from your MCP client. The first uses a Python interpreter path and the second uses the FastMCP launcher. Both options require absolute paths to your installation.
Fetches the most recent market price for a given ticker symbol.
Retrieves historical OHLCV data for a ticker over a specified period.
Returns comprehensive stock fundamentals and key metrics.
Adds a stock to the portfolio with automatic cost basis tracking.
Sells shares from the portfolio and computes realized P/L.
Displays current holdings with real-time valuations and P/L.
Shows the transaction history with optional limits.
Simple SMA crossover based buy signal detector.
Calculates RSI for a ticker with optional period and timeframe.
Calculates MACD for momentum analysis.
Performs multi-indicator trend analysis for a ticker.
Compares multiple tickers side-by-side on key metrics.
Configures price-based alerts for a ticker.
Configures RSI-based alerts for a ticker.
Evaluates active alerts and returns triggered ones.
Lists all configured alerts.
Removes alerts that have been triggered.
Deletes all configured alerts.
Fetches dividend history for a ticker over a period.
Retrieves current dividend yield and related metrics.
Estimates expected annual dividend income from the portfolio.
Finds high-yield stocks by minimum yield and sector.
Provides comprehensive sector analysis for a given sector.
Compares performance across major sectors.
Gets top performing stocks within a sector by a metric.
Analyzes your portfolioβs sector diversification.
Calculates risk-adjusted return with an optional risk-free rate.
Calculates a tickerβs beta against a benchmark.
Performs a comprehensive risk analysis for the portfolio.
Computes Value at Risk for a ticker with confidence and size.
Analyzes maximum drawdown and peak-to-trough changes.
Retrieves fundamental data and key metrics for a ticker.
Tracks historical sentiment scores over a period.