File size: 3,650 Bytes
ed72e55
53e0bdc
af48e3f
146552c
53e0bdc
ed72e55
ff1fa38
53e0bdc
af48e3f
 
 
 
 
 
ed72e55
 
 
 
 
53e0bdc
 
 
 
 
d1e576c
53e0bdc
 
538fbf8
af48e3f
 
 
 
 
 
 
 
 
d1e576c
ff1fa38
 
 
 
 
 
 
 
 
 
 
 
 
d1e576c
ff1fa38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d1e576c
53e0bdc
 
 
 
 
 
 
 
d1e576c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53e0bdc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
---
title: Code Analysis MCP
emoji: πŸ‘©β€πŸ’»
colorFrom: gray
colorTo: yellow
sdk: gradio
sdk_version: 5.33.0
app_file: src/app.py
tags:
  - mcp-server-track
  - code-analysis
  - openai
  - anthropic
  - mistral
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.

**Watch the demo video:** [Code Analysis MCP Demo (Agents MCP Hackathon)](https://www.youtube.com/watch?v=A4YWMMyJRsA)
<iframe
  width="560"
  height="315"
  src="https://www.youtube.com/embed/A4YWMMyJRsA"
  frameborder="0"
  allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
  allowfullscreen
></iframe>

## 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.  Clone the repository.
2.  Navigate to the project directory.
3.  Install the required dependencies:

    ```bash
    pip install -r requirements.txt
    ```

4. 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.

5. Run the application:

    ```bash
    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

7. 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.

8. Add the following JSON configuration to the MCP settings file:
```json
{
  "mcpServers": {
    "gradio": {
      "url": "http://127.0.0.1:7860/gradio_api/mcp/sse"
    }
  }
}
```

9. 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.