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.
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
.envfile 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
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。