MCP Server for using Semgrep to scan code
Project description
Semgrep MCP Server
An MCP server for using Semgrep to scan code for security vulnerabilies. Secure your vibe coding! 😅
Model Context Protocol (MCP) is a standardized API for LLMs, Agents, and IDEs like Cursor, VS Code, Windsurf, or anything that supports MCP, to get specialized help, context, and harness the power of tools. Semgrep is a fast, deterministic static analysis semantically understands many languages and comes with with over 5,000 rules. 🛠️
[!NOTE] This beta project is under active development, we would love your feedback, bug reports, feature requests, and code. Join the
#mcp
community slack channel!
Contents
- Getting Started
- Demo
- API
- Usage
- Semgrep AppSec Platform
- Integrations
- Contributing, Community, and Running From Source
Getting started
Run the python package as a CLI command using uv
:
uvx semgrep-mcp # see --help for more options
or as a docker container:
docker run -i --rm ghcr.io/semgrep/mcp -t stdio
Cursor
example mcp.json
{
"mcpServers": {
"semgrep": {
"command": "uvx",
"args": ["semgrep-mcp"],
"env": {
"SEMGREP_APP_TOKEN": "<token>"
}
}
}
}
Add an instruction to your .cursor/rules
to use automatically
Always scan code generated using Semgrep for security vulnerabilities
Hosted Server
[!WARNING] This is an experimental server that may break. Once the MCP spec gains support for HTTP Streaming and OAuth in the near future, it will gain new functionality. 🚀
mcp.json
{
"mcpServers": {
"semgrep": {
"url": "https://mcp.semgrep.ai/sse"
}
}
}
Demo
API
Tools
Scanning Code
security_check
: Scan code for security vulnerabilitiessemgrep_scan
: Scan code files for security vulnerabilities with a given config stringsemgrep_scan_with_custom_rule
: Scan code files using a custom Semgrep rule
Understanding Code
get_abstract_syntax_tree
: Output the Abstract Syntax Tree (AST) of code
Meta
supported_languages
: Return the list of langauges Semgrep supportssemgrep_rule_schema
: Fetches the latest semgrep rule JSON Schema
Prompts
write_custom_semgrep_rule
: Return a prompt to help write a Semgrep rule
Usage
This python package is published to PyPI as semgrep-mcp and can be installed and run with pip, pipx, uv, poetry, or any python package manager.
$ 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.
Standard Input/Output (stdio)
The stdio transport enables communication through standard input and output streams. This is particularly useful for local integrations and command-line tools. See the spec for more details.
Python
semgrep-mcp
By default, the python package will run in stdio
mode. Because it's using the standard input and output streams, it will look like the tool is hanging without any print outs but this is normal.
Docker
This server is published to Github's Container Registry (ghcr.io/semgrep/mcp)
docker run -i --rm ghcr.io/semgrep/mcp -t stdio
By default, the docker container is in SSE
mode, so you will have to include -t stdio
after the image name and run with -i
to run in interactive mode.
Server-Sent Events (SSE)
SSE transport enables server-to-client streaming with HTTP POST requests for client-to-server communication. See the spec for more details.
By default, the server wil listen on 0.0.0.0:8000/sse for client connections. To change any of this, set FASTMCP_* environment variables. The server must be running for clients to connect to it.
Python
semgrep-mcp -t sse
By default, the python package will run in stdio
mode, so you will have to include -t sse
.
Docker
docker run -p 8000:0000 ghcr.io/semgrep/mcp
Semgrep AppSec Platform
To optionally connect to Semgrep AppSec Platform:
- Login or sign up
- Generate a token from Settings page
- Add it to your environment variables
-
CLI (
export SEMGREP_APP_TOKEN=<token>
) -
Docker (
docker run -e SEMGREP_APP_TOKEN=<token>
) -
MCP Config JSON
"env": { "SEMGREP_APP_TOKEN": "<token>" }
-
[!TIP] Please reach out to support@semgrep.com if needed. ☎️
Integrations
Cursor IDE
Add the following JSON block to your ~/.cursor/mcp.json
global or .cursor/mcp.json
project-specific configuration file:
{
"mcpServers": {
"semgrep": {
"command": "uvx",
"args": ["semgrep-mcp"]
}
}
}
See cursor docs for more info.
VS Code / Copilot
Click the install buttons at the top of this README for the quickest installation.
Manual Configuration
Add the following JSON block to your User Settings (JSON) file in VS Code. You can do this by pressing Ctrl + Shift + P
and typing Preferences: Open User Settings (JSON)
.
{
"mcp": {
"servers": {
"semgrep": {
"command": "uvx",
"args": ["semgrep-mcp"]
}
}
}
}
Optionally, you can add it to a file called .vscode/mcp.json
in your workspace:
{
"servers": {
"semgrep": {
"command": "uvx",
"args": ["semgrep-mcp"]
}
}
}
Using Docker
{
"mcp": {
"servers": {
"semgrep": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"ghcr.io/semgrep/mcp",
"-t",
"stdio"
]
}
}
}
}
See VS Code docs for more info.
Windsurf
Add the following JSON block to your ~/.codeium/windsurf/mcp_config.json
file:
{
"mcpServers": {
"semgrep": {
"command": "uvx",
"args": ["semgrep-mcp"]
}
}
}
See Windsurf docs for more info.
Claude Desktop
Add the following JSON block to your claude_desktop_config.json
file:
{
"mcpServers": {
"semgrep": {
"command": "uvx",
"args": ["semgrep-mcp"]
}
}
}
See Anthropic docs for more info.
OpenAI
async with MCPServerStdio(
params={
"command": "uvx",
"args": ["semgrep-mcp"],
}
) as server:
tools = await server.list_tools()
See OpenAI Agents SDK docs for more info.
Custom Clients
Example Python SSE Client
from mcp.client import Client
client = Client()
client.connect("localhost:8000")
# Scan code for security issues
results = client.call_tool("semgrep_scan",
{
"code_files": [
{
"filename": "hello_world.py",
"content": "def hello(): ..."
}
]
})
See offical SDK docs for more info.
Contributing, Community, and Running From Source
[!NOTE] We love your feedback, bug reports, feature requests, and code. Join the
#mcp
community slack channel!
See CONTRIBUTING.md for more info and details how to run from the MCP server from source code.
Similar Tools 🔍
- semgrep-vscode - Official VS Code extension
- semgrep-intellij - IntelliJ plugin
Community Projects 🌟
- semgrep-rules - The official collection of Semgrep rules
- mcp-server-semgrep - Original inspiration written by Szowesgad and stefanskiasan
MCP Server Registries
Made with ❤️ by the Semgrep Team
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file semgrep_mcp-0.1.13.tar.gz
.
File metadata
- Download URL: semgrep_mcp-0.1.13.tar.gz
- Upload date:
- Size: 127.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c4efe5f052581048cb94d1a51c176b131a2e687aeeb62e3e9d6d057ce36d525 |
|
MD5 | ce4ac8f19d22d0ce5ccad12d3c4c10e8 |
|
BLAKE2b-256 | 7598c4e1136fa67d9b585d2f06960e17180ec9dbfdc7b025b159d2590efb10bf |
Provenance
The following attestation bundles were made for semgrep_mcp-0.1.13.tar.gz
:
Publisher:
publish.yml
on semgrep/mcp
-
Statement:
- Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
semgrep_mcp-0.1.13.tar.gz
- Subject digest:
5c4efe5f052581048cb94d1a51c176b131a2e687aeeb62e3e9d6d057ce36d525
- Sigstore transparency entry: 193155949
- Sigstore integration time:
- Permalink:
semgrep/mcp@fc77859514124fb1c27f4f8e9848c741515b370f
- Branch / Tag:
refs/tags/v0.1.13
- Owner: https://github.com/semgrep
- Access:
public
- Token Issuer:
https://token.actions.githubusercontent.com
- Runner Environment:
github-hosted
- Publication workflow:
publish.yml@fc77859514124fb1c27f4f8e9848c741515b370f
- Trigger Event:
push
- Statement type:
File details
Details for the file semgrep_mcp-0.1.13-py3-none-any.whl
.
File metadata
- Download URL: semgrep_mcp-0.1.13-py3-none-any.whl
- Upload date:
- Size: 14.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca1749a6ce7f7a5e698fc7adfff6f5b738e6eec7bbe723fc5a39b36b68f13f81 |
|
MD5 | 1cabe1275b541b1d4f4e97795bfb71e9 |
|
BLAKE2b-256 | 4425915ccb771017dec761767aa40e5d9ad67d6cb9c715876981cb6a186f59b6 |
Provenance
The following attestation bundles were made for semgrep_mcp-0.1.13-py3-none-any.whl
:
Publisher:
publish.yml
on semgrep/mcp
-
Statement:
- Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
semgrep_mcp-0.1.13-py3-none-any.whl
- Subject digest:
ca1749a6ce7f7a5e698fc7adfff6f5b738e6eec7bbe723fc5a39b36b68f13f81
- Sigstore transparency entry: 193155950
- Sigstore integration time:
- Permalink:
semgrep/mcp@fc77859514124fb1c27f4f8e9848c741515b370f
- Branch / Tag:
refs/tags/v0.1.13
- Owner: https://github.com/semgrep
- Access:
public
- Token Issuer:
https://token.actions.githubusercontent.com
- Runner Environment:
github-hosted
- Publication workflow:
publish.yml@fc77859514124fb1c27f4f8e9848c741515b370f
- Trigger Event:
push
- Statement type: