首页
学习
活动
专区
圈层
工具
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
首页
学习
活动
专区
圈层
工具
MCP广场
MCP广场 >详情页
mcp云托管模式2025-06-160分享
github
一种MCP服务器,它为Semgrep提供了一个全面的接口,使用户能够通过模型上下文协议扫描代码以查找安全漏洞、创建自定义规则并分析扫描结果。
By semgrep
2025-06-160
github
详情内容

Semgrep logo

Documentation Join Semgrep community Slack Follow on LinkedIn Follow @semgrep on X

Semgrep MCP 服务器

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

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

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

[!NOTE]
这个测试版项目正在积极开发中。我们非常欢迎你的反馈、错误报告、功能请求和代码。加入 #mcp 社区 Slack 频道!

目录

开始使用

使用 uv 运行 Python 包 作为 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 扫描生成的代码以查找安全漏洞

ChatGPT

  1. 转到 Connector Settings 页面 (直接链接)
  2. 命名 连接为 Semgrep
  3. 设置 MCP Server URLhttps://mcp.semgrep.ai/sse
  4. 设置 AuthenticationNo authentication
  5. 勾选 I trust this application 复选框
  6. 点击 Create

更多详情请参阅 官方文档

托管服务器

[!WARNING]
mcp.semgrep.ai 是一个实验性服务器,可能会意外中断。它将快速获得新功能。🚀

Cursor

  1. Cmd + Shift + J 打开 Cursor 设置
  2. 选择 MCP Tools
  3. 点击 New MCP Server
{
  "mcpServers": {
    "semgrep": {
      "type": "streamable-http",
      "url": "https://mcp.semgrep.ai/mcp"
    }
  }
}

演示

API

工具

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

扫描代码

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

资源

向 LLMs 公开数据和内容

  • semgrep://rule/schema: 使用 JSON schema 规范 Semgrep 规则 YAML 语法
  • semgrep://rule/{rule_id}/yaml: 从 Semgrep 注册表中获取完整的 Semgrep 规则 YAML 格式

使用

这个 Python 包已发布到 PyPI,名为 semgrep-mcp,可以使用 pippipxuvpoetry 或任何 Python 包管理器安装和运行。

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

Usage: semgrep-mcp [OPTIONS]

  MCP 服务器的入口点

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

Options:
  -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 运行以在 交互式 模式下运行。

可流式 HTTP

可流式 HTTP 通过 HTTP POST 请求实现流式 JSON RPC 响应。更多详情请参阅 规范

默认情况下,服务器监听 127.0.0.1:8000/mcp 以连接客户端。要更改任何设置,请设置 FASTMCP_* 环境变量。服务器必须运行,客户端才能连接。

Python

semgrep-mcp -t streamable-http

默认情况下,Python 包将以 stdio 模式运行,因此你必须包含 -t streamable-http

Docker

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

服务器发送事件 (SSE)

[!WARNING]
MCP 社区认为这是一种遗留的传输协议,主要用于向后兼容。可流式 HTTP 是推荐的替代方案。

SSE 传输通过服务器发送事件实现服务器到客户端的流式通信。更多详情请参阅 规范

默认情况下,服务器监听 127.0.0.1:8000/sse 以连接客户端。要更改任何设置,请设置 FASTMCP_* 环境变量。服务器必须运行,客户端才能连接。

Python

semgrep-mcp -t sse

默认情况下,Python 包将以 stdio 模式运行,因此你必须包含 -t sse

Docker

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

Semgrep 应用安全平台

可选地,连接到 Semgrep 应用安全平台:

  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]
如果需要,请 联系支持。☎️

集成

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": {
通过SSE URL连接服务
Server已在腾讯云托管,可在连接后免费调用和在线进行工具测试~
工具测试
已支持Server下的6个工具,可选择工具进行在线测试
get_abstract_syntax_tree
Returns the Abstract Syntax Tree (AST) for the provided code file in JSON format Use this tool when you need to: - get the Abstract Syntax Tree (AST) for the provided code file - get the AST of a file - understand the structure of the code in a more granular way - see what a parser sees in the code
get_supported_languages
Returns a list of supported languages by Semgrep Only use this tool if you are not sure what languages Semgrep supports.
security_check
Runs a fast security check on code and returns any issues found. Use this tool when you need to: - scan code for security vulnerabilities - verify that code is secure - double check that code is secure before committing - get a second opinion on code security If there are no issues, you can be reasonably confident that the code is secure.
semgrep_rule_schema
Get the schema for a Semgrep rule Use this tool when you need to: - get the schema required to write a Semgrep rule - need to see what fields are available for a Semgrep rule - verify what fields are available for a Semgrep rule - verify the syntax for a Semgrep rule is correct
semgrep_scan
Runs a Semgrep scan on provided code content and returns the findings in JSON format Use this tool when you need to: - scan code files for security vulnerabilities - scan code files for other issues
semgrep_scan_with_custom_rule
Runs a Semgrep scan with a custom rule on provided code content and returns the findings in JSON format Use this tool when you need to: - scan code files for specific security vulnerability not covered by the default Semgrep rules - scan code files for specific issue not covered by the default Semgrep rules
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档