FinTest MCP 数据库查询服务

FinTest MCP Server 是一个模型上下文协议服务,通过 STDIO 为 Claude 提供对 FinTest PostgreSQL 数据库的只读访问,支持 SQL 查询、股票代码与历史行情、机器学习训练记录和任务跟踪信息查询。

  • by jhersbo
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 jhersbo/FinTest_MCP

使用说明

FinTest MCP Server

An MCP (Model Context Protocol) server that provides Claude with read-only access to the FinTest PostgreSQL database. Enables querying of stock tickers, historical price data, ML training runs, and job tracking information over the STDIO transport.

Prerequisites

  • Docker and Docker Compose
  • Parent FinTest stack running (provides the fintest_ps_default network and PostgreSQL instance)

Project Structure

mcp/
├── server/
│   ├── __init__.py        # FastMCP server initialization
│   ├── __main__.py        # Entry point (STDIO transport)
│   ├── db.py              # Database connection and queries
│   ├── logger.py          # Logging config (stderr only)
│   └── tools.py           # MCP tool definitions
├── Dockerfile
├── docker-compose.yml
├── .mcp.json              # Claude Code MCP integration config
├── .env                   # Database connection env vars
└── requirements.txt

Setup

  1. Ensure the parent FinTest stack is running and the fintest_ps_default network exists.

  2. Build and start the MCP server:

    docker compose up -d fintest_mcp
    
  3. For Claude Code integration, the server is registered as fintest-db in .mcp.json and starts automatically when needed.

Available Tools

Tool Description
query(sql) Execute arbitrary read-only SQL queries
list_tables() List all tables/views with column details
get_tickers() Get all tracked stock tickers
get_ticker_history(ticker, limit) Recent OHLCV price history for a ticker
get_training_runs(status) ML training run records, optionally filtered
get_job_details(gid_job_unit) Full job details including logs and stats
get_timeseries(ticker, limit) Joined daily aggregates with SMA indicators

Database

Connects to the FinTest PostgreSQL instance via a read-only user (claude_readonly). Multiple safety layers are in place:

  • Dedicated read-only database user
  • Connection-level default_transaction_read_only=on
  • Large result sets are automatically truncated to 100 rows

Tech Stack

  • Python 3.11 with FastMCP (MCP SDK)
  • psycopg2 for PostgreSQL connectivity
  • Docker for containerized deployment
  • STDIO transport (JSON-RPC over stdin/stdout)