Write .kern, compile to secure MCP servers, auto-review with 13 OWASP rules.
Build and secure Model Context Protocol servers. Write .kern and compile to TypeScript or Python with security guards auto-injected. Scan existing MCP servers with 13 rules mapped to the OWASP MCP Top 10. Extension for VS Code and compatible editors (Cursor, Windsurf, Antigravity) + CLI + GitHub Action.
Powered by KERN — the structural language for AI-generated code.
Every AI tool is adding MCP support. Security scanning hasn't kept up. MCP servers handle file I/O, shell commands, network requests, and database queries — all triggered by LLM tool calls. One missing input validation and your agent becomes an attack surface.
KERN MCP takes two approaches:
- Review — scan existing MCP servers and find vulnerabilities at development time
- Build — write
.kernand compile to MCP servers with security guards injected by construction
mcp name=MyAPI version=1.0
tool name=search
description text="Search for items"
param name=query type=string required=true
param name=limit type=number default=10
guard type=sanitize param=query
guard type=validate param=limit min=1 max=100
guard type=rateLimit window=60000 requests=100
handler <<<
const results = await db.search(args.query, args.limit);
return { content: [{ type: "text", text: JSON.stringify(results) }] };
>>>
Click Compile -> TypeScript or Compile -> Python in the sidebar. The transpiler auto-injects:
- Zod validation from
paramdefinitions - 7 security guards:
sanitize,pathContainment,validate,auth,rateLimit,sizeLimit,sanitizeOutput - Structured JSON logging on every call
- Error handling with
isErrorresponses
Compiled output is auto-reviewed with the 13 OWASP rules.
Describe what you want, pick your AI engine, get a production .kern server:
- Click the BUILD tab in the sidebar
- The extension auto-detects installed AI CLIs (Claude, Ollama, Codex, Gemini, OpenCode)
- Select context from your workspace (package.json, database schemas, API routes, OpenAPI specs)
- Describe your server — "Postgres CRUD for users and posts, with JWT auth and rate limiting"
- Click Generate .kern — AI writes the server with guards
- Review, edit, compile, done
Also supports:
- Import to .kern — convert existing TS/Python MCP servers to
.kernwith guards added - Convert TS <-> Python — direct AI translation between languages
- Syntax highlighting (TextMate grammar)
- Validation-on-save with inline error diagnostics
- Right-click context menu for compile/validate
Every MCP server gets a security score based on four weighted metrics:
| Metric | Weight | What it measures |
|---|---|---|
| Guard Coverage | 40% | % of effects with preceding guards |
| Input Validation | 25% | % of tool handlers with validation |
| Rule Compliance | 20% | Penalty per critical/warning finding |
| Auth Posture | 15% | Auth guards on HTTP/SSE transport |
Grades: A (90+), B (75+), C (60+), D (40+), F (<40)
| Rule | OWASP | What it catches |
|---|---|---|
mcp-command-injection |
#04 | User params flowing to shell commands |
mcp-path-traversal |
#02 | File ops with unvalidated paths |
mcp-tool-poisoning |
#03 | Hidden instructions in tool descriptions |
mcp-secrets-exposure |
#04 | Hardcoded keys/tokens in server code |
mcp-unsanitized-response |
#05 | Raw external data / XML returned to LLM |
mcp-missing-validation |
#06 | Tool params used without validation |
mcp-missing-auth |
#07 | HTTP/SSE server without auth |
mcp-typosquatting |
#08 | Suspicious package name similarity |
mcp-data-injection |
#09 | Hidden instructions in string literals |
mcp-ssrf |
#02 | Server-side request forgery via unvalidated URLs |
mcp-secret-leakage |
#04 | Secrets, system info, IP disclosure in responses |
mcp-ir-unguarded-effect |
Structural | Effects without guards (KERN IR) |
mcp-ir-low-confidence |
Structural | Low guard/effect ratio |
The sidebar renders your MCP server's security structure as a tree:
- Actions — each
server.tool()or@mcp.tool()handler - Effects — dangerous operations (shell exec, file I/O, network, database)
- Guards — validation, path containment, auth checks
- Color-coded: GUARDED (green) vs UNGUARDED (red)
6 one-click fixes for both languages:
eval()toJSON.parse()(TS) /ast.literal_eval()(Python)- Path traversal guard insertion
- Input validation scaffolding (Zod / Pydantic)
- Auth middleware stub
- Response sanitization
- Secrets to env vars
Scans your MCP configuration files (claude_desktop_config.json, .cursor/mcp.json, .vscode/mcp.json, .windsurf/mcp.json) for:
- Hardcoded secrets (Shannon entropy + pattern detection)
- Missing version pins on
npx/uvxpackages (supply chain risk) @latesttreated as error — it's NOT a version pin- Wide permission flags (
--allow-all,--no-sandbox) - Unresolvable command paths
Shows a "My MCP Servers" section in the sidebar with trust indicators.
Pin your MCP server's tool schemas to detect unauthorized changes:
kern-mcp-security --lock ./src/server.ts # generate lockfile
kern-mcp-security --verify ./src/server.ts # check for driftDetects: removed tools, new tools, description changes (tool poisoning), schema changes.
Generate a Shields.io security badge for your project:
KERN: Generate MCP Security Badge
Writes a badge, per-tool score table, and JSON report to your README between <!-- kern-mcp-security-start/end --> markers.
Works in VS Code, Cursor, Windsurf, Antigravity, and other compatible editors.
- Install the extension
- Open an MCP server file (TypeScript, JavaScript, or Python)
- The sidebar shows score, IR tree, and findings
- Click any finding to jump to the line
- Use
Cmd+Shift+M/Ctrl+Shift+Mto scan manually
- Click the BUILD tab in the sidebar
- Open or create a
.kernfile - Click Compile -> TypeScript or Compile -> Python
- Compiled output opens beside with auto-review results
- Click BUILD tab -> Generate .kern
- Select AI engine from the dropdown (auto-detects installed CLIs)
- Describe your server, select workspace context
- Review and compile the generated
.kern
| Setting | Default | Description |
|---|---|---|
kernMcpSecurity.enabled |
true |
Enable/disable scanning |
kernMcpSecurity.severity |
"all" |
Filter: all, errors, warnings |
kernMcpSecurity.animations |
true |
Enable sidebar animations |
kernMcpSecurity.ai.provider |
"openai" |
LLM provider for AI features (openai, anthropic, gemini, custom) |
kernMcpSecurity.ai.apiKey |
"" |
API key (only for API mode, CLIs use their own auth) |
kernMcpSecurity.ai.model |
"" |
Model ID (only for API/Ollama) |
kernMcpSecurity.ai.endpoint |
"" |
Custom endpoint URL |
Project-level config via .mcpsecurityrc.json:
{
"enabled": true,
"severity": "errors"
}npx @kernlang/review-mcp ./src/server.tsOptions: --format json|sarif|text, --threshold 60 (fail if below), --quiet, --output report.json.
See @kernlang/review-mcp for full CLI docs.
Add to .github/workflows/mcp-security.yml:
name: MCP Security
on: [push, pull_request]
jobs:
scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: KERNlang/kern-lang/packages/review-mcp/ci@main
with:
threshold: 60 # fail if score < 60
sarif: true # upload to GitHub Code Scanning
comment: true # post score + findings to PRThe extension spawns a lightweight MCP subprocess for analysis — the editor stays fast. The engine combines three layers:
- Legacy regex rules — fast pattern matching for known vulnerability patterns
- Compiled
.kernrules — declarative, human-auditable rules with taint tracking and guard dependencies - KERN IR inference — translates MCP server code to KERN's intermediate representation, checks structural invariants (effects must have guards)
The build pipeline uses @kernlang/core (parser) and @kernlang/mcp (transpiler) to compile .kern to MCP servers. 112 tests, 7 security guard types, both TypeScript and Python targets runtime-verified.
No network calls. No telemetry. Everything runs locally.
Tested against the official MCP servers and the vulnerable-mcp-servers-lab:
| Test Suite | Servers | Findings |
|---|---|---|
| Official MCP (filesystem, git, memory, fetch, time) | 7 | 37 |
| Vulnerable MCP lab (7 intentional vuln servers) | 7 | 50 |
All 7 lab servers detected. Catches command injection (eval), hardcoded secrets, prompt injection, data injection markers, SSRF, unsanitized external data, missing auth on remote servers, system info disclosure, typosquatting, and rug-pull patterns.
- VS Code 1.85+ or compatible editor (Cursor, Windsurf, Antigravity)
- Node.js 18+ (for the CLI)
- MCP servers using
@modelcontextprotocol/sdk(TypeScript) ormcp.server/FastMCP(Python)
- KERN Language — the structural language powering the analysis and compilation
- OWASP MCP Top 10 — the security framework we map to
- Contact — bug reports, feature requests, commercial licensing
Part of the KERN project. AGPL-3.0 — free for individuals and open-source projects. Commercial use requires a license. See LICENSE.
