Semgrep MCP Server

Semgrep MCP Server

一个 MCP 服务器,它为 Semgrep 提供了一个全面的接口,使用户能够扫描代码中的安全漏洞、创建自定义规则,并通过模型上下文协议分析扫描结果。

Category
访问服务器

Tools

start_scan_from_content

Starts a Semgrep scan with code content provided directly Args: ctx: MCP context for sending notifications code_files: List of dictionaries with 'filename' and 'content' keys config: Semgrep configuration (e.g. "auto" or absolute path to rule file) Returns: Dictionary with scan information

get_scan_status

Gets the current status of a scan Args: scan_id: Identifier for the scan Returns: Dictionary with scan status information

get_scan_results

Gets the results of a completed scan Args: scan_id: Identifier for the scan Returns: Dictionary with scan results

get_supported_languages

Returns a list of supported languages by Semgrep Returns: List of supported languages

semgrep_scan

Runs a Semgrep scan on provided code content and returns the findings in JSON format Args: code_files: List of dictionaries with 'filename' and 'content' keys config: Semgrep configuration (e.g. "auto" or absolute path to rule file) Returns: Dictionary with scan results in Semgrep JSON format

start_scan

Starts a Semgrep scan with progress updates via notifications Args: ctx: MCP context for sending notifications target_path: Absolute path to the file or directory to scan config: Semgrep configuration (e.g. "auto" or absolute path to rule file) Returns: Dictionary with scan information

README

<p align="center"> <a href="https://semgrep.dev"> <picture> <source media="(prefers-color-scheme: light)" srcset="images/semgrep-logo-light.svg"> <source media="(prefers-color-scheme: dark)" srcset="images/semgrep-logo-dark.svg"> <img src="https://raw.githubusercontent.com/semgrep/mcp/main/images/semgrep-logo-light.svg" height="60" alt="Semgrep logo"/> </picture> </a> </p> <p align="center"> <a href="https://semgrep.dev/docs/"> <img src="https://img.shields.io/badge/Semgrep-docs-2acfa6?style=flat-square" alt="Documentation" /> </a> <a href="https://go.semgrep.dev/slack"> <img src="https://img.shields.io/badge/Slack-4.5k%20-4A154B?style=flat-square&logo=slack&logoColor=white" alt="Join Semgrep community Slack" /> </a> <a href="https://www.linkedin.com/company/semgrep/"> <img src="https://img.shields.io/badge/LinkedIn-follow-0a66c2?style=flat-square" alt="Follow on LinkedIn" /> </a> <a href="https://x.com/intent/follow?screen_name=semgrep"> <img src="https://img.shields.io/badge/semgrep-000000?style=flat-square&logo=x&logoColor=white?style=flat-square" alt="Follow @semgrep on X" /> </a> </p>

Semgrep MCP 服务器

在 VS Code UV 中安装 在 VS Code Docker 中安装 在 VS Code semgrep.ai 中安装 PyPI Docker 在 VS Code Insiders 中安装 在 VS Code Insiders 中安装

一个 MCP 服务器,用于使用 Semgrep 扫描代码中的安全漏洞。保护你的 vibe coding!😅

模型上下文协议 (MCP) 是 LLM、代理和 IDE(如 Cursor、VS Code、Windsurf 或任何支持 MCP 的工具)的标准 API,用于获取专门的帮助、上下文并利用工具的力量。Semgrep 是一种快速、确定性的静态分析工具,可以语义理解多种 语言,并提供超过 5,000 条规则。🛠️

[!NOTE] 这个 beta 项目正在积极开发中,我们欢迎您的反馈、错误报告、功能请求和代码。加入 #mcp 社区 slack 频道!

目录

入门

使用 uvpython 包 作为 CLI 命令运行:

uvx semgrep-mcp # 查看 --help 获取更多选项

或者作为 docker 容器

docker run -i --rm ghcr.io/semgrep/mcp -t stdio

