FinanceToolkit

repository·main·Indexed 26 days ago

https://github.com/jerbouma/financetoolkit

An open-source Python library for transparent financial analysis providing over 200 financial ratios, indicators, and performance measurements across equities, options, and crypto. It includes modules for financial statements, risk metrics (VaR), technical indicators, options pricing (Black-Scholes), and economic indicators. The toolkit supports integration as an MCP server for AI clients like Claude, Cursor, and Windsurf, and utilizes FinancialModelingPrep and Yahoo Finance as data sources.

Tokens
16.1K
Snippets
48
Records
89
Agent score
85%

What's inside financetoolkit

  1. Build and Test the MCP Bundle Locally

    main

    To build the MCP bundle from a local repository for testing purposes, follow these steps:

    1. Clone the repository: git pull https://github.com/JerBouma/FinanceToolkit
    2. Install dependencies: uv sync
    3. Run the build script: bash financetoolkit/mcp_server/mcpb/build-mcpb.sh
    4. The resulting bundle will be located in the dist/ directory.

    Note: By default, the bundle uses the published PyPI package. To include uncommitted local changes in your bundle, use the --local flag. This produces dist/financetoolkit-local.mcpb, which points to your local checkout via uv's [tool.uv.sources].

  2. Install the Finance Toolkit MCP Server locally

    main

    To install the MCP server locally, you can use the automated setup wizard which locates your client's configuration file and writes the necessary MCP entry and API key automatically.

    Alternatively, you can manually add the server configuration to your client's MCP config file (e.g., claude_desktop_config.json, .cursor/mcp.json, or .vscode/mcp.json).

    uvx --from "financetoolkit[mcp]" financetoolkit-mcp-setup
  3. Use FinanceToolkit as an MCP Server

    main

    You can query over 200 financial metrics from MCP-compatible clients (like Claude, Copilot, Cursor, or Windsurf) without writing code.

    Local Setup

    Use uvx to set up your client configuration and API key automatically:

    uvx --from "financetoolkit[mcp]" financetoolkit-mcp-setup

    Hosted Setup

    Connect to the hosted server: https://financetoolkit.jeroenbouma.com/mcp (OAuth handles authentication on first use).

  4. Initialize the Finance Toolkit

    main

    To begin using the toolkit, initialize the Toolkit class with a list of ticker symbols, your API key, and a starting date. This instance serves as the base for accessing various financial modules like ratios, technicals, and risk metrics.

    from financetoolkit import Toolkit
    
    # Initialize the Toolkit for Apple and Microsoft
    companies = Toolkit(["AAPL", "MSFT"], api_key=API_KEY, start_date="2017-12-31")
  5. Install the Finance Toolkit MCP Bundle

    main

    You can install the Finance Toolkit MCP Server into compatible AI clients (like Claude Desktop or Claude Code) using the .mcpb bundle. This method requires no manual Python configuration.

    1. Download the latest financetoolkit.mcpb from the releases page.
    2. Double-click the downloaded file to open Claude Desktop.
    3. Click "Install" when prompted by the Claude Desktop prompt.
    4. Confirm the installation by clicking "Install" again.
    5. Provide your Financial Modeling Prep API key (obtain one here) and click "Save".
    6. Toggle the bundle switch from "Disabled" to "Enabled".
    7. Restart Claude Desktop to begin using the Finance Toolkit MCP Server in your conversations.
  6. Connect to the Finance Toolkit Remote MCP Server

    main

    You can connect directly to the hosted Finance Toolkit MCP server without local installation. On the first connection, you will be prompted via an OAuth consent page to provide your Financial Modeling Prep (FMP) API key.

    Connection URLs and Methods:

    • Claude Desktop / Claude.ai: Customize → Connectors → Add custom connector → paste https://financetoolkit.jeroenbouma.com/mcp
    • Claude Code: Use the CLI command provided below.
    • VS Code: Command Palette → MCP: Add Server → HTTP → paste the URL.
    • Cursor: Settings → Features → MCP Servers → Add new → http → paste the URL.
    • Windsurf: Settings → MCP Servers → Add Server → Remote/HTTP → paste the URL.
    claude mcp add --transport http finance-toolkit https://financetoolkit.jeroenbouma.com/mcp
  7. Configure metric windows, growth, and standardization

    main

    The Finance Toolkit provides three powerful capabilities across nearly all get_* and collect_* functions to transform raw data into time series or standardized scores:

    • rolling=<n> and trailing=<n>: Use rolling for a sliding window or trailing for a trailing sum/average (e.g., trailing=4 for a trailing 4-quarter sum) to turn snapshots into time series.
    • growth=True and lag: Pass growth=True to return period-over-period growth. Use lag (an int or list of ints, default 1) to specify the comparison period (e.g., lag=4 for year-over-year growth on quarterly data). Combine with trailing (e.g., trailing=4, growth=True) to calculate Trailing Twelve Months (TTM) growth.
    • standardize=True: Converts raw values into Z-Scores (standard deviations from their historical mean/std). This is useful for ranking or comparing metrics on different scales.
  8. Configure manual MCP server settings

    main

    If you prefer manual configuration, add the following block to your MCP configuration file. Ensure you replace YOUR_API_KEY_HERE with your actual Financial Modeling Prep API key.

    {
      "mcpServers": {
        "finance-toolkit": {
          "command": "uvx",
          "args": ["--from", "financetoolkit[mcp]", "financetoolkit-mcp"],
          "env": { "FINANCIAL_MODELING_PREP_API_KEY": "YOUR_API_KEY_HERE" }
        }
      }
    }
  9. Deploy the finance-toolkit-mcp server using Docker Compose

    main

    You can deploy a local instance of the finance-toolkit-mcp server using Docker Compose. This setup allows for testing, development, or server deployment. The service exposes an HTTP transport interface on port 8000.

    Required Environment Variables

    • FT_MCP_SECRET_KEY: A secret key required for the MCP server. This should be provided as an environment variable to the Docker Compose process.

    Configuration Details

    • Ports: Maps host port 8000 to container port 8000.
    • Transport: Configured to use streamable-http via MCP_TRANSPORT.
    • Persistence: Uses a named volume ft_cache mapped to /root/.config/financetoolkit to persist toolkit configuration and cache.
    • Healthcheck: The service performs a health check by requesting http://localhost:8000/health every 30 seconds.
    services:
      finance-toolkit-mcp:
        build: .
        restart: unless-stopped
        ports:
          - "8000:8000"
        environment:
          MCP_TRANSPORT: streamable-http
          MCP_HOST: "0.0.0.0"
          MCP_PORT: "8000"
          FT_MCP_SECRET_KEY: "${FT_MCP_SECRET_KEY}"
        volumes:
          - ft_cache:/root/.config/financetoolkit
    
    volumes:
      ft_cache:
  10. Configure Finance Toolkit for MCP clients

    main

    Use the setup() function (exposed via the financetoolkit-mcp-setup command) to configure the Finance Toolkit for various Model Context Protocol (MCP) clients.

    Interactive Mode

    Running setup() without arguments launches an interactive wizard that allows you to select one or more clients (Claude Desktop, Claude Code, VS Code, Cursor, Gemini, Windsurf) and manage your API key.

    Non-interactive Mode

    To configure a specific client without the interactive menu, use the --client flag. This is useful for automated environments or scripts.

    Arguments

    • --client {claude-desktop,claude-code,vscode,cursor,gemini,windsurf}: Configure a specific client non-interactively.
    • --overwrite: Silently overwrite an existing configuration without prompting.