CoolFace
Apppublic

Agents-MCP-Hackathon/code-analysis-mcp

sourceHugging Faceapache-2.0updated 1y agoView on Hugging Face
10likes
App README

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).
  • Vulnerability Score: Measures the likelihood of the code containing vulnerabilities.
  • Style Score: Measures the adherence to coding style guidelines.
  • Quality Score: Measures the overall quality of the code.
  • Code Analysis Report: Generates a detailed report using Claude Sonnet 4, providing insights about the provided code, including basic information and suggesting 5-10 potential fixes to improve the code.

Video & Demo

  • Gradio App URL: https://agents-mcp-hackathon-code-analysis-mcp.hf.space
  • MCP Server URL: https://agents-mcp-hackathon-code-analysis-mcp.hf.space/gradio_api/mcp/sse

![Watch the demo on YouTube](https://youtu.be/A4YWMMyJRsA)

Integration with MCP clients

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

json
{
  "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:

json
{
  "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. 1.Clone the repository.
  2. 2.Navigate to the project directory.
  3. 3.Install the required dependencies:
bash
    pip install -r requirements.txt
  1. 1.Set up the required environment variables for the API keys:
bash
    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.

  1. 1.Run the application:
bash
    python src/app.py
  1. 1.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. 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.
  1. 1.Add the following JSON configuration to the MCP settings file:
json
{
  "mcpServers": {
    "gradio": {
      "url": "http://127.0.0.1:7860/gradio_api/mcp/sse"
    }
  }
}
  1. 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.