Skip to content

leofan-lab/Denoise

Repository files navigation

Denoise

An AI agent that analyzes stocks and sectors using the Seeking Alpha API via MCP (Model Context Protocol).

🚀 Quick Start Guide - Get started in 5 minutes!

Language: Python 3.8+ | Protocol: MCP | APIs: Seeking Alpha, OpenAI, Anthropic

Features

  • 🔍 Query real-time stock information from Seeking Alpha
  • 🤖 AI-powered analysis and summaries (OpenAI or Anthropic)
  • 💬 Interactive chat mode for dynamic stock research
  • 📊 Comprehensive data gathering from multiple Seeking Alpha endpoints
  • 🚀 Built with Python for ease of use and extensibility
  • 🎨 Beautiful terminal output with Rich library

Prerequisites

  1. Python 3.8+ - Install from python.org
  2. pip - Comes with Python
  3. npx - Required for MCP server (comes with Node.js)
  4. API Keys (optional, for AI summaries):
    • OpenAI API key OR
    • Anthropic API key

Quick Setup

# Create virtual environment
python3 -m venv venv

# Activate virtual environment
source venv/bin/activate  # On macOS/Linux
# OR
venv\Scripts\activate     # On Windows

# Install dependencies
pip install -r requirements.txt

# Test MCP connection
python test_mcp.py

# Analyze a stock
python main.py --symbol AAPL

Detailed Setup

1. Install Dependencies

Important: Use a virtual environment to avoid conflicts with system packages.

# Create virtual environment
python3 -m venv venv

# Activate it
source venv/bin/activate  # macOS/Linux
# OR
venv\Scripts\activate     # Windows

# Install dependencies
pip install -r requirements.txt

This installs:

  • mcp - Model Context Protocol SDK
  • openai - OpenAI API client
  • anthropic - Anthropic API client
  • python-dotenv - Environment variable management
  • rich - Beautiful terminal formatting

2. Configure Environment Variables (Optional)

Add this to your Cursor settings (~/.cursor/settings.json or Library/Application Support/Cursor/User/settings.json):

{
  "mcpServers": {
    "RapidAPI Hub - Seeking Alpha API": {
      "command": "npx",
      "args": [
        "mcp-remote",
        "https://mcp.rapidapi.com",
        "--header",
        "x-api-host: seeking-alpha-api.p.rapidapi.com",
        "--header",
        "x-api-key: 882d16763emsh6e0d8ed5eb83338p14d810jsna53fd0525bf8"
      ]
    }
  }
}

For AI-powered summaries, edit the .env file:

# Uncomment and add your API key
OPENAI_API_KEY=sk-your-key-here

# OR use Anthropic
# ANTHROPIC_API_KEY=sk-ant-your-key-here

3. Configure MCP Server in Cursor (Optional)

Usage

Basic Stock Analysis

npm start -- --symbol AAPL

Ask Specific Questions

npm start -- --symbol TSLA --query "What are the latest earnings?"

Interactive Mode

npm start -- --interactive

In interactive mode:

  • Type a stock symbol (e.g., AAPL, TSLA) to load its data
  • Ask questions about the current stock
  • Type exit to quit

CLI Options

Usage: python main.py [-h] [-s SYMBOL] [-q QUERY] [-i]

Options:
  -h, --help            Show help message and exit
  -s, --symbol SYMBOL   Stock ticker symbol (e.g., AAPL, TSLA)
  -q, --query QUERY     Specific question about the stock
  -i, --interactive     Start interactive chat mode

How It Works

  1. MCP Integration: The agent connects to the Seeking Alpha API through the MCP server configured in Cursor
  2. Data Gathering: Automatically discovers and calls available Seeking Alpha API endpoints for the requested stock
  3. AI Analysis: Uses OpenAI or Anthropic to generate insightful summaries and answer questions
  4. Fallback Mode: Works without API keys by displaying raw data in structured format

Project Structure

Denoise/
├── src/
│   ├── main.ts          # CLI entry point
│   ├── agent.ts         # Stock analysis agent
│   └── mcp-client.ts    # MCP protocol client
├── package.json         # Node.js configuration
├── tsconfig.json        # TypeScript configuration
├── .env.example         # Environment variables template
└── README.md

Examples

Example 1: Quick Stock Overview

$ python main.py --symbol AAPL

🔌 Connecting to Seeking Alpha API...
✓ Connected! Available tools: 5

📊 Analyzing AAPL...

📋 Analysis:

Apple Inc. (AAPL) is currently trading with strong fundamentals...
[AI-generated summary with key metrics and insights]

Example 2: Specific Query

$ python main.py --symbol NVDA --query "What is the P/E ratio?"

🔌 Connecting to Seeking Alpha API...
✓ Connected! Available tools: 5

📊 Analyzing NVDA...

🤔 Question: What is the P/E ratio?

📋 Analysis:

NVIDIA's current P/E ratio is approximately 95.3...
[Detailed analysis with context]

Example 3: Interactive Session

$ python main.py --interactive

💬 Interactive Stock Analysis Mode
Type a stock symbol or ask questions. Type 'exit' to quit.

You: TSLA
📊 Loading data for TSLA...

Agent: Tesla Inc. (TSLA) is an electric vehicle manufacturer...
[Summary with key information]

You: What about their revenue growth?
Agent: Tesla's revenue has grown significantly...
[Detailed response based on fetched data]

You: exit
👋 Goodbye!

Troubleshooting

Test MCP Connection

Before running the agent, you can test the MCP connection:

python test_mcp.py

This will list all available Seeking Alpha API tools and verify connectivity.

MCP Server Connection Issues

If you see connection errors:

  1. Run python test_mcp.py to diagnose
  2. Check that npx is available: which npx
  3. Verify internet connection
  4. Test the MCP server manually:
    npx mcp-remote https://mcp.rapidapi.com \
      --header "x-api-host: seeking-alpha-api.p.rapidapi.com" \
      --header "x-api-key: YOUR_KEY"

Python Version Issues

  • Requires Python 3.8 or later
  • Check version: python --version or python3 --version
  • Use python3 if python points to Python 2.x

API Key Issues

  • Verify your API key is in the .env file
  • Check the key format (should start with sk- for OpenAI)
  • The agent works without API keys but provides less detailed analysis

Module Not Found Errors

  • Run pip install -r requirements.txt
  • Make sure you're in the project directory
  • Try pip3 if pip doesn't work

No Data Returned

  • Verify the stock symbol is correct (NYSE/NASDAQ tickers)
  • Some endpoints may require different parameter formats
  • Check the Seeking Alpha API status

Development

Run with verbose output:

python -u main.py --symbol AAPL

Format code (if using black):

pip install black
black *.py

License

Apache License 2.0 - See LICENSE file for details

Contributing

Contributions welcome! Please feel free to submit a Pull Request.

Future Enhancements

  • Add sector analysis capabilities
  • Support for comparing multiple stocks
  • Historical data analysis and trends
  • Export reports to PDF/JSON
  • Real-time price alerts
  • Portfolio tracking

About

An AI agent that analyze stocks and sectors

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages