Back to MCP directory
publicPublicdnsLocal runtime

mcp-server-semgrep

MCP Server Semgrep是一个符合Model Context Protocol标准的服务器,集成了Semgrep静态分析工具与AI助手,提供代码安全分析、质量改进和漏洞检测功能。项目简化了架构设计,支持多平台运行,可通过多种方式安装,并提供了丰富的代码分析功能。

article

README

🚀 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/                # 单元测试文件

进一步文档

详细使用说明请参考:

📄 许可证

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

👨‍💻 开发者信息

🤝 关于贡献

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


感谢您的支持与合作!

help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client