Get the FREE Ultimate OpenClaw Setup Guide →

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.

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
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:

  1. Clone the repository: git clone https://github.com/your-org/mcportfolio.git cd mcportfolio

  2. Create and activate a virtual environment (recommended): python -m venv venv source venv/bin/activate # on Unix/macOS

    or: .\venv\Scripts\activate # on Windows

  3. Install required Python dependencies: python -m pip install --upgrade pip pip install -r requirements.txt

  4. Run the MCP server: python -m mcportfolio_server

  5. 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

Sponsor this space

Reach thousands of developers