Cursor

示例 mcp.json

{
  "mcpServers": {
    "semgrep": {
      "command": "uvx",
      "args": ["semgrep-mcp"],
      "env": {
        "SEMGREP_APP_TOKEN": "<token>"
      }
    }
  }
}

在你的 .cursor/rules 中添加一条指令以自动使用

始终使用 Semgrep 扫描生成的代码中的安全漏洞

托管服务器

[!WARNING] 这是一个实验性服务器,可能会崩溃。一旦 MCP 规范在不久的将来获得对 HTTP 流和 OAuth 的支持,它将获得新的功能。🚀

mcp.json

{
  "mcpServers": {
    "semgrep": {
      "url": "https://mcp.semgrep.ai/sse"
    }
  }
}

演示

<a href="https://www.loom.com/share/8535d72e4cfc4e1eb1e03ea223a702df"> <img style="max-width:300px;" src="https://cdn.loom.com/sessions/thumbnails/8535d72e4cfc4e1eb1e03ea223a702df-1047fabea7261abb-full-play.gif"> </a>

API

工具

使 LLM 能够执行操作、进行确定性计算以及与外部服务交互。

扫描代码

  • security_check: 扫描代码中的安全漏洞
  • semgrep_scan: 使用给定的配置字符串扫描代码文件中的安全漏洞
  • semgrep_scan_with_custom_rule: 使用自定义 Semgrep 规则扫描代码文件

理解代码

  • get_abstract_syntax_tree: 输出代码的抽象语法树 (AST)

元数据

  • supported_languages: 返回 Semgrep 支持的语言列表
  • semgrep_rule_schema: 获取最新的 semgrep 规则 JSON Schema

提示

可重用的提示,用于标准化常见的 LLM 交互。

  • write_custom_semgrep_rule: 返回一个提示,以帮助编写 Semgrep 规则

用法

此 python 包作为 semgrep-mcp 发布到 PyPI,可以使用 pippipxuvpoetry 或任何 python 包管理器安装和运行。

$ pipx install semgrep-mcp
$ semgrep-mcp --help

用法: semgrep-mcp [OPTIONS]

  MCP 服务器的入口点

  支持 stdio 和 sse 传输。对于 stdio,它将从 stdin 读取并写入 stdout。对于 sse,它将在端口 8000 上启动一个 HTTP 服务器。

选项:
  -v, --version                显示版本并退出。
  -t, --transport [stdio|sse]  要使用的传输协议(stdio 或 sse)
  -h, --help                   显示此消息并退出。

标准输入/输出 (stdio)

stdio 传输支持通过标准输入和输出流进行通信。这对于本地集成和命令行工具特别有用。有关更多详细信息,请参阅 规范

Python

semgrep-mcp

默认情况下,python 包将在 stdio 模式下运行。因为它使用标准输入和输出流,所以看起来该工具在没有任何打印输出的情况下挂起,但这是正常的。

Docker

此服务器已发布到 Github 的容器注册表 (ghcr.io/semgrep/mcp)

docker run -i --rm ghcr.io/semgrep/mcp -t stdio

默认情况下,docker 容器处于 SSE 模式,因此您必须在镜像名称后包含 -t stdio 并使用 -i 运行以在 交互式 模式下运行。

服务器发送事件 (SSE)

SSE 传输支持服务器到客户端的流式传输,并使用 HTTP POST 请求进行客户端到服务器的通信。有关更多详细信息,请参阅 规范

默认情况下,服务器将侦听 0.0.0.0:8000/sse 以进行客户端连接。要更改任何这些设置,请设置 FASTMCP_* 环境变量。服务器必须正在运行,客户端才能连接到它。

Python

semgrep-mcp -t sse

默认情况下,python 包将在 stdio 模式下运行,因此您必须包含 -t sse

Docker

docker run -p 8000:0000 ghcr.io/semgrep/mcp

