Modal MCP Stock Analysis Server
Provides real-time stock price lookup and comprehensive investment analysis for Amazon stock, including current price, YTD returns, P/E ratio, and investment score with buy/hold/sell recommendations.
Provides real-time stock price lookup and comprehensive investment analysis for AMD stock, including current price, YTD returns, P/E ratio, and investment score with buy/hold/sell recommendations.
Provides real-time stock price lookup and comprehensive investment analysis for Apple stock, including current price, YTD returns, P/E ratio, and investment score with buy/hold/sell recommendations.
Provides real-time stock price lookup and comprehensive investment analysis for Facebook (Meta) stock, including current price, YTD returns, P/E ratio, and investment score with buy/hold/sell recommendations.
Provides real-time stock price lookup and comprehensive investment analysis for Alphabet (Google) stock, including current price, YTD returns, P/E ratio, and investment score with buy/hold/sell recommendations.
Provides real-time stock price lookup and comprehensive investment analysis for Meta stock, including current price, YTD returns, P/E ratio, and investment score with buy/hold/sell recommendations.
Provides real-time stock price lookup and comprehensive investment analysis for Netflix stock, including current price, YTD returns, P/E ratio, and investment score with buy/hold/sell recommendations.
Provides real-time stock price lookup and comprehensive investment analysis for NVIDIA stock, including current price, YTD returns, P/E ratio, and investment score with buy/hold/sell recommendations.
Provides real-time stock price lookup and comprehensive investment analysis for Tesla stock, including current price, YTD returns, P/E ratio, and investment score with buy/hold/sell recommendations.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Modal MCP Stock Analysis Serverwhat's the stock price of AAPL?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
๐ Modal MCP Stock Analysis Server
A cloud-hosted Model Context Protocol (MCP) server for real-time stock analysis, built with Modal and FastAPI.
๐ Overview
This MCP server provides stock analysis tools through a RESTful API, demonstrating how to implement the Model Context Protocol in a distributed, cloud-native architecture.
๐๏ธ Architecture
Backend: Modal serverless platform
Framework: FastAPI for HTTP endpoints
Protocol: Model Context Protocol (MCP) implementation
Data Source: yfinance for real-time stock market data
Related MCP server: Yahoo Finance MCP Server
โจ Features
๐ง MCP Tools Available:
get_stock_price- Retrieve current stock price and basic company informationanalyze_stock_comprehensive- Complete investment analysis with scoring algorithmsmart_ticker_search- Convert company names to ticker symbols
๐ Analysis Capabilities:
Real-time stock price lookup
YTD return calculations
P/E ratio analysis
Investment scoring (0-100 scale)
Buy/Hold/Sell recommendations
Smart company name โ ticker conversion
๐ Quick Start
Prerequisites
Python 3.11+
Modal account (modal.com)
Modal CLI installed
Installation & Setup
Clone the repository
git clone <your-repo-url> cd modal-mcp-serverInstall Modal CLI
pip install modalAuthenticate with Modal
modal token newDeploy the MCP server
modal deploy modal_mcp_complete.py
๐ก API Endpoints
Base URL
https://koyeliaghoshroy1--mcp-stock-analysis-server-web-app.modal.run
Available Endpoints:
GET / - Server Information
curl https://koyeliaghoshroy1--mcp-stock-analysis-server-web-app.modal.run/GET /health - Health Check
curl https://koyeliaghoshroy1--mcp-stock-analysis-server-web-app.modal.run/healthGET /tools - MCP Tools Discovery
curl https://koyeliaghoshroy1--mcp-stock-analysis-server-web-app.modal.run/toolsPOST /call - Execute MCP Tool
curl -X POST https://koyeliaghoshroy1--mcp-stock-analysis-server-web-app.modal.run/call \
-H "Content-Type: application/json" \
-d '{"name": "TOOL_NAME", "arguments": {"key": "value"}}'๐ ๏ธ Usage Examples
Stock Price Lookup
curl -X POST https://koyeliaghoshroy1--mcp-stock-analysis-server-web-app.modal.run/call \
-H "Content-Type: application/json" \
-d '{"name": "get_stock_price", "arguments": {"symbol": "AAPL"}}'Response:
{
"success": true,
"tool": "get_stock_price",
"result": [{
"symbol": "TSLA",
"company_name": "Tesla, Inc.",
"current_price": 248.50,
"market_cap": 790000000000,
"sector": "Consumer Cyclical"
}],
"timestamp": "2025-06-10T..."
}Comprehensive Analysis
curl -X POST https://koyeliaghoshroy1--mcp-stock-analysis-server-web-app.modal.run/call \
-H "Content-Type: application/json" \
-d '{"name": "analyze_stock_comprehensive", "arguments": {"symbol": "AAPL"}
}'Response:
{
"success": true,
"tool": "analyze_stock_comprehensive",
"result": [{
"symbol": "AAPL",
"company_name": "Apple Inc.",
"current_price": 185.50,
"ytd_return": 12.5,
"pe_ratio": 28.5,
"investment_score": 75,
"recommendation": "Buy",
"sector": "Technology"
}],
"timestamp": "2025-06-10T..."
}Smart Ticker Search
curl -X POST https://koyeliaghoshroy1--mcp-stock-analysis-server-web-app.modal.run/call \
-H "Content-Type: application/json" \
-d '{
"name": "smart_ticker_search",
"arguments": {"query": "microsoft"}
}'๐ง Configuration
Environment Variables
MCP_SERVER_SECRET- Optional server secret for authentication
Modal Secrets
The server can optionally use Modal secrets for configuration:
stock_secrets = modal.Secret.from_name("Stock-api-config")๐ Project Structure
modal-mcp-server/
โโโ modal_mcp_complete.py # Main MCP server implementation
โโโ README.md # This file
โโโ requirements.txt # Dependencies (handled by Modal)๐ง Investment Scoring Algorithm
The comprehensive analysis uses a proprietary scoring algorithm:
score = 50 # Base score
if ytd_return > 15: score += 25
elif ytd_return > 5: score += 15
elif ytd_return > 0: score += 5
if 10 < pe_ratio < 25: score += 15
# Final score: 0-100
recommendation = "Buy" if score >= 70 else "Hold" if score >= 50 else "Sell"๐ฏ Supported Stock Symbols
Direct Ticker Symbols:
Tech: AAPL, GOOGL, MSFT, TSLA, META, NVDA, AMD, INTC
Finance: JPM, BAC, WFC, GS
Consumer: WMT, KO, PEP, NKE, MCD
ETFs: SPY, QQQ
Company Name Mapping:
apple โ AAPL
microsoft โ MSFT
google/alphabet โ GOOGL
amazon โ AMZN
tesla โ TSLA
meta/facebook โ META
netflix โ NFLX
nvidia โ NVDA
๐ Development
Local Testing
# Test health endpoint
curl http://localhost:8000/health
# Test tools discovery
curl http://localhost:8000/tools
# Test tool execution
curl -X POST http://localhost:8000/call \
-H "Content-Type: application/json" \
-d '{"name": "get_stock_price", "arguments": {"symbol": "AAPL"}}'Deployment
# Deploy to Modal
modal deploy modal_mcp_complete.py
# Check deployment status
modal app list
# View logs
modal logs <app-id>๐ Monitoring & Debugging
Health Checks
Monitor server health via the /health endpoint:
curl https://koyeliaghoshroy1--mcp-stock-analysis-server-web-app.modal.run/healthError Handling
The server provides detailed error responses:
{
"error": "No data available for INVALID",
"success": false,
"timestamp": "2025-06-10T..."
}๐ MCP Protocol Implementation
This server implements the Model Context Protocol specification:
Tool Discovery:
GET /toolsreturns available MCP toolsTool Execution:
POST /callexecutes tools with proper request/response formatError Handling: Standardized error responses
Type Safety: JSON schema validation for tool inputs
๐ค Integration Examples
Python Client
import requests
def call_mcp_tool(tool_name, arguments):
response = requests.post(
"https://your-modal-url/call",
json={"name": tool_name, "arguments": arguments}
)
return response.json()
# Get stock price
result = call_mcp_tool("get_stock_price", {"symbol": "AAPL"})JavaScript Client
async function callMCPTool(toolName, arguments) {
const response = await fetch('https://your-modal-url/call', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: toolName, arguments })
});
return response.json();
}
// Analyze stock
const analysis = await callMCPTool('analyze_stock_comprehensive', { symbol: 'TSLA' });๐ License
MIT License - see LICENSE file for details.
๐ Acknowledgments
Modal - For serverless cloud infrastructure
Hugging Face - For hackathon organization
yfinance - For stock market data
FastAPI - For web framework
MCP Community - For protocol specification
๐ Related Links
Frontend Interface: [Gradio MCP Client] (https://huggingface.co/spaces/Agents-MCP-Hackathon/mcp-stock-analysis-hackathon)
Modal Platform: modal.com
MCP Specification: Model Context Protocol
Built for the Hugging Face Gradio MCP Hackathon ๐
This server cannot be deployed
Maintenance
Related MCP Connectors
Unlock the power of real-time financial data with our Finance MCP. Easily retrieve the latest
Production MCP server for US equity and options intelligence: real-time IV radar, Monte Carlo simulation, options pressure, strategy backtesting, AI prediction, pre-trade risk analysis, and automated stock research reports.
Finnhub MCP โ wraps Finnhub Stock API (finnhub.io)
Quant intelligence over MCP: backtest, signals, screens, scores & portfolios for US & TSX stocks.
Related MCP Servers
- AlicenseCqualityDmaintenanceProvides comprehensive Taiwan stock market data and analysis through MCP tools. Enables querying real-time stock prices, historical data, company information, technical analysis, and market overviews for TWSE and TPEx listed companies.816MIT
- AlicenseNot gradedqualityAmaintenanceProvides real-time stock market data for Claude Desktop and MCP-compatible clients, enabling natural language queries for quotes, historical prices, company profiles, financial statements, analyst ratings, comparisons, news, options, holdings, dividends, estimates, symbol search, and market status.210 npm21MIT
- AlicenseAqualityCmaintenanceProvides live stock data and market news for financial analysis via any MCP-compatible AI app.2MIT
- FlicenseNot gradedqualityDmaintenanceProvides live US stock quotes and historical price data via MCP tools.-