Pratham-Prog861/mcp-code-analyzer
If you are the rightful owner of mcp-code-analyzer and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
The MCP Code Analyzer is a dual-mode JavaScript/TypeScript code analyzer that operates as both a Model Context Protocol (MCP) server and a standalone HTTP API, providing real-time code quality analysis.
MCP Code Analyzer
A dual-mode JavaScript/TypeScript code analyzer powered by ESLint. Works as both a Model Context Protocol (MCP) server and a standalone HTTP API for real-time code quality analysis.
Features
- 🔍 ESLint-Powered Analysis - Comprehensive JavaScript/TypeScript code analysis
- 🔌 Dual Mode Operation - Works as both MCP server and HTTP API
- ⚡ Real-time Analysis - Get instant feedback on code quality
- 🎯 Common Issues Detection - Finds unused variables, missing semicolons, undefined references, and more
- 🌐 REST API - Easy integration with any application via HTTP endpoints
- 🤖 MCP Integration - Compatible with Claude Desktop and other MCP clients
Installation
# Clone the repository
git clone https://github.com/pratham-prog861/mcp-code-analyzer.git
cd mcp-code-analyzer
# Install dependencies
npm install
Usage
Running the Server
npm run dev
The server runs in two modes simultaneously:
- MCP Server: Stdio transport for MCP clients
- HTTP API: REST endpoint on
http://localhost:8000/analyze
HTTP API Usage
Endpoint: POST http://localhost:8000/analyze
Request Body:
{
"code": "let x = 5;\nconst y = 10;\nconsole.log(x + y);"
}
Response:
{
"analysis": [
{
"ruleId": "prefer-const",
"severity": 2,
"message": "'x' is never reassigned. Use 'const' instead.",
"line": 1,
"column": 5
}
],
"summary": "Found 1 issue(s)."
}
MCP Usage with Claude Desktop
- Add to your Claude Desktop MCP configuration (
claude_desktop_config.json):
{
"mcpServers": {
"code-analyzer": {
"command": "node",
"args": ["C:/path/to/mcp-code-analyzer/index.js"]
}
}
}
-
Restart Claude Desktop
-
Use the analyzer in conversations:
Analyze this code: let http = require('http');
Code Analysis Rules
The analyzer checks for:
- ✅
prefer-const- Suggests const for variables that are never reassigned - ⚠️
no-unused-vars- Warns about declared but unused variables - ❌
no-undef- Errors on undefined variables - ❌
semi- Enforces semicolons - ❌
no-extra-semi- Prevents unnecessary semicolons - ⚠️
no-unreachable- Warns about unreachable code
Example
Input Code:
let http = require("http");
http
.createServer(function (req, res) {
res.writeHead(200, { "Content-Type": "text/html" });
res.end("Hello World!");
})
.listen(8080);
Analysis Result:
ERROR: 'http' is never reassigned. Use 'const' instead.
Location: Line 1, Column 5
Rule: prefer-const
Recommendation: Change 'let' to 'const'
Configuration
The analyzer uses ESLint 9+ flat config format. You can customize the rules by modifying the overrideConfig in index.js.
Supported Globals
- Node.js:
require,module,exports,process,__dirname,__filename - Browser:
window,document,console
API Reference
MCP Tool: analyze_code
Parameters:
code(string): The JavaScript/TypeScript code to analyze
Returns:
{
"content": [
{
"type": "text",
"text": "{\"analysis\": [...], \"summary\": \"...\"}"
}
]
}
HTTP Endpoint: POST /analyze
Request:
- Content-Type:
application/json - Body:
{ "code": "your code here" }
Response:
- Success (200):
{ "analysis": [...], "summary": "..." } - Error (400):
{ "error": "code is required" } - Error (500):
{ "error": "error message" }
Dependencies
@modelcontextprotocol/sdk- MCP server implementationeslint- JavaScript/TypeScript lintingexpress- HTTP server framework
Development
# Run in watch mode
npm run dev
# Test the HTTP endpoint
curl -X POST http://localhost:8000/analyze \
-H "Content-Type: application/json" \
-d '{"code":"let x = 5;"}'
Requirements
- Node.js >= 18
- npm or yarn
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the file for details.
Author
Your Name
Acknowledgments
- Built with Model Context Protocol
- Powered by ESLint
- Express.js for HTTP API
Support
If you encounter any issues or have questions, please open an issue on GitHub.
Note: This project requires Node.js 18+ due to MCP SDK requirements.