Skip to content

Kudo510/MCPStockAgent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

12 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

MCP Stock Agent

Production-ready stock market analysis backend with automated CI pipeline and cloud deployment

GitLab CI Kubernetes AWS EKS

๐ŸŽฏ Overview

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

Key Features:

  • โœ… 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

๐Ÿ—๏ธ 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

๐Ÿš€ Quick Start

Prerequisites

Python 3.10+
Docker & Kubernetes (for deployment)
OpenAI API Key
NewsAPI Key (free tier available at https://newsapi.org/)

Local Development

# 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.py

Frontend Setup (Optional - AI-Assisted Demo UI)

cd 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 dev

๐Ÿ“ฆ Production Deployment

CI Pipeline (GitLab)

Automated Docker image building and tagging on every commit via .gitlab-ci.yaml:

# Local test on built Docker images
make test

Kubernetes Deployment

1๏ธโƒฃ Local Staging (Minikube)

# 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):30032

2๏ธโƒฃ AWS EKS Production

Setup 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 version

Deploy 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

โš ๏ธ Cost Management

# 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)

๐Ÿ› ๏ธ Technology Stack

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

๐Ÿ”ฎ Future Enhancements

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

๐Ÿ“„ License

MIT License - See LICENSE file for details


๐Ÿ‘ค Contact

Cuong Van Dam - LinkedIn | Email

About

Production-ready stock market analysis agent with robust CI pipeline and scalable cloud deployment

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors