Finance Intelligence MCP Server

Finance Intelligence MCP Server

A production-grade MCP server that provides AI assistants with real-time financial market data, company metrics, and historical prices using yfinance and FastMCP.

Category
访问服务器

README

Finance Intelligence MCP Server

Python 3.12+ License: MIT Ruff Checked with mypy

A production-grade, asynchronous Model Context Protocol (MCP) server that grants AI assistants (Claude Desktop, Cursor, ChatGPT, VS Code, etc.) access to real-time financial market data, company metrics, and history.

Powered by FastMCP, yfinance, and Pydantic, this server uses advanced thread-offloading, caching, and robust error isolation to provide standard JSON-RPC tools with zero crashes.


Architecture Overview

               +--------------------------------------+
               |    LLM Client (e.g. Claude Desktop)  |
               +------------------+-------------------+
                                  |
                                  | (JSON-RPC over stdio / SSE)
                                  v
               +------------------+-------------------+
               |      Finance Intelligence MCP        |
               |                                      |
               |   +------------------------------+   |
               |   |          server.py           |   |
               |   +--------------+---------------+   |
               |                  |                   |
               |                  v                   |
               |   +------------------------------+   |
               |   |   tools (stocks / companies) |   |
               |   +--------------+---------------+   |
               |                  |                   |
               |                  v                   |
               |   +------------------------------+   |
               |   |        clients/yahoo.py      |   |
               |   |   (Thread Pool & TTL Cache)  |   |
               |   +--------------+---------------+   |
               +------------------|-------------------+
                                  |
                                  v (asyncio.to_thread)
               +------------------+-------------------+
               |         Yahoo Finance Service        |
               +--------------------------------------+

Key Design Decisions

  1. Async Thread Pool Execution yfinance is fundamentally a blocking synchronous library. Directly calling it in async tool handlers would block the event loop, freezing the MCP server. We offload every yfinance call to a thread pool via asyncio.to_thread.
  2. In-Memory TTL Caching To prevent Yahoo Finance rate limits and reduce tool latency during conversational loops, we implement a thread-safe, in-memory cache with a configurable TTL (default: 5 minutes) for ticker info and history query responses.
  3. Safe Log Handling Stdout (sys.stdout) is strictly reserved for the MCP JSON-RPC protocol transport. Standard logs are redirected entirely to stderr (sys.stderr) using a custom structured logger to prevent channel corruption.
  4. Crash-Resilient Tool Handlers Every tool is wrapped in strict try-except blocks. Instead of crashing the server, exceptions (e.g., TickerNotFound, network timeouts) are caught, logged, and returned as structured JSON error responses.

Features & Available MCP Tools

The server exposes 5 standardized tools:

Tool Name Parameters Description Returns
search_company query: str Search for matching company names, tickers, and exchanges JSON array of results
get_stock_price symbol: str Retrieve real-time pricing and basic exchange details Current price, state, currency, time
get_stock_info symbol: str Retrieve key fundamentals, stats, and company info Market cap, P/E, beta, dividend yield, etc.
compare_companies symbol1: str, symbol2: str Side-by-side metric comparison of two tickers Structured comparative matrix
get_stock_history symbol: str, period: str Download historical prices (1d, 5d, 1mo, 3mo, 6mo, 1y, 5y, max) Chronological price records

Installation

Prerequisites

  • Python 3.12 or newer
  • Virtual Environment or uv package manager

Standard Setup

  1. Clone the repository:

    git clone https://github.com/yourusername/finance-intelligence-mcp.git
    cd finance-intelligence-mcp
    
  2. Create a virtual environment and install dependencies:

    python3 -m venv .venv
    source .venv/bin/activate
    pip install --upgrade pip
    pip install -e ".[dev]"
    
  3. Configure the environment: Create a .env file from the example:

    cp .env.example .env
    

    (Adjust values like CACHE_TTL_SECONDS or LOG_LEVEL if needed.)


Usage

Running Locally

To run the server in the default stdio mode (which local clients like Claude Desktop use):

python -m src.main

To run the server in SSE (HTTP) mode:

python -m src.main --transport sse --port 8000

Client Integration Configurations

1. Claude Desktop Configuration

Add the following to your Claude Desktop configuration file (typically at ~/Library/Application Support/Claude/claude_desktop_config.json on macOS or %APPDATA%\Claude\claude_desktop_config.json on Windows):

Standard Execution (Python Venv):

{
  "mcpServers": {
    "finance-intelligence": {
      "command": "/Users/YOUR_USER/Desktop/finance mcp/.venv/bin/python",
      "args": [
        "-m",
        "src.main"
      ],
      "env": {
        "LOG_LEVEL": "INFO",
        "CACHE_TTL_SECONDS": "300"
      }
    }
  }
}

Docker Execution:

{
  "mcpServers": {
    "finance-intelligence-docker": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "finance-intelligence-mcp:latest"
      ]
    }
  }
}

2. Cursor Configuration

To add the server to Cursor:

  1. Open Cursor Settings -> Features -> MCP.
  2. Click + Add New MCP Server.
  3. Fill out the fields:
    • Name: Finance Intelligence
    • Type: command
    • Command: /path/to/project/.venv/bin/python -m src.main

Docker Containerization

  1. Build the image:

    docker build -t finance-intelligence-mcp:latest .
    
  2. Run the image locally in stdio mode:

    docker run -i --rm finance-intelligence-mcp:latest
    
  3. Run the image locally in HTTP/SSE mode:

    docker run -d -p 8000:8000 --name finance-mcp finance-intelligence-mcp:latest --transport sse --port 8000
    

Example Prompts

Here are some prompt examples you can ask your AI model once the server is connected:

  • Search: "Find the stock ticker for Nvidia." -> Triggers search_company(query="Nvidia")
  • Price: "What is the current stock price and market state of Apple (AAPL)?" -> Triggers get_stock_price(symbol="AAPL")
  • Info: "Show me the key financials for Microsoft, including market cap, beta, and P/E ratio." -> Triggers get_stock_info(symbol="MSFT")
  • Comparison: "Compare Apple and Microsoft stocks side by side." -> Triggers compare_companies(symbol1="AAPL", symbol2="MSFT")
  • History: "Analyze the historical performance of Tesla (TSLA) over the past month." -> Triggers get_stock_history(symbol="TSLA", period="1mo")

Quality & Testing

We enforce code quality through automated checks.

Run Tests

pytest tests/ -v

Run Linter

ruff check src/ tests/

Run Type Checker

mypy src/

Roadmap

Roadmap

  • [x] Stock prices
  • [x] Company information
  • [x] Stock comparison
  • [ ] Financial statements
  • [ ] Crypto support
  • [ ] Macroeconomic indicators
  • [ ] Portfolio analysis
  • [ ] DCF valuation

Contributing

Contributions are welcome! Please open an issue or submit a pull request with any suggestions or improvements. Make sure to run the formatting and test suite before submitting code.


License

This project is licensed under the MIT License - see the LICENSE file for details.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选