financial-data-mcp-server

financial-data-mcp-server

An MCP server that exposes real-time financial data tools for stock search, company info, historical prices, and financial metrics from Yahoo Finance, enabling AI agents to answer natural-language questions about stocks and financial markets.

Category
Visit Server

README

๐Ÿ“Š Chat with Financial Data

An AI-powered financial data assistant that uses LLM agents, LangGraph, and Model Context Protocol (MCP) to answer questions about stocks and financial markets using real-time financial data tools.


๐Ÿš€ Overview

Chat with Financial Data is an AI-powered financial assistant designed to help users explore and analyze stock market information through natural language.

Instead of manually searching financial websites or running separate queries, users can simply ask questions such as:

  • "Give me information about ASII stock."
  • "What are the financial metrics of BBCA?"
  • "Show me the historical prices of TLKM."
  • "What is the P/E ratio of ASII?"
  • "Tell me about Astra International."

The application uses an AI agent to understand the user's question and dynamically select only the financial data tools needed to answer it.

The project uses Model Context Protocol (MCP) to provide a standardized interface between the AI agent and financial data tools.


โœจ Features

๐Ÿค– AI-Powered Financial Assistant

Users can interact with financial data using natural language instead of manually calling APIs or writing queries.

๐Ÿ”Œ MCP-Based Tool Integration

Financial data capabilities are exposed through an MCP server, allowing the AI agent to discover and use available tools dynamically.

๐Ÿง  Intelligent Tool Selection

The AI agent determines which tools are required based on the user's question.

For example:

User:
"Give me information about ASII stock."

        โ”‚
        โ–ผ

AI Agent
        โ”‚
        โ”œโ”€โ”€ search_stock_tool
        โ”‚
        โ””โ”€โ”€ stock_info

        โ”‚
        โ–ผ

Human-readable response

The agent does not need to execute every available tool for every question.

๐Ÿ“ˆ Financial Data Tools

The current MCP server provides the following tools:

Tool Description
search_stock_tool Searches for a stock ticker and company
stock_info Retrieves basic company information
historical_prices Retrieves historical stock price data
financial_metrics Retrieves key financial metrics
ping Checks MCP server availability

๐Ÿ’ฌ Streamlit Chat Interface

The project provides a user-friendly Streamlit interface with:

  • Chat-style conversation
  • Persistent chat history during the session
  • Natural language questions
  • Loading indicators
  • Human-readable AI responses
  • Financial data analysis through MCP tools

๐Ÿ“ Chat Logging

Chat interactions can be logged for monitoring and analysis.

The log can include:

  • Timestamp
  • User question
  • AI response
  • Runtime
  • Tools used
  • Token usage
  • Estimated API cost

Example:

Timestamp Question Answer Runtime Tools Used Cost
2026-08-03 Give me information about ASII ... 4.21 sec stock_info $0.002
2026-08-03 What is ASII P/E ratio? ... 3.15 sec financial_metrics $0.001

Chat logs are stored locally and are excluded from GitHub using .gitignore.


๐Ÿ—๏ธ System Architecture

                         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                         โ”‚      User Question   โ”‚
                         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                    โ”‚
                                    โ–ผ
                         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                         โ”‚     Streamlit UI     โ”‚
                         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                    โ”‚
                                    โ–ผ
                         โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                         โ”‚    Financial Agent   โ”‚
                         โ”‚      LangGraph       โ”‚
                         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                    โ”‚
                         Selects required tools
                                    โ”‚
                                    โ–ผ
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚    LangChain MCP Adapter     โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                   โ”‚
                                   โ–ผ
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚   Financial Data MCP Server  โ”‚
                    โ”‚                              โ”‚
                    โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
                    โ”‚  โ”‚ search_stock_tool      โ”‚  โ”‚
                    โ”‚  โ”‚ stock_info             โ”‚  โ”‚
                    โ”‚  โ”‚ historical_prices      โ”‚  โ”‚
                    โ”‚  โ”‚ financial_metrics      โ”‚  โ”‚
                    โ”‚  โ”‚ ping                   โ”‚  โ”‚
                    โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                   โ”‚
                                   โ–ผ
                         Financial Data Source
                                   โ”‚
                                   โ–ผ
                          AI-generated Response
                                   โ”‚
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ–ผ                              โ–ผ
             Streamlit UI                    Chat Logger
                                                   โ”‚
                                                   โ–ผ
                                          Local CSV Log

๐Ÿงฉ Technology Stack

AI & Agent

  • Python
  • OpenAI
  • LangChain
  • LangGraph

MCP

  • Model Context Protocol
  • MCP Python SDK
  • LangChain MCP Adapters

Financial Data

  • Yahoo Finance data source

Application

  • Streamlit
  • Python AsyncIO

Logging

  • CSV-based chat history
  • Runtime tracking
  • Token usage tracking
  • Estimated API cost tracking

๐Ÿ“ Project Structure

