FinSight Copilot MCP Server
Provides real-time financial market lookups (stock quotes, volume, P/E ratios) and deterministic portfolio risk (VaR) calculations as standardized MCP endpoints for AI assistant integration.
README
FinSight Copilot: Financial Research & Analysis RAG Agent
FinSight Copilot is an end-to-end, AI-powered financial research assistant for financial analysts. Built on top of the Anthropic Claude Messages API, PostgreSQL with pgvector, real-time financial market tools and the Model Context Protocol (MCP), FinSight Copilot provides cited earnings report analysis, deterministic portfolio risk metrics, and guardrail-enforced financial research capabilities.
Key Capabilities & Features
- Analyst Copilot Engine: Powered by Claude Messages API with XML-structured prompts, Chain-of-Thought (CoT) reasoning, structured output parsing, and real-time response handling.
- Vector RAG with In-line Citations: Grounded analysis over SEC filings (10-Ks, earnings disclosures, and transcripts) using
pgvector. Every claim includes strict document and section citations. - Live Financial Tools: Real-time financial market lookups (quotes, P/E ratios, trading volumes) integrated via external financial data APIs (Yahoo Finance /
yfinance). - Deterministic Portfolio Math: Value at Risk (VaR) calculations combined with enforced constitutional disclaimers.
- Model Context Protocol (MCP): Exposes financial tools as standardized MCP endpoints using
fastmcp. - Optimization & Caching: Leverages active Anthropic Prompt Caching (
cache_control={"type": "ephemeral"}) to reduce input token overhead by up to ~90% on repeated RAG queries. - Evaluation & Defense Harness: Includes an automated test suite verifying grounding accuracy, prompt injection defense, guardrail adherence, and execution cost tracking.
Project Structure
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
Prerequisites
Ensure you have the following installed on your machine before setup:
- Python:
v3.10or higher - Docker Desktop: Required for running the PostgreSQL + pgvector container (or local PostgreSQL v15+ with pgvector)
- Anthropic API Key: Active key from the Anthropic Console
Installation & Setup Guide
Step 1: Clone Project Directory
git clone https://github.com/ayadav6/finsight-copilot.git
cd finsight-copilot
Step 2: Set Up Python Virtual Environment (venv)
Create and activate an isolated Python virtual environment:
macOS / Linux:
python3 -m venv venv
source venv/bin/activate
Windows (Command Prompt):
python -m venv venv
venv\Scripts\activate.bat
Windows (PowerShell):
python -m venv venv
.\venv\Scripts\Activate.ps1
Step 3: Install Project Dependencies
pip install --upgrade pip
pip install -r requirements.txt
(Note: fastmcp is included in requirements.txt for the MCP server functionality).
Step 4: Configure Environment Variables
Create a .env file in the root directory:
touch .env
Add your API credentials and database connection details to .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
Step 5: Start & Configure PostgreSQL Vector Database
Start a containerized PostgreSQL instance with pgvector enabled using Docker:
docker run --name pgvector-finsight \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_DB=postgres \
-p 5432:5432 \
-d pgvector/pgvector:pg16
Execution Guide
Step 1: Seed Data & Ingest Financial Disclosures
Place all target SEC Form 10-K PDFs (e.g., Tesla_2025_10K.pdf, Nvidia_2025_10K.pdf, Amazon_2025_10K.pdf) into the data/10k_reports/ directory.
Run the RAG document ingestion script to parse disclosures, chunk text using sliding context windows, compute embeddings, and populate PostgreSQL:
python src/rag.py
(Note: Ingesting multi-page PDF filings locally on CPU can take between 5 to 15 minutes. The script contains an automated document count check to bypass redundant re-ingestion on subsequent executions).
Step 2: Running FinSight Copilot
Once the vector database is populated with financial disclosures, run the main interactive copilot application:
python src/copilot.py
Supported Operations in copilot.py:
- Live Market Lookups: Fetches current stock prices, volume, and P/E ratios (e.g., "What is NVDA's current stock price and P/E ratio?").
- Portfolio Risk Calculations: Computes deterministic Value at Risk (VaR) metrics for user portfolios while appending mandatory disclaimers.
- Document Grounded RAG: Inquires about historical financial data (e.g., "Summarize Tesla's related party transactions with xAI in 2025 and 2026.") with document citations.
Step 3: Running the Automated Evaluation Harness
To run adversarial compliance tests, verify grounded citations, check guardrails, and generate an execution token micro-cost report:
python src/eval.py
Step 4: Running the MCP Server
FinSight's tools are packaged into an MCP server. Run the MCP server inspector using:
fastmcp dev inspector src/mcp_server.py
This command launches a local web server (usually http://localhost:5173) where you can visually inspect, connect, and test the get_stock_quote and compute_portfolio_risk tools directly via a web UI.
Engineering & Architectural Highlights
| Feature | Description |
|---|---|
| Prompt Caching | Utilizes cache_control={"type": "ephemeral"} to lower input token overhead from ~4,000 tokens down to 1 token on repeated system prompts, reducing latency and costs by up to 90%. |
| Context Windowing | Overlapping sliding window text chunking (1500 characters, 300-character overlap) prevents splitting financial figures, tables, or key sentences across boundaries. |
| Constitutional Guardrails | System instructions enforce strict non-personalized advice policies and mandate liability disclaimers on portfolio risk outputs. |
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.