
Okama Mcp
io.github.mbk-dev由 GitHub 帳號 mbk-dev 發布v3.1.0更新於 Oct 29, 2026
Portfolio analytics via the okama library: backtests, Monte Carlo, efficient frontier, PNG charts
概覽
本機 MCP 伺服器,封裝 okama 投資組合工具庫,讓助理能回測組合、執行蒙地卡羅預測、建立效率前緣並產生 PNG 圖表。
- 可以做什麼
- 搜尋資產與命名空間,讀取資產中繼資料、價格歷史、股利與總體經濟序列
- 比較資產:統計指標、相關性、滾動風險與報酬、基準指標
- 回測投資組合:主要指標、回撤、VaR/CVaR、財富指數、滾動 CAGR
- 執行蒙地卡羅預測、IRR、可持續提領規模與多階段財務規劃
- 建立效率前緣,含切點組合、最小變異數組合與最大分散化組合
- 產生財富指數、回撤、預測扇形圖、分布圖與效率前緣的 PNG 圖表
- 適用情境
- 適合讓助理直接回答投資組合問題——回測、退休或提領模擬、風險統計與效率前緣最佳化——不必撰寫 Python 程式碼。適用於在桌面 MCP 用戶端使用 okama 市場資料的分析師與顧問。
- 執行需求
- 以 Python 套件形式透過 stdio 在本機執行(以 uvx、pipx 或 pip 安裝 okama-mcp);需要 Python 3.11 以上,以及 okama 與 okama-planner 相依套件。未宣告 API 金鑰或帳號。README 指出 PyPI 已發布版本落後於原始碼版本,部分用戶端工具與 Excel 匯出需要相容的 Planner 配套元件。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Okama Mcp,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
okama-mcp
[PyPI] [CI] [Python] [License: MIT]
[okama-mcp — investment analytics for AI assistants]
MCP (Model Context Protocol) server that exposes the okama investment portfolio toolkit and okama Planner to AI assistants — Claude Desktop, Claude Code, Cursor, Codex, 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 self-hosting).
okama-mcp is free and open source. Run it locally or on your own server. The HTTP
transport is intended for self-hosting; mcp.okama.io serves the project
landing page, not a public MCP endpoint. Client registry tools and Excel exports
require a compatible Planner companion and a configured local stdio installation.
Install
Development status (26 October 2026): main prepares MCP 3.1.0 with Planner
0.5.0; neither version has been published yet. Use the source setup below.
PyPI still provides MCP 3.0.0 with Planner 0.4.1 and its earlier contracts.
Requires Python ≥ 3.11 (same floor as okama itself); okama ≥ 4.0.0 and
okama-planner[reports]>=0.5.0,<0.6.0 are required.
Client data modes (source checkout): local MCP defaults to anonymous reads.
client_data_mode_set({"mode":"personal_data"}) enables full client CRUD;
{"mode":"anonymous"} disables client writes again. The setting persists per
database across connections. uv sync installs a pinned Planner 0.5.0 source
revision with the required access API. PyPI still provides Planner 0.4.1, so the prepared release remains blocked until the compatible companion is published;
see installation and release gates.
Market and finplan_* tools remain available independently. See the
3.0 migration notes for the earlier release behavior.
The easiest way — no clone, no venv — is uv or pipx:
Plain pip works too:
[!WARNING] With pip, prefer a dedicated virtual environment: on most modern Linux distros the system Python is marked externally managed (PEP 668), so
pip installoutside a venv fails, and a shared environment risks dependency conflicts. In your MCP client config, pointcommandat the absolute path of theokama-mcpscript inside the venv — GUI clients don't see your shellPATH.uvxandpipxavoid all of this by isolating the install automatically.
To work on the code, install from source instead:
Until Planner 0.5.0 is published, tool.uv.sources pins an immutable development
companion. Release gates use uv sync --all-groups --no-sources and require
published dependencies; no source substitution is used for publication.
Remove the development pin after published-pair acceptance passes.
Run
When running from a source checkout, prefix each command with uv run.
Each worktree has its own .venv; test and dev groups are installed by default.
uv.lock is generated locally and is not committed, so fresh checkouts resolve
compatible versions independently. Orca runs the bootstrap in orca.yaml before
starting the agent; its source MCP configuration uses uv run --no-sync after setup.
Connect a client
Claude Desktop
Edit ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or
%APPDATA%\Claude\claude_desktop_config.json (Windows):
Restart Claude Desktop; the server appears in the tools menu.
Claude Code
To make the server available in every project (works from any directory):
Developers running from a source checkout can use claude mcp add okama -- uv run okama-mcp stdio from the project root instead.
Or commit a .mcp.json at the project root so the whole team picks it up:
Cursor
Add the server to .cursor/mcp.json in your project (or ~/.cursor/mcp.json to make
it global):
Codex (CLI & Desktop)
Add the server with one command:
Or declare it in ~/.codex/config.toml (or a project-scoped .codex/config.toml
in trusted projects):
The Codex CLI, desktop app, and IDE extension share this configuration — set it up once and it works in all three.
Self-hosting (streamable HTTP)
Run okama-mcp on your own server and share it across your MCP clients:
(From source: uv run okama-mcp http ...)
Then point your MCP client at http://<your-server>:8765/mcp. For a production
setup put nginx + TLS in front; ready-made examples live in deploy/:
deploy/systemd/okama-mcp.service— systemd unit (hardened, runs as a dedicated user)deploy/nginx/self-hosted.conf— nginx vhost: TLS, SSE-friendly proxying of/mcp
The server is open by design — free to run, no registration. If your instance must not be public, restrict access at the nginx level (allow-list, VPN, or HTTP basic auth).
Tool catalog
A multi-stage financial plan (contribute $1,000/month for 20 years into a 70/30 SPY/AGG portfolio, then withdraw $6,000/month indexed to inflation for 25 years), a Monte Carlo retirement forecast (30% gold / 70% real estate, withdrawing $1,000/month indexed to inflation over 25 years) and the efficient frontier of SPY/BND/GLD:
[Financial-plan forecast fan — percentile bands with dashed stage boundaries]
[Monte Carlo forecast fan — percentile bands of future wealth]
[Efficient frontier — SPY.US, BND.US, GLD.US (USD)]
Financial tools are stateless — pass the full portfolio specification with every call.
Optional local client tools use stable registry codes and a persistent, database-scoped access mode.
Client creation is not idempotent: inspect the registry before retrying an ambiguous creation result.
The server caches expensive okama objects (Portfolio, EfficientFrontier) by content
hash, so repeated calls on the same spec are fast.
Nested portfolios. Wherever a list of assets is accepted — the assets field of
PortfolioSpec/FrontierSpec, or the portfolios argument on the comparison tools —
an entry may be a ticker string or a nested portfolio object (the same spec shape).
This lets you treat a whole portfolio as a single component: e.g. compare a 60/40
portfolio against gold, or put a sub-portfolio on the efficient frontier.
Search & metadata
Single asset & comparisons
Portfolio backtest
Monte Carlo DCF
The mc argument accepts distribution_parameters to override the fitted distribution (e.g. a fixed Student-t df); see the MCSpec shape below.
Financial plan (multi-stage)
A plan is an ordered sequence of stages, each with its own portfolio, horizon and
cash-flow regime. Scenarios are chained: the balance a Monte Carlo scenario ends a
stage with is the balance it starts the next one with, so the retirement stage is
funded by whatever the accumulation stage produced in that same scenario — not by
a percentile of it. Use these instead of monte_carlo_forecast whenever the portfolio
or the contribution/withdrawal regime changes partway through the horizon.
Distribution diagnostics
DCF (historical cash-flow analysis)
Efficient Frontier
Macro
Charts
Each tool renders a PNG (default 1500×900) and returns it as MCP image content —
clients like Claude Desktop display it inline. Every chart tool also accepts
optional width / height (pixels, 300–4000) for custom sizes and aspect ratios,
and an optional save_path — the chart is then also written to that file and the
path reported back. Use save_path in clients that don't render MCP images in
their UI (e.g. Claude Code's terminal): ask for a chart "saved to /tmp/chart.png"
and open the file reference. Note: in self-hosted (streamable-http) deployments
save_path is written on the server's filesystem, not the client's machine.
Finding symbols and choosing tools
Start with list_namespaces(): its original namespaces description mapping is
preserved, and usage explains what each namespace supports. Use
search_assets(namespace="INDX") to browse an index catalog, or
search_assets(query="bitcoin", namespace="CC") for cryptocurrencies. Search rows
include namespace and supports_asset_returns (null when unknown).
Search is case-insensitive; exact symbol/ticker/ISIN matches rank first, then
exact names, prefixes and other matches. Scoped queries match punctuation
literally. With oldest_first=true, date order takes precedence. Symbol order
breaks ties. Results are ordered before paging: repeat the same query and filters
with offset=next_offset until has_more=false. count describes all filtered
matches; truncated means the current page is not the entire result set, including
the last page of a multi-page result. Pages reflect the current catalog, so data
updates between calls can move page boundaries.
RATE, INFL and RATIO are macroeconomic series. Read their values and metadata
with get_central_bank_rate, get_inflation and get_indicator, respectively.
For example, RUS_RUB.RATE describes a deposit rate, whereas OKID.INDX is an
investment-return index: they are different inputs. Asset tools reject a macro
symbol with the appropriate next call; they never replace it with an index.
Discover the intended index separately before comparing returns. Unknown upstream
namespaces have no advertised MCP routes until support is implemented.
Spec shapes
The complex tools accept JSON objects described by complete Pydantic-generated
input schemas in MCP tools/list: nested fields, required values, constraints,
defaults and cash-flow variants are visible to the client. Definitions live in
src/okama_mcp/schemas.py; here are the headline shapes:
Development
The project follows TDD (see AGENTS.md). After every code change run:
To run the live-API integration test (hits api.okama.io):
Project layout
License
MIT — same license as okama itself.
Planner and local client workflows
Planner tools require a companion providing okama_planner.ai; local client
modes additionally require PlannerClientAccess. uv sync resolves the pinned
compatible source. Missing APIs fail closed. Configured local stdio exposes
17 client tools and Excel export (70 tools total); HTTP has no client or local report tools.
The default anonymous mode returns pseudonyms and refuses all persistent client
writes. Personal details are maintained in Planner. Call client_data_mode_set
with mode="personal_data" to read full records, create, update or delete clients,
and save residency notes and plan versions through Planner's API. Call it with
mode="anonymous" to return to anonymous access. client_data_mode_get shows the
saved mode, shared by connections using the same database and retained on restart.
Deletion includes the selected client's linked Planner records. Sparse updates
preserve omitted fields; explicit null clears an optional field where Planner
permits it. Forecasts and reports stay anonymous in both modes. Errors use fixed
messages without private values, database details or filesystem paths.
The legacy --allow-personal-data flag only initializes a missing saved setting;
it never overrides a mode explicitly saved through MCP. Meetings and bounded
history pages use the same access policy. The former packaged intake skill remains retired.
See configuration and tool contracts and
language behavior.
Explore the okama family
Tools for investing and financial planning.
Ask questions, share examples and discuss financial planning.
來源:README.md,提交 27745d7
工具
0版本歷史
4- v3.1.0最新Oct 29, 2026
- v3.0.0Oct 26, 2026
- v2.0.0Oct 9, 2026
- v1.9.0Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分
