
Ai Quality Gate
io.github.mustafacagri由 GitHub 帳號 mustafacagri 發布v1.1.0更新於 Oct 24, 2026
🚀 Kill the Junior AI Era. 🤖 Level up AI code to automatically Principal standards. 🛡️ Quality Gate ✨
概覽
本機 MCP 伺服器,對程式碼檔案執行 ESLint、Prettier 及選用的 SonarQube 檢查,自動修好能修的問題,並把剩下的問題回報給助理。
- 可以做什麼
- 對指定檔案路徑執行品質閘門,回傳已套用的修正與剩餘問題的結構化結果
- 自動修正程式碼風格與格式問題:ESLint 規則、大括號與箭頭函式 AST 轉換、Prettier 格式化、清除未使用的 import
- 驗證 JSON 與語系檔,並比對各語系檔之間的鍵值
- 依自訂正規表示式規則逐行檢查,將命中項目回報為問題
- 可選擇執行第二階段 SonarQube 分析,並把結果併入報告
- 提供唯讀檢查模式,以及產生專案設定檔的互動式設定精靈
- 適用情境
- 適合在助理撰寫或修改 JavaScript/TypeScript 程式碼時,讓每次變更在宣告完成前先經過檢查、格式化與驗證。對已使用 ESLint/Prettier 的團隊,或已運行 SonarQube 並希望其問題在同一流程中呈現的團隊特別有用。
- 執行需求
- 透過 npx(npm 套件 ai-quality-gate)或全域安裝在本機以 stdio 執行;需要 PATH 中有 Node.js 20.10+ 或 21.1+,以及支援 MCP 的編輯器。專案根目錄會依 package.json 或 tsconfig.json 自動偵測,也可用 PROJECT_ROOT 指定。選用的 SonarQube 階段需要運行中的伺服器、已安裝 sonar-scanner,並同時提供 SONAR_HOST_URL、SONAR_TOKEN 與 SONAR_PROJECT_KEY。
安裝
在 SourceWeft 中
- 開啟 儀表板中的 Ai Quality Gate,將其新增到工作區。
- 為需要使用其工具的對話啟用該服務。
Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。
其他 MCP 客戶端
參照 儲存庫 中的啟動說明。
README
AI Quality Gate
MCP Server for AI code quality automation.
What It Does
AI writes code → calls quality_fix → Server fixes what it can → Reports remaining issues to AI.
Hybrid Approach:
- Phase 1: ESLint + 627 rules + Prettier (~2-8s, always runs)
- Phase 2: SonarQube Server (~30-60s, optional)
Important: ESLint vs Prettier
ESLint rules are controlled by MCP for consistent quality gates. Prettier uses project's config so formatting matches project preferences.
Phase 1 Rule Coverage:
Installation
Prerequisites
- Node.js 20.10+ or 21.1+ on your PATH (
node -v). - Cursor, Antigravity, OpenCode (or another MCP-capable editor) with MCP enabled.
Project root is auto-detected when PROJECT_ROOT is omitted: the server walks up from the MCP process working directory until it finds package.json or tsconfig.json. Set PROJECT_ROOT in env only to analyze a different tree than the inferred root.
MCP configuration (Cursor)
Open Settings → Tools & MCP → Edit (user mcp.json). Add one server block; the examples below match .cursor/mcp.json.example (JSONC with comments — if your editor rejects comments, copy the JSON blocks below only).
Server name vs tool name: The key under mcpServers (e.g. "ai-quality-gate") is only the label for that connection in Cursor. The MCP tool your agent calls is always quality_fix — that name is fixed by this package and is separate from the server key and from ai-quality-gate.
A) Recommended: npx (no global install)
Always runs the published package; good for teams and CI-like setups.
B) Optional: global npm install
After npm i -g ai-quality-gate, the ai-quality-gate binary is on your PATH:
C) SonarQube (Phase 2)
Requires a running SonarQube instance, sonar-scanner available (see SonarQube Setup), and all three variables below. Phase 1 still runs first.
D) Optional environment variables (any server)
Add an "env" object when you need overrides. Merge order for config is defaults → .quality-gate.yaml / .quality-gate.json → environment variables.
MCP configuration
Cursor, Antigravity, etc..
(OpenCode)
Create or edit OpenCode config (typically ~/.config/opencode/opencode.json or project-level config):
Environment variables can be added under the server config if needed (see C) SonarQube (Phase 2) above).
Local development (this repository)
To dogfood or contribute:
yarn build— generatesdist/server.js.- Point MCP at the built file (absolute paths):
- Reload MCP. Use
env.PROJECT_ROOTonly if the repo you analyze differs from the inferred root.
2. Add AI Rule
Settings → Rules and Commands → Add Rule:
3. Use It
CLI: interactive config (--setup)
The interactive wizard creates or updates .quality-gate.yaml without hand-editing: it walks you through project root, optional SonarQube (host URL + project key; token is not saved to disk — use SONAR_TOKEN in your environment), which Phase 1 tools to enable (ESLint, curly-brace / arrow AST fixers, Prettier, JSON validator), timeouts, and i18n rules. The generated file includes a fixers: block you can adjust later.
After yarn build (or install from npm), run from the target project (or any path under it):
PROJECT_ROOT is inferred when unset (see MCP configuration). Use the same entrypoint as the MCP server (node dist/server.js or npx ai-quality-gate); only the --setup flag switches to wizard mode. Answer prompts in the terminal; on success you get a ready-to-use config next to your project root.
Other CLI modes: --check (read-only Phase 1), --fix (default behavior when using CLI quality run), --phase1-only, --phase2-only — see docs/DEVELOPMENT.md.
Optional: SonarQube Server (Phase 2)
Configure Sonar env in MCP as in C) SonarQube (Phase 2) above, or copy from .cursor/mcp.json.example. You need sonar-scanner on your machine for analysis (see below).
SonarQube Setup
Docker (Recommended)
Docker Compose
Creating SonarQube Token
- http://localhost:9000 → Login (admin)
- My Account → Security → Generate Tokens
- Select token type: Global Analysis Token
- Copy token → use as
SONAR_TOKEN
Installing sonar-scanner
For custom path: SONAR_SCANNER_PATH env var
Configuration
Optional files (discovered by walking up from the inferred project root — same algorithm as package.json / tsconfig.json — or from PROJECT_ROOT when set): .quality-gate.yaml (preferred) or .quality-gate.json. Same fields as environment variables (camelCase); you may nest Sonar settings under sonar: { hostUrl, token, projectKey, scannerPath }.
Merge order: defaults → config file → environment variables (ENV wins on conflicts).
Set QUALITY_GATE_CONFIG to an explicit path to skip discovery.
Custom rules (customRules)
Optional line-based regex checks on lintable files (Phase 1). Each match is reported as an issue with rule set to custom:<id> (and included in quality_fix remaining). Example:
Patterns use JavaScript RegExp source (escape backslashes as in YAML strings). An invalid pattern is skipped, and says so in warnings.
JSON validator & i18n locale files
When fixers.jsonValidator is enabled and you pass JSON paths that match locale patterns (for example locales/en.json / locales/tr.json), the tool compares keys across those files.
- Syntax errors, invalid UTF-8 BOM, etc. → reported as
issuesand fail Phase 1 /quality_fixuntil fixed. - Missing or extra keys between locale files → collected as
i18nIssuesin the validator result and printed as warnings on stderr during Phase 1. They do not setpassed: falseand do not block the gate.
Treat i18nIssues as advisory unless you add your own CI check on top.
Environment Variables
All variables are optional unless you use Phase 2, which requires SONAR_HOST_URL, SONAR_TOKEN, and SONAR_PROJECT_KEY together.
Auto-Fix
Phase 1 automatically fixes these issues:
ESLint Auto-Fix (~100+ rules)
AST Auto-Fix
Prettier Formatting
After ESLint fixes, Prettier runs to ensure consistent formatting:
Note: Prettier uses project's config, not MCP's.
Everything else: Reported to AI, AI fixes it.
API
Tool: quality_fix
What a failed run leaves on disk. The gate applies every fix it can and keeps them. Findings it cannot fix
(a lint rule, a custom rule, a == that is not provably safe to change) come back in remaining with
success: false; the kept fixes are counted in fixed. The run is rolled back only when the fixers themselves broke
something: a type error after the fix, a Vue file the compiler rejects, ESLint or Prettier failing to run. Then
fixed is zero and the edits that were tried are listed in attempted. If that rollback itself fails, the response is ROLLBACK_FAILED: error.details.unrestoredFiles lists the files that may still hold the edits, phase is the phase that failed, and remaining is what failed, without locations. SonarQube (Phase 2) findings, or an
unreachable server, do not undo the verified Phase 1 edits either: they stay and the findings come back in remaining.
Retrying. If the same failure comes back unchanged three times in a row (same files with the same content, same
findings), the MCP server answers with error.code: "PERSISTENT_FAILURE" and tells the caller to stop retrying and ask
the human. Changing a file, or the findings changing, starts the count over. fixedCount counts edits only; JSON
validation passes are in fixed.json and are not fixes.
Overlapping calls. The MCP server runs quality_fix calls whose file sets overlap one after the other, in the order
they arrived, so one call's rollback can never restore an older copy over another call's kept edits. Calls on different
files still run side by side.
Feature Flags
ENABLE_I18N_RULES
For projects with internationalization (i18n), enable literal string detection:
When enabled:
Troubleshooting
MCP: quality_fix does not appear
- Node.js 20.10+ or 21.1+ — run
node -vandnpx --version. - Reload Cursor after editing
mcp.json(or use the MCP refresh control). - JSON — the file must be valid JSON (no trailing commas). Copy from the MCP configuration section if unsure.
- Global install — if you use
"command": "ai-quality-gate", runnpm i -g ai-quality-gateonce so the binary exists.
Windows
"npx not found" error:
Permission denied:
macOS / Linux
"Permission denied" error:
"sonar-scanner not found" error:
SonarQube
"Insufficient privileges" error:
- SonarQube → Administration → Security → Global Permissions
- Give Anyone group Browse and Execute Analysis permissions
"Project not found" error:
- Create project manually for first analysis: Projects → Create Project → Manually
Clone & build (contributors)
Use Local development (this repository) for MCP pointing at dist/server.js.
Docs
- SETUP.md — Local setup (if included in your tree)
- AGREEMENTS.md, docs/ARCHITECTURE.md, etc. — optional; some files may be omitted in minimal clones. README +
.cursor/mcp.json.exampleare enough to run the published package.
Principles
- ✅ 627 ESLint rules (SonarJS, Unicorn, TypeScript-ESLint, etc.)
- ✅ Prettier integration (uses project's config)
- ✅ AST-based transforms (no regex)
- ✅ Verify after each fix
- ✅ Rollback on error
- ✅ ESLint config discovery (uses project config if available, otherwise embedded)
- ✅ Zero workaround
- ✅ Principal level
License
MIT © Mustafa Çağrı Güven
v0.0.1 — Initial release! MCP quality_fix, Phase 1/2 pipeline, CLI, config files, custom rules (see CHANGELOG)
Readonly local verification
Run ai-quality-gate --check --phase1-only <selected-file ...> for readonly local
verification. ESLint checks only the explicitly selected real .js, .jsx,
.mjs, .cjs, .ts, .tsx, .mts, .cts, and .vue paths, including executable JS
configuration and TS declarations. It never expands lint scope through imports.
A .vue file is linted in place: vue-eslint-parser applies script rules to
<script> and <script setup> only. Template and style are not JavaScript, and
no extracted script file is written. @vue/compiler-sfc parse() and
compileScript() failures are diagnostics. A structurally invalid SFC fails
before ESLint, so a missing end tag is not reported as an unused binding.
AST edits keep arrow signatures and terminate a brace-less if with a semicolon.
Prettier, when enabled, formats the whole SFC. Deleted and old rename endpoints must first be
materialized as real files in an isolated snapshot by the caller, with their base
content and endpoint identity retained.
TypeScript checks the full nearest tsconfig.json project context with --noEmit;
this can include imports and other project files and does not expand ESLint's
selected scope. A .vue file with a TypeScript script (lang="ts" or tsx) is checked with
vue-tsc, which also checks its template expressions. A project that compiles .vue files uses vue-tsc for
its .ts files too, so they can import .vue modules; a project counts as one that compiles .vue files when its
include matches any, or when the nearest package.json depends on vue. The project is the tsconfig that includes the
file: for a create-vue style root config that only lists references, that is the referenced project, and a file such as
a shared helper that no project lists but a referenced project imports is checked in that project. A .vue file that no
tsconfig includes fails instead of passing unchecked. A plain-JavaScript .vue file is not type checked, as a .js
file is not. This holds for .ts files too: a file that no tsconfig includes, directly or through imports, fails with
"Not included by " instead of passing unchecked. Type errors anywhere in the program fail the check and are all
reported (those in the selected files first, at most 50). A plain-JavaScript <script> is linted with the rules a .js file gets, and a lang="ts" one with
the TypeScript rules. Type-aware ESLint rules (such as no-floating-promises) are not applied to .vue files: that is a
deliberate choice, not a limit of the parser. TypeScript incremental metadata is redirected to a temporary
folder outside the project and removed after the check. No source, configuration,
lockfile, or control file is rewritten by check mode. The MCP quality_fix tool
continues to be a mutating operation; use the CLI check interface for readonly work.
The embedded config uses typescript-eslint's recommendedTypeChecked and
projectService for TS sources. TS files must belong to a real tsconfig project.
JavaScript files use the non-typed lint profile. Named import aliases, including
type aliases, are checked by an AST rule; unchanged named imports are allowed.
Warnings fail strict verification (--max-warnings 0). Local check JSON includes
checks.typecheck and, when reached, checks.lint, with PASS/FAIL/ERROR status,
checked projects, and actual lint result paths. The existing fail-fast pipeline
can stop before lint after a failed typecheck or custom rule.
Exit 0 means all reached checks succeeded; exit 1 reports real code findings;
exit 2 reports configuration, process, parser, or coverage errors. Empty/malformed
lint output, missing selected files, unexpected/duplicate result paths, fatal
parser failures, and failed subprocesses cannot become a successful check.
The installed package carries its embedded parser, lint plugins/resolver, and
TypeScript runtime dependencies. Supported Node versions are ^20.10.0 || >=21.1.0,
the intersection required by the retained lint dependency baseline.
來源:README.md,提交 067b3ba
工具
0版本歷史
2- v1.1.0最新Oct 7, 2026
- v1.0.4Sep 16, 2026
評分
已滿足適用檢查項的 50%
該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。
- 近 30 天內可連通25 分
請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。
- 已宣告認證方式10 分
請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。
- 已列出工具15 分
請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。
- 描述必需15 分
- 圖示10 分
- 文件15 分
- 授權條款10 分