Skip to main content
Semgrep runs static analysis over code you hand it and returns concrete findings: rule id, severity, line number, and why the pattern is dangerous. Pairing it with an LLM is a good division of labour — the scanner finds occurrences deterministically, the model explains impact and drafts the fix. This is also the Bearer token authentication shape.
This endpoint accepted anonymous traffic historically and now returns 401 without a token. Get a free one at semgrep.devSettingsTokens.

Why not just ask the model?

Because LLMs are extremely good at producing security findings that sound right. Asked to review code for vulnerabilities, a model will reliably return a well-formatted list — some of it real, some of it invented, with no signal distinguishing the two. Splitting the job fixes that: findings come from the scanner; the model’s job is triage, not imagination. The system prompt below is written to enforce exactly that boundary.

Build it

1

Install and set both keys

2

Constrain the model to what the scanner found

Two instructions carry the weight: only what the scanner returned, and say when a flagged line is a false positive. The second is what makes the report worth reading — a raw Semgrep dump is noise until someone judges context.
3

Build the agent with a Bearer token

mcp_api_key="env:SEMGREP_APP_TOKEN" sends Authorization: Bearer <token>. The env: prefix is resolved when the connection is made, so the token never appears in your source or in a serialized agent config.
4

Give it something to scan

Three genuine issues are planted here — SQL injection, shell injection, and unsafe deserialization — so you can check the scan caught what it should.
5

Fail fast when the token is missing

Without this you get a 401 from inside the tool call, which surfaces as an unhelpful agent-level error.

Putting it in a review pipeline

The single-agent version reviews a snippet. To review a diff, feed it the changed files and let a second agent decide what blocks the merge:
The triager has no tools — it has nothing left to look up, and giving it the scanner’s tools would only tempt it to re-run the scan.
A clean scan is not a clean bill of health. Semgrep finds patterns it has rules for; it does not find logic flaws, broken authorization, or design mistakes. Ask the agent to say what the scan does not cover, and treat that sentence as part of the report.

Next