semgrep-mcp

repository·main·Indexed 20 days ago

https://github.com/semgrep/mcp

A Model Context Protocol (MCP) server implementation that enables LLMs, Agents, and IDEs (such as Cursor and VS Code) to use Semgrep for automated security scanning and code analysis. It provides tools for scanning code, retrieving Abstract Syntax Trees (AST), and fetching findings from the Semgrep AppSec Platform. Supports multiple transport protocols including stdio, streamable-http, and SSE.

Tokens
5.3K
Snippets
26
Records
35
Agent score
71%

What's inside semgrep-mcp

  1. Install the semgrep-mcp Helm Chart

    main

    Deploy the semgrep-mcp server using Helm. This chart uses the semgrep/mcp:main Docker image by default.

    Run the following command to install the chart locally:

    helm install my-semgrep-mcp ./chart/semgrep-mcp
    helm install my-semgrep-mcp ./chart/semgrep-mcp
  2. Configure Semgrep MCP in ChatGPT

    main

    To connect Semgrep to ChatGPT via the hosted SSE server:

    1. Go to the Connector Settings page.
    2. Name the connection Semgrep.
    3. Set MCP Server URL to https://mcp.semgrep.ai/sse.
    4. Set Authentication to No authentication.
    5. Check the I trust this application checkbox.
    6. Click Create.
  3. Integrate semgrep-mcp with Cursor IDE

    main

    Add the following configuration to your ~/.cursor/mcp.json (global) or .cursor/mcp.json (project-specific) file to use uvx to run the server.

    {
      "mcpServers": {
        "semgrep": {
          "command": "uvx",
          "args": ["semgrep-mcp"]
        }
      }
    }
  4. Run semgrep-mcp using Docker

    main

    The server is available as a Docker image on GitHub Container Registry (ghcr.io/semgrep/mcp).

    • For stdio mode: You must use -i (interactive) and specify -t stdio because the default container mode is SSE.
    • For Streamable HTTP: Map port 8000 and use the -t streamable-http flag.
    • For SSE mode: Map port 8000 and use the -t sse flag.
    # Run in stdio mode
    docker run -i --rm ghcr.io/semgrep/mcp -t stdio
    
    # Run in Streamable HTTP mode
    docker run -p 8000:8000 ghcr.io/semgrep/mcp -t streamable-http
    
    # Run in SSE mode
    docker run -p 8000:8000 ghcr.io/semgrep/mcp -t sse
  5. Configure Semgrep MCP in Cursor

    main

    To use Semgrep in Cursor, add the server to your mcp.json configuration. If you are using the local uvx method, you may need to provide a SEMGREP_APP_TOKEN in the environment variables.

    Alternatively, you can use the Hosted Server (experimental) by adding a new MCP server in Cursor Settings (Cmd + Shift + J) with the type streamable-http and the URL https://mcp.semgrep.ai/mcp.

    {
      "mcpServers": {
        "semgrep": {
          "command": "uvx",
          "args": ["semgrep-mcp"],
          "env": {
            "SEMGREP_APP_TOKEN": "<token>"
          }
        }
      }
    }
  6. Install the Semgrep MCP Server

    main

    The Semgrep MCP server can be run locally using uvx or via a Docker container.

    Using uvx:

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

    Using Docker:

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

    Note: This repository is deprecated. Further updates will be made via the official semgrep binary in the main semgrep repository.

    uvx semgrep-mcp
  7. Install semgrep-mcp via pipx

    main

    The semgrep-mcp package is available on PyPI and can be installed using standard Python package managers like pipx, uv, or poetry. To install it globally using pipx:

    $ pipx install semgrep-mcp
  8. Integrate semgrep-mcp with VS Code / Copilot

    main

    To use the server in VS Code, add the configuration to your User Settings (JSON) or a workspace-specific .vscode/mcp.json file.

    Using uvx:

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

    Using Docker:

    {
      "mcp": {
        "servers": {
          "semgrep": {
            "command": "docker",
            "args": [
              "run",
              "-i",
              "--rm",
              "ghcr.io/semgrep/mcp",
              "-t",
              "stdio"
            ]
          }
        }
      }
    }
  9. Connect to Semgrep AppSec Platform

    main

    To use the Semgrep AppSec Platform features, you must provide an API token generated from your Semgrep organization settings. Use the environment variable SEMGREP_APP_TOKEN.

    Methods to provide the token:

    • CLI: export SEMGREP_APP_TOKEN=<token>
    • Docker: docker run -e SEMGREP_APP_TOKEN=<token> ...
    • MCP Config JSON:
      "env": {
        "SEMGREP_APP_TOKEN": "<token>"
      }
    "env": {
      "SEMGREP_APP_TOKEN": "<token>"
    }