Finance MCP Aggregator
A scoped aggregator MCP server that routes intent to the 4-7 relevant finance tools from a 43-tool catalog, reducing token cost and improving tool-selection accuracy.
README
Finance MCP Aggregator
A Scoped Aggregator pattern MCP server: 43 real finance tools, but the model only ever sees the 4–7 that matter for the current turn.
Built to solve a real, measured problem: MCP servers that statically register every tool up front degrade as the tool count grows past ~15. This project implements the fix — dynamic, intent-routed tool exposure — for a domain (personal finance / investing analytics) where 40+ tools is the realistic end state, not a contrived example.
1. The problem, with numbers
Give an LLM 40+ tool schemas in its system prompt on every single turn and four failure modes compound:
| Failure mode | Mechanism | Effect |
|---|---|---|
| Attention dilution | Tool definitions in the middle of a long prompt get less attention ("lost in the middle") | Wrong tool picked, or the right tool picked with the wrong arguments |
| Name/description collisions | get_stock_price vs get_after_hours_price, calculate_var vs calculate_volatility — semantic overlap is inevitable at 40+ tools |
Coin-flip tool selection |
| Parameter hallucination | Model has 40+ schemas competing for context; it blends fields from one schema into a call to another | Invalid API calls, retries, silent wrong answers |
| Context/cost bloat | Every tool schema is JSON sent on every turn, whether used or not | Fewer tokens left for actual conversation, higher per-call cost |
This project measures — not just claims — the first and last of those for its
own tool catalog. Run benchmarks/benchmark_routing.py yourself; here's what
it produced on this repo's 43-tool registry:
TOKEN COST: static merge (43 tools) vs scoped aggregator
Architecture Tokens/turn Tokens/10 turns
Static merge (all 43) 1754 17540
Scoped aggregator 338 3380
Reduction in tool-schema tokens per turn: 80.7%
ROUTING ACCURACY: expected tool in top-6 results
Top-6 accuracy: 25/26 (96.2%) on a 26-query evaluation set spanning all 6 domains
(Token counts are a ~4-chars/token estimate, order-of-magnitude accurate —
swap in tiktoken or Anthropic's tokenizer for exact figures. The
methodology is transparent in the script, not a black box.)
What this means in practice: at $3/M input tokens and 500 tool-augmented
turns/day, the static-merge architecture spends roughly $0.79/day on tool
schemas alone that never get called; the scoped aggregator spends about
$0.15/day for the same volume — and, more importantly, the accuracy numbers
above are what actually protects you from a misrouted execute_trade-style
call in a finance context, where a wrong tool call isn't just an annoyance.
2. Why finance, specifically
Personal finance / investing assistants are one of the few domains where 40+ distinct tools is the honest requirement, not an artificially inflated demo:
- Market data (quotes, history, news, earnings dates, dividends, splits)
- Portfolio analytics (value, returns, Sharpe ratio, diversification, rebalancing, CAGR, drawdown, benchmarking)
- Risk analytics (VaR, beta, volatility, stress testing, correlation, Monte Carlo simulation)
- Technical analysis (SMA, EMA, RSI, MACD, Bollinger Bands, support/resistance, ATR, Fibonacci)
- Fundamental analysis (P/E, EPS, balance sheet, income statement, cash flow, DCF valuation)
- Currency & crypto (FX conversion, live rates, crypto pricing, gas fees)
A real product covering all six domains genuinely needs on the order of 40+ tools. Trying to force that into a single flat MCP tool list is exactly the scenario the Scoped Aggregator pattern is meant for — this repo is that pattern applied to a domain where it's load-bearing, not decorative.
3. Architecture
┌─────────────────────────┐
│ LLM / MCP Client │
│ (Claude Desktop, etc.) │
└────────────┬─────────────┘
│ sees only 4 meta-tools,
│ not all 43
┌───────────────────▼────────────────────┐
│ finance_mcp/server.py │
│ list_finance_categories() │
│ search_finance_tools(query, top_k) ────┼──┐
│ get_tool_schema(tool_name) │ │ 1. TF-IDF cosine
│ execute_finance_tool(tool_name, params) │ │ similarity ranks
└───────────────────┬────────────────────┘ │ query against all
│ │ 43 tool docs
┌────────────▼────────────┐ ◄────────┘
│ router.py (IntentRouter)│
│ ranks registry.py's │
│ 43 ToolSpecs by relevance │
└────────────┬────────────┘
│ 2. top-k names resolved
┌────────────▼────────────┐
│ executor.py │
│ lazily imports + calls │
│ the winning tool │
└────────────┬────────────┘
│
┌───────────────────▼────────────────────┐
│ tools/market_data.py │
│ tools/portfolio_analysis.py │
│ tools/risk_analysis.py │ ← 43 tools total,
│ tools/technical_analysis.py │ only imported when
│ tools/fundamental_analysis.py │ actually called
│ tools/currency_crypto.py │
└──────────────────────────────────────────┘
The flow an LLM actually follows:
search_finance_tools("what's my portfolio's Sharpe ratio")→ returns the 5–6 relevant tools (not all 43), each with its exact parameter schema.execute_finance_tool("calculate_sharpe_ratio", {...})→ runs it.
No dependence on MCP clients supporting tools/list_changed notifications
(many don't, reliably) — the narrowing happens inside a normal tool call,
which every MCP client already supports. This is the same "search then act"
shape you'll recognize from how large codebases expose tool search to
coding agents, applied here to a finance tool catalog.
Why TF-IDF instead of an LLM router or embeddings model
- No extra LLM call — a router that itself needs GPT-4 to pick a tool defeats the purpose (latency + cost on every turn).
- No heavyweight download —
scikit-learninstalls in seconds on a plain Windows Python 3.12 environment; notorch, no model weights. - Deterministic and debuggable — you can inspect exactly which words matched.
- Swappable —
router.pyincludes anEmbeddingRouterwith the same interface for when a catalog grows past a few hundred tools and paraphrase-level matching starts to matter more than raw token overlap. See Scaling further below.
4. Project structure
finance-mcp-aggregator/
├── README.md
├── requirements.txt
├── pyproject.toml
├── .env.example
├── .gitignore
├── LICENSE
├── src/finance_mcp/
│ ├── server.py # MCP server: 4 meta-tools only
│ ├── router.py # IntentRouter (TF-IDF) + EmbeddingRouter
│ ├── registry.py # Metadata for all 43 tools (no imports of impls)
│ ├── executor.py # Lazy resolve + call by dotted path
│ └── tools/
│ ├── _data_source.py # yfinance wrapper w/ offline synthetic fallback
│ ├── market_data.py # 8 tools
│ ├── portfolio_analysis.py # 8 tools
│ ├── risk_analysis.py # 7 tools
│ ├── technical_analysis.py # 8 tools
│ ├── fundamental_analysis.py # 6 tools
│ └── currency_crypto.py # 6 tools
├── benchmarks/
│ └── benchmark_routing.py # Token-cost + routing-accuracy measurements
├── tests/
│ └── test_router.py
└── examples/
└── demo_client.py # Runs the search→execute flow with no LLM/API key
5. Setup (Windows, Python 3.12.4)
git clone https://github.com/<you>/finance-mcp-aggregator.git
cd finance-mcp-aggregator
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt
copy .env.example .env
Run the demo (no MCP client, no API key needed)
python examples\demo_client.py "what's my portfolio's value at risk"
Run the benchmark yourself
python benchmarks\benchmark_routing.py
Run tests
pytest tests\ -v
Run the actual MCP server
Built on the standalone fastmcp
package (not the trimmed-down mcp.server.fastmcp bundled inside the
official mcp SDK) — it tracks the MCP spec closer to real-time and adds a
dev inspector, auth providers, and an HTTP transport out of the box.
# stdio (default) -- what Claude Desktop and most MCP clients expect
python -m finance_mcp.server
# or run it as a standalone HTTP server instead
$env:MCP_TRANSPORT="http"; $env:MCP_PORT="8000"; python -m finance_mcp.server
To use it from Claude Desktop, add to your MCP config
(%APPDATA%\Claude\claude_desktop_config.json):
{
"mcpServers": {
"finance-aggregator": {
"command": "C:\\path\\to\\finance-mcp-aggregator\\.venv\\Scripts\\python.exe",
"args": ["-m", "finance_mcp.server"]
}
}
}
You can also inspect it live with FastMCP's built-in dev tool before wiring it into any client:
fastmcp dev src\finance_mcp\server.py
Note on live data: every tool falls back to deterministic synthetic
data when yfinance has no network access, so the whole test/benchmark
suite runs fully offline. With network access, get_stock_price,
get_historical_prices, get_pe_ratio, etc. pull real data via yfinance
(no API key required).
6. Scaling further than this repo
This repo's registry (43 tools, TF-IDF router) is sized to be genuinely runnable end-to-end without any paid API or heavy install. If you fork this for a catalog of hundreds of tools across many MCP servers, the pattern extends cleanly:
- Categorization → Intent routing → Dynamic ingestion, exactly as
described in the architecture above, generalizes past one server: put an
aggregator server in front of multiple downstream MCP servers (each
exposing its native tools), and have the aggregator's
search_toolsfan out across all of them. - Swap
IntentRouterfor the includedEmbeddingRouter(pip install sentence-transformers) once paraphrase matching ("how risky is my portfolio" ≈ "what's my VaR") starts mattering more than keyword overlap — this repo's benchmark script is the harness to validate that swap actually improves top-k accuracy before you ship it. - For MCP clients that do support
notifications/tools/list_changed, you can go further and only ever expose the narrowed tool list itself (not meta-tools) — trading universal compatibility for a marginally smaller prompt.
7. What this is not
- Not investment advice, and not wired to a brokerage — every calculation tool is a standalone analytics function you'd still validate before acting on.
- The offline synthetic price fallback exists so tests/CI/demos don't
require network or an API key; it is clearly labeled
"source": "synthetic-offline"in every response so it's never confused with real market data. - The DCF, Monte Carlo, and VaR implementations are standard textbook formulations for demonstration; a production system would want a reviewed quant library and real-world backtesting before being trusted with real allocation decisions.
Repository health and contribution model
This repository is structured so it can be pushed and maintained as a clean, open-source Python package:
- Source code lives under
src/finance_mcp/and is buildable throughpyproject.toml. - Tool metadata lives in a registry rather than scattered implementation details.
- The public API is exposed through the server entry point and a stable set of search/execute tools.
- Contribution docs are available in
CONTRIBUTING.md,SECURITY.md, andCHANGELOG.md. - CI automation, issue templates, and pull request templates are available under
.github/.
If you are preparing a public repository push, keep the branch history small and the release artifacts explicit.
License
MIT — see LICENSE.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。