mcportfolio
McPortfolio: A Model Context Protocol server providing 9 specialized tools for LLM-driven portfolio optimization using natural language, covering mean-variance to machine learning approaches.
claude mcp add --transport stdio ebrandler-mcportfolio python -m mcportfolio_server \ --env PYTHONUNBUFFERED="1" \ --env MC_PORTFOLIO_LOG_LEVEL="INFO"
How to use
McPortfolio exposes a suite of MCP tools that bring PyPortfolioOpt-style portfolio optimization into an LLM-friendly MCP server. Core capabilities include data retrieval for assets, general portfolio optimization with flexible constraints, and classical/modern optimization methods. Available tools cover tasks such as retrieving historical stock data, solving generic portfolios with custom constraints, and specialized optimizers like the Efficient Frontier (mean-variance), CLA (Critical Line Algorithm), and additional methods aligned with risk budgeting and downside risk measures. You can invoke these tools in an MCP flow by specifying a description of the problem, the tickers involved, any constraints (for example, max_weight 0.3 or min_weight 0.05), and the objective you want to optimize (e.g., maximize_sharpe_ratio or minimize_volatility). The server then returns optimized weights along with key metrics such as expected return, volatility, and Sharpe ratio, enabling you to iterate with natural-language prompts or structured inputs from your LLM.
How to install
Prerequisites:
- Python 3.8 or later
- Git
- Internet access to install dependencies
Step-by-step installation:
-
Clone the repository: git clone https://github.com/your-org/mcportfolio.git cd mcportfolio
-
Create and activate a virtual environment (recommended): python -m venv venv source venv/bin/activate # on Unix/macOS
or: .\venv\Scripts\activate # on Windows
-
Install required Python dependencies: python -m pip install --upgrade pip pip install -r requirements.txt
-
Run the MCP server: python -m mcportfolio_server
-
Verify the server is running by sending a test MCP request (see docs for the MCP protocol).
Notes:
- If the project provides a Dockerfile, you can alternatively build and run the container following the Docker instructions in the repository.
- Ensure your environment has network access to fetch market data if retrieve_stock_data requires external data sources.
Additional notes
Tips and common issues:
- Review inputs carefully: LLM prompts can propose unconventional constraints; validate that weights sum to 1 (or handle accordingly if the solver supports unconstrained weights).
- Check output metrics (expected return, volatility, Sharpe) against known library docs to catch mismatches.
- For HRP/alternative risk measures, ensure any clustering or param settings are aligned with your data size and frequency.
- Use verbose server logs to trace which tool and parameters were used for a given optimization run.
- Environment variables can adjust logging level and runtime behavior; set MC_PORTFOLIO_LOG_LEVEL to INFO or DEBUG for troubleshooting.
Related MCP Servers
metatrader
Model Context Protocol (MCP) to enable AI LLMs to trade using MetaTrader platform
monarch
MCP Server for use with Monarch Money
mcp
Official Python MCP server for local interactions with the QuantConnect API
tradememory-protocol
MCP server for AI trading memory — 3-layer memory system with LLM-powered reflection engine.
finance
LLM-powered MCP server for building financial deep-research agents, integrating web search, Crawl4AI scraping, and entity extraction into composable analysis flows.
qonto
Qonto MCP Server