Mcp Server Semgrep

Mcp Server Semgrep

🚀 MCP 服务器 Semgrep 静态代码分析工具

MCP 服务器 Semgrep 静态代码分析工具可帮助开发者高效地对代码进行静态分析,检测潜在的安全问题、样式不一致等问题,还支持自定义规则,提升代码质量。

🚀 快速开始

要使用 MCP 服务器 Semgrep 静态代码分析工具,您首先需要安装 Semgrep 工具并配置环境变量。

📦 安装指南

安装 Semgrep 工具

您可以通过多种方式安装 Semgrep:

  • Node.js 方式
npm install -g semgrep
  • Python 方式
pip install semgrep
  • Homebrew(macOS)
brew install semgrep
  • Linux 系统
sudo apt-get install semgrep
# 或者
curl -sSL https://install.semgrep.dev | sh
  • Windows 系统
pip install semgrep

配置环境变量

安装完成后,请将 Semgrep 工具的路径添加到您的系统环境变量中,以便后续使用。

💻 使用示例

基础用法

项目扫描

Could you scan my source code in the /projects/my-application directory for potential security issues?

样式一致性分析

Analyze the z-index values in the project's CSS files and identify inconsistencies and potential layer conflicts.

创建自定义规则

Create a Semgrep rule that detects improper use of input sanitization functions.

过滤结果

Show me only scan results related to SQL injection vulnerabilities.

识别问题模式

Find all "magic numbers" in the code and suggest replacing them with named constants.

高级用法

创建自定义规则示例

检测 z-index 不一致的规则
rules:
- id: inconsistent-z-index
pattern: z-index: $Z
message: "Z-index $Z 可能与项目分层系统不兼容"
languages: [css, scss]
severity: WARNING
检测已弃用导入的规则
rules:
- id: deprecated-import
pattern: import $X from 'old-library'
message: "正在使用一个已弃用的库。建议使用 'new-library'"
languages: [javascript, typescript]
severity: WARNING

📚 详细文档

项目结构

├── src/
│   ├── config.ts         # 服务器配置文件
│   └── index.ts          # 程序入口和所有处理程序实现
├── scripts/
│   └── check-semgrep.js  # Semgrep 检测和安装辅助工具
├── build/                # 编译后的 JavaScript 文件(构建后生成)
└── tests/                # 单元测试文件

进一步文档

详细使用说明请参考:

  • USAGE.md - 详细的使用指南
  • README_PL.md - 中文 documentation
  • examples/ - 示例规则和“代码恐怖大厅”案例

📄 许可证

本项目采用 MIT 许可证,详情请见 LICENSE 文件。

👨‍💻 开发者信息

🤝 关于贡献

欢迎社区开发者积极参与本项目的开发与维护。如您有任何问题或建议,请通过以下方式联系我们:


感谢您的支持与合作!

  • 0 关注
  • 0 收藏,12 浏览
  • system 提出于 2025-09-30 12:51

相似服务问题