codesafer
CodeSafer (cleaner-code)
AI code security scanner as a Model Context Protocol (MCP) server. Detects hidden threats in AI-generated code that traditional linters miss.
Website: codesafer.org · MCP Clients: Claude Code, Cursor, VS Code + Copilot, Cline
Why CodeSafer?
AI coding assistants generate code fast — but who's checking it for hidden threats?
Recent supply-chain attacks show that malicious code can hide in ways human reviewers and traditional linters routinely miss:
Invisible Unicode characters injected into identifiers (30+ variants)
BiDi / Trojan Source attacks that reorder how code is displayed vs. executed (CVE-2021-42574)
Homoglyphs — Cyrillic characters masquerading as Latin (CVE-2021-42694)
Glassworm-style Unicode steganography hiding payloads in whitespace
Rules file backdoors planted in
.cursorrules,CLAUDE.md, and other AI config filesTyposquatted dependencies in
package.jsonObfuscation patterns —
eval+ base64, reverse shells, packed payloads
CodeSafer scans for all of these before the code runs on your machine.
Related MCP server: guardvibe
How it works
CodeSafer runs as a local MCP server. Your AI client (Claude Code, Cursor, etc.) calls its tools when reviewing or generating code, and findings are returned inline.
Hybrid detection:
8 static analysis scanners — deterministic rules for known attack categories (fast, zero false-negatives on the patterns they cover).
CodeBERT deep analysis — transformer model classifies code chunks as malicious/benign with confidence scores. Catches obfuscated or novel patterns that static rules miss.
Nothing leaves your machine. The AI analysis runs locally against a tokenizer server.
Features
Capability | Details |
Invisible character detection | 30+ Unicode variants including Zero-Width Space, Mongolian Vowel Separator |
BiDi / Trojan Source | Full CVE-2021-42574 coverage |
Homoglyph detection | Cyrillic/Greek/Latin confusables (CVE-2021-42694) |
Unicode steganography | Glassworm-style whitespace payloads |
Rules file backdoors | Scans |
Dependency scanning | Typosquatting + suspicious install scripts in |
Obfuscation detection |
|
AI deep analysis | CodeBERT transformer classifier with confidence scores |
MCP native | 6 MCP tools, stdio transport |
Local-first | No code uploaded — runs entirely on your machine |
MCP Tools
CodeSafer exposes six tools to your MCP client:
Tool | Purpose |
| Scan a single file for hidden malicious code patterns |
| Recursively scan a directory across all source files |
| Scan an AI configuration/rules file for prompt injection and Rules File Backdoor attacks |
| Check |
| Deep AI analysis using the trained CodeBERT model (classifies chunks as malicious/benign with confidence) |
| Get detailed explanation of a specific threat category, with attack scenarios and remediation |
Installation
Prerequisites
Node.js 18 or later
An MCP-compatible client (Claude Code, Cursor, VS Code + Copilot, Cline)
From source
git clone https://github.com/goldmembrane/cleaner-code.git
cd cleaner-code
npm install
npm run buildConfigure your MCP client
Claude Code (~/.claude.json or project .mcp.json):
{
"mcpServers": {
"codesafer": {
"command": "node",
"args": ["/absolute/path/to/cleaner-code/dist/index.js"]
}
}
}Cursor (.cursor/mcp.json):
{
"mcpServers": {
"codesafer": {
"command": "node",
"args": ["/absolute/path/to/cleaner-code/dist/index.js"]
}
}
}Restart your client, and CodeSafer tools will appear in the tool picker.
Usage
Once configured, ask your AI client things like:
"Scan this file for hidden security issues."
"Check the dependencies in package.json for typosquatting."
"Scan
.cursorrulesfor a rules-file backdoor.""Run a deep AI analysis of
src/auth.ts.""Explain what a Trojan Source attack is and how to fix the finding above."
The client will call the appropriate MCP tool and return findings with severity, line numbers, and remediation guidance.
Free tier & Plans
CodeSafer is free to use. Static analysis (scan_file, scan_directory, scan_rules_file, check_dependencies, explain_finding) has no limits.
AI deep analysis (ai_analyze) includes 10 free runs per session. Paid plans for higher AI quotas are available at codesafer.org.
Detection categories
CodeSafer detects threats across 9 categories:
Invisible Unicode characters — 30+ variants including Zero-Width Space, Zero-Width Joiner
BiDi / Trojan Source attacks — CVE-2021-42574
Homoglyphs — Cyrillic/Greek characters masquerading as Latin (CVE-2021-42694)
Unicode steganography — Glassworm patterns in whitespace
Rules file backdoors — malicious instructions in
.cursorrules,CLAUDE.md, etc.Dependency risks — typosquatting and suspicious install scripts
Obfuscation patterns —
eval+ base64, packed payloads, reverse shellsStatic analysis findings — 8 deterministic scanners
AI deep analysis — CodeBERT transformer for novel and obfuscated threats
Project structure
cleaner-code/
├── src/
│ ├── index.ts # MCP server entry point
│ ├── api-server.ts # Optional HTTP API server
│ ├── types.ts # Scanner interfaces
│ ├── utils.ts # File collection, summary formatting
│ └── scanner/
│ ├── invisible.ts # Invisible Unicode scanner
│ ├── bidi.ts # BiDi / Trojan Source scanner
│ ├── homoglyph.ts # Homoglyph scanner
│ ├── encoding.ts # Encoding / charset scanner
│ ├── obfuscation.ts # Obfuscation pattern scanner
│ ├── steganography.ts # Unicode steganography scanner
│ ├── rules-backdoor.ts # Rules file backdoor scanner
│ ├── dependency.ts # Dependency risk scanner
│ └── ai-analyzer.ts # CodeBERT deep analyzer
├── ml/ # ML model assets and tokenizer
├── functions/ # Cloud function deployments
├── deploy/ # Deployment manifests
└── web/ # Landing page assetsLicense
ISC — see the LICENSE file for details.
Links
Website: codesafer.org
Model Context Protocol: modelcontextprotocol.io
Report issues: GitHub Issues
Available Tools
6 toolsai_analyzeA
Deep AI analysis of code using the trained CodeBERT model. Classifies code chunks as malicious or benign with confidence scores. Detects obfuscated payloads, novel attack patterns, and threats that static rules may miss.
Inputs: file_path (required).
check_dependenciesB
Check package.json for typosquatting, suspicious install scripts, and dependency risks
Inputs: file_path (required).
explain_findingA
Get detailed explanation of a specific threat category including attack scenarios, real-world examples, and remediation steps
Inputs: category (required).
scan_directoryB
Recursively scan a directory for hidden malicious code patterns across all source files
Inputs: dir_path (required), extensions.
scan_fileB
Scan a single file for hidden malicious code patterns (invisible chars, BiDi, homoglyphs, steganography, obfuscation, etc.)
Inputs: file_path (required).
scan_rules_fileA
Scan an AI configuration/rules file for prompt injection and Rules File Backdoor attacks
Inputs: file_path (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 6 tools
Each tool has a clearly distinct purpose: scan_file vs scan_directory differ by scope, ai_analyze uses ML, check_dependencies focuses on dependencies, and scan_rules_file is for configuration files. No ambiguity.
Tools mostly follow verb_noun snake_case pattern (e.g., scan_file, check_dependencies). The outlier is ai_analyze, which uses a prefix instead of a verb-noun structure, but it's still clear and consistent overall.
With 6 tools covering scanning, AI analysis, dependency checks, and explanations, the count is well-scoped for a focused security analysis server. Not too many or too few.
The tools cover core scanning and analysis tasks well, including file/directory scanning, dependency risks, AI-based analysis, and explanations. A minor gap is the lack of a tool for aggregated reporting or finding management, but the surface is largely complete for detection and explanation.
Maintenance
Related MCP Connectors
Audit your MCP servers for poisoned tools and leaked secrets, and check AI-generated code for flaws.
Zero-config MCP security scanner for AI-generated apps. 25K+ vulnerability patterns.
Security scanner for MCP servers. Detect vulnerabilities, prompt injection, and tool poisoning.
Security scanner for AI agents and MCP servers: injection, jailbreak, tool abuse.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceSecurity scanner for MCP servers and AI-generated code. Detects leaked API keys, PII, prompt injection, and MCP misconfigs with A-F security grades.MIT
- AlicenseBqualityBmaintenanceSecurity MCP server with 300+ rules for AI-generated code. Scans Next.js, Supabase, Clerk, Stripe, Prisma, Hono, GraphQL and 20+ modules. Zero config, runs locally.392,686 npm6Apache 2.0
- AlicenseAqualityBmaintenanceMCP security server for AI coding agents. 12 tools: pre-install guardian, vulnerability audit, supply-chain attack detection via static code analysis, and CycloneDX 1.6 SBOM generation. Zero runtime dependencies.1581 npm15Apache 2.0
- AlicenseNot gradedqualityCmaintenanceScans MCP servers, AI agent skills, and plugins for 68+ malicious patterns including credential exfiltration, prompt injection, and code execution.65 npm5MIT