Skip to main content
Glama
bramesh1

FinSight Copilot MCP Server

by bramesh1

FinSight Copilot:金融研究与分析 RAG 智能体

FinSight Copilot 是一款面向金融分析师的端到端 AI 驱动金融研究助手。它基于 Anthropic Claude Messages API、带 pgvector 的 PostgreSQL、实时金融市场工具和模型上下文协议(MCP)构建,提供带引用的财报分析、确定性投资组合风险指标以及受护栏约束的金融研究能力。


核心能力与特性

  • 分析师 Copilot 引擎: 由 Claude Messages API 驱动,支持 XML 结构化提示、思维链(CoT)推理、结构化输出解析和实时响应处理。

  • 带行内引用的向量 RAG: 使用 pgvector 对 SEC 文件(10-K、财报披露和会议记录)进行基于事实的分析。每项主张都包含严格的文档和章节引用。

  • 实时金融工具: 通过外部金融数据 API(Yahoo Finance / yfinance)集成实时金融市场查询(报价、市盈率、交易量)。

  • 确定性投资组合计算: 风险价值(VaR)计算,并强制附加宪法性免责声明。

  • 模型上下文协议(MCP): 使用 fastmcp 将金融工具暴露为标准化 MCP 端点。

  • 优化与缓存: 利用 Anthropic 主动提示缓存(cache_control={"type": "ephemeral"}),在重复 RAG 查询中将输入 token 开销降低高达约 90%。

  • 评估与防御测试框架: 包含自动化测试套件,用于验证事实依据准确性、提示注入防御、护栏合规性以及执行成本跟踪。


Related MCP server: FinImpulse MCP Server

项目结构

finsight-copilot/
│
├── data/
│   ├── 10k_reports/             # Seed Data: Raw PDF filings (e.g., Tesla, Nvidia, Amazon 10-Ks)
│   ├── research_notes/          # Supplementary RAG context (e.g., tech_sector_2024.txt)
│   └── transcripts/             # Adversarial testing data (e.g., malicious_hack.txt for prompt injection defenses)
│
├── src/
│   ├── agent.py                 # Autonomous State Machine loop (e.g., FETCH -> FLAG_RISK -> SUMMARIZE)
│   ├── copilot.py               # Main agent logic, tool routing, guardrails, and prompt caching
│   ├── eval.py                  # Automated evaluation suite testing accuracy, security, and token costs
│   ├── mcp_server.py            # Model Context Protocol (MCP) server exposing tools via fastmcp
│   ├── rag.py                   # Ingestion pipeline, PDF sliding-window chunker, and pgvector engine
│   ├── skills.py                # Modular AI skill definitions and instructions used by the agent/server
│   └── tools.py                 # Live yfinance integration and portfolio risk (VaR) math functions
│
├── .env                         # Local environment variables (Git ignored)
├── .env.example                 # Template for required environment variables
├── requirements.txt             # Python project dependencies
└── README.md                    # Project documentation

环境要求

开始设置前,请确保你的机器上已安装以下内容:

  • Python: v3.10 或更高版本

  • Docker Desktop: 用于运行 PostgreSQL + pgvector 容器(或本地安装带 pgvector 的 PostgreSQL v15+)

  • Anthropic API 密钥: 来自 Anthropic Console 的有效密钥


安装与设置指南

第 1 步:克隆项目目录

git clone https://github.com/ayadav6/finsight-copilot.git
cd finsight-copilot

