Portfolio Rotation MCP Server
MCP server for portfolio rotation analysis. Score holdings and candidates across 5 dimensions, identify optimal swaps, validate with risk checks and backtests.
Works with any MCP client: Claude Desktop, ChatGPT, Gemini, LangChain, Cursor, Windsurf, VS Code, Ollama clients, and more.
What It Does
You give it a portfolio and candidate tickers. It returns:
ROTATION SCORECARD (GARP Style)
Ticker | Thesis | Valuation | Momentum | Catalyst | Technical | Composite | Action
META | 75ᴾ | 80ᴬ | 78ᴬ | 85ᴾ | 74ᴬ | 78.4 | Strong Buy
AVGO | 70ᴾ | 72ᴬ | 75ᴬ | 70ᴾ | 80ᴬ | 73.1 | Buy
AAPL | 70ᴾ | 65ᴬ | 62ᴬ | 60ᴾ | 68ᴬ | 65.5 | Hold
MSFT | 65ᴾ | 60ᴬ | 58ᴬ | 55ᴾ | 62ᴬ | 60.2 | Hold
JPM | 50ᴾ | 55ᴬ | 45ᴬ | 40ᴾ | 42ᴬ | 47.4 | Watch
KEY METRICS
Ticker | P/E | EV/EBITDA | P/FCF | ROE | D/E | Beta | Rev Growth
META | 22.5 | 15.2 | 18.1 | 35% | 0.3 | 1.18 | +22.4%
AVGO | 28.3 | 20.1 | 25.5 | 42% | 1.5 | 1.32 | +15.8%
RISK DASHBOARD
Portfolio Beta: 1.05 | VaR(95%): 1.85% | CVaR(95%): 2.45%
⚠️ Technology sector: 35% (>30% limit)
SWAP RECOMMENDATIONS
Sell JPM (47.4) → Buy META (78.4) | Delta: +31.0 | Strong Swap
ALLOCATION (NORMAL regime)
Conservative: META 6% | Balanced: META 10% | Aggressive: META 15%
Quick Start
# Install from PyPI
pip install portfolio-rotation-mcp
# Or run directly (no install needed)
uvx portfolio-rotation-mcp
# Set API key (optional -- falls back to yfinance without it)
export FINANCIAL_DATASETS_API_KEY=your-key
Prerequisites
- Python >= 3.10
- Optional: financial-datasets.ai API key for premium data (without it, prices come from yfinance and financial statements are unavailable)
11 Tools
| Tool | Description |
|---|---|
fetch_prices |
Historical OHLCV prices (API + yfinance fallback) |
fetch_financials |
Income/balance/cashflow statements |
fetch_ff_factors |
Fama-French 5-factor + momentum data |
score_tickers |
5-dimension scoring (auto + manual) |
analyze_risk |
Concentration, correlation, volatility, beta, VaR, CVaR |
compare_swaps |
Pairwise swap recommendations (delta >= 15) |
run_backtest |
Historical strategy simulation |
stress_test |
Scenario replay, Monte Carlo, factor decomposition |
compute_attribution |
Trade attribution and swap alpha |
run_pipeline |
Full 6-stage rotation analysis (regime-adaptive allocation) |
get_skill |
Retrieve domain knowledge (scoring rules, swap logic, risk thresholds) |
Platform Setup
Claude Desktop
Add to your config file:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/claude/claude_desktop_config.json
{
"mcpServers": {
"portfolio-rotation": {
"command": "uvx",
"args": ["portfolio-rotation-mcp"],
"env": {
"FINANCIAL_DATASETS_API_KEY": "your-key"
}
}
}
}
Then in Claude Desktop, just say:
My portfolio is AAPL 20%, MSFT 15%, JPM 10%. Evaluate META and AVGO as swap candidates.
Claude will automatically call the MCP tools.
Claude Code (CLI)
claude mcp add portfolio-rotation -- uvx portfolio-rotation-mcp
Cursor / Windsurf / VS Code
Add to your MCP settings (.cursor/mcp.json, .windsurf/mcp.json, or VS Code MCP config):
{
"mcpServers": {
"portfolio-rotation": {
"command": "uvx",
"args": ["portfolio-rotation-mcp"],
"env": {
"FINANCIAL_DATASETS_API_KEY": "your-key"
}
}
}
}
LangChain (any model: DeepSeek, GPT, Llama, etc.)
from langchain_mcp_adapters.client import MultiServerMCPClient
from langchain_openai import ChatOpenAI
# Use any model -- DeepSeek, GPT, Llama, etc.
llm = ChatOpenAI(
model="deepseek-chat", # or "gpt-4o", etc.
base_url="https://api.deepseek.com/v1",
api_key="sk-...",
)
async with MultiServerMCPClient({
"portfolio-rotation": {
"command": "uvx",
"args": ["portfolio-rotation-mcp"],
"env": {"FINANCIAL_DATASETS_API_KEY": "your-key"},
}
}) as client:
tools = client.get_tools()
# Create agent with tools and invoke
OpenAI Agents SDK
from agents import Agent
from agents.mcp import MCPServerStdio
async with MCPServerStdio(
command="uvx",
args=["portfolio-rotation-mcp"],
) as server:
tools = await server.list_tools()
agent = Agent(name="Rotation Analyst", tools=tools)
Ollama + Continue / LibreChat
Configure in the MCP settings of your Ollama frontend:
{
"command": "uvx",
"args": ["portfolio-rotation-mcp"],
"env": {
"FINANCIAL_DATASETS_API_KEY": "your-key"
}
}
Usage Examples
Quick: Full Pipeline (one tool call)
Ask your AI agent:
Analyze my portfolio: AAPL 20% (Technology), MSFT 15% (Technology), JPM 10% (Financials). Candidates: META, AVGO. Use GARP style.
The agent will call run_pipeline which runs all 6 stages automatically: data fetch -> scoring -> risk check -> swap comparison -> backtest -> report.
Targeted: Score Specific Tickers
Score AAPL, META, and AVGO. My thesis score for META is 80 and catalyst is 85.
The agent will call fetch_prices, then score_tickers with your manual overrides.
Deep Dive: Stress Test
Stress test my portfolio under a 2008-style crash scenario. Include Monte Carlo simulation.
The agent will call fetch_prices, fetch_ff_factors, then stress_test.
Post-Trade: Attribution
I sold INTC and bought NVDA on Jan 15 at $120. How did that swap perform?
The agent will call fetch_prices, then compute_attribution to measure swap alpha.
Development
# Clone and install in development mode
git clone git@github.com:mothanaprime/Rebalance-MCP.git
cd Rebalance-MCP
pip install -e .
# Run the server
portfolio-rotation-mcp
# Test with MCP inspector
mcp dev src/portfolio_rotation/server.py
Scoring Framework
5 dimensions, 0-100 each, weighted by investment style:
| Dimension | GARP Weight | Scoring Mode |
|---|---|---|
| Thesis Integrity | 25% | ᴾ Auto-proxy (financial trends) or ᴹ manual override |
| Valuation Attractiveness | 25% | ᴬ Auto: P/E + PEG + EV/EBITDA + P/FCF (4-methodology blend) |
| Fundamental Momentum | 20% | ᴬ Auto (price momentum + revenue growth) |
| Catalyst Proximity | 15% | ᴾ Auto-proxy (earnings, volume, analyst targets) or ᴹ manual |
| Technical Trend | 15% | ᴬ Auto (MA crossovers, RSI, relative strength) |
Valuation blends up to 4 methodologies: P/E (35%), PEG (20%), EV/EBITDA (25%), P/FCF (20%). Missing methods redistribute weight. Falls back to P/E-only without balance sheet/cash flow data.
Risk metrics: Portfolio beta, individual stock betas, parametric VaR (95%/99%), historical VaR, CVaR (Expected Shortfall).
Allocation: Regime-adaptive — parameters auto-adjust for VIX level (LOW/NORMAL/ELEVATED/HIGH).
Swap threshold: Buy Score - Hold Score >= 15
Style presets: garp (default), value, growth, momentum, event_driven -- each has different dimension weights.
See docs/scoring-framework.md for full details.
Agent Prompt
See docs/agent-prompt.md for a model-agnostic system prompt you can use to configure any AI agent for rotation analysis.
Environment Variables
| Variable | Required | Default | Description |
|---|---|---|---|
FINANCIAL_DATASETS_API_KEY |
No | -- | API key for financial-datasets.ai. Without it, prices fall back to yfinance and financials are unavailable. |
PORTFOLIO_ROTATION_SOURCE |
No | auto |
Data source: auto (API first, yfinance fallback), api, financial-datasets, or yfinance. Can be overridden per-call. |
License
MIT
Metadata
Release files for portfolio-rotation-mcp 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| portfolio_rotation_mcp-0.4.0.tar.gz | 70.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| portfolio_rotation_mcp-0.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 124.6 kB
Release files / portfolio_rotation_mcp-0.4.0.tar.gz
| Download URL | portfolio_rotation_mcp-0.4.0.tar.gz |
|---|---|
| Size | 70.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c2359d480ecf8e8e628e70e483a9910e67e4c8abbf0313b89bc7e03ac2528c27
|
|
BLAKE2b-256 checksum How to use checksums |
e1b111cd058bef0f8e2b8f445e209b3d3552ec32bff80f062619c5ac80bc3e07
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Release files / portfolio_rotation_mcp-0.4.0-py3-none-any.whl
| Download URL | portfolio_rotation_mcp-0.4.0-py3-none-any.whl |
|---|---|
| Size | 53.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ec03e7fe2378678c696f76eb18521c46bc8b5030a757b586684134531926927f
|
|
BLAKE2b-256 checksum How to use checksums |
30bc529eb49a76d8bc44a43ea1c59d06a7172a7c28bbd324a5228570af3b7477
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.12
|
Security for portfolio-rotation-mcp 0.4.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.