Skip to main content
Glama

Semgrep MCP Server

Official
by semgrep

Semgrep MCP 服务器

一个模型上下文协议 (MCP) 服务器,用于使用Semgrep扫描代码以查找安全漏洞。保护你的Vibe 代码安全!😅

模型上下文协议 (MCP)是面向 LLM、代理和 IDE(例如 Cursor、VS Code、Windsurf 或任何支持 MCP 的 IDE)的标准化 API,用于获取专业帮助、获取上下文并充分利用工具的强大功能。Semgrep 是一款快速、确定性的静态分析工具,能够从语义上理解多种语言,并拥有超过5,000 条规则。🛠️

此 Beta 项目正在积极开发中。我们期待您的反馈、错误报告、功能请求和代码。加入#mcp社区 Slack频道!

内容

入门

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

uvx semgrep-mcp # see --help for more options

或者,作为Docker 容器运行:

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

光标

示例mcp.json

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

向您的.cursor/rules添加一条指令以自动使用:

Always scan code generated using Semgrep for security vulnerabilities

托管服务器

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

mcp.json

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

演示

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 规则

资源

向法学硕士 (LLM) 公开数据和内容

  • semgrep://rule/schema :使用 JSON 模式指定 Semgrep 规则 YAML 语法
  • semgrep://rule/{rule_id}/yaml :来自 Semgrep 注册表的 YAML 格式的完整 Semgrep 规则

用法

该 Python 包以semgrep-mcp的形式发布到 PyPI,可以使用pippipxuvpoetry或任何 Python 包管理器进行安装和运行。

$ pipx install semgrep-mcp $ semgrep-mcp --help Usage: semgrep-mcp [OPTIONS] Entry point for the MCP server Supports both stdio and sse transports. For stdio, it will read from stdin and write to stdout. For sse, it will start an HTTP server on port 8000. Options: -v, --version Show version and exit. -t, --transport [stdio|sse] Transport protocol to use (stdio or sse) -h, --help Show this message and exit.

标准输入/输出(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 应用安全平台

或者,要连接到 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>" }

如有需要,请联系support@semgrep.com。☎️

集成

游标 IDE

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

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

光标 MCP 设置

请参阅光标文档以了解更多信息。

VS Code/Copilot

单击此自述文件顶部的安装按钮,即可实现最快安装。

手动配置

将以下 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 文档

风帆冲浪

将以下 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 客户端示例

请参阅examples/sse_client.py中的完整示例

from mcp.client.session import ClientSession from mcp.client.sse import sse_client async def main(): async with sse_client("http://localhost:8000/sse") as (read_stream, write_stream): async with ClientSession(read_stream, write_stream) as session: await session.initialize() results = await session.call_tool( "semgrep_scan", { "code_files": [ { "filename": "hello_world.py", "content": "def hello(): print('Hello, World!')", } ] }, ) print(results)

一些客户端库需要URL : http://localhost:8000/sse ,而其他客户端库只需要HOST : localhost:8000 。请在 Web 浏览器中尝试该URL ,确认服务器正在运行,并且没有网络问题。

请参阅官方 SDK 文档以了解更多信息。

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

我们期待您的反馈、错误报告、功能请求和代码。加入#mcp社区 Slack频道!

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

类似工具🔍

社区项目🌟

MCP 服务器注册表


Semgrep 团队倾情打造

Install Server
A
security – no known vulnerabilities
A
license - permissive license
A
quality - confirmed to work

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

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

  1. 内容
    1. 入门
      1. 光标
      2. 托管服务器
    2. 演示
      1. API
        1. 工具
        2. 提示
        3. 资源
      2. 用法
        1. 标准输入/输出(stdio)
        2. 服务器发送事件 (SSE)
      3. Semgrep 应用安全平台
        1. 集成
          1. 游标 IDE
          2. VS Code/Copilot
          3. 风帆冲浪
          4. 克劳德桌面
          5. OpenAI
          6. 自定义客户端
        2. 贡献、社区和从源代码运行
          1. 类似工具🔍
          2. 社区项目🌟
          3. MCP 服务器注册表

        Related MCP Servers

        • -
          security
          A
          license
          -
          quality
          MCP Server simplifies the implementation of the Model Context Protocol by providing a user-friendly API to create custom tools and manage server workflows efficiently.
          Last updated -
          4
          3
          TypeScript
          MIT License
        • -
          security
          A
          license
          -
          quality
          Enables integration of Semgrep in development environments via the MCP protocol, supporting static code analysis, rule management, and scan result operations.
          Last updated -
          1
          JavaScript
          MIT License
        • A
          security
          A
          license
          A
          quality
          A Model Context Protocol (MCP) server for querying the CVE-Search API. This server provides comprehensive access to CVE-Search, browse vendor and product、get CVE per CVE-ID、get the last updated CVEs.
          Last updated -
          6
          15
          Python
          MIT License
        • -
          security
          A
          license
          -
          quality
          A server implementation that exposes grep functionality through the Model Context Protocol, allowing MCP-compatible clients to search for patterns in files using regular expressions.
          Last updated -
          1
          Python
          GPL 3.0

        View all related MCP servers

        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/semgrep/mcp'

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