code-security-mcp

code-security-mcp

MCP server that provides a 216-rule, framework-aware Kotlin/JVM security analyzer, enabling AI coding agents to query real security findings while writing code.

Category
访问服务器

README

code-security-mcp

CI License: MIT Python 3.11+

A security MCP server for AI coding agents. It gives Claude Code, Cursor, and other agents real security findings while they write, not after — and each language is analyzed by its best native security tool, not one generic scanner stretched across everything.

A specialist, not a generalist. Kotlin is analyzed by detekt with a 216-rule, framework-aware ruleset (Spring, WebFlux, Ktor, Quarkus, Micronaut, Vert.x); Java by SpotBugs + FindSecBugs; Python by Bandit; C# by the Roslyn security analyzers; JS/TS by ESLint + eslint-plugin-security — each the established native security analyzer for its language, routed automatically.

New languages arrive as their own native analyzer — never a single lowest-common-denominator scanner.

Quickstart

git clone https://github.com/JasminGuberinic/code-security-mcp
cd code-security-mcp
python3 -m venv .venv && .venv/bin/pip install -e ".[python]"

# Download the analyzers into an isolated cache (nothing global is touched):
./scripts/setup.sh                              # Kotlin + Java
./scripts/setup.sh --with-dotnet --with-eslint  # + C# and JS/TS (optional)

The script prints the claude mcp add … command to paste. Python works out of the box — the [python] extra installs Bandit.

Why

Generic assistants and multi-language scanners are shallow on framework idioms — they don't know that a @GetMapping is missing @PreAuthorize, that a WebClient trusts all certificates, or that a Vert.x cookie isn't HttpOnly. This server wraps a 216-rule, framework-aware analyzer (the kotlin-security-scanner detekt ruleset) and exposes it to agents through three tools.

Design principle: each language is handled by its best native security analyzer — routed automatically — never a single lowest-common-denominator generic scanner.

Languages

Language Analyzer Analyzes
Kotlin detekt + the 216-rule framework-aware ruleset source (.kt, .kts)
Java SpotBugs + FindSecBugs compiled bytecode — point at the project root (it finds build/classes, target/classes, …), a classes dir, or a .jar (build first)
Python Bandit source (.py) — no build, just pip install
C# Roslyn security analyzers builds the project — point at a .sln, .csproj, or its directory
JavaScript / TypeScript ESLint + eslint-plugin-security source (.js, .ts, .jsx, .tsx, …)

Tools

Tool What it does
security_scan(path) Scan a file/directory (Kotlin, Java, Python, C#, or JS/TS) and return every security finding (rule, line, severity, CWE).
review_diff(diff) Review a unified diff and flag only the issues the change introduces — a pre-commit self-check.
secure_pattern(task, framework?) Get the vetted secure way to do a risky task — before writing it.

For Kotlin, security_scan returns security findings only — detekt's built-in style/complexity rules are switched off, so the agent gets signal, not noise.

Example

"What's the secure way to create a session cookie in Vert.x?"

// secure_pattern(task = "create a session cookie", framework = "vertx")  →  CWE-614
val cookie = Cookie.cookie("session", token)
    .setSecure(true)      // only sent over HTTPS
    .setHttpOnly(true)    // hidden from JavaScript
    .setSameSite(CookieSameSite.STRICT)
response.addCookie(cookie)

Architecture

Clean, hexagonal (ports & adapters). Dependencies point inward; the domain knows nothing about detekt or MCP.

server.py            MCP surface + composition root   (knows MCP)
   │
application/         use cases: scan / review_diff / secure_pattern
   │
domain/              Finding, ScanResult, ports         (pure vocabulary)
   ↑ implemented by
adapters/            DetektAnalyzer, JavaAnalyzer, RoutingAnalyzer,
                     SARIF & diff parsers, pattern catalog

A RoutingAnalyzer sends each target to the analyzers that support it, so the use cases treat "one language" and "many" identically. Adding a language = one new adapter implementing the same LanguageAnalyzer port — the domain and use cases do not change.

Requirements

  • Python 3.11+
  • Kotlin: a JDK + the detekt CLI jar + the ruleset jar(s)
  • Java: a JDK + the SpotBugs jar + the FindSecBugs plugin jar
  • Python: Bandit (pip install "code-security-mcp[python]") — no JDK, no jars
  • C#: the .NET SDK (its Roslyn security analyzers are built in)
  • JS/TS: Node.js + ESLint with eslint-plugin-security (and typescript-eslint)

Each analyzer is optional and enabled independently — configure only the languages you need. (Python auto-enables whenever Bandit is installed.)

Configuration

./scripts/setup.sh fills these in for you and prints the ready-to-paste command; the reference below is for when you want to point at your own tools. The server locates its tools through environment variables:

Variable Meaning
KSM_JAVA Path to the java executable (shared)
KSM_DETEKT_CLI_JAR Kotlin: detekt CLI (-all) jar
KSM_PLUGIN_JARS Kotlin: comma-separated ruleset jar(s)
KSM_DETEKT_CONFIG Kotlin: (optional) path to a detekt.yml
KSM_SPOTBUGS_JAR Java: SpotBugs engine jar
KSM_FINDSECBUGS_JARS Java: comma-separated plugin jar(s) (FindSecBugs)
KSM_JAVA_AUXCLASSPATH Java: (optional) comma-separated dependency jars/dirs for more accurate analysis
KSM_DOTNET_ROOT C#: root of the .NET SDK install
KSM_NUGET_PACKAGES C#: (optional) NuGet cache dir (keeps restores isolated)
KSM_DOTNET_CLI_HOME C#: (optional) dotnet CLI home dir (keeps state isolated)
KSM_ESLINT_BIN JS/TS: path to the ESLint executable
KSM_ESLINT_CONFIG JS/TS: path to the security flat config (see configs/)

Python needs no variables — install Bandit and it is used automatically.

Use with Claude Code

claude mcp add code-security -s user \
  -e KSM_JAVA=/path/to/java \
  -e KSM_DETEKT_CLI_JAR=/path/to/detekt-cli-<ver>-all.jar \
  -e KSM_PLUGIN_JARS=/path/to/scanner-core.jar,/path/to/scanner-spring-boot.jar,... \
  -- /path/to/.venv/bin/code-security-mcp

Then ask the agent, e.g. "run security_scan on src/Main.kt" or "review_diff on my staged changes".

Development

python3 -m venv .venv
.venv/bin/pip install -e ".[dev]"
.venv/bin/pytest

The test suite is hermetic — it uses fake analyzers and hand-built SARIF / diff / Bandit-JSON fixtures, so it needs no external analyzer (JDK, detekt, SpotBugs, or Bandit) to run.

Roadmap

Each new language arrives as its own native, framework-aware analyzer adapter (never a generic multi-language scanner):

  • ✅ Kotlin — detekt + the 216-rule framework-aware ruleset.
  • ✅ Java — SpotBugs + FindSecBugs.
  • ✅ Python — Bandit.
  • ✅ C# — Roslyn security analyzers.
  • ✅ JavaScript / TypeScript — ESLint + eslint-plugin-security.
  • Deeper C# via Security Code Scan (taint analysis).
  • Zero-setup: auto-resolve the analyzer runtimes and rulesets.

License

MIT — see LICENSE.


<sub>Keywords: MCP server, Model Context Protocol, Kotlin security, JVM security, SAST, static analysis, detekt, Spring Security, AI coding agent, Claude Code, Cursor, secure coding.</sub>

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选