StocksMCP

StocksMCP

AI-powered stock research MCP server with real-time data, CRUD operations, and interactive dashboard for fundamental analysis and comparisons.

Category
Visit Server

README

šŸ“ˆ MCP Stock Research Agent & Dashboard

An AI-powered stock research platform built using the Model Context Protocol (MCP). It implements a fully compliant FastMCP server exposing fundamental analysis, local file-based database CRUD tools, and a dynamic dashboard layout via the Prefab UI protocol, combined with a standalone FastAPI + HTML5 interactive browser terminal.


šŸ—ļø Architecture

                       User Prompt (e.g., "Analyze National Aluminium")
                                     │
                                     ā–¼
                              ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
                              │  MCP Client  │
                              │   (Agent)    │
                              ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
                                     │ (stdio connection)
                                     ā–¼
                              ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
                              │  MCP Server  │
                              │  (FastMCP)   │
                              ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”¬ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜
                                     │
         ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”¼ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
         ā–¼                           ā–¼                           ā–¼
ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”         ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”         ā”Œā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”
│  Internet Tool  │         │    CRUD Tool    │         │     UI Tool     │
│                 │         │                 │         │   (Prefab UI)   │
│  yfinance API   │         │  local reports/ │         │  Generative App │
ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜         ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜         ā””ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”€ā”˜

The system is split into two access interfaces:

  1. MCP Protocol Interface: For AI agent clients (like Claude Desktop) using Stdio transport and Prefab UI.
  2. Standalone Web Terminal: A browser interface at http://localhost:8000 presenting a fully responsive dark-themed terminal with real-time Plotly.js charts, quarterly indicators, and side-by-side stock comparisons.

⚔ Key Features

  • Internet Data Tool: Real-time fundamentals, quarterly statement retrieval, and historical OHLCV pricing via yfinance.
  • Local CRUD Tool: Persistent JSON storage for analyzed stocks under reports/.
  • UI Communication (Prefab UI): Exposes structural layout component trees (show_dashboard) to MCP-compatible rendering clients.
  • Valuation Estimation Model: Calculates growth-adjusted fair PE, EPS, and valuation gap percentage.
  • Growth Scoring System: Evaluates companies out of 10 points based on quarterly revenue/PAT trends, ROE, debt-to-equity, and promoter holdings.
  • Interactive Candlestick Charts: Fully interactive Plotly.js charting (Zoom, Pan, Hover details, Date range slider).
  • Stock Comparison: Compare two stocks side-by-side on all fundamental metrics.

šŸ› ļø Setup Instructions

1. Prerequisites

  • Python 3.8 or higher installed on your system.

2. Project Directory Installation

Clone or navigate to the project directory:

cd /Users/pawanthanay/Project/StocksMCP

3. Create a Virtual Environment and Install Dependencies

Initialize a Python virtual environment, activate it, and install all required modules (this also installs prefab-ui, the rendering engine behind the show_dashboard Prefab UI tool):

python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt

macOS / Homebrew Python troubleshooting: If pip install fails with ImportError: ... Symbol not found: _XML_SetAllocTrackerActivationThreshold (a known Homebrew Python 3.12 ↔ system libexpat mismatch), prefix your pip/python3 commands with the Homebrew expat lib path, e.g.:

export DYLD_LIBRARY_PATH="$(brew --prefix expat)/lib:$DYLD_LIBRARY_PATH"
pip install -r requirements.txt

4. Configuration

Create a .env file from the example:

cp .env.example .env

šŸš€ Running the Application

Option A: Running the Standalone Web Dashboard (Recommended)

This starts the FastAPI web server. You can view the dashboard in any standard browser:

python3 -m src.web_dashboard

Once started, open your browser and go to: šŸ‘‰ http://localhost:8000

Select stocks from the dropdown (e.g. National Aluminium, TCS, Infosys) to perform live analysis, view interactive Plotly candlestick charts, read AI-generated summaries, and run comparisons.

Option B: Running the MCP Client Agent (Automatic Workflow)

Run the client script to execute the agentic loop. The agent connects to the server, fetches data, performs calculations, saves the JSON report, and registers the Prefab dashboard:

