--- title: Competitive Analysis Single Agent emoji: 📊 colorFrom: blue colorTo: green sdk: gradio sdk_version: 4.19.2 python_version: 3.11 app_file: app.py pinned: false --- # 🏆 Competitive Analysis Agent - MCP Implementation A sophisticated single-agent system for comprehensive competitive analysis using the **Model Context Protocol (MCP)** with FastMCP. This implementation combines web research, intelligent reasoning, and structured analysis to provide actionable competitive insights. ## 🎯 Architecture Overview ``` ┌──────────────────────────────────────────────────────────┐ │ Single-File Application (app.py) │ ├──────────────────────────────────────────────────────────┤ │ │ │ ┌────────────────────────────────────────────────────┐ │ │ │ Gradio Web Interface (User UI) │ │ │ │ :7860 │ │ │ └────────────────────────────────────────────────────┘ │ │ │ │ │ ┌────────────────────────────────────────────────────┐ │ │ │ Analysis Engine & Tools: │ │ │ │ • validate_company() - Verify company │ │ │ │ • identify_sector() - Find industry │ │ │ │ • identify_competitors() - Discover rivals │ │ │ │ • browse_page() - Extract data │ │ │ │ • generate_report() - Create analysis │ │ │ └────────────────────────────────────────────────────┘ │ │ │ │ │ ┌────────────────────────────────────────────────────┐ │ │ │ AI Agent (OpenAI GPT-4) │ │ │ │ Strategic reasoning & insights generation │ │ │ └────────────────────────────────────────────────────┘ │ │ │ │ External APIs: │ │ • DuckDuckGo (Web Search) │ │ • OpenAI (LLM Analysis) │ │ • External Web Pages (Scraping) │ │ │ └──────────────────────────────────────────────────────────┘ ``` **Single-File Design**: All functionality is consolidated in one `app.py` file for simplicity and ease of deployment. No separate MCP server needed. ## ✨ Features ### 🔍 Company Analysis - **Validation**: Confirms company legitimacy using web search - **Sector Identification**: Determines industry using multi-stage analysis - **Competitor Discovery**: Identifies top 3 competitors with ranking ### 📊 Strategic Analysis - **Web Research**: Automatically gathers company information - **Content Extraction**: Extracts relevant strategic data - **Structured Reports**: Generates professional analysis with: - Executive summary - Competitor comparison table - Strategic recommendations - Actionable insights ### 🛠️ MCP Architecture - **FastMCP Server**: Lightweight, high-performance tool hosting - **Tool Isolation**: Each analysis function is a callable MCP tool - **Scalable Design**: Easy to add new tools or extend functionality - **Robust Error Handling**: Graceful fallbacks and error management ## 📋 Prerequisites - Python 3.8+ - OpenAI API key (get at https://platform.openai.com/api-keys) - Internet connection (for web search and scraping) ## ⚙️ Installation 1. **Clone the repository**: ```bash git clone cd single-agent-competitive-analysis-agent ``` 2. **Install dependencies**: ```bash pip install -r requirements.txt ``` 3. **Verify installation**: ```bash python -c "import gradio; import openai; import requests; import beautifulsoup4; print('✓ All dependencies installed')" ``` ## 🚀 Running the Application ### Quick Start (One Command!) ```bash python app.py ``` That's it! The application will: 1. Start the Gradio web interface at **http://0.0.0.0:7860** 2. Initialize the analysis engine 3. Open in your browser automatically (or visit http://localhost:7860) ### Expected Output ``` Running on local URL: http://0.0.0.0:7860 Opening in browser... ``` ## 💡 Usage Guide ### Basic Workflow 1. **Enter Company Name**: Type the name of the company you want to analyze - Example: "Tesla", "Spotify", "Microsoft", "Stripe" 2. **Provide OpenAI API Key**: Paste your OpenAI API key - Get one at: https://platform.openai.com/api-keys 3. **Click "Analyze Competitors"**: The system will: - Validate the company exists - Identify its sector - Find top 3 competitors - Analyze competitor strategies - Generate comprehensive report 4. **Review Analysis Report**: The report includes: - Company overview and sector - Top 3 competitors - Detailed competitor comparison - Strategic insights - Actionable recommendations ## 📁 Project Structure ``` single-agent-competitive-analysis-agent/ ├── app.py # Complete application (Gradio UI + Analysis Engine) ├── requirements.txt # Python dependencies ├── .env.example # Environment variables template ├── README.md # This file └── ARCHITECTURE.md # Detailed architecture documentation ``` ### Application Components The `app.py` file includes: #### 🔍 Analysis Tools - **validate_company**: Company existence verification via web search - **identify_sector**: Industry classification with multi-strategy analysis - **identify_competitors**: Competitor discovery and ranking - **browse_page**: Web content extraction and parsing - **generate_report**: Structured competitive analysis report generation #### 🤖 AI Agent - OpenAI GPT-4 integration for strategic reasoning - Orchestrates analysis tools in logical sequence - Generates insights and actionable recommendations - Error handling with fallback modes #### 💻 User Interface - Gradio-based web interface - Professional report formatting in Markdown - Real-time analysis execution - Input validation and error handling ## 🔒 Security & Privacy - ✅ **API Keys**: Never stored, used only in current session - ✅ **Web Data**: Temporary, not cached - ✅ **No Tracking**: Local processing only ## 🚀 Quick Start ```bash # 1. Install dependencies pip install -r requirements.txt # 2. Run the application python app.py # 3. Open browser to http://localhost:7860 # (usually opens automatically) ``` **That's all!** No need for multiple terminals or separate server startup. # 4. Enter company name and OpenAI API key # 5. Click "Analyze Competitors" ``` ## 🐛 Troubleshooting **OpenAI API Key invalid**: Check it starts with `sk-` and is active **MCP Server not running**: Run `python mcp_server.py` in separate terminal **Web search failing**: Check internet connection and try different company name **Rate limit errors**: Wait 5 minutes before next analysis ## 📊 Performance - Analysis Time: 30-60 seconds - Report Generation: ~10 seconds - API Calls: 5-8 requests per analysis - Max Competitors: 3 (quality optimized) --- **Version**: 1.0.0 (MCP Architecture) **Last Updated**: March 2026