Stock Research Assistant MCP Server
A comprehensive stock research assistant built with FastMCP for Databricks AI/BI integration. Enables natural-language interaction with real market data, watchlist management, company analysis, and research note tracking.
Features
π― Watchlist Management
- Track personal watchlists of tickers
- Add/remove stocks with custom notes
- View watchlist with live prices and performance
π Market Data
- Real-time quotes from Massive Stocks API
- Historical price data and performance metrics
- Company fundamentals and profile information
- Multi-ticker comparisons
π° News & Research
- Fetch and summarize recent company news
- Save research notes with investment thesis
- Set price targets and confidence levels
- Flag notable price moves automatically
ποΈ Data Persistence
- Lakebase Postgres backend for all user data
- Complete schema for users, watchlists, prices, news, and research
- Optimized for future semantic search capabilities
Architecture
βββββββββββββββββββ
β AI/BI Agent β β Natural language queries
ββββββββββ¬βββββββββ
β
βΌ
βββββββββββββββββββ
β FastMCP Server β β stocks_mcp_server.py
ββββββββββ¬βββββββββ
β
ββββββ΄βββββ
βΌ βΌ
βββββββββββ ββββββββββββββββ
βLakebase β βMassive Stocksβ
βPostgres β β API β
βββββββββββ ββββββββββββββββ
MCP Tools
The server exposes 10 agent tools:
Watchlist Tools
add_to_watchlist(ticker, watchlist_name, notes)- Add a stock to your watchlistremove_from_watchlist(ticker, watchlist_name)- Remove a stockget_watchlist(watchlist_name)- View all stocks with live prices
Market Data Tools
get_price_data(ticker, days)- Current and historical prices with performance summaryget_company_info(ticker)- Company fundamentals and profilecompare_tickers(tickers, metric)- Compare multiple stocks
Research Tools
get_recent_news(ticker, limit)- Fetch and summarize recent newssave_research_note(ticker, title, content, thesis, target_price, confidence)- Log analysisflag_notable_moves(threshold_percent)- Alert on significant price changes
Utility
get_current_user()- Get authenticated user email
Setup Instructions
1. Set Up Databricks Secrets
You need two secrets:
Lakebase Connection URL
databricks secrets create-scope database
databricks secrets put-secret database lakebase-url
The value should be a standard Postgres connection URL:
postgresql://role:password@host:5432/databricks_postgres?sslmode=require
Massive Stocks API Key
databricks secrets create-scope massive
databricks secrets put-secret massive api-key
Get your API key from Massive Stocks API or similar provider.
2. Initialize Database Schema
Run the SQL schema against your Lakebase instance:
psql <lakebase-url> < schema_stocks.sql
This creates all required tables:
users- User profileswatchlists- Named watchlists per userwatchlist_tickers- Stocks in watchlistscompanies- Company profiles and fundamentalsprice_snapshots- Historical price datanews_articles- News articles per tickerresearch_notes- User research and thesesanalysis_reports- Agent-generated reports
3. Deploy as Databricks App
cd stocks_research_assistant
databricks apps create stock-research-assistant \
--description "Stock Research Assistant with MCP" \
--source-code-path .
databricks apps deploy stock-research-assistant
Or use the UI:
- Go to Databricks Apps β Create App
- Set source path to
/Workspace/Users/<your-email>/databricks-lakebase-app-day-3-hw/stocks_research_assistant - Click Deploy
4. Connect to AI Playground or Agent Bricks
Once deployed, your app URL will be: https://stock-research-assistant-<id>.aws.databricksapps.com
Option A: AI Playground
- The Playground auto-discovers workspace MCP servers
- Your tools should appear automatically
Option B: Agent Bricks
- Go to Machine Learning β Agents
- Create a new agent
- Add External Tool β MCP Server
- URL:
https://stock-research-assistant-<id>.aws.databricksapps.com
Example Usage
Natural Language Queries
Managing Watchlists:
"Add AAPL and MSFT to my watchlist"
"Show me my watchlist"
"Remove TSLA from my default watchlist"
Market Research:
"What's the price of NVDA over the last 30 days?"
"Compare GOOGL and META on performance"
"Show me recent news for AAPL"
Investment Analysis:
"Save a research note for TSLA: Bullish on FSD progress, target $350"
"Which stocks in my watchlist moved more than 5% today?"
"Get company fundamentals for AMD"
Direct Tool Calls
You can also call tools directly via the MCP protocol:
# Add to watchlist
{
"tool": "add_to_watchlist",
"arguments": {
"ticker": "AAPL",
"watchlist_name": "tech_giants",
"notes": "Strong services revenue, AI potential"
}
}
# Get price data
{
"tool": "get_price_data",
"arguments": {
"ticker": "NVDA",
"days": 90
}
}
# Save research note
{
"tool": "save_research_note",
"arguments": {
"ticker": "TSLA",
"title": "Q4 2025 Analysis",
"content": "Strong deliveries, margin expansion expected...",
"thesis": "Bullish on FSD monetization and energy storage growth",
"target_price": 350.0,
"confidence": "high"
}
}
Database Schema
Key tables and relationships:
users
βββ watchlists
β βββ watchlist_tickers
βββ research_notes
βββ analysis_reports
companies (ticker lookup)
price_snapshots (time series)
news_articles (ticker, published_at)
API Rate Limits
Massive Stocks API (Polygon.io) free tier:
- 5 API calls per minute
- Delayed data (15-minute delay for stocks)
For production use, upgrade to a paid plan for:
- Real-time data
- Higher rate limits
- WebSocket streaming
Future Enhancements
Context Engineering (Semantic Search)
The schema includes VECTOR columns for embeddings:
companies.profile_embeddingnews_articles.content_embeddingresearch_notes.content_embedding
Enables queries like:
- "Find companies exposed to rising interest rates in regional banking"
- "Show me research notes about AI chip manufacturers"
- "Surface news about EV battery supply chain issues"
Implement with:
- Databricks sentence-transformers models
- pgvector extension in Lakebase
- Semantic similarity search
Additional Features
- Real-time price alerts via WebSocket
- Technical analysis indicators (RSI, MACD, etc.)
- Portfolio tracking and P&L
- Earnings calendar integration
- Options data and Greeks
- Sector rotation analysis
Troubleshooting
"API request failed"
- Check that your Massive Stocks API key is valid
- Verify the secret is properly configured
- Check API rate limits
"Could not retrieve Lakebase connection"
- Verify Lakebase secret is set correctly
- Test connection string manually:
psql <connection-url> - Check that Lakebase endpoint is running
"No results returned for {ticker}"
- Ticker may be invalid or delisted
- Use
search_companiestool to find correct symbol - Some tickers may not be available on free tier
App deployment failed
- Check logs:
databricks apps logs stock-research-assistant --tail 100 - Verify all dependencies in requirements.txt
- Ensure app.yaml env vars match your secret scopes
Files
stocks_research_assistant/
βββ README.md # This file
βββ app.yaml # Databricks App configuration
βββ requirements.txt # Python dependencies
βββ schema_stocks.sql # Lakebase schema
βββ lakebase.py # Postgres connection helper
βββ massive_stocks_broker.py # Massive API client
βββ stocks_mcp_server.py # FastMCP server with tools
License
MIT
Support
For issues or questions:
- Check the troubleshooting section
- Review Databricks Apps documentation
- Check FastMCP docs at https://gofastmcp.com
- Review Massive Stocks API docs at https://polygon.io/docs