第 2 步:设置 Python 虚拟环境(venv

创建并激活一个隔离的 Python 虚拟环境:

macOS / Linux:

python3 -m venv venv
source venv/bin/activate

Windows(命令提示符):

python -m venv venv
venv\Scripts\activate.bat

Windows(PowerShell):

python -m venv venv
.\venv\Scripts\Activate.ps1

第 3 步:安装项目依赖

pip install --upgrade pip
pip install -r requirements.txt

(注意:fastmcp 已包含在 requirements.txt 中,用于 MCP 服务器功能)。

第 4 步:配置环境变量

在根目录中创建 .env 文件:

touch .env

将你的 API 凭据和数据库连接信息添加到 .env 中:

# Anthropic API Configuration
ANTHROPIC_API_KEY=your_anthropic_api_key_here

# PostgreSQL database connection string (Default for local Docker pgvector)
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres

第 5 步:启动并配置 PostgreSQL 向量数据库

使用 Docker 启动一个启用 pgvector 的容器化 PostgreSQL 实例:

docker run --name pgvector-finsight \
  -e POSTGRES_USER=postgres \
  -e POSTGRES_PASSWORD=postgres \
  -e POSTGRES_DB=postgres \
  -p 5432:5432 \
  -d pgvector/pgvector:pg16

执行指南

第 1 步:准备数据并导入财务披露

将所有目标 SEC 10-K 表格 PDF(例如 Tesla_2025_10K.pdfNvidia_2025_10K.pdfAmazon_2025_10K.pdf)放入 data/10k_reports/ 目录。

运行 RAG 文档导入脚本,解析披露文件、使用滑动上下文窗口对文本进行分块、计算嵌入向量并填充 PostgreSQL:

python src/rag.py

(注意:在本地 CPU 上导入多页 PDF 文件可能需要 5 到 15 分钟。脚本包含自动文档计数检查,可在后续执行时跳过冗余的重复导入)。

第 2 步:运行 FinSight Copilot

向量数据库填充完财务披露数据后,运行主交互式 copilot 应用程序:

python src/copilot.py

copilot.py 中支持的操作:

  • 实时市场查询: 获取当前股价、交易量和市盈率(例如:"NVDA 当前的股价和市盈率是多少?")。

  • 投资组合风险计算: 为用户投资组合计算确定性风险价值(VaR)指标,并附加强制性免责声明。

  • 文档事实依据 RAG: 查询历史财务数据(例如:"总结特斯拉在 2025 年和 2026 年与 xAI 的关联方交易。"),并附带文档引用。

第 3 步:运行自动化评估测试框架

运行对抗性合规测试、验证事实依据引用、检查护栏并生成执行 token 微成本报告:

python src/eval.py

第 4 步:运行 MCP 服务器

FinSight 的工具被打包到 MCP 服务器中。使用以下命令运行 MCP 服务器检查器:

fastmcp dev inspector src/mcp_server.py

该命令会启动一个本地 Web 服务器(通常为 http://localhost:5173),你可以在其中通过 Web UI 直观地检查、连接和测试 get_stock_quotecompute_portfolio_risk 工具。


工程与架构亮点

特性

描述

提示缓存

利用 cache_control={"type": "ephemeral"},在重复系统提示中将输入 token 开销从约 4,000 个 token 降至 1 个 token,延迟和成本降低高达 90%。

上下文窗口

重叠滑动窗口文本分块(1500 个字符,300 个字符重叠)可防止财务数据、表格或关键句子在边界处被拆分。

宪法性护栏

系统指令强制执行严格的非个性化建议政策,并强制要求在投资组合风险输出中附加责任免责声明。

F
license - not found
Not graded
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • F
    license
    Not graded
    quality
    D
    maintenance
    Provides real-time stock analysis tools including price lookup, comprehensive investment scoring, and company-to-ticker conversion through a MCP interface.
    1
  • A
    license
    A
    quality
    C
    maintenance
    Provides structured financial market data (stocks, ETFs, mutual funds, fundamentals, market indicators) to AI systems via MCP, enabling natural language access to financial datasets with both hosted and local deployment options.
    31
    11
    ISC
  • F
    license
    Not graded
    quality
    D
    maintenance
    Provides real-time financial data including stock quotes, news, and market movers through a secure FastMCP gateway, enabling conversational finance queries.
    17
  • F
    license
    Not graded
    quality
    D
    maintenance
    Production-grade MCP server that enables AI assistants to access real-time financial market data with intelligent fallback mechanisms, supporting stock prices, comparisons, fundamentals, and market summaries via Yahoo Finance and CSV.

View all related MCP servers

Related MCP Connectors

  • The financial MCP for AI agents - 90+ financial tables, SEC filings, signals, alt-data.

  • Real SEC, 13F, insider, congress & macro data your AI agent can cite. Hosted MCP, 24 tools.

  • Alpha Vantage MCP — Stock market data, fundamentals, and earnings

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/bramesh1/finsight-copilot-main'

If you have feedback or need assistance with the MCP directory API, please join our Discord server