使用说明
MCP代码分析器
一个由ESLint支持的双模式JavaScript/TypeScript代码分析器。可作为模型上下文协议(MCP)服务器和独立的HTTP API进行实时代码质量分析。
特性
- 🔍 ESLint动力分析 -全面的JavaScript/TypeScript代码分析
- 🔌 双模式操作 -同时作为MCP服务器和HTTP API工作
- ⚡ 实时分析 -获得代码质量的即时反馈
- 🎯 常见问题检测 -查找未使用的变量、缺少的分号、未定义的引用等
- 🌐 REST API -通过HTTP端点与任何应用程序轻松集成
- 🤖 MCP集成 -与Claude Desktop和其他MCP客户端兼容
安装
# Clone the repository
git clone https://github.com/pratham-prog861/mcp-code-analyzer.git
cd mcp-code-analyzer
# Install dependencies
npm install
用法
运行服务器
npm run dev
服务器同时以两种模式运行:
- MCP服务器:MCP客户端的标准传输
- HTTP API:REST端点在
http://localhost:8000/analyze
HTTP API使用情况
端点: POST http://localhost:8000/analyze
请求体:
{
"code": "let x = 5;\nconst y = 10;\nconsole.log(x + y);"
}
回应:
{
"analysis": [
{
"ruleId": "prefer-const",
"severity": 2,
"message": "'x' is never reassigned. Use 'const' instead.",
"line": 1,
"column": 5
}
],
"summary": "Found 1 issue(s)."
}
Claude Desktop的MCP使用
- 添加到您的Claude Desktop MCP配置(
claude_desktop_config.json):
{
"mcpServers": {
"code-analyzer": {
"command": "node",
"args": ["C:/path/to/mcp-code-analyzer/index.js"]
}
}
}
-
重新启动克劳德桌面
-
在对话中使用分析器:
Analyze this code: let http = require('http');
代码分析规则
分析仪检查:
- ✅
prefer-const-为从不重新分配的变量建议使用const - ⚠️
no-unused-vars-警告已声明但未使用的变量 - ❌
no-undef-未定义变量错误 - ❌
semi-强制使用分号 - ❌
no-extra-semi-防止不必要的分号 - ⚠️
no-unreachable-警告无法访问的代码
示例
输入代码:
let http = require("http");
http
.createServer(function (req, res) {
res.writeHead(200, { "Content-Type": "text/html" });
res.end("Hello World!");
})
.listen(8080);
分析结果:
ERROR: 'http' is never reassigned. Use 'const' instead.
Location: Line 1, Column 5
Rule: prefer-const
Recommendation: Change 'let' to 'const'
配置
分析仪使用ESLint 9+平面配置格式。您可以通过修改来自定义规则 overrideConfig 在 index.js.
支持的全局
- Node.js:
require,module,exports,process,__dirname,__filename - 浏览器:
window,document,console
api参考
MCP工具: analyze_code
参数:
code(string):要分析的JavaScript/TypeScript代码
退货:
{
"content": [
{
"type": "text",
"text": "{\"analysis\": [...], \"summary\": \"...\"}"
}
]
}
HTTP终结点: POST /analyze
请求:
- 内容类型:
application/json - 主体:
{ "code": "your code here" }
回应:
- 成功(200):
{ "analysis": [...], "summary": "..." } - 错误(400):
{ "error": "code is required" } - 错误(500):
{ "error": "error message" }
依赖项
@modelcontextprotocol/sdk-MCP服务器实现eslint-JavaScript/TypeScript lintingexpress-HTTP服务器框架
发展
# 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;"}'
需求
- Node.js>=18
- npm或纱线
贡献
欢迎投稿!请随时提交拉取请求。
- 复刻仓库
- 创建功能分支(
git checkout -b feature/amazing-feature) - 提交您的更改(
git commit -m 'Add some amazing feature') - 推到分支(
git push origin feature/amazing-feature) - 打开拉取请求
许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
作者
你的名字
致谢
支持
如果您遇到任何问题或有疑问,请在GitHub上打开问题。
备注:由于MCP SDK的要求,此项目需要Node.js 18+。
