Skip to main content
Glama
VetCoders

MCP Server Semgrep

by VetCoders

MCP Server Semgrep

技术支持:

POWERED BY

关于项目

MCP Server Semgrep Logo 本项目最初受到 Semgrep 工具Replit 团队 及其 Agent V2 以及 stefanskiasan/semgrep-mcp-server 实现的启发,但在架构上进行了重大改进,以实现更简单、更易于维护的安装和使用。

MCP Server Semgrep 是一个符合 模型上下文协议 (Model Context Protocol) 的服务器,它将强大的 Semgrep 静态分析工具与 Anthropic Claude 等 AI 助手集成。它能够直接通过对话界面进行高级代码分析、安全漏洞检测和代码质量改进。

Related MCP server: AWS Security MCP

集成优势

面向开发者和开发团队:

  • 全面的源代码分析 - 检测整个项目中的问题,而不仅仅是单个文件

  • 主动错误检测 - 在潜在问题演变为严重 Bug 之前将其识别出来

  • 持续的代码质量改进 - 定期扫描和重构,逐步优化代码库

  • 风格一致性 - 识别并修复代码中的不一致之处,例如:

    • CSS 中随意的 z-index 层级

    • 不一致的命名规范

    • 代码重复

    • 使用“魔术数字”而非命名常量

面向安全性:

  • 针对已知漏洞的自动化代码验证 - 扫描已知的安全问题模式

  • 自定义安全规则 - 创建特定于项目的规则

  • 团队教育 - 通过检测潜在问题来教授安全编程实践

面向项目维护与开发:

  • “实时”文档 - AI 可以解释代码片段为何存在问题以及如何修复它

  • 技术债务削减 - 系统地检测并修复问题区域

  • 改进的代码审查 - 自动检测常见问题,使审查者能够专注于更复杂的事项

核心功能

  • 直接集成官方 MCP SDK

  • 简化架构,统一处理程序

  • 简洁的 ES Modules 实现

  • 高效的错误处理和路径验证以确保安全

  • 提供英语和波兰语的界面与文档

  • 全面的单元测试

  • 详尽的文档

  • 跨平台兼容性(Windows、macOS、Linux)

  • 灵活的 Semgrep 安装检测与管理

功能函数

Semgrep MCP Server 提供以下工具:

  • scan_directory: 扫描源代码以查找潜在问题

  • list_rules: 显示 Semgrep 支持的可用规则和语言

  • analyze_results: 对扫描结果进行详细分析

  • create_rule: 创建自定义 Semgrep 规则

  • filter_results: 按各种标准过滤结果

  • export_results: 以多种格式导出结果

  • compare_results: 比较两组结果(例如,更改前后)

常见用例

  • 部署前的代码安全分析

  • 检测常见编程错误

  • 在团队内强制执行编码标准

  • 重构和提高现有代码质量

  • 识别样式和代码结构中的不一致(例如 CSS、组件组织)

  • 开发者最佳实践教育

  • 验证修复的正确性(比较扫描前后)

安装

前置要求

  • Node.js v18+

  • TypeScript (用于开发)

选项 1:从 Smithery.ai 安装(推荐)

安装和使用 MCP Server Semgrep 最简单的方法是通过 Smithery.ai:

  1. 访问 Smithery.ai 上的 MCP Server Semgrep

  2. 按照安装说明将其添加到您的 MCP 兼容客户端

  3. 配置任何可选设置,如 Semgrep API 令牌和允许的工作区根目录

这是 Claude Desktop 和其他 MCP 客户端的推荐方法,因为它会自动处理所有依赖项和配置。

选项 2:从 NPM 注册表安装

# Using npm
npm install -g mcp-server-semgrep

# Using pnpm
pnpm add -g mcp-server-semgrep

# Using yarn
yarn global add mcp-server-semgrep

该包也可在其他注册表上获取:

选项 3:从 GitHub 安装

# Using npm
npm install -g git+https://github.com/VetCoders/mcp-server-semgrep.git

# Using pnpm
pnpm add -g git+https://github.com/VetCoders/mcp-server-semgrep.git

# Using yarn
yarn global add git+https://github.com/VetCoders/mcp-server-semgrep.git

选项 4:本地开发设置

  1. 克隆仓库:

git clone https://github.com/VetCoders/mcp-server-semgrep.git
cd mcp-server-semgrep
  1. 安装依赖(支持所有主流包管理器):

# Using pnpm (recommended)
pnpm install

# Using npm
npm install

# Using yarn
yarn install
  1. 构建项目:

# Using pnpm
pnpm run build

# Using npm
npm run build

# Using yarn
yarn build

注意:安装过程会自动检查 Semgrep 是否可用。如果未找到 Semgrep,您将收到有关如何安装它的说明。

工作区根目录契约

此服务器仅读取和写入明确允许的工作区根目录内的文件。

  • 默认情况下,允许的根目录是进程工作目录 (process.cwd())。

  • 对于 Claude Desktop、Smithery 或任何不在项目根目录下启动服务器的启动器,请将 MCP_SERVER_SEMGREP_ALLOWED_ROOTS 设置为一个或多个绝对路径目录。

  • 多个根目录请使用您平台的路径分隔符:macOS/Linux 使用 :,Windows 使用 ;