python3 -m src.client "Analyze National Aluminium stock"

To run a different stock, pass it in the prompt:

python3 -m src.client "Analyze TCS stock"

Option C: Testing the MCP Server Directly

To run the server in stdio mode (for Claude Desktop or testing):

python3 -m src.server

ā˜ļø Deploying the Web Dashboard (Render)

The web dashboard is a standard FastAPI app and can be deployed for free on Render:

  1. Fork or push this repo to your own GitHub account.
  2. On Render, choose New + → Blueprint and point it at your repo — it will pick up render.yaml automatically and configure the build (pip install -r requirements.txt) and start (uvicorn src.web_dashboard:app --host 0.0.0.0 --port $PORT) commands.
  3. Click Apply / Create Web Service. Render builds and deploys automatically, and redeploys on every push to main.
  4. Once live, share the https://<your-service>.onrender.com URL — every visitor gets the same live Yahoo Finance data, fetched fresh per request.

No server-side secrets are required: each visitor supplies their own optional Gemini API key directly in the dashboard UI (used only for that request, never stored server-side — see gemini_client.py).

Note: Render's free tier spins the service down after periods of inactivity, so the first request after idling can take ~30–60 seconds to wake up.


šŸ“Š Growth Scoring System

Ratios are checked and scored out of 10 points:

  • Revenue Growth QoQ: Growing = 2 points, Flat = 1 point, Declining = 0 points
  • PAT Growth QoQ: Growing = 2 points, Flat = 1 point, Declining = 0 points
  • ROE (Return on Equity): >15% = 2 points, 10-15% = 1 point, <10% = 0 points
  • Debt-to-Equity: <50% (0.5) = 2 points, 50-100% (0.5-1.0) = 1 point, >100% = 0 points
  • Promoter Holdings: >=50% = 2 points, 30-50% = 1 point, <30% = 0 points

Growth Categories:

  • 0-4 Points: šŸ”“ Weak
  • 5-7 Points: 🟔 Neutral
  • 8-10 Points: 🟢 Growth

šŸ“ Project Structure

StocksMCP/
ā”œā”€ā”€ requirements.txt            # Python dependencies (fastmcp, yfinance, fastapi, etc.)
ā”œā”€ā”€ .env.example                # Template for server & dashboard config
ā”œā”€ā”€ .gitignore                  # Git rules (ignoring .env and reports/*.json)
ā”œā”€ā”€ reports/                    # Directory where local JSON reports are saved
│   └── NATIONALUM_NS.json      # Sample generated report
ā”œā”€ā”€ src/
│   ā”œā”€ā”€ __init__.py             # Package init
│   ā”œā”€ā”€ server.py               # FastMCP Server containing tool endpoints
│   ā”œā”€ā”€ client.py               # MCP client agent running automatic pipelines
│   ā”œā”€ā”€ data_fetcher.py         # yfinance scraper & parser
│   ā”œā”€ā”€ analyzer.py             # Computes fair value, growth scores, & AI summaries
│   ā”œā”€ā”€ dashboard.py            # Prefab UI layout compiler
│   └── web_dashboard.py        # FastAPI server backend
└── templates/
    └── dashboard.html          # HTML5 terminal dashboard with Plotly charts

šŸ“ˆ Verification Checklist

To verify all requirements are met:

  1. Tool 1: fetch_stock_data: Call fetch_stock_data("NATIONALUM.NS") → returns raw stock fundamentals, financials, and historical price history.
  2. Tool 2: save_stock_report: Call save_stock_report("NATIONALUM", report) → creates reports/NATIONALUM_NS.json with calculated metrics, AI summary, and raw data.
  3. Tool 3: show_dashboard: Call show_dashboard("NATIONALUM.NS") → registers and returns structural generative UI.
  4. CRUD CRUD CRUD: Test update/delete tools (update_stock_report and delete_stock_report).
  5. FastAPI Web Server: Run python3 -m src.web_dashboard and inspect interactive elements at http://localhost:8000.

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured