Scans Node.js projects for API authentication gaps, security vulnerabilities, dependency issues, and testing coverage.
Also known as sabahattink/codediag, @sabahattink/codediag
- Stars
- 2
- Tools
- —
- Downloads, 30 days
- —
- Latest version
- 0.13.0
- Last commit
- Nov 16, 2026
- License
- MIT
What is CodeDiag MCP?
CodeDiag scans Node.js projects for API authentication gaps, security vulnerabilities, dependency issues, and testing coverage.
Summary generated from the project's README
About CodeDiag MCP server
Scanning Node.js projects for API authentication gaps and security vulnerabilities is what CodeDiag enables for web developers. This tool performs deep AST analysis to identify unprotected routes across various frameworks including Next.js, Express, Fastify, Hono, Elysia, NestJS, SvelteKit, React Router, and tRPC. It evaluates whether your application properly implements auth guards, middleware, or validation schemas to prevent unauthorized access.
Beyond API health, the tool inspects code for security risks like hardcoded credentials, SSRF, and XSS by tracing request data through your logic. It also audits dependencies using native package managers, checks testing coverage against specific thresholds, and validates project structure. The scanner runs locally via a single command and can operate fully offline using the --no-audit flag. It requires no account or external server to function, making it suitable for private environments and CI/CD pipelines.
What you can do with it
- 1Identify unprotected API routesFind which specific routes in your Express or NestJS application are missing authentication guards or validation middleware.
- 2Detect security vulnerabilities in data flowTrace how request data moves through your services to find potential path traversal or reflected XSS risks.
- 3Audit project security health scoresGenerate a weighted grade for your project based on API health, security, dependencies, testing, and structure.
- 4Automate security checks in CI/CDFail a build if the project score falls below a certain threshold or if critical findings are detected.
Written from the project's README. Every use case is checked against a quote from it.
How to install CodeDiag MCP
Formats verified 10 Nov 2026Add to CursorAdd to GooseInstall CodeDiag MCP in Claude Code
$ claude mcp add codediag -- npx -y @sabahattink/codediagInstall CodeDiag MCP in Cursor
~/.cursor/mcp.json
{
"mcpServers": {
"codediag": {
"command": "npx",
"args": [
"-y",
"@sabahattink/codediag"
]
}
}
}Install CodeDiag MCP in VS Code
.vscode/mcp.json
{
"servers": {
"codediag": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"@sabahattink/codediag"
]
}
}
}Install CodeDiag MCP in VS Code CLI
$ code --add-mcp '{"name":"codediag","type":"stdio","command":"npx","args":["-y","@sabahattink/codediag"]}'Install CodeDiag MCP in Claude Desktop
claude_desktop_config.json
{
"mcpServers": {
"codediag": {
"command": "npx",
"args": [
"-y",
"@sabahattink/codediag"
]
}
}
}Install CodeDiag MCP in Codex
$ codex mcp add codediag -- npx -y @sabahattink/codediagInstall CodeDiag MCP in Codex config.toml
~/.codex/config.toml
[mcp_servers.codediag] command = "npx" args = ["-y", "@sabahattink/codediag"]
Install CodeDiag MCP in Gemini CLI
$ gemini mcp add -s user codediag npx -- -y @sabahattink/codediagInstall CodeDiag MCP in Gemini settings.json
~/.gemini/settings.json
{
"mcpServers": {
"codediag": {
"command": "npx",
"args": [
"-y",
"@sabahattink/codediag"
]
}
}
}Automated checks
Ran Nov 14, 2026Full report →Passed our automated checks. That is not a security audit: read the code and give the server the narrowest access it needs. How checks work
- Source repository linked and reachablesabahattink/codediag is public and reachablegithub.com/sabahattink/codediag ↗Pass
- Package names this repository as its source@sabahattink/codediag names sabahattink/codediag as sourcenpmjs.com/package/@sabahattink/codediag ↗Pass
- Build provenance (Sigstore attestation)Sigstore attestation for @sabahattink/codediagnpmjs.com/package/@sabahattink/codediag/v/0.13.0#provenance ↗Pass
- Open source license (OSI)MITspdx.org/licenses/MIT.html ↗Pass
- Commit or release in the last yearLast commit or release 2026-11-09github.com/sabahattink/codediag ↗Pass
- OpenSSF ScorecardNot checked
- Package name not close to a popular packageNo popular package one edit away from @sabahattink/codediagPass
- No critical advisory in the package or its dependencies41 resolved dependencies checked; no critical advisoryosv.dev ↗Pass
- No hidden instructions to the model0 tool descriptions and the README read; no override phrases, credential paths or hidden charactersPass
- Destructive tools are labelledNot checked
- Remote endpoint answers the MCP handshakeNot checked
README
View on GitHubInstall
npx @sabahattink/codediag scan .
That's it. Configuration is optional, no account or server is required, and
--no-audit keeps the scan fully offline.
Or install globally — this also puts the codediag command on your PATH,
which every other example below assumes:
npm install -g @sabahattink/codediag
Package name note: published as
@sabahattink/codediagwhile ownership of the legacycodediagname on npm is transferred. The CLI binary is stillcodediagafter install. A migration announcement will follow if/when the unscoped name becomes available again.
What it checks
codediag auto-detects your stack and runs 5 analyzers. Every finding has a stable rule ID (rule reference), a severity, a location when one exists, and a suggested fix.
API Health NestJS · Express · Fastify · Hono · Elysia · Next.js · SvelteKit · React Router · tRPC
AST analysis (ts-morph, not regex) of the routes your app actually exposes.
- NestJS: auth guards, including global guards (
useGlobalGuards,APP_GUARD), customUseGuards-based decorators, and@Public()-style opt-outs; DTO classes for request bodies (notany,Record, or interfaces) and whether aValidationPipeenforces them; Swagger docs and return types. - Express: routers resolved from
express(),Router(), and typed parameters; auth and validation middleware on routes, earlierrouter.use()calls, andapp.use(path, mw, router)mounts across files; centralized error handling and health endpoints. - Fastify: routes from
fastify.get()andfastify.route(), followed throughregister()-ed plugins,fastify-pluginencapsulation, and@fastify/autoloaddirectories (directory prefixes,autoPrefix, and autohooks, asfastify-cliprojects use them);onRequest/preHandlerauth hooks on the route or its context, body schemas on mutating routes,setErrorHandler, and health endpoints. - Hono: routes on
new Hono()apps,basePath(), and sub-apps mounted withapp.route()across files, replayed in registration order; auth middleware (jwt(),bearerAuth(),basicAuth(), or your own) on the route or an earlier matchingapp.use();zValidatorand other body validators;onError; and health endpoints. - Elysia: routes on
new Elysia()instances,prefix,group(), and plugins mounted withuse()across files, functional plugins included, replayed in registration order with Elysia's hook scope: a plugin's hooks reach the instance that uses it only when they arescopedorglobal({ as: 'scoped' },.as('scoped')). Auth fromonBeforeHandle(), aderive()orresolve()that rejects with 401,guard(), auth macros such as better-auth's{ auth: true },onRequest(), or a check in the handler; when a route misses an auth hook that exists, the finding says whether the hook stayed local to its plugin or came after the route. Body schemas (TypeBox, Zod, or another Standard Schema) in the route options or aguard();onError; and health endpoints. - Next.js: App Router and Pages Router API handlers, without penalizing
frontend-only projects. Middleware (
proxy.tsin Next.js 16) protects a route only if it turns an anonymous request to that path away: itsmatcher, pathname checks, next-auth, Clerk'sprotect(), Auth.jsauthorizedcallbacks, and helpers it returns, such as Supabase'supdateSession(), are evaluated for each route. - SvelteKit:
+serverendpoints and form actions, with route ids fromsrc/routes; auth in thehandlehook (throughsequence()and path or route id guards) or in the handler and the helpers it calls; a note when the only auth check sits in a layoutload, which never runs for actions and endpoints; body validation; and CSRF origin checks turned off insvelte.config.js. - React Router and Remix: actions and loaders from
app/routes.tsor Remix v2 flat-route files; auth in the action, its helpers, or routemiddleware; a separate rule when a parent's or the route's own loader holds the only auth check, since neither runs before an action; and schema validation of form and JSON bodies. - tRPC: procedures resolved from
initTRPCthrough builder chains, exported builders such asprotectedProcedure, and nested or merged routers across files (including~/path aliases); mutations without auth middleware (judged by what the middleware checks, not its name),.input()parsers that accept anything, and error formatters orisDev: truethat expose stack traces. Auth in front of every procedure counts too: acreateContextthat rejects anonymous callers, auth middleware ahead of the Express or Hono mount, an auth hook over the Fastify plugin, or a Next.jsmiddleware.ts(proxy.tsin Next.js 16), Auth.js included, that rejects anonymous requests to the tRPC route. The checks run inside whichever server hosts tRPC (T3/Next.js, Express, Fastify, Hono, Elysia, SvelteKit), and a standalone tRPC server is its own stack. An intentionally public mutation, such as sign-up, is accepted with a reasonedcodediag-ignore-next-linedirective.
Security
Hardcoded credentials, .env protection in .gitignore, Helmet, rate
limiting, open CORS, weak password hashing, and direct password comparisons.
Runtime sinks (eval, new Function, shell commands, raw SQL, disabled TLS
verification) are found in the AST, and request data is traced through
variables, destructuring, reassignments, and up to two calls into your own
helper functions and services, so const cmd = req.query.cmd; exec(cmd) is
critical, and so is run(req.query.cmd) when run calls exec in another
file. Request data is also followed into fields a class stores it in, through
constructors, into map/forEach callbacks and for...of loops, and to
NestJS providers behind an interface or injection token. tRPC procedure
input is request data too, even after .input(schema) validates it. Request data that reaches a file path, an outgoing
request's host, a redirect, or an HTML response is reported as path
traversal, SSRF, an open redirect, or reflected XSS; request data compiled as
a template or used as an object path is template injection or prototype
pollution. JWT options that accept none or ignore expiration, and session
cookies without httpOnly/secure, are flagged too. Secrets are also looked
for in JSON, YAML, Dockerfiles, .npmrc, and .env files that Git tracks,
and no report ever contains the value. With --secret-history (or
secretHistory in .codediag.yml), the lines recent commits added are also
searched for credentials that were committed and later deleted, which every
clone still contains (secret-in-git-history); it is off by default because
results depend on clone depth. In Supabase projects, supabase/migrations
is replayed in order and tables the API exposes without row level security
are critical (supabase-table-without-rls), as are write policies whose
using or with check is true (supabase-permissive-policy). See
Security analysis.
Dependencies
Runs the matching npm, pnpm, Yarn Classic, or Yarn Berry audit (skipped with
--no-audit; audit: production checks only the dependencies you ship),
names the affected packages and their advisories in each vulnerability
finding, checks the lock file and packageManager consistency, flags
deprecated packages, and validates engine specs and essential scripts.
Monorepo lock files are found up to three parent directories. A successful
audit is kept for an hour in node_modules/.cache/codediag, keyed by the lock
file and package.json, so repeated scans reuse it (the Dependencies summary
says when); delete that directory to force a fresh audit. pnpm audits a whole
workspace lock file from any package, so packages that share one run a single
audit and each reports only the advisories its own dependencies reach.
Testing
Test files and frameworks (Jest, Vitest, Mocha, Ava, node:test), the
test-to-source ratio, integration test directories, and coverage. A
coverage-summary.json is measured against 80% lines/statements and 70%
functions/branches; otherwise CodeDiag checks for a real coverage threshold in
Jest, Vitest, node:test, c8, or nyc configuration.
Structure
README content, lint and format config (also inherited from a workspace root),
resolved TypeScript strict mode, NestJS feature modules, and environment
templates such as .env.example.
Scoring
Each analyzer scores 0-100. Weighted average determines the grade:
API Health: 25% · Security: 30% · Dependencies: 20% · Testing: 15% · Structure: 10%
| A+ | A | B+ | B | C | D | F |
|---|---|---|---|---|---|---|
| 95+ | 90+ | 85+ | 80+ | 70+ | 60+ | <60 |
Analyzer scores use scoring version 2 by default: every analyzer starts at
100 and each finding subtracts a severity weight (critical 25, warning 8,
info 2). Further findings of the same rule cost half the previous one, so a
single rule costs at most twice its weight. A finding whose root cause is also
reported (for example "no test directory" when there are no tests at all) is
downgraded to info, linked with causedBy, and costs nothing. Findings that
leave an analyzer with nothing to evaluate, such as a missing package.json,
set that analyzer to 0.
Every lost point is listed in scoreBreakdown in JSON output, in the HTML and
Markdown reports, and under each analyzer with --verbose. Set
scoring: { version: 1 } to keep the previous checks-passed scores for one
more release.
CLI
codediag scan . # Full report
codediag scan . --format json # JSON (for CI/CD)
codediag scan . --format sarif # SARIF 2.1.0 (for code scanning)
codediag scan . --format md # Markdown (for PRs)
codediag scan . --format svg # SVG score badge
codediag scan . --format html > codediag-report.html # Interactive dashboard
codediag scan . --format fixes > codediag-fixes.md # Review checklist
codediag scan . --format prompt > codediag-prompt.txt # Review-only AI handoff
codediag scan . --ci # JSON output + exit code
codediag scan . --threshold 80 # Exit 1 below 80 in any output mode
codediag scan . --fail-on critical # Exit 1 on any active critical finding
codediag scan . --quiet # Score only
codediag scan . --verbose # All issues and the score breakdown
codediag scan . --no-audit # Offline: skip the package manager audit
codediag scan . --update-baseline .codediag-baseline.json # Record accepted findings
codediag scan . --ci --baseline .codediag-baseline.json # Fail only on new findings
codediag scan . --compare previous.json # Score change, new and fixed findings
codediag scan . --changed-since origin/main # Only files this branch changes
codediag scan . --workspaces # Every monorepo package, combined
codediag scan . --history .codediag/history # Record scans, show the trend
codediag scan . --secret-history # Also secrets removed but still in Git history
codediag rules # List every rule
codediag explain open-cors # Explain a rule and how to suppress it
codediag init # Create .codediag.yml
codediag mcp # Serve MCP on stdio for AI agents
Generate a repository badge:
codediag scan . --format svg > codediag.svg
Trends and changed files
--compare takes any earlier JSON report and shows what changed: the score
and each analyzer's delta, findings that are new (marked NEW and
isNew: true), and findings that have been fixed since. It works in every
output format; the HTML report adds a change panel and a "New" filter, and
SARIF marks results with baselineState.
codediag scan . --format json > reports/main.json # on main
codediag scan . --compare reports/main.json --verbose # on your branch
--changed-since <revision> limits a scan to the files that differ from a Git
revision: commits since the merge base, staged and unstaged edits, and new
untracked files. Only findings in those files are reported and scored, so the
score describes the change rather than the whole project, and the report says
how many findings elsewhere were left out.
codediag scan . --changed-since origin/main --threshold 90
--history <directory> keeps a trend: each scan is saved in the directory
(codediag-<timestamp>.json), and the report shows the score over the last
50 recorded scans, as a sparkline in the terminal and Markdown and as a chart
with a table view in the HTML report. Commit the directory, or cache it in CI,
to keep the history.
codediag scan . --history .codediag/history
Monorepos
--workspaces scans every package of an npm, pnpm, or Yarn workspace, a
Lerna repository, or an Nx workspace (Turborepo uses your package manager's
workspaces). Each package gets its own stack detection and score, using its
own .codediag.yml if it has one and otherwise the root configuration, with
root ignore paths rebased into the package. The combined report lists every
package and averages each analyzer over the packages it ran in; the total
uses the usual analyzer weights. Package audits run four at a time before
the packages are analyzed. Findings are located relative to the root,
and project-level findings point at the package's package.json, so
baselines, --compare, --changed-since, SARIF, and the GitHub Action
(workspaces: true) work across the whole repository.
codediag scan . --workspaces
codediag scan . --workspaces --format html > monorepo-report.html
codediag scan . --workspaces --package-threshold 70 # Gate every package too
A combined average can hide one weak package. packageThreshold (or
--package-threshold, or the Action's package-threshold input) gates every
package on its own score as well: a package below it fails the scan, is
named on stderr and in the job summary, and is marked in every report. A
package's own .codediag.yml can set a different packageThreshold.
Scanning a workspace root without --workspaces scans it as one project and
suggests the flag.
Review-first fix proposals
CodeDiag can turn analyzer findings into a prioritized remediation checklist. Every item remains unchecked and explicitly requires review; CodeDiag never edits project files or applies a recommendation automatically.
codediag scan . --format fixes > codediag-fixes.md
For use with a coding agent, --format prompt creates a structured handoff
that treats diagnostics as untrusted data and instructs the agent to inspect
the referenced files before proposing a patch. The prompt contains diagnostic
metadata only, not source file contents or secrets, and prohibits edits until
the user gives explicit approval.
codediag scan . --format prompt > codediag-prompt.txt
See the review-first fix proposal guide for the output contract and recommended workflow.
VS Code extension
The VS Code extension runs the same analyzer engine, publishes located
findings to the Problems panel, and opens HTML reports, fix plans, or AI review
prompts directly in the editor. Quick fixes on each problem suppress the rule
on that line or in the file (you type the reason) or open its documentation. Successful GitHub Actions runs publish an
installable .vsix artifact until the extension is available in the Visual
Studio Marketplace.
npm run extension:package
See the VS Code extension guide for installation, commands, workspace trust boundaries, and scan-on-save behavior.
The JSON output contract is published as
schema/scan-result.schema.json.
See the
JSON output documentation
for compatibility guarantees and field definitions.
For code-scanning platforms, --format sarif emits SARIF 2.1.0 with stable
rule IDs, source locations, severity levels, and finding fingerprints:
codediag scan . --format sarif > codediag-report.sarif
See the SARIF output documentation for the field mapping and GitHub Code Scanning workflow. Every rule is described in the rule reference.
Guides
Short, sourced answers to auth checks that look like they protect a route but don't:
- Does an auth check in
+layout.server.tsprotect SvelteKit form actions? - Does a parent loader's auth check protect child routes in React Router?
- Is your Next.js middleware protecting your API routes?
AI agents
Let your coding agent answer "which of my routes can anyone call?" with CodeDiag's analysis. In Claude Code, install the plugin, which adds a skill and the MCP server:
/plugin install codediag --marketplace sabahattink/codediag
Any other MCP client can start the server with npx -y @sabahattink/codediag mcp.
It offers find_unprotected_routes, scan_project, and explain_rule, and
stays offline. The AI agents guide has setup for Claude
Code, Cursor, VS Code, and Claude Desktop, and the
Agent Skill for agents without MCP.
CI/CD
# GitHub Actions (no npm install required)
- uses: sabahattink/codediag@v0
id: codediag
with:
threshold: 80
The Action adds score annotations and a job summary, writes JSON and SARIF
reports, and fails when the score is below the requested threshold. With
comment: true (and pull-requests: write permission) it also keeps one
pull request comment up to date with the score, its change since the last
push, and the findings in the files the pull request changes. Its
score, grade, report, and sarif outputs can be used by later steps. See
the GitHub Action guide for all inputs, outputs, and a
complete workflow.
✅ CodeDiag: 88/100 (B+)
▲ +4 since the last run · threshold 80
Analyzer Score Findings API Health 92/100 1 Security 67/100 2 Dependencies 100/100 0 Testing 98/100 1 Structure 100/100 0 Findings in changed files (2)
Rule Location Finding 🔴 reflected-xsssrc/routes/search.ts:14Request data is written into an HTML response without escaping 🟡 open-redirectsrc/routes/auth.ts:31A redirect target comes from request data Not listed: 1 finding elsewhere in the project.
Adopting CodeDiag on an existing codebase? Commit a baseline so the gate only fails on new findings:
- uses: sabahattink/codediag@v0
with:
threshold: 80
baseline: .codediag-baseline.json # created with --update-baseline
# npm-based GitHub Actions step
- run: npx @sabahattink/codediag scan . --ci --threshold 80
# GitLab CI
codediag:
script: npx @sabahattink/codediag scan . --ci --threshold 80
# Pre-push hook (husky)
npx @sabahattink/codediag scan . --quiet --threshold 70
Config
Optional. Create .codediag.yml or run codediag init. Command-line
--threshold takes precedence over the configured threshold. A configured
threshold is enforced whenever that project is scanned. Without a config file,
plain scans are informational; --ci uses the default threshold of 70.
threshold: 70
failOn: critical # optional; any active critical finding fails the scan
packageThreshold: 60 # optional; each --workspaces package must reach it
ignore: [node_modules, dist, .git, coverage]
maxFileSizeKb: 512
scoring:
version: 2
rules:
missing-swagger: off # or info, warning, critical
audit: true # false skips the network audit; production skips devDependencies
secretHistory: false # true searches the last 1000 commits for removed secrets, or give a number
analyzers:
api: true
security: true
dependencies: true
testing: true
structure: true
Unknown options and invalid values fail the scan instead of being silently
ignored. Directory and glob entries under ignore are applied to analyzers
that inspect source files.
Individual findings can be suppressed in source with a required reason, and existing findings can be accepted with a baseline so CI fails only on new problems:
// codediag-ignore-next-line unsafe-dynamic-code -- plugin code is signed and sandboxed
See suppressions, rule settings, and baselines.
Source discovery always skips node_modules, dist, coverage, .next, and
.turbo directories at any depth, *.min.js and *.map files, dot
directories, and everything matched by the project's .gitignore files
(including nested ones and those in parent directories up to the Git root).
Code files larger than maxFileSizeKb or that look like minified bundles are
skipped and reported in the JSON skipped summary.
Supported stacks
| Stack | API Health | Security | Deps | Testing | Structure |
|---|---|---|---|---|---|
| NestJS | ✅ | ✅ | ✅ | ✅ | ✅ |
| Next.js | ✅ | ✅ | ✅ | ✅ | ✅ |
| SvelteKit | ✅ | ✅ | ✅ | ✅ | ✅ |
| React Router / Remix | ✅ | ✅ | ✅ | ✅ | ✅ |
| Express | ✅ | ✅ | ✅ | ✅ | ✅ |
| Fastify | ✅ | ✅ | ✅ | ✅ | ✅ |
| Hono | ✅ | ✅ | ✅ | ✅ | ✅ |
| Elysia | ✅ | ✅ | ✅ | ✅ | ✅ |
| tRPC | ✅ | ✅ | ✅ | ✅ | ✅ |
| Node.js | — | ✅ | ✅ | ✅ | ✅ |
CodeDiag MCP questions
How do I add CodeDiag MCP to Claude Code?
Run claude mcp add codediag -- npx -y @sabahattink/codediag in your terminal. Add --scope user to make it available in every project.
How do I add CodeDiag MCP to Cursor?
Open ~/.cursor/mcp.json and add the server under mcpServers, using the Cursor config shown in the install section above.
Does CodeDiag require an account or internet connection?
No, it requires no account or server, and you can run it fully offline using the --no-audit flag.
Which web frameworks does it support for API health checks?
It supports a wide range of frameworks including NestJS, Express, Fastify, Hono, Elysia, Next.js, SvelteKit, React Router, and tRPC.
How is the project health score calculated?
The score is a weighted average of five analyzers: Security (30%), API Health (25%), Dependencies (20%), Testing (15%), and Structure (10%).