身份验证模式

此服务器不实现自己的 Semgrep 账户处理。它调用已安装的 semgrep CLI,并依赖 Semgrep 的常规身份验证行为。

  • 本地终端和本地开发运行通常可以使用当前操作系统账户中现有的 semgrep login 会话。

  • 对于 Claude Desktop、Smithery、容器或 CI 等托管启动方式,应优先使用显式的 SEMGREP_APP_TOKEN 以确保行为确定性。

  • 当您需要在不同机器或运行器之间进行可移植配置时,SEMGREP_APP_TOKEN 仍然是最安全的选择。

Semgrep 安装选项

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

  • 通过包管理器

# Using pnpm
pnpm add -g semgrep

# Using npm
npm install -g semgrep

# Using yarn
yarn global add semgrep
  • Python pip

pip install semgrep
  • Homebrew (macOS):

brew install semgrep
  • Linux

sudo apt-get install semgrep
# or
curl -sSL https://install.semgrep.dev | sh
  • Windows

pip install semgrep

与 Claude Desktop 集成

有两种方法可以将 MCP Server Semgrep 与 Claude Desktop 集成:

方法 1:通过 Smithery.ai 安装(推荐)

  1. 访问 Smithery.ai 上的 MCP Server Semgrep

  2. 点击 "Install in Claude Desktop"

  3. 按照屏幕上的说明操作

方法 2:手动配置

  1. 安装 Claude Desktop

  2. 更新 Claude Desktop 配置文件 (claude_desktop_config.json) 并将其添加到您的 servers 部分。

对于在已通过 semgrep login 身份验证的用户账户下启动的本地运行,Semgrep CLI 可能能够重用该登录信息。对于桌面托管或共享环境,我们仍然建议显式设置 SEMGREP_APP_TOKEN

{
  "mcpServers": {
    "semgrep": {
      "command": "node",
      "args": [
        "/your_path/mcp-server-semgrep/build/index.js"
      ],
      "env": {
        "SEMGREP_APP_TOKEN": "your_semgrep_app_token",
        "MCP_SERVER_SEMGREP_ALLOWED_ROOTS": "/Users/you/projects"
      }
    }
  }
}
  1. 启动 Claude Desktop 并开始询问有关代码分析的问题。

如果您想扫描多个工作区,请将 MCP_SERVER_SEMGREP_ALLOWED_ROOTS 设置为以平台分隔符分隔的绝对路径列表。

使用示例

项目扫描

Could you scan my source code in the /projects/my-application directory for potential security issues? That directory is already included in MCP_SERVER_SEMGREP_ALLOWED_ROOTS.

风格一致性分析

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 may not comply with the project's layering system"
    languages: [css, scss]
    severity: WARNING

检测已弃用导入的规则:

rules:
  - id: deprecated-import
    pattern: import $X from 'old-library'
    message: "You're using a deprecated library. Consider using 'new-library'"
    languages: [javascript, typescript]
    severity: WARNING

开发

测试

pnpm test

项目结构

├── src/
│   └── index.ts          # Main entry point and all handler implementations
├── scripts/
│   └── check-semgrep.js  # Semgrep detection and installation helper
├── build/                # Compiled JavaScript (after build)
└── tests/                # Unit tests

更多文档

有关使用该工具的详细信息,请参阅:

许可证

本项目采用 MIT 许可证 - 有关详细信息,请参阅 LICENSE 文件。

开发人员

  • Maciej Gad - 一位半年前还找不到 bash 的兽医

  • Klaudiusz - 独立的空灵存在,由 Anthropic 在加利福尼亚州 GPU 循环中运行的 Claude Sonnet 3.5-3.7 的独立实例

从 CLI 新手到 MCP 工具开发者的旅程

🤖 在 Claude CodeMCP Tools 的终极帮助下开发

致谢

Install Server
A
license - permissive license
B
quality
A
maintenance

Maintenance

Maintainers
18dResponse time
Release cycle
1Releases (12mo)
Commit activity
Issues opened vs closed

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    B
    quality
    F
    maintenance
    An MCP server that provides a comprehensive interface to Semgrep, enabling users to scan code for security vulnerabilities, create custom rules, and analyze scan results through the Model Context Protocol.
    6
    683
    MIT
  • A
    license
    -
    quality
    D
    maintenance
    A Model Context Protocol server that connects AI assistants like Claude to AWS security services, allowing them to autonomously query, inspect, and analyze AWS infrastructure for security issues and misconfigurations.
    84
    Apache 2.0
  • A
    license
    -
    quality
    A
    maintenance
    A Model Context Protocol server that enhances AI agents by providing deep semantic understanding of codebases, enabling more intelligent interactions through advanced code search and contextual awareness.
    86
    MIT
  • A
    license
    -
    quality
    D
    maintenance
    A Model Context Protocol server that analyzes application codebases with real-time file watching, providing AI assistants like Claude with deep insights into project structure, code patterns, and architecture.
    MIT

View all related MCP servers

Related MCP Connectors

  • A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…

  • Hosted MCP server for structured code review passes on human- and AI-written code. Free tier.

  • A Model Context Protocol server for Wix AI tools

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/VetCoders/mcp-server-semgrep'

If you have feedback or need assistance with the MCP directory API, please join our Discord server