Semgrep AppSec 平台

要选择性地连接到 Semgrep AppSec 平台:

  1. 登录 或注册
  2. 设置 页面生成令牌
  3. 将其添加到您的环境变量中
    • CLI (export SEMGREP_APP_TOKEN=<token>)

    • Docker (docker run -e SEMGREP_APP_TOKEN=<token>)

    • MCP 配置 JSON

      "env": {
        "SEMGREP_APP_TOKEN": "<token>"
      }
      

[!TIP] 如果需要,请联系 support@semgrep.com。☎️

集成

Cursor IDE

将以下 JSON 块添加到您的 ~/.cursor/mcp.json 全局或 .cursor/mcp.json 项目特定配置文件中:

{
  "mcpServers": {
    "semgrep": {
      "command": "uvx",
      "args": ["semgrep-mcp"]
    }
  }
}

cursor MCP 设置

有关更多信息,请参阅 cursor 文档

VS Code / Copilot

单击此 README 顶部的安装按钮以进行最快的安装。

手动配置

将以下 JSON 块添加到 VS Code 中的用户设置 (JSON) 文件中。您可以通过按 Ctrl + Shift + P 并键入 Preferences: Open User Settings (JSON) 来执行此操作。

{
  "mcp": {
    "servers": {
      "semgrep": {
        "command": "uvx",
        "args": ["semgrep-mcp"]
      }
    }
  }
}

或者,您可以将其添加到工作区中名为 .vscode/mcp.json 的文件中:

{
  "servers": {
    "semgrep": {
      "command": "uvx",
        "args": ["semgrep-mcp"]
    }
  }
}

使用 Docker

{
  "mcp": {
    "servers": {
      "semgrep": {
        "command": "docker",
        "args": [
          "run",
          "-i",
          "--rm",
          "ghcr.io/semgrep/mcp",
          "-t",
          "stdio"
        ]
      }
    }
  }
}

有关更多信息,请参阅 VS Code 文档

Windsurf

将以下 JSON 块添加到您的 ~/.codeium/windsurf/mcp_config.json 文件中:

{
  "mcpServers": {
    "semgrep": {
      "command": "uvx",
      "args": ["semgrep-mcp"]
    }
  }
}

有关更多信息,请参阅 Windsurf 文档

Claude Desktop

将以下 JSON 块添加到您的 claude_desktop_config.json 文件中:

{
  "mcpServers": {
    "semgrep": {
      "command": "uvx",
      "args": ["semgrep-mcp"]
    }
  }
}

有关更多信息,请参阅 Anthropic 文档

OpenAI

async with MCPServerStdio(
    params={
        "command": "uvx",
        "args": ["semgrep-mcp"],
    }
) as server:
    tools = await server.list_tools()

有关更多信息,请参阅 OpenAI Agents SDK 文档

自定义客户端

示例 Python SSE 客户端

from mcp.client import Client

client = Client()
client.connect("localhost:8000")

# 扫描代码中的安全问题
results = client.call_tool("semgrep_scan", 
  {
  "code_files": [
    {
      "filename": "hello_world.py",
      "content": "def hello(): ..."
    }
  ]
})

有关更多信息,请参阅 官方 SDK 文档

贡献、社区和从源代码运行

[!NOTE] 我们欢迎您的反馈、错误报告、功能请求和代码。加入 #mcp 社区 slack 频道!

有关更多信息和如何从源代码运行 MCP 服务器的详细信息,请参阅 CONTRIBUTING.md

类似工具 🔍

社区项目 🌟

MCP 服务器注册表

  • Glama

    <a href="https://glama.ai/mcp/servers/4iqti5mgde"> <img width="380" height="200" src="https://glama.ai/mcp/servers/4iqti5mgde/badge" alt="Semgrep Server MCP server" /> </a>

  • MCP.so


Semgrep 团队 用 ❤️ 制作

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选