Skip to main content

English | 简体中文

typing

PyPI Version Downloads Stars Python MIT License


31 Tools A Shares HK US Futures

⚡ 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


✨ 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

Claude Desktop
{
  "mcpServers": {
    "mcp-finance": {
      "command": "python",
      "args": ["-m", "mcp_finance.server"]
    }
  }
}
Codex
codex mcp add mcp-finance -- python -m mcp_finance.server
Cursor / VS Code
{
  "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/ojkkk/mcp-finance.git
cd mcp-finance
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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_markets-0.13.1.tar.gz (328.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_markets-0.13.1-py3-none-any.whl (131.3 kB view details)

Uploaded Python 3

File details

Details for the file mcp_markets-0.13.1.tar.gz.

File metadata

  • Download URL: mcp_markets-0.13.1.tar.gz
  • Upload date:
  • Size: 328.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.9

File hashes

Hashes for mcp_markets-0.13.1.tar.gz
Algorithm Hash digest
SHA256 eef663a4b434f9aa2f944d2671e9f58823713b98c3327887c0a3038b9f7084e7
MD5 0f56ecc8b52a2565faf2bcd593e5b4c8
BLAKE2b-256 4441dce77cf4ec23a6f5c60b1463496b37108d9561468958abc40eb2f3c24dd8

See more details on using hashes here.

File details

Details for the file mcp_markets-0.13.1-py3-none-any.whl.

File metadata

  • Download URL: mcp_markets-0.13.1-py3-none-any.whl
  • Upload date:
  • Size: 131.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.9

File hashes

Hashes for mcp_markets-0.13.1-py3-none-any.whl
Algorithm Hash digest
SHA256 681248370cd6b7dbe2694dfd634a8b14b6637da188eccec969146033271b5175
MD5 c418546816140c904527642dbe7236dc
BLAKE2b-256 72b56babffdeb72777b3b5e5d9e0909943d4233375be49891c878617c9a8690d

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.13.1 This release

2 files

0.13.0

2 files

0.12.10

1 file

0.12.9

1 file

0.12.8

1 file

0.12.7

2 files

0.12.6

2 files

0.12.5

2 files

0.12.4

2 files

0.12.3

2 files

0.12.2

2 files

0.12.1

2 files

0.12.0

2 files

0.11.0

2 files

0.10.0

2 files

0.9.6

2 files

0.9.5

2 files

0.9.4

2 files

0.9.0

2 files

0.8.0

2 files

0.6.1

1 file

0.6.0

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page