MCP (Model Context Protocol) server that exposes the okama investment portfolio toolkit to AI assistants — Claude Desktop, Claude Code, Cursor, and any other MCP-compatible client.
With okama-mcp installed, you can ask an AI things like:
"Backtest a portfolio of 30% gold and 70% real estate over the last 15 years."
"Run a Monte Carlo retirement forecast on that portfolio, withdrawing $1,000/month indexed to inflation, over 25 years."
"What's the tangency portfolio of SPY, BND, and GLD with a 3% risk-free rate?"
…and the AI uses the MCP tools to call okama directly — no Python code needed.
Built on FastMCP. Single codebase, two transports:
stdio (for local clients) and streamable-http (for remote deployment).
Requires Python ≥ 3.14.
git clone <repo-url> okama-mcp
cd okama-mcp
poetry install# stdio — for Claude Desktop, Claude Code, Cursor (local IPC)
poetry run okama-mcp stdio
# streamable HTTP — for remote/multi-client deployments
poetry run okama-mcp http --host 127.0.0.1 --port 8765Edit ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or
%APPDATA%\Claude\claude_desktop_config.json (Windows):
{
"mcpServers": {
"okama": {
"command": "poetry",
"args": ["run", "okama-mcp", "stdio"],
"cwd": "/absolute/path/to/okama-mcp"
}
}
}Restart Claude Desktop; the server appears in the tools menu.
From the project root:
claude mcp add okama poetry run okama-mcp stdioOr commit a .claude/mcp.json so the whole team picks it up:
{
"mcpServers": {
"okama": {
"command": "poetry",
"args": ["run", "okama-mcp", "stdio"]
}
}
}Open Settings → MCP, click Add new MCP Server, and use:
- Name:
okama - Type:
stdio - Command:
poetry run okama-mcp stdio - Working dir: this project's root
# server
poetry run okama-mcp http --host 0.0.0.0 --port 8765 --path /mcpThen point your MCP client at http://<server>:8765/mcp. For production put nginx + TLS
in front and add bearer-token auth (TODO: bearer-token support is on the roadmap).
All tools are stateless — pass the full portfolio specification with every call.
The server caches expensive okama objects (Portfolio, EfficientFrontier) by content
hash, so repeated calls on the same spec are fast.
| Tool | Purpose |
|---|---|
search_assets(query, namespace?) |
Free-text search across all okama symbols by name / ticker / ISIN. |
list_namespaces(kind="all"|"assets"|"macro") |
Show the available okama namespaces. |
get_asset_info(symbol) |
Metadata for one symbol — name, country, currency, type, date range. |
| Tool | Purpose |
|---|---|
get_asset_history(symbol, kind, first_date?, last_date?) |
Time series for one asset. kind ∈ {close_monthly, close_daily, adj_close, ror, dividends}. |
compare_assets(symbols, ccy, first_date?, last_date?, inflation) |
Side-by-side statistics (describe() table: CAGR, risk, drawdowns by period). |
get_correlations(symbols, ccy, ...) |
Correlation matrix of monthly returns. |
| Tool | Purpose |
|---|---|
analyze_portfolio(portfolio) |
Headline metrics + full describe() for a PortfolioSpec. |
get_portfolio_drawdowns(portfolio) |
Drawdown time series + max drawdown / recovery period. |
get_portfolio_var_cvar(portfolio, time_frame=12, level=1) |
Historical Value at Risk and CVaR. |
get_portfolio_wealth_index(portfolio, full=False) |
Wealth-index series (cumulative growth of 1000). |
| Tool | Purpose |
|---|---|
monte_carlo_forecast(portfolio, mc, cashflow) |
Forward simulation with one of five cash-flow strategies (indexation, percentage, time_series, vanguard, cut_if_drawdown). Returns percentile wealth bands, terminal-wealth stats, and survival metrics. |
| Tool | Purpose |
|---|---|
build_efficient_frontier(frontier) |
Full EF point table (Risk / Mean return / CAGR + per-asset weights). |
get_tangency_portfolio(frontier, rf_return, rate_of_return) |
Max-Sharpe portfolio on the EF. |
get_min_variance_portfolio(frontier) |
Global Minimum Variance portfolio. |
| Tool | Purpose |
|---|---|
get_inflation(currency, first_date?, last_date?, include_cumulative?) |
Inflation series for a currency (USD, EUR, RUB, …). |
get_central_bank_rate(country, first_date?, last_date?) |
Central-bank policy rate (US, ECB, RUS, …). |
The complex tools take typed dicts validated by pydantic. The full schemas live in
src/okama_mcp/schemas.py; here are the headline shapes:
The project follows TDD (see AGENTS.md). After every code change run:
poetry run pytest -q
poetry run ruff check .To run the live-API integration test (hits api.okama.io):
poetry run pytest -m integrationsrc/okama_mcp/
├── server.py # FastMCP instance + registration entry point
├── transport.py # CLI: `okama-mcp stdio | http`
├── schemas.py # PortfolioSpec, MCSpec, CashflowSpec, FrontierSpec
├── cache.py # TTL+LRU cache keyed by sha256 of canonical spec
├── serialization.py # pandas → JSON-safe with smart truncation
├── errors.py # Translate okama exceptions to actionable MCP errors
└── tools/
├── search.py, asset.py, asset_list.py
├── portfolio.py, monte_carlo.py
├── frontier.py, macro.py
Same as okama itself: MIT.