Content
# TradingAgents-MCPmode
Multi-Agent Trading Analysis System Based on MCP Tool
## 🌟 Project Overview
**TradingAgents-MCPmode** is an innovative multi-agent trading analysis system that integrates the Model Context Protocol (MCP) tools to achieve intelligent stock analysis and trading decision-making processes. The system provides comprehensive market analysis, investment recommendations, and risk management through the collaboration of 15 specialized agents.
### 🎯 Core Features
- **🤖 Multi-Agent Collaboration**: 15 specialized agents working together
- **⚡ Parallel Processing**: The analyst team employs a parallel architecture, significantly enhancing analysis efficiency
- **🔧 MCP Tool Integration**: Supports external data sources and real-time information retrieval
- **📊 Comprehensive Analysis**: Seven-dimensional analysis covering company overview, market, sentiment, news, fundamentals, shareholder structure, and product business
- **💭 Intelligent Debate**: Bullish/Bearish researcher debate mechanism with configurable debate rounds
- **⚠️ Risk Management**: Three-tier risk analysis and management decision-making, supporting dynamic risk debates
- **🎛️ Agent Control**: Frontend allows dynamic enabling/disabling of specific agents, flexibly customizing workflows
- **🌀 Debate Round Configuration**: Real-time setting of investment and risk debate rounds on the frontend, precisely controlling analysis depth
- **🔧 Flexible Configuration**: Control agent MCP permissions through environment variables
- **🌍 Multi-Market Support**: US stocks (US), A-shares (CN), Hong Kong stocks (HK)
- **🗣️ Natural Language**: Supports natural language queries without specifying market and date
- **📈 Real-Time Decision Making**: Trading suggestions based on the latest data
- **🌐 Web Frontend**: Complete Streamlit Web interface, supporting real-time analysis and historical management
## 🏗️ System Architecture
### Agent Organization Structure
```
┌─────────────────────────────────────────────────────────────┐
│ TradingAgents-MCPmode │
├─────────────────────────────────────────────────────────────┤
│ 📊 Analysts Team (分析师团队) - Parallel Execution │
│ ├── CompanyOverviewAnalyst (公司概述分析师) │
│ ├── MarketAnalyst (市场分析师) ┐ │
│ ├── SentimentAnalyst (情绪分析师) │ Parallel Processing │
│ ├── NewsAnalyst (新闻分析师) │ 6 Analysts │
│ ├── FundamentalsAnalyst(基本面分析师) │ Executing Simultaneously │
│ ├── ShareholderAnalyst (股东分析师) │ │
│ └── ProductAnalyst (产品分析师) ┘ │
├─────────────────────────────────────────────────────────────┤
│ 🔬 Researchers Team (研究员团队) │
│ ├── BullResearcher (看涨研究员) │
│ └── BearResearcher (看跌研究员) │
├─────────────────────────────────────────────────────────────┤
│ 👔 Managers (管理层) │
│ ├── ResearchManager (研究经理) │
│ └── Trader (交易员) │
├─────────────────────────────────────────────────────────────┤
│ ⚠️ Risk Management Team (风险管理团队) │
│ ├── AggressiveRiskAnalyst (激进风险分析师) │
│ ├── SafeRiskAnalyst (保守风险分析师) │
│ ├── NeutralRiskAnalyst (中性风险分析师) │
│ └── RiskManager (风险经理) │
└─────────────────────────────────────────────────────────────┘
```
### 🚀 Parallel Workflow
```mermaid
graph TD
%% User Input
USER[👤 User Input<br/>user_query]
%% Stage 0: Company Overview Analyst
A0[🏢 Company Overview Analyst<br/>📥 Input: user_query<br/>📤 Output: company_details + company_overview_report]
%% Stage 1: Analyst Parallel Node
PARALLEL[⚡ Analyst Parallel Node<br/>📥 Input: user_query + company_details<br/>🔄 Concurrently execute 6 analysts<br/>📤 Output: All 6 analysis reports]
%% Concurrently executed 6 analysts
A1[🔍 Market Analyst]
A2[😊 Sentiment Analyst]
A3[📰 News Analyst]
A4[📊 Fundamental Analyst]
A5[👥 Shareholder Analyst]
A6[🏭 Product Analyst]
%% Stage 2: Researcher Debate
B1[📈 Bullish Researcher<br/>📥 Input: user_query + All 7 analyst reports<br/>📤 Output: Bullish Argument + Debate History]
B2[📉 Bearish Researcher<br/>📥 Input: user_query + All 7 analyst reports + Debate History<br/>📤 Output: Bearish Argument + Debate History]
%% Stage 3: Management
C1[🎯 Research Manager<br/>📥 Input: user_query + All 7 analyst reports + Complete Debate History<br/>📤 Output: investment_plan]
C2[💰 Trader<br/>📥 Input: user_query + All 7 analyst reports + Debate History + investment_plan<br/>📤 Output: trader_investment_plan]
%% Stage 4: Risk Management Team
D1[🔥 Aggressive Risk Analyst<br/>📥 Input: All Information<br/>📤 Output: Aggressive Risk Perspective + Risk Debate History]
D2[🛡️ Conservative Risk Analyst<br/>📥 Input: All Information + Risk Debate History<br/>📤 Output: Conservative Risk Perspective + Risk Debate History]
D3[⚖️ Neutral Risk Analyst<br/>📥 Input: All Information + Risk Debate History<br/>📤 Output: Neutral Risk Perspective + Risk Debate History]
D4[🎯 Risk Manager<br/>📥 Input: All Information + Complete Risk Debate History<br/>📤 Output: final_trade_decision]
%% Main Flow Connections
USER --> A0
A0 --> PARALLEL
PARALLEL --> B1
B1 --> B2
B2 -.->|Debate Loop| B1
B1 --> C1
C1 --> C2
C2 --> D1
D1 -.->|Risk Debate Loop| D2
D2 -.->|Risk Debate Loop| D3
D3 -.->|Risk Debate Loop| D1
D1 --> D4
D2 --> D4
D3 --> D4
%% Internal Connections of Parallel Node (dashed lines indicate concurrency)
PARALLEL -.-> A1
PARALLEL -.-> A2
PARALLEL -.-> A3
PARALLEL -.-> A4
PARALLEL -.-> A5
PARALLEL -.-> A6
%% Style Definitions
style USER fill:#f9f9f9,stroke:#333,stroke-width:2px
style A0 fill:#e1f5fe,stroke:#0277bd
style PARALLEL fill:#fff3e0,stroke:#ff8f00,stroke-width:3px
style A1 fill:#e8f5e8,stroke:#4caf50
style A2 fill:#e8f5e8,stroke:#4caf50
style A3 fill:#e8f5e8,stroke:#4caf50
style A4 fill:#e8f5e8,stroke:#4caf50
style A5 fill:#e8f5e8,stroke:#4caf50
style A6 fill:#e8f5e8,stroke:#4caf50
style B1 fill:#e3f2fd,stroke:#1976d2
style B2 fill:#e3f2fd,stroke:#1976d2
style C1 fill:#fff3e0,stroke:#ef6c00
style C2 fill:#fff3e0,stroke:#ef6c00
style D1 fill:#fce4ec,stroke:#c2185b
style D2 fill:#fce4ec,stroke:#c2185b
style D3 fill:#fce4ec,stroke:#c2185b
style D4 fill:#fce4ec,stroke:#c2185b
```
### ⚡ Advantages of Parallelization
1. **Significant Efficiency Improvement**: Six analysts executing concurrently, with total time close to that of the slowest analyst's execution time.
2. **Resource Optimization**: Fully utilizes system resources, avoiding serial waiting.
3. **Data Consistency**: Each analyst uses a deep copy of the state to avoid concurrent conflicts.
4. **Result Merging**: Intelligent merging of reports and execution histories from each analyst.
#### Online Experience (Public Address)
- Experience Address: `http://47.79.147.241:8501`
- Description: Open to the public for free to experience and demonstrate features.
- Note: Please use it responsibly and do not engage in any form of attacks, stress testing, or malicious access to avoid affecting service stability.
<img width="1920" height="1080" alt="image" src="https://github.com/user-attachments/assets/c557e15a-de1e-4dbe-b619-b8f32a2a91c2" />
## 🚀 Quick Start
### Environment Requirements
- Python 3.8+
- Supported Operating Systems: Windows, macOS, Linux
### Installation Steps
1. **Clone the Project**
```bash
git clone https://github.com/guangxiangdebizi/TradingAgents-MCPmode.git
cd TradingAgents-MCPmode
```
2. **Install Dependencies**
```bash
pip install -r requirements.txt
```
3. **Configure Environment Variables**
```bash
cp env.example .env
```
# Edit the .env file to configure your API key and workflow parameters
```
4. **Configure MCP Tool**
```bash
# Edit the mcp_config.json file to configure the MCP Server
```
### 🌐 Web Frontend Usage
**Recommended Usage** - Interact through the web interface:
```bash
streamlit run web_app.py
```
Then access in your browser: `http://localhost:8501`
<img width="1920" height="1080" alt="image" src="https://github.com/user-attachments/assets/280599ee-c00a-4c8c-b61f-c786e43cc6d4" />
#### Web Frontend Features
- **🏠 Home**: System overview and quick navigation
- **⚙️ System Configuration**: Online editing of .env and MCP configuration
- **🔍 Real-time Analysis**: Input queries and monitor analysis progress in real-time
- **🤖 Agent Control**: Dynamically enable/disable specific agents with a checkbox interface organized by team
- **🌀 Debate Configuration**: Adjust investment and risk debate rounds in real-time for precise control over analysis depth
- **📊 Agent Page**: View detailed analysis results of each agent by team
- **📚 Historical Reports**: Manage historical sessions, supporting export to Markdown, PDF, and DOCX
#### 🎛️ Frontend Agent Control Features
**Agent Enable Control**:
- ✅ **Group Management**: Organized by four main teams: Analysts, Researchers, Management, and Risk Management
- ✅ **Real-time Selection**: Checkbox interface supporting quick operations for select all/deselect all
- ✅ **Dynamic Count**: Real-time display of the number of enabled agents (e.g., 12/15 enabled)
- ✅ **Smart Skip**: Disabled agents will be automatically skipped, ensuring workflow continuity
**Debate Round Configuration**:
- 🔄 **Investment Debate**: Slider to set bullish/bearish researcher debate rounds (each round = one speech from each side)
- ⚖️ **Risk Debate**: Slider to set aggressive/conservative/neutral risk analyst debate rounds (each round = one speech from each of the three parties)
- 📊 **Real-time Preview**: Displays current settings and expected number of speeches
- 🚀 **Automatic Application**: Automatically applies frontend settings when analysis begins, no manual confirmation required
### 💻 Command Line Usage
If you prefer using the command line:
```bash
python main.py -c "Analyze Apple Inc. stock"
```
#### Interactive Mode
```bash
python main.py
```
Then follow the prompts to enter your query, for example:
- "Analyze Tesla stock"
- "Give me an analysis of 600036 China Merchants Bank"
- "Analyze the investment value of NVDA"
## 📊 Data Flow Mechanism
### 🎯 Key Design Features
1. **company_details Placeholder System**
- 🏢 **Company Overview Analyst** first obtains the basic information about the company
- 📥 **Only passed to the Analyst Team**: 6 professional analysts can access accurate company background
- 🚫 **Not passed to subsequent agents**: Researchers and later agents focus on the comprehensive evaluation of the analysis report
2. **Information Accumulation Effect**
- **Phase 0**: User query only
- **Phase 1**: User query + Company details (parallel processing)
- **Phase 2**: User query + All 7 analyst reports
- **Phase 3**: User query + Analyst reports + Debate history + Investment decisions
- **Phase 4**: User query + All information + Risk perspectives
3. **Dual Debate Mechanism**
- **Investment Debate**: Bullish ↔ Bearish analysts engage in a cyclical debate
- **Risk Debate**: Aggressive ↔ Conservative ↔ Neutral risk analysts engage in a cyclical debate
### 💡 Practical Application Example
**User Input**: "Analyze Tesla stock"
1. **🏢 Company Overview Analyst**: Gather basic information about Tesla Inc., TSLA, NASDAQ, electric vehicle industry, etc.
2. **⚡ Analyst Parallel Nodes**: 6 analysts conduct professional analysis simultaneously based on accurate information about "Tesla Inc."
3. **📈 Bullish Researcher**: Integrate all 7 professional analysis reports to construct a bullish investment thesis for Tesla.
4. **🎯 Risk Manager**: Make the final risk decision on Tesla investment based on all information and debate results.
This design ensures **accurate information transmission** and **gradual refinement**, allowing each agent to leverage their expertise in the most suitable information environment!
## 🎯 Usage Example
### 📱 Frontend Operation Example
**Scenario**: Quickly analyze Apple Inc. stock, enabling only core analysts and setting up a simplified debate.
1. **Start the System**:
```bash
streamlit run web_app.py
```
2. **Configure Agents** (expand in "🤖 Enable Agents for This Round"):
- ✅ Analyst Team: Select All (7 agents)
- ✅ Researcher Team: Select only bullish researchers
- ❌ Management: Deselect All (quick analysis)
- ❌ Risk Management: Deselect All (quick analysis)
- 📊 Display: Enabled 8/15
3. **Set Debate Rounds** (expand in "🌀 Debate Rounds Settings"):
- 🔄 Investment Debate Rounds: 1 round (only bullish researchers speak once)
- ⚖️ Risk Debate Rounds: 0 rounds (skip risk debate)
4. **Execute Analysis**:
- Input: "Analyze the investment value of Apple Inc. stock"
- Click "🚀 Start Analysis"
- The system automatically applies the frontend settings and begins execution.
5. **Expected Results**:
- ⚡ Quick Execution: Only 8 agents involved, significantly reducing analysis time
- 📊 Core Report: Obtain 7 professional analyst reports
- 🎯 Investment Advice: Bullish researchers provide investment advice based on analyst reports.
### 🎛️ Advantages of Dynamic Configuration
- **🚀 Fast Experience**: Disable non-core agents to obtain analysis results in 1-2 minutes
- **🔬 In-Depth Analysis**: Enable all agents + multi-round debates for comprehensive decision support
- **🎯 Customization**: Flexibly choose agent combinations based on analysis needs
- **💡 Real-Time Adjustment**: Adjust parameters in real-time on the front end without restarting the service
## 🛠️ Configuration Instructions
### Environment Variable Configuration
Configure the following parameters in the `.env` file:
```env
# Large Model Configuration
OPENAI_API_KEY=your_openai_api_key
OPENAI_BASE_URL=https://api.openai.com/v1
MODEL_NAME=gpt-4
# Workflow Configuration
MAX_DEBATE_ROUNDS=1 # Default rounds for investment debate (can be dynamically adjusted in the frontend)
MAX_RISK_DEBATE_ROUNDS=1 # Default rounds for risk debate (can be dynamically adjusted in the frontend)
DEBUG_MODE=true # Debug mode, displays detailed logs
VERBOSE_LOGGING=true # Detailed log output
# Intelligent Agent MCP Permission Configuration
# Analyst Team - It is recommended to enable MCP for real-time data
COMPANY_OVERVIEW_ANALYST_MCP=true
MARKET_ANALYST_MCP=true
SENTIMENT_ANALYST_MCP=true
NEWS_ANALYST_MCP=true
FUNDAMENTALS_ANALYST_MCP=true
SHAREHOLDER_ANALYST_MCP=true
PRODUCT_ANALYST_MCP=true
# Researcher/Management/Risk Team - Suggest to Disable MCP Focused Comprehensive Analysis
BULL_RESEARCHER_MCP=false
BEAR_RESEARCHER_MCP=false
RESEARCH_MANAGER_MCP=false
TRADER_MCP=false
AGGRESSIVE_RISK_ANALYST_MCP=false
SAFE_RISK_ANALYST_MCP=false
NEUTRAL_RISK_ANALYST_MCP=false
RISK_MANAGER_MCP=false
# Task Concurrency Limit
MAX_CONCURRENT_ANALYSIS=2 # Number of analysis tasks running concurrently
```
> **💡 Tip**: The environment variables `MAX_DEBATE_ROUNDS` and `MAX_RISK_DEBATE_ROUNDS` are only default values and can be adjusted in real-time on the front end during actual operation. It is recommended to set them to 1 for a quick experience, and if in-depth analysis is needed, you can increase the rounds on the front end.
### MCP Tool Configuration
Configure the MCP server in the `mcp_config.json` file:
```json
{
"mcpServers": {
"finance-mcp": {
"disabled": false,
"timeout": 600,
"transport": "streamable_http",
"url": "https://finvestai.top/mcp",
"headers": {
"X-Tushare-Token": "Your Tushare token"
}
}
}
}
```
**Configuration Description**:
- `disabled`: Whether to disable the MCP server (false means enabled)
- `timeout`: Request timeout duration (in seconds), default is 600 seconds
- `transport`: Transport protocol, use `streamable_http`
- `url`: MCP server address `https://finvestai.top/mcp`
- `X-Tushare-Token`: Please replace with your actual Tushare API Key
> **💡 Tip**: After modifying the configuration, please restart the application or hot reload the MCP client to apply the changes.
## 📈 Performance Optimization
### Advantages of Parallel Processing
- **Original Serial Architecture**: 6 analysts execute sequentially, total time = Σ(time taken by each analyst)
- **New Parallel Architecture**: 6 analysts execute concurrently, total time ≈ max(time taken by each analyst)
- **Performance Improvement**: Theoretically, efficiency can be improved by 5-6 times; actual improvement depends on the time distribution of each analyst
### Resource Management
- Use deep copy to avoid state contention
- Smartly merge execution history and tool invocation records
- Optimize memory usage to avoid state redundancy
## 🤝 Contribution Guidelines
We welcome you to submit Issues and Pull Requests to improve the project!
## 📄 License
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
---
**TradingAgents-MCPmode** - Let AI agent teams safeguard your investment decisions! 🚀📈
## 📬 Contact Information
- Email: `guangxiangdebizi@gmail.com`
- LinkedIn: [Xingyu Chen](https://www.linkedin.com/in/xingyu-chen-b5b3b0313/)
- Facebook: [Personal Page](https://www.facebook.com/profile.php?id=100072282093932)
- Bilibili: [Personal Space](https://space.bilibili.com/51239486?spm_id_from=333.1007.0.0)
Connection Info
You Might Also Like
valuecell
ValueCell is a community-driven, multi-agent platform for financial applications.
hexstrike-ai
HexStrike AI MCP Agents is an advanced MCP server that lets AI agents...
YC-Killer
A library of enterprise-grade AI agents designed to democratize artificial...
AP2
Building a Secure and Interoperable Future for AI-Driven Payments.
solana-agent-kit
connect any ai agents to solana protocols
Stripe
The Stripe Agent Toolkit integrates agent frameworks with Stripe APIs via...