Abid Ali Awan
Update README.md to expand the code quality metrics section with detailed descriptions for vulnerability, style, and quality scores. Add Gradio app and MCP server URLs, and include a demo video link for better project visibility.
8b0ab06
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). | |
- **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 video:** [Code Analysis MCP Demo (Agents MCP Hackathon)](https://www.youtube.com/watch?v=A4YWMMyJRsA) | |
[](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. 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. | |