Skip to main content
Glama
mcp-finance

mcp-finance

by xiaobinzhe

English | 简体中文


⚡ Quick Start

pip install mcp-markets

# Mode 1: Run as an MCP Server (for Claude / Codex / Cursor)
python -m mcp_finance.server

# Mode 2: Launch the built-in Web Dashboard
mcp-dashboard              # default http://localhost:8080

Python 3.10+ · MCP Python SDK 2.x · Zero config · Optional TUSHARE_TOKEN env var for advanced fundamentals


Related MCP server: Stock SDK MCP Server

✨ Capabilities at a Glance

Module

Capability

Highlight

📈 Real-time Quotes

A-Share / HK / US / Futures / Indices

easy-tdx millisecond-level with tri-source fallback

📊 K-line Data

Daily / Weekly / Monthly / Minute bars, adj.

800 bars for A-shares, yfinance fallback for HK/US

🔬 Technical Analysis

MA·MACD·KDJ·RSI·BOLL·WR·BIAS

Auto-detect golden/dead cross & overbought/oversold

🔍 Stock Screener

11-dimension filter + 5-factor ranking

Momentum · Value · Quality · Growth · Volatility

🧪 Backtesting

9 strategies + parameter optimization

Backtrader event-driven, 125× performance boost

💼 Portfolio

Multi-stock comparison + correlation + portfolio backtest

Equal-weight or custom weights

🏢 Fundamentals

Financials / Holdings / Research / Dragon-Tiger

AKShare + Tushare dual source

🖥️ Web Dashboard

Flask real-time dashboard

Plotly + ECharts interactive charts


🏗️ Four-Source Architecture

graph LR
    A["📡 Data Sources"] --> B["⚡ easy-tdx<br/>TDX TCP · <50ms"]
    A --> C["🌐 AKShare<br/>Sina / THS / EastMoney"]
    A --> D["🌍 yfinance<br/>Yahoo Finance Fallback"]
    A --> E["📈 Tushare<br/>Deep Fundamentals · Token"]

    B --> F["🔧 31 MCP Tools"]
    C --> F
    D --> F
    E --> F

    F --> G["📈 Quotes<br/>Real-time · Batch · K-line"]
    F --> H["🔬 Technical<br/>MA·MACD·KDJ·RSI·BOLL"]
    F --> I["📋 Screening<br/>Conditional · 5-Factor"]
    F --> J["⚙️ Backtest<br/>9 Strategies · Bayesian Opt"]
    F --> K["📊 Portfolio<br/>Comparison · Correlation"]
    F --> L["🏢 Fundamentals<br/>Financials · Research · Flow"]
    F --> M["🖥️ Dashboard<br/>Flask Web · Live Refresh"]

    style A fill:#1e1b4b,stroke:#6366f1,color:#fff
    style F fill:#0f172a,stroke:#334155,color:#fff
    style G fill:#312e81,color:#fff
    style H fill:#312e81,color:#fff
    style I fill:#312e81,color:#fff
    style J fill:#312e81,color:#fff
    style K fill:#312e81,color:#fff
    style L fill:#312e81,color:#fff
    style M fill:#be185d,color:#fff

🎯 All 31 MCP Tools

Quotes & Market Data

Tool

Description

Data Source

Latency

get_realtime_quote

Single-stock real-time quote (price / change / volume ratio / turnover)

easy-tdx → AKShare → yfinance

< 100ms

batch_quotes

Batch real-time quotes for multiple stocks

easy-tdx

< 1s / batch

get_kline

Daily / Weekly / Monthly K-line with forward/backward adjust

easy-tdx (A) / AKShare+yfinance (HK/US)

< 500ms

get_minute_kline

1/5/15/30/60 minute K-line (A-shares only)

easy-tdx

< 200ms

get_market_indices

A-share / HK / US market indices

easy-tdx → AKShare

< 500ms

get_futures_list

China commodity & index futures main contracts

AKShare Sina

~1s

search_stock

Fuzzy search by code or name

Local mapping

Instant

Technical Analysis

Tool

Description

get_technical_indicators

MA·MACD·KDJ·RSI·BOLL·WR·BIAS + auto signal detection

plot_kline

Interactive candlestick HTML with moving averages, volume, MACD/KDJ/RSI sub-charts

Screening & Analysis

Tool

Description

stock_screener

11-dimension conditional screening (change / volume ratio / turnover / PE / PB / ROE / market cap…)

factor_screener

5-factor composite scoring & ranking (momentum · value · quality · growth · volatility)

analyze_stock

One-stop stock analysis report (quote + technicals + financials + score 0-100)

compare_stocks

Multi-stock comparison ranked by score

correlation_matrix

Return correlation matrix for diversification

Backtesting & Optimization

Tool

Description

Strategies

backtest_strategy

Single-stock strategy backtest

MA Cross · MACD · RSI · KDJ · BOLL · Turtle · Vol Trend · Mean Reversion · Custom Combo

optimize_strategy

Grid search / Optuna TPE Bayesian optimization

Auto-pruning + parameter importance

walk_forward

Walk-Forward out-of-sample validation

Rolling train/test · overfitting assessment

monte_carlo_test

Monte Carlo robustness test

Return reshuffling · probability and drawdown distributions

portfolio_backtest

Multi-stock portfolio backtest

Custom weights / equal weight

Market Intelligence

