code-analysis-mcp / README.md
Abid Ali Awan
Enhance README with detailed local setup instructions, clarify integration with MCP clients, and update code quality score description. Remove outdated sections and improve formatting for better readability.
d1e576c
|
raw
history blame
3.22 kB
metadata
title: Code Analysis MCP
emoji: πŸ§‘β€πŸ’»
colorFrom: gray
colorTo: yellow
sdk: gradio
sdk_version: 5.33.0
app_file: src/app.py
pinned: false
license: apache-2.0
short_description: Generate quality metrics and a detailed report for your code

Code Analysis MCP Server

This project is a Gradio-based MCP server that provides two code analysis functionalities:

  • Code Quality Score: Provides an averaged score across vulnerability, style, and quality for the provided code using top three AI providers (OpenAI, Anthropic, Mistral).
  • Code Analysis Report: Generates a detailed report about the provided code, including basic information and suggesting 5-10 potential fixes to improve the code.

Integration with MCP clients

For clients that support SSE (e.g. Cursor, Windsurf, Cline), simply add the following configuration to your MCP config:

{
  "mcpServers": {
    "gradio": {
      "url": "https://agents-mcp-hackathon-code-analysis-mcp.hf.space/gradio_api/mcp/sse"
    }
  }
}

For clients that dose not support SSE, first install Node.js. Then, you can use the following command:

{
  "mcpServers": {
    "gradio": {
      "command": "npx",
      "args": [
        "mcp-remote",
        "https://agents-mcp-hackathon-code-analysis-mcp.hf.space/gradio_api/mcp/sse",
        "--transport",
        "sse-only"
      ]
    }
  }
}

Sample Prompts

Here are a few ways you can ask Cursor AI to use these tools:

  • "Can you give me a code quality score for this Python snippet?"
  • "Generate a code analysis report for the following JavaScript code."
  • "Analyze this code and tell me how to fix the top issues."
  • "What is the quality score of this code?"

Local Setup and Running

  1. Clone the repository.

  2. Navigate to the project directory.

  3. Install the required dependencies:

    pip install -r requirements.txt
    
  4. Set up the required environment variables for the API keys:

    export OPENAI_API_KEY=your_openai_api_key
    export ANTHROPIC_API_KEY=your_anthropic_api_key
    export MISTRAL_API_KEY=your_mistral_api_key
    

    Replace your_openai_api_key, your_anthropic_api_key, and your_mistral_api_key with your actual API keys.

  5. Run the application:

    python src/app.py
    
  6. The Gradio interface will be available at http://127.0.0.1:7860/ and MCP server will be avaible at http://127.0.0.1:7860/gradio_api/mcp/sse.

Connecting to Cursor AI

  1. To test the MCP server with Cursor AI, open Cursor Settings, navigate to the "MCP" tab, and click the "+ Add new global MCP server" button.

  2. Add the following JSON configuration to the MCP settings file:

{
  "mcpServers": {
    "gradio": {
      "url": "http://127.0.0.1:7860/gradio_api/mcp/sse"
    }
  }
}
  1. Save the file. You will now see an active MCP server named gradio with the tools code_analysis_report and code_analysis_score.

To test this MCP server, you can create a new chat in agent mode of the Cursor using (CTRL +T) and ask for a code analysis report (e.g., "analyze this Python code: print('hello')"). Cursor will ask for permission to run the MCP tool. Approve it.