SCA-Triage MCP Server
# SCA-Triage MCP Server
A powerful MCP (Model Context Protocol) server for AI assistants (Cline, Claude
Desktop, Cursor, etc.) that performs **deep security auditing of Java/Spring
projects** using the `ripgrep` (`rg`) utility.
The server exposes three tools that let an AI find dangerous sink methods,
inventory dependencies, and assess the real exploitability of vulnerable
components — without bloating the context.
---
## Capabilities (Tools)
### 1. `search_multi_patterns` — multi-pattern search
Searches for a list of concrete strings/methods/regexes **or** a ready-made
vulnerability profile (e.g. `deserialization`) in **one efficient pass** through
`ripgrep` (multiple `-e`). Results are grouped by pattern and file, with line
numbers and code snippets.
* Arguments:
* `patterns` (`list[str]`, optional) — concrete strings, methods, regexes.
* `profile` (`string`, optional) — a security profile (see below).
* `path` (`string`, optional, default `.`) — subdirectory to narrow the scope.
* `max_matches` (`int`, default `500`) — limit on total matches.
### 2. `analyze_project_structure` — project overview
Locates and parses `pom.xml` / `build.gradle(.kts)`, extracts the **Java**,
**Spring Boot**, **Spring Framework** versions, key dependencies (with scope and
version) and configuration files (`application.yml`, `application.properties`).
* Arguments: `project_root` (`string`).
### 3. `analyze_vulnerability_usage` — applicability audit
Checks the **real exposure** of the project: searches for imports/usages of
vulnerable components and groups them by architectural layer (Controller, Service,
Repository, Test, etc.), flagging controller usages as
`[HIGH]` (potentially externally reachable).
* Arguments:
* `components` (`list[str]` or `string`) — FQCN or keywords.
* `project_root` (`string`, optional, default `.`).
* `max_matches` (`int`, optional).
* **False-positive filtering.** If `ast-grep` is installed, matches that ripgrep
found inside comments/string literals are discarded before final
categorization. Each candidate receives an explicit status:
`ast_verified` (structurally confirmed), `ast_rejected` (purely textual match —
discarded) or `text_only` (verification unavailable/timeout/error — candidate
kept, but flagged as unverified). Matching is done by line and column ranges,
which correctly distinguishes multiple expressions on the same line. Results
are cached by `(file, pattern, mtime, size)`.
---
## Security profiles (for `search_multi_patterns`)
| Profile | What it searches for |
|---|---|
| `deserialization` | `readObject`, `XMLDecoder`, `XStream.fromXML`, `enableDefaultTyping`, `Hessian`, `Kryo`, `SnakeYAML`, `convertValue`, etc. |
| `sqli` | `createQuery`, `JdbcTemplate`, `prepareStatement`, `EntityManager`, `@Query`, LDAP/XPath/SpEL sinks |
| `command-execution` | `Runtime.exec`, `ProcessBuilder` |
| `path-traversal` | `Paths.get`, `FileInputStream`, `ZipEntry`, `transferTo` (zip-slip) |
| `xxe` | `DocumentBuilderFactory`, `SAXParserFactory`, `XMLInputFactory`, `resolveEntity` |
| `ssti` | `Velocity`, `FreeMarker`, `Thymeleaf`, `Mustache` |
| `ssrf` | `RestTemplate`, `WebClient`, `HttpURLConnection`, `openConnection` |
| `jndi-rmi` | `InitialContext`, `lookup(`, `ldap://`, `rmi://` (log4shell family) |
| `reflection` | `Class.forName`, `invoke(`, `sun.misc.Unsafe` |
| `logging-injection` | `LoggerFactory`, `.info(`, `JNDI` lookups |
| `spring-security-config` | `SecurityFilterChain`, `permitAll`, `csrf().disable`, `@PreAuthorize` |
| `insecure-config` | `management.endpoints.web.exposure.include`, `h2.console.enabled`, `spring.jackson.default-typing` |
| `all` | Union of all profiles (broad sweep) |
Profiles can be combined with an explicit `patterns` list — they are merged and
deduplicated.
---
## Installation
### 1. Install the `ripgrep` utility
| OS | Command |
|---|---|
| macOS (Homebrew) | `brew install ripgrep` |
| Debian / Ubuntu / Kali | `sudo apt install ripgrep` |
| Fedora | `sudo dnf install ripgrep` |
| Arch | `sudo pacman -S ripgrep` |
| Windows (Chocolatey) | `choco install ripgrep` |
Verification:
```bash
rg --version # e.g. ripgrep 15.2.0
```
### 2. (Optional) Install `ast-grep` for false-positive filtering
`ast-grep` (the `sg` binary) is used in `analyze_vulnerability_usage` to discard
matches that ripgrep found inside **comments and string literals** — this
reduces the number of false positives. It is an **optional** binary installed the
same way as `ripgrep`. Without it, the server works as before, relying only on
ripgrep.
| OS / manager | Command |
|---|---|
| macOS (Homebrew) | `brew install ast-grep` |
| Linux (cargo) | `cargo install ast-grep --locked` |
| Linux / Windows / macOS (npm) | `npm i -g @ast-grep/cli` |
| Nix | `nix-shell -p ast-grep` |
| Download the binary manually | see [GitHub Releases](https://github.com/ast-grep/ast-grep/releases) |
Verification:
```bash
ast-grep --version # or: sg --version
```
> **Important (Linux).** On Linux the `sg` command is already taken by the system
> `setgroups` utility from the `util-linux` package (`/usr/bin/sg`). Therefore, on
> Linux it is recommended to use the full name `ast-grep`, or make sure the
> directory containing the ast-grep binary (e.g. `~/.cargo/bin`) comes **before**
> `/usr/bin` in `PATH`. The server can detect the system `sg` and in that case
> correctly falls back to ripgrep. In the Docker image ast-grep is placed in
> `/usr/local/bin` (overriding `/usr/bin/sg`).
### 3. Install the Python dependencies
Python 3.10+ is required.
```bash
cd sca-triage-mcp
# (recommended) isolated environment
python3 -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt # or: pip install mcp
```
**Important.** On some distributions (Kali, Debian 12+) system Python is
protected by PEP 668. Use `venv` (as above) or the `--break-system-packages` flag.
### 3. Verify the server works
```bash
python server.py # runs in stdio mode (MCP clients connect on their own)
```
## Open WebUI (native MCP over HTTP)
Starting with MCP SDK 2.x the server supports a **native** HTTP transport
(Streamable HTTP) directly from `server.py` — a separate REST bridge is no longer
needed. Open WebUI connects as to a regular MCP server over HTTP.
### Streamable HTTP (recommended)
```bash
python server.py --transport streamable-http --port 8000
# listens on http://127.0.0.1:8000, endpoint: /mcp
```
For external access (e.g. if Open WebUI runs in Docker):
```bash
python server.py --transport streamable-http --host 0.0.0.0 --port 8000
```
In Open WebUI add the server (User settings → Tools, or the MCP servers section
of the configuration) with the **URL** `http://<host>:8000/mcp` (type — MCP over
HTTP/SSE). Both Streamable HTTP (`/mcp`) and legacy SSE are supported.
Additional flags:
| Flag | Purpose |
|---|---|
| `--transport {stdio,sse,streamable-http}` | transport (default `stdio`) |
| `--host` | address for HTTP transports (default `127.0.0.1`) |
| `--port` | port (default `8000`) |
| `--streamable-http-path` | endpoint path (default `/mcp`) |
| `--json-response` | respond with JSON instead of SSE (no request back-channel) |
| `--stateless-http` | disable session management |
### SSE (legacy)
```bash
python server.py --transport sse --port 8000
# endpoint: /sse (messages — /messages/)
```
### Manual verification
```bash
curl -X POST http://127.0.0.1:8000/mcp \
-H 'Content-Type: application/json' \
-H 'Accept: application/json, text/event-stream' \
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26","capabilities":{},"clientInfo":{"name":"curl","version":"1"}}}'
```
The response contains an `mcp-session-id` which must be passed in the
`mcp-session-id` header for subsequent requests (`tools/list`, `tools/call`).
> **Note about `webui_proxy.py`.** The `webui_proxy.py` script (a pure REST bridge
> on stdlib + an OpenAPI schema) remains in the repository as an alternative for
> environments that specifically need HTTP/REST without SSE. When using the
> native transport it is not required.
> **Security.** The HTTP transport performs no authentication and exposes auditing
> of the server's filesystem. Run it on the local host (`127.0.0.1`) or behind a
> reverse proxy with authorization.
### Running via Docker Compose
A turnkey recipe for Open WebUI — `docker-compose.yml` starts our server in
`streamable-http` mode and (optionally) Open WebUI itself in a shared docker
network.
```bash
docker compose up -d --build
```
| Service | What it does |
|---|---|
| `sca-triage` | our MCP server (Streamable HTTP, `0.0.0.0:8000`, path `/mcp`) |
| `open-webui` | UI at `http://localhost:3000` (optional) |
Projects are mounted from the host directory `${SCA_PROJECTS_DIR:-~/projects}`
into `/projects:ro` inside the container. In requests, pass
`project_root="/projects/<subdir-name>"`.
Connecting in Open WebUI:
* Type — **MCP (Streamable HTTP)**.
* URL — `http://sca-triage:8000/mcp` (by service name inside the docker network).
* If you forwarded the port to the host — `http://localhost:8000/mcp`.
Startup parameters are set via environment variables: `SCA_TRANSPORT`,
`SCA_HOST`, `SCA_PORT`, `SCA_MCP_PATH` (alias `SCA_STREAMABLE_HTTP_PATH`).
### Resolving projects from GitLab (optional)
Instead of an explicit `project_root=/projects/...` you can just write the
GitLab project name in the prompt: **"analyze the `services/shop` project"**. The
server will find the project via the GitLab REST API (v4) by
`path_with_namespace` and clone it into a temporary directory, then run the normal
pipeline (ripgrep → ast-grep → layer classification).
Required environment variables (see also `.env.example`):
| Variable | What to set |
|---|---|
| `GITLAB_URL` | self-hosted GitLab base URL, e.g. `https://gitlab.corp.example.com` (no trailing slash) |
| `GITLAB_TOKEN` | Personal/Group Access Token with `read_api` + `read_repository` scopes |
| `SCA_CLONE_DIR` | writable directory for clones **inside the container** (default `/tmp/sca-clones`) |
Important:
* Cloning is done over HTTPS with a token; the token is masked in logs/errors.
* The container must have network access to `GITLAB_URL` (for a self-hosted
GitLab on the internal network — a correspondingly configured docker network).
* If `GITLAB_URL` is not set — resolution falls back to local directories
(`SCA_PROJECTS_DIR` / existing paths), as before.
#### Which directory to specify in `SCA_CLONE_DIR`
This is the **directory writable by the process that runs `server.py`** — the
server clones GitLab projects there. The main mistake is specifying a path that
does not exist or is not writable, which causes a `PermissionError: [Errno 13]`
(or `No such file or directory`) at clone time. Rules by scenario:
| Scenario | What to set | Why |
|---|---|---|
| **Docker Compose** (as in `docker-compose.yml`) | `/tmp/sca-clones` (already set) | a path **inside** the container, created in the image (`Dockerfile`) and owned by `appuser` |
| **Docker with your own volume** | a path mounted into the container, e.g. `/clones` (+ `volumes: - ./clones:/clones`) | the volume must be writable for `appuser` (uid 10001) |
| **Local run** (`python server.py`) | any writable directory, e.g. `~/.cache/sca-clones` or `./.clones` | the process runs as your user; the directory must exist |
What **not** to do:
* ❌ don't specify a host path like `/opt/projects` when running in Docker — such
a path does not exist inside the container and the clone will fail with
`PermissionError`;
* ❌ don't specify an empty/nonexistent directory without creating it first
(`mkdir -p <dir>`) if you run without permission to create the parent;
* ❌ don't specify a read-only directory (for example, one mounted as `:ro`).
Simplest approach: **leave the default value** (in Docker it is already
`/tmp/sca-clones`; for local runs you can set any writable path). The value is
not required in `.env` — if `SCA_CLONE_DIR` is not set, the server uses
`/tmp/sca-clones` in all modes.
## Setup in VS Code + Cline
1. In Cline, click the **MCP Servers** button in the top-right corner and add a
new server, or edit the configuration file manually.
The **`cline_mcp_settings.json`** file is usually located in one of these
places:
* `~/.cline/cline_mcp_settings.json`
* `~/.config/Code/User/globalStorage/saoudrizwan.claude-dev/settings/cline_mcp_settings.json`
2. Add the following section (use **absolute paths**):
```json
{
"mcpServers": {
"sca-triage": {
"command": "/absolute/path/to/sca-triage-mcp/.venv/bin/python",
"args": [
"/absolute/path/to/sca-triage-mcp/server.py"
],
"env": {},
"disabled": false,
"alwaysAllow": [
"search_multi_patterns",
"analyze_project_structure",
"analyze_vulnerability_usage"
]
}
}
}
```
> **Windows** — use the path to `python.exe` inside the `venv`:
> `C:\\path\\to\\sca-triage-mcp\\.venv\\Scripts\\python.exe`
3. Restart Cline / reconnect the server. The tool list should now include
`search_multi_patterns`, `analyze_project_structure` and
`analyze_vulnerability_usage`.
---
## Example queries for a comprehensive audit
### Deserialization check
```
Scan the project at /home/user/my-api for deserialization vulnerabilities
(the deserialization profile) and show all dangerous sink methods.
```
```text
search_multi_patterns(profile="deserialization", path="/home/user/my-api")
```
### Dependencies and versions overview
```
Analyze the structure of the project at /home/user/my-api: Java, Spring Boot
versions, key dependencies and configs.
```
```text
analyze_project_structure(project_root="/home/user/my-api")
```
### Applicability audit of a vulnerable component
```
Check whether XStream (CVE-2021-21341) is actually used in the project and how
externally reachable it is.
```
```text
analyze_vulnerability_usage(
components=["com.thoughtworks.xstream.XStream"],
project_root="/home/user/my-api"
)
```
The result shows in which layers the component appears, and flags `[HIGH]` if it
is used in the `Controller`/`Web`/`REST` layers (externally reachable), or
`[LOW]` — if only inside services/tests.
### Searching for a list of specific methods
```
Find occurrences of Runtime.getRuntime().exec, ProcessBuilder and Class.forName.
```
```text
search_multi_patterns(
patterns=["Runtime.getRuntime().exec", "ProcessBuilder", "Class.forName"],
path="/home/user/my-api"
)
```
---
## File structure
```
sca-triage-mcp/
├── server.py # main MCP server (3 tools)
├── profiles.py # vulnerability profiles and pattern sets
├── rg_runner.py # ripgrep wrapper (subprocess + --json parsing)
├── project_analyzer.py # parsing pom.xml / build.gradle and configs
├── webui_proxy.py # HTTP/REST bridge for Open WebUI (no dependencies)
├── requirements.txt # dependencies (mcp)
├── pyproject.toml # package metadata
├── cline_mcp_settings.example.json # example configuration for Cline
└── README.md # this documentation
```
---
## How it works
* **A single `rg` pass.** All patterns are passed to a single `ripgrep` call via
multiple `-e` (for literals — `--fixed-strings`, for regexes — regular mode).
This is several times faster than sequential runs.
* **Machine-readable output.** `rg --json` is used with parsing of `match` events,
so there is no need to parse fragile text output.
* **Ignoring service directories.** `target/`, `build/`, `.gradle/`, `.mvn/`,
`.idea/`, `bin/`, `.git/`, `node_modules/`, as well as binary artifacts
(`*.class`, `*.jar`, `*.zip`, …) are excluded from the search.
* **Compact output.** Results are grouped by pattern → file → line (with
`max_matches` limits and truncation of long lines) so as not to overload the AI
context.
* **Clear errors.** When `rg` is missing the server returns installation
instructions; an invalid profile/path produces a clear message listing the
available profiles.
* **False-positive filtering via `ast-grep`.** Used in
`analyze_vulnerability_usage`: for each file where ripgrep found a hit, an
additional `sg --lang java --pattern ... --json` is run (strictly file-by-file,
with a 2 s timeout) and matches inside comments/string literals are discarded.
ripgrep↔ast-grep matching is done by `[line, column)` ranges, not just the line
number, so multiple expressions on the same line are distinguished correctly.
If `ast-grep` is unavailable, timed out, returned an error or invalid JSON, the
candidate is **not discarded** but flagged as `text_only` (unverified). The
output reports counters (`ast_verified` / `ast_rejected` / `text_only`), errors
and timeouts, as well as the analysis-completeness flag
(`complete` / `incomplete`). Results are cached by `(file, pattern, mtime,
size)`, and the total number of AST checks is limited by a per-tool-call budget.
* **Code-based layer classification.** The layer of a file is determined not only
by its path, but also by its content: if a file contains Spring web-layer
annotations (`@RestController`, `@Controller`, `@RequestMapping`, `@GetMapping`,
`@PostMapping`, `@PutMapping`, `@DeleteMapping`, plus Spring Security
`@PreAuthorize`/`@Secured`/`@PostAuthorize` and GraphQL/WebFlux
`@QueryMapping`/`@SchemaMapping`), it is forcibly classified as `controller` and
receives the `[HIGH]` flag — even if there is no `controller` token in the path
(for example, a root `App.java`). Files are read safely (`utf-8`,
`errors="replace"`, size limit) with an LRU cache keyed by `(path, mtime, size)`.
---
## License / disclaimer
The tool is intended for legitimate security auditing of your own or authorized
projects. Use for unauthorized testing is prohibited and governed by applicable
law.
TDQS
Scored across 3 tools
Each tool has a distinct role: raw pattern search, project metadata extraction, and vulnerability-usage assessment. There is mild overlap between search_multi_patterns and analyze_vulnerability_usage, since the latter performs import/usage searches internally, but the descriptions make the boundary clear (generic grep vs. component-level exploitability triage).
All three names follow a consistent snake_case verb_noun pattern (search_multi_patterns, analyze_project_structure, analyze_vulnerability_usage). Two share the 'analyze_' prefix on distinct objects, which reads predictably.
Three well-scoped, non-trivial tools fit a focused SCA triage workflow without bloat. It is on the lean side, but each tool earns its place rather than being a thin single-purpose wrapper.
The surface covers search, build-file/dependency discovery, and usage-based exploitability assessment, but there is no way to match discovered dependencies against a vulnerability database/CVE feed, nor to emit a structured triage report or read an arbitrary file. An agent would hit dead ends when the actual CVE-to-dependency correlation is needed.