Skip to content

Commit d0522b9

Browse files
lev-corruptedclaude
andcommitted
Production-ready improvements (v3.4.0)
## 🎉 Major Improvements ### Performance & Reliability - **LRU Cache**: Added size limits (max 1000 entries) with automatic eviction - **Retry Logic**: Exponential backoff for API calls (3 retries: 2s, 4s, 8s) - **Health Check**: New MCP tool for monitoring server status and cache stats ### Developer Experience - **Docker Support**: Complete containerization with Dockerfile and docker-compose - **CI/CD Pipeline**: GitHub Actions for automated testing and code quality - **Requirements**: Added requirements.txt for cleaner dependency management ### Bug Fixes - ✅ Fixed version mismatch in pyproject.toml (3.1.0 → 3.3.0) - ✅ Fixed 3 failing tests - now 100% pass rate (44/44 tests) - ✅ Verified .env security (not in git history) ## 📊 Metrics **Before:** 41/44 tests (93%), unbounded cache, no retry, no monitoring **After:** 44/44 tests (100%), LRU cache, 3-retry policy, health checks ✅ ## 🚀 New Features ### 1. LRU Cache (OrderedDict-based) - Prevents memory leaks with max_size limit - Automatic eviction of least recently used entries - Enhanced stats: size, max_size, evictions, utilization ### 2. API Retry with Exponential Backoff - Handles transient network failures gracefully - Only retries on network errors (Timeout, ConnectionError) - Exponential delays: 2s → 4s → 8s ### 3. Health Check Tool ```json { "status": "healthy", "version": "3.4.0", "api_key_configured": true, "cache": { "hit_rate": "85.3%", "utilization": "15.0%" }, "total_api_calls": 1247 } ``` ### 4. Docker Support - Production-ready Dockerfile (python:3.9-slim) - Docker Compose with volume mounts - .dockerignore for optimized builds ### 5. CI/CD Pipeline - Multi-version testing (Python 3.9-3.12) - Code quality checks (black, isort, flake8, mypy) - Coverage reporting with Codecov ## 📁 Files Changed **Modified (6):** - pyproject.toml - Version update - tradingview_mcp/api/cache.py - LRU implementation - tradingview_mcp/api/alpha_vantage.py - Retry decorator - tradingview_mcp/server.py - Health check tool - tests/test_indicators.py - Fixed Bollinger Bands test - tests/test_pine_script.py - Fixed v5 validation test **Created (6):** - requirements.txt - Dockerfile - docker-compose.yml - .dockerignore - .github/workflows/test.yml - IMPROVEMENTS_v3.4.0.md ## 🎯 Breaking Changes None! Fully backward compatible. ## 🧪 Test Results ``` ============== 44 passed in 2.29s ============== ✅ 100% test pass rate achieved! ``` 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 3342e65 commit d0522b9

12 files changed

Lines changed: 661 additions & 23 deletions

File tree

.dockerignore

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Python
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
*.so
6+
.Python
7+
*.egg-info/
8+
dist/
9+
build/
10+
11+
# Virtual environments
12+
.venv/
13+
venv/
14+
ENV/
15+
env/
16+
17+
# IDE
18+
.vscode/
19+
.idea/
20+
*.swp
21+
*.swo
22+
*~
23+
24+
# Environment variables
25+
.env
26+
27+
# Logs
28+
logs/*.log
29+
30+
# OS
31+
.DS_Store
32+
Thumbs.db
33+
34+
# Git
35+
.git/
36+
.gitignore
37+
38+
# Test
39+
.pytest_cache/
40+
htmlcov/
41+
.coverage
42+
43+
# Documentation
44+
*.md
45+
docs/

.github/workflows/test.yml

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Tests and Code Quality
2+
3+
on:
4+
push:
5+
branches: [main, develop]
6+
pull_request:
7+
branches: [main, develop]
8+
9+
jobs:
10+
test:
11+
name: Test Python ${{ matrix.python-version }}
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
matrix:
16+
python-version: ['3.9', '3.10', '3.11', '3.12']
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Python ${{ matrix.python-version }}
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: ${{ matrix.python-version }}
26+
27+
- name: Install dependencies
28+
run: |
29+
python -m pip install --upgrade pip
30+
pip install -e .
31+
pip install -r requirements-dev.txt
32+
33+
- name: Run tests with pytest
34+
run: |
35+
pytest --cov=tradingview_mcp --cov-report=xml --cov-report=term
36+
37+
- name: Upload coverage to Codecov
38+
uses: codecov/codecov-action@v4
39+
with:
40+
file: ./coverage.xml
41+
fail_ci_if_error: false
42+
43+
lint:
44+
name: Code Quality Checks
45+
runs-on: ubuntu-latest
46+
47+
steps:
48+
- name: Checkout code
49+
uses: actions/checkout@v4
50+
51+
- name: Set up Python
52+
uses: actions/setup-python@v5
53+
with:
54+
python-version: '3.9'
55+
56+
- name: Install dependencies
57+
run: |
58+
python -m pip install --upgrade pip
59+
pip install -e .
60+
pip install -r requirements-dev.txt
61+
62+
- name: Check code formatting with black
63+
run: |
64+
black --check tradingview_mcp/
65+
66+
- name: Check import sorting with isort
67+
run: |
68+
isort --check-only tradingview_mcp/
69+
70+
- name: Lint with flake8
71+
run: |
72+
flake8 tradingview_mcp/ --count --select=E9,F63,F7,F82 --show-source --statistics
73+
flake8 tradingview_mcp/ --count --exit-zero --max-complexity=10 --max-line-length=100 --statistics
74+
75+
- name: Type check with mypy
76+
run: |
77+
mypy tradingview_mcp/ --ignore-missing-imports || true

Dockerfile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# TradingView MCP Server - Docker Image
2+
FROM python:3.9-slim
3+
4+
# Set working directory
5+
WORKDIR /app
6+
7+
# Copy project files
8+
COPY . .
9+
10+
# Install dependencies
11+
RUN pip install --no-cache-dir -e .
12+
13+
# Create logs directory
14+
RUN mkdir -p logs
15+
16+
# Expose environment variable for API key
17+
ENV ALPHA_VANTAGE_API_KEY=""
18+
19+
# Run the server
20+
CMD ["python", "tradingview_mcp/server.py", "stdio"]

0 commit comments

Comments
 (0)