chat-with-financial-data/
โ”‚
โ”œโ”€โ”€ app/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ agent/
โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”‚   โ”œโ”€โ”€ agent.py
โ”‚   โ”‚   โ”œโ”€โ”€ graph.py
โ”‚   โ”‚   โ””โ”€โ”€ mcp_client.py
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ mcp_servers/
โ”‚   โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”‚   โ”‚
โ”‚   โ”‚   โ””โ”€โ”€ financial_data/
โ”‚   โ”‚       โ”œโ”€โ”€ __init__.py
โ”‚   โ”‚       โ”œโ”€โ”€ server.py
โ”‚   โ”‚       โ””โ”€โ”€ tools.py
โ”‚   โ”‚
โ”‚   โ””โ”€โ”€ logging/
โ”‚       โ”œโ”€โ”€ __init__.py
โ”‚       โ””โ”€โ”€ chat_logger.py
โ”‚
โ”œโ”€โ”€ logs/
โ”‚   โ””โ”€โ”€ .gitkeep
โ”‚
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ test_agent.py
โ”‚   โ”œโ”€โ”€ test_financial_tools.py
โ”‚   โ”œโ”€โ”€ test_financial_mcp.py
โ”‚   โ””โ”€โ”€ test_langchain_mcp.py
โ”‚
โ”œโ”€โ”€ .env.example
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ requirements.txt
โ””โ”€โ”€ streamlit_app.py

โš™๏ธ Installation

1. Clone the Repository

git clone https://github.com/fifah123/chat-with-financial-data.git

cd chat-with-financial-data

2. Create a Virtual Environment

Windows

python -m venv .venv

Activate the environment:

.venv\Scripts\Activate.ps1

If PowerShell blocks script execution, you can activate using:

.venv\Scripts\activate

3. Install Dependencies

pip install -r requirements.txt

4. Configure Environment Variables

Create a .env file in the project root:

OPENAI_API_KEY=your_openai_api_key

You can use .env.example as a template.

โš ๏ธ Never commit your .env file or expose your API key publicly.


โ–ถ๏ธ Running the Application

Start the Streamlit application:

streamlit run streamlit_app.py

The application will open in your browser.

You can then ask questions such as:

Give me information about ASII stock.
What are the financial metrics of BBCA?
Show me the historical prices of TLKM.
What is the P/E ratio of ASII?

๐Ÿ”Œ Running the MCP Server

The Financial Data MCP server can be started with:

python -m app.mcp_servers.financial_data.server

The MCP server communicates through stdio, so it may not display a visible response when started directly.

The server is designed to be launched and consumed by the MCP client.


๐Ÿงช Testing

Test Financial Tools

python tests/test_financial_tools.py

Test MCP Server

python tests/test_financial_mcp.py

Test LangChain MCP Integration

python tests/test_langchain_mcp.py

Test Financial Agent

python tests/test_agent.py

๐Ÿ”„ Example Workflow

Suppose the user asks:

Give me information about ASII stock.

The system processes the request as follows:

Step 1 โ€” User Input

Give me information about ASII stock.

Step 2 โ€” AI Agent Understands the Question

The agent identifies that the user is asking for basic stock information.

Step 3 โ€” Agent Selects Required MCP Tools

The agent may call:

search_stock_tool
stock_info

It does not need to call:

historical_prices
financial_metrics

unless the question requires them.

Step 4 โ€” MCP Server Executes the Tools

The MCP server retrieves the requested financial data.

Step 5 โ€” AI Generates a Human-Friendly Answer

The raw tool output is converted into a natural-language response.

Example:

Astra International Tbk (ASII.JK) is an Indonesian company
listed on the Indonesia Stock Exchange.

Sector: Industrials
Industry: Conglomerates
Currency: IDR
Country: Indonesia
Exchange: Jakarta Stock Exchange

๐Ÿ“Š Example Financial Metrics

For example, the financial_metrics tool may return:

Ticker: ASII.JK
Market Cap: 203,323,869,233,152
P/E Ratio: 6.47
Forward P/E: 6.61
Price-to-Book: 0.87
Dividend Yield: 7.65%
Return on Equity: 11.98%
Profit Margin: 9.35%
Debt-to-Equity: 41.13

The AI agent can then transform this raw data into an understandable financial summary.


๐Ÿ“ Chat Logging

The application records chat interactions locally.

Example log structure:

logs/
โ””โ”€โ”€ chat_history.csv

Typical information captured includes:

timestamp
question
answer
runtime_seconds
tools_used
input_tokens
output_tokens
total_tokens
estimated_cost_usd

The log file is intentionally excluded from GitHub to prevent personal conversation data and potentially sensitive information from being committed.


โš ๏ธ Disclaimer

This project is intended for educational and informational purposes only.

The financial information provided by the application may be delayed, incomplete, or inaccurate. Nothing in this application should be considered financial, investment, or trading advice.

Always conduct your own research and consult a qualified financial professional before making investment decisions.


โญ Acknowledgements

This project uses open-source technologies including:

  • OpenAI
  • LangChain
  • LangGraph
  • Model Context Protocol (MCP)
  • Streamlit
  • Yahoo Finance

Recommended Servers

playwright-mcp

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.

Official
Featured
TypeScript
Magic Component Platform (MCP)

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.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

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.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

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.

Official
Featured
TypeScript
Kagi MCP Server

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.

Official
Featured
Python
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Exa Search

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.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured