A Model Context Protocol (MCP) server for using Semgrep to scan code for security vulnerabilities. Secure your vibe coding! 🔒
Model Context Protocol (MCP) is a standardized API for LLMs, Agents, and IDEs like Claude Code, Cursor, VS Code, Windsurf, or anything that supports MCP, to get specialized help, get context, and harness the power of tools. Semgrep is a fast, deterministic static analysis tool that semantically understands many languages and comes with over 10,000 rules. 🛠️
Note
This project is under active development. We would love your feedback. Join the #mcp community Slack channel!
MCP-demo-video-RSA.mov
-
Start a new Claude Code instance in the terminal:
claude
-
Open the plugin marketplace:
/plugin
-
Go to Discover, search for Semgrep, and click Install.
-
Set up the Semgrep plugin by running the following skill. This also installs the Semgrep CLI:
/setup-semgrep-plugin
-
Open Cursor
-
Find Semgrep in the Cursor Plugin Marketplace, or open
Cursor > ⌘⇧J > Pluginsand Search "Semgrep" and click Add to Cursor. -
Set up the Semgrep plugin by running the following skill. This also installs the Semgrep CLI:
/setup-semgrep-plugin
-
Restart Cursor to apply configuration.
In order to use the Semgrep MCP server, you must first have the Semgrep CLI:
$ brew install semgrep
The server can then be invoked via the mcp subcommand:
$ semgrep mcp --help
Usage: semgrep mcp [OPTIONS]
Entry point for the MCP server
Supports stdio and streamable-http transports. For stdio, it will read
from stdin and write to stdout. For streamable-http, it will start
an HTTP server on port 8000.
Options:
-v, --version Show version and exit.
-t, --transport [stdio|streamable-http]
Transport protocol to use:
stdio or streamable-http
-p, --port INTEGER Port to use for the MCP server
-h, --help Show this message and exit.
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.
semgrep mcpBy default, the server 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 output, but this is expected.
The Semgrep binary is published to Docker:
docker run -i --rm semgrep/semgrep semgrep mcp -t stdio
Streamable HTTP enables streaming responses over JSON RPC via HTTP POST requests. See the spec for more details.
By default, the server listens on 127.0.0.1:8000/mcp for client connections. To change any of this, set FASTMCP_* environment variables. The server must be running for clients to connect to it.
semgrep mcp -t streamable-httpBy default, the server will run in stdio mode, so you will have to include -t streamable-http.
docker run -p 8000:8000 semgrep/semgrep semgrep mcp
Optionally, to connect to Semgrep AppSec Platform:
- Login or sign up
- Generate a token from Settings
- Add the token 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 for support if needed. ☎️
-
Start a new Claude Code instance in the terminal:
claude
-
Open the plugin marketplace:
/plugin
-
Go to Discover, search for Semgrep, and click Install.
-
Set up the Semgrep plugin by running the following skill. This also installs the Semgrep CLI:
/setup-semgrep-plugin
See Claude Code docs for more info.
-
Open Cursor
-
Find Semgrep in the Cursor Plugin Marketplace, or open
Cursor > ⌘⇧J > Pluginsand Search "Semgrep" and click Add to Cursor. -
Set up the Semgrep plugin by running the following skill. This also installs the Semgrep CLI:
/setup-semgrep-plugin
-
Restart Cursor to apply configuration.
See cursor docs for more info.
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": "semgrep",
"args": ["mcp"]
}
}
}
}
Optionally, you can add it to a file called .vscode/mcp.json in your workspace:
{
"servers": {
"semgrep": {
"command": "semgrep",
"args": ["mcp"]
}
}
}
See VS Code docs for more info.
-
Install Semgrep:
# install through homebrew brew install semgrep# install through pip python3 -m pip install semgrep -
Verify that you've installed the latest version of Semgrep by running the following:
semgrep --version
-
Log in to Semgrep and install Semgrep Pro:
semgrep login && semgrep install-semgrep-pro -
Create a
hooks.jsonfile at~/.codeium/windsurf/hooks.jsonand paste the following configuration:{ "hooks": { "post_write_code": [ { "command": "semgrep mcp -k post-tool-cli-scan -a windsurf", "show_output": true } ] } } -
Restart Windsurf to apply hook configuration.
See Windsurf docs for more info.
import asyncio
import json
from mcp.client.session import ClientSession
from mcp.client.streamable_http import streamablehttp_client
async def main():
async with streamablehttp_client("http://localhost:8000/mcp") as (read_stream, write_stream, _):
async with ClientSession(read_stream, write_stream) as session:
await session.initialize()
results = await session.call_tool(
"semgrep_scan_remote",
{
"code_files": [
{
"path": "hello_world.py",
"content": "def hello(): print('Hello, World!')",
}
]
},
)
content_block = results.content[0]
content = json.loads(content_block.text)
paths = content.get("paths", None)
if paths:
scanned = paths.get("scanned", [])
findings = content.get("results", [])
print(f"Scanned {len(scanned)} paths. Found {len(findings)} findings.")Tip
Some client libraries want the URL: http://localhost:8000/mcp
and others only want the HOST: localhost:8000.
Try out the URL in a web browser to confirm the server is running, and there are no network issues.
Set SEMGREP_IS_HOSTED=true to use the semgrep_scan_remote tool
See official SDK docs for more info.
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 on how to run from the MCP server from source code.
- semgrep-rules - The official collection of Semgrep rules
- mcp-server-semgrep - Original inspiration written by Szowesgad and stefanskiasan
Made with ❤️ by the Semgrep Team