Tool

Description

get_sector_ranking

Industry / Concept / Region sector rankings

get_north_flow

North/South-bound capital flow (Stock Connect)

get_fund_flow

Individual stock fund flow (easy-tdx millisecond-level)

get_dragon_tiger

Dragon & Tiger list (broker buy/sell details)

get_block_trades

Block trade details

get_margin_trading

Margin trading & short selling data

get_macro_data

China macroeconomics (GDP / CPI / PMI / M2 / FX reserves)

Fundamentals

Tool

Description

get_financials

5 categories, 19+ indicators (core / profitability / growth / risk / operations)

get_institutional_holdings

Top 10 shareholders & institutional holdings

get_research_reports

Analyst research reports (ratings + price targets)

comparison_chart

Multi-stock normalized comparison chart (interactive HTML)

test_data_sources

One-click diagnostic of all data source availability


🖥️ Web Dashboard

Built-in Flask dashboard that visualizes all MCP tool capabilities.

mcp-dashboard              # http://localhost:8080
mcp-dashboard 3000         # custom port
mcp-dashboard --host 0.0.0.0  # explicitly allow LAN access

Page

Route

Features

Market Overview

/

Indices · Hot stocks · Sector rankings · North flow · K-line lookup · Search

Screener

/screener

5-factor ranking + 11-dimension conditional screening

Backtest

/backtest

9 strategies · Grid / Bayesian optimization · Walk-Forward · Monte Carlo (Dashboard and MCP)

Responsive layout · Plotly / ECharts interactive charts · Live quote refresh


🔌 MCP Client Setup

{
  "mcpServers": {
    "mcp-finance": {
      "command": "python",
      "args": ["-m", "mcp_finance.server"]
    }
  }
}
codex mcp add mcp-finance -- python -m mcp_finance.server
{
  "mcpServers": {
    "mcp-finance": {
      "type": "stdio",
      "command": "python",
      "args": ["-m", "mcp_finance.server"]
    }
  }
}

Optional: Tushare fundamentals — Set TUSHARE_TOKEN=your_token env var. Register free. Falls back gracefully without it.


🧪 Development & Testing

git clone https://github.com/xiaobinzhe/finance-anyl-mcp.git
cd finance-anyl-mcp
pip install -e ".[dev]"

# Run tests
pytest tests/ -v

# Lint
ruff check mcp_finance/

🌟 AI Conversation Examples

Scenario

Natural Language Query

Quote

"What's the price of Moutai (600519)?" / "How are Tencent HK and Apple US doing today?"

Technical

"Is Moutai's MACD golden cross? What's the RSI?"

Screening

"Find A-shares up >3%, volume ratio >1.5, PE <30" / "Top 20 by 5-factor ranking"

Backtest

"Backtest MA cross (5,20) on Moutai for 2024" / "Find the best MACD params for Moutai"

Portfolio

"Backtest equal-weight portfolio of Moutai + CATL + CMB for the past year"

Analysis

"Give me a comprehensive analysis of Moutai" / "Compare Moutai, Wuliangye, Luzhou Laojiao"

Macro

"Show me recent China CPI data" / "What is north-bound capital buying recently?"

Research

"Latest analyst ratings for Moutai"


⚠️ Disclaimer

This tool is for educational purposes only. All data is for reference and does not constitute investment advice.

  • Data is sourced from third-party public APIs and web scraping, with no guarantee of accuracy, completeness, or timeliness

  • No proprietary data sources; all data depends on easy-tdx (reverse-engineered TDX protocol), AKShare (web scraping), yfinance, and Tushare

  • No commercial data license; personal non-commercial use is acceptable, commercial use carries copyright and compliance risks

  • Backtest results do not predict future performance

  • The author bears no responsibility for any investment losses · Invest at your own risk


📄 License

MIT © mcp-finance

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables AI assistants to query real-time and historical market data across A-shares, Hong Kong, US stocks, funds, futures, and options, including K-lines, technical indicators (MA/MACD/BOLL/KDJ/RSI), sector and capital-flow data. It also provides composite analysis tools, presets, and prompts for stock screening, multi-stock comparison, portfolio monitoring, and market overviews.
      140 npm
      ISC
    • A
      license
      Not graded
      quality
      A
      maintenance
      Enables AI assistants to fetch real-time and historical market data across A-shares, Hong Kong and US equities, funds, futures, and options, including technical indicators, sector and capital-flow data, and trading calendars. It also provides composite analysis tools and built-in prompts/skills for full-stock diagnostics, multi-stock comparison, market overviews, conditional screening, and portfolio monitoring.
      140 npm
      ISC
    • A
      license
      Not graded
      quality
      A
      maintenance
      Enables AI assistants to query real-time and historical market data across A-share, Hong Kong, US, and fund markets, including quotes, K-line data, technical indicators, sector and futures/options data. It also supports batch market scans, composite stock analysis, condition-based screening, and built-in analyst prompts and skills for financial workflows.
      140 npm
      ISC
    • A
      license
      Not graded
      quality
      A
      maintenance
      Enables AI assistants to query real-time and historical market data for A-shares, Hong Kong, US stocks, funds, futures, options, and sectors, calculate technical indicators, and run screening and composite analysis workflows. It also exposes prompts and resources for stock analysis, market overviews, monitoring, and futures data.
      140 npm
      ISC