Production-ready stock market analysis backend with automated CI pipeline and cloud deployment
This repository is a production-ready stock market analysis backend leveraging the Model Context Protocol (MCP) from Anthropic. The backend service enables AI agents to evaluate specific stocks through comprehensive analysis powered by real-time news aggregation from NewsAPI, Yahoo Finance, and Google.
Demo:
mcp_stock_agent_chatbot.mp4
- โ Automated CI Pipeline: GitLab CI for automated Docker image building and tagging
- โ Cloud-Native Design: Kubernetes orchestration with AWS EKS deployment
- โ MCP Protocol Implementation: Streamable HTTP-based communication between AI agent and tools
- โ Extensible Architecture: Modular MCP-based tool system allows seamless integration of additional data sources (e.g., history charts, images for deeper analysis)
- โ Modern Backend Stack: FastAPI with containerized architecture
โโโโโโโโโโโโโโโ HTTP/MCP Protocol โโโโโโโโโโโโโโโ
โ FastAPI โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโบ โ MCP Server โ
โ Client โ โ (Tools) โ
โ (GPT-4o) โ โ โ
โโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโ
โ
โโโบ NewsAPI
โโโบ Yahoo Finance
โโโบ Google
Backend Components:
- Client Service: FastAPI application with GPT-4o integration for intelligent query processing
- MCP Server: Standardized HTTP service following Anthropic's Model Context Protocol for tool orchestration
Python 3.10+
Docker & Kubernetes (for deployment)
OpenAI API Key
NewsAPI Key (free tier available at https://newsapi.org/)# Environment setup
python -m venv venv
source venv/bin/activate
pip install -r client/requirements.txt -r server/requirements.txt
# Configuration
cat > .env << EOF
OPENAI_KEY=your_openai_api_key
NEWS_API_KEY=your_newsapi_key
EOF
# Launch backend services
pip install python-dotenv
python -m dotenv -f .env run -- python server/mcp_server.py &
python -m dotenv -f .env run -- python client/service.pycd ui
# Setup Tailwind
npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init -p
# Install icon library
npm install lucide-react
npm install
# Update apiUrl in src/App.tsx with your backend URL
npm run devAutomated Docker image building and tagging on every commit via .gitlab-ci.yaml:
# Local test on built Docker images
make test# Create GitLab registry credentials
kubectl create secret docker-registry gitlab-registry-secret \
--docker-server=registry.gitlab.com \
--docker-username=<your-username> \
--docker-password=<deploy-token> \
--docker-email=<your-email>
# Deploy to staging
make staging_deploy
# Access backend service
# URL: http://$(minikube ip):30031
# Once staging service works, deploy release version
make release
# URL: http://$(minikube ip):30032Setup AWS CLI & eksctl:
# Install AWS CLI
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip && sudo ./aws/install
aws --version
# Configure credentials (requires IAM user with EKS permissions)
aws configure
# Install eksctl
curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
sudo mv /tmp/eksctl /usr/local/bin
eksctl versionDeploy to EKS:
# Provision cluster (uses t3.micro free-tier nodes - adjust in aws-eks/eks-cluster.yaml for production)
eksctl create cluster -f aws-eks/eks-cluster.yaml
# Deploy application
make release_aws_eks
# Get service endpoint
kubectl get svc mcp-stock-agent -n agentic-release
# Access at: http://<EXTERNAL-IP>/docs# Always delete cluster after testing
eksctl delete cluster -f aws-eks/eks-cluster.yaml
# Verify deletion in AWS Console:
# - EC2 instances
# - EKS cluster
# - EBS volumes (if persistent storage was used)| Layer | Technology |
|---|---|
| Backend | FastAPI, Python |
| AI Integration | OpenAI GPT-4o |
| Protocol | Anthropic MCP (Model Context Protocol) |
| Containerization | Docker |
| Orchestration | Kubernetes |
| CI | GitLab CI |
| Cloud | AWS EKS |
DevOps:
- Automated CD pipeline for direct EKS deployment
- Prometheus + Grafana monitoring stack
- Helm charts for templated deployments
Backend Features:
- Technical analysis APIs (price charts, indicators)
- Valuation metrics endpoints (P/E, P/B, DCF analysis)
- Stock screening API for undervalued opportunities
- Buy/sell recommendation engine
Performance:
- Explore open-source models (trade-off: reduced accuracy in complex tool-calling scenarios)
- Caching layer for frequently requested stock data
- Rate limiting and request optimization
MIT License - See LICENSE file for details