🚀 CORBAT MCP
AI編碼標準服務器,讓AI生成的代碼一次通過代碼審查。
🚀 快速開始
⚡ 30秒即可體驗 — 只需添加以下配置並開始編碼。
1. 添加到您的MCP配置中
{
"mcpServers": {
"corbat": {
"command": "npx",
"args": ["-y", "@corbat-tech/coding-standards-mcp"]
}
}
}
2. 配置文件位置
| 工具 |
位置 |
| Cursor |
.cursor/mcp.json |
| VS Code |
.vscode/mcp.json |
| Windsurf |
~/.codeium/windsurf/mcp_config.json |
| JetBrains |
設置 → AI 助手 → MCP |
| Claude Desktop |
~/.config/Claude/claude_desktop_config.json |
| Claude Code |
claude mcp add corbat -- npx -y @corbat-tech/coding-standards-mcp |
完整設置指南 適用於所有25+種工具
3. 完成! Corbat會自動檢測您的技術棧並應用合適的標準。
零開銷:Corbat在本地運行,檢測您的技術棧大約需要50ms。之後,它只是為AI提供上下文。
完全可定製:如果您不喜歡某個規則,可以在 .corbat.json 中覆蓋它。跳轉至自定義 →
✨ 主要特性
- 解決AI代碼審查難題:AI生成的代碼通常難以通過代碼審查,Corbat MCP通過在AI生成代碼之前注入團隊的編碼標準來解決這個問題。
- 多工具兼容:與GitHub Copilot、Continue、Cline、Tabnine、Amazon Q等25+種工具兼容。
- 自動檢測技術棧:Corbat可以自動檢測您的技術棧並應用合適的標準。
- 可定製性強:支持交互式設置、手動配置和使用模板進行定製。
💻 使用示例
基礎用法
您:"創建一個用戶註冊服務"
沒有使用Corbat時,您會得到:
class UserService {
private users: Map<string, User> = new Map();
register(name: string, email: string, password: string) {
if (!name || !email || !password) throw new Error('Invalid input');
const user = { id: crypto.randomUUID(), name, email, password };
this.users.set(user.id, user);
return user;
}
}
使用Corbat時,您會得到:
interface UserRepository {
save(user: User): Promise<void>;
findByEmail(email: string): Promise<User | null>;
}
class EmailAlreadyExistsError extends Error {
constructor(email: string) {
super(`Email already registered: ${email}`);
}
}
class RegisterUserUseCase {
constructor(
private readonly repository: UserRepository,
private readonly hasher: PasswordHasher
) {}
async execute(input: RegisterUserInput): Promise<User> {
const existing = await this.repository.findByEmail(input.email);
if (existing) throw new EmailAlreadyExistsError(input.email);
const user = User.create({
...input,
password: await this.hasher.hash(input.password)
});
await this.repository.save(user);
return user;
}
}
describe('RegisterUserUseCase', () => {
const repository = { save: vi.fn(), findByEmail: vi.fn() };
const hasher = { hash: vi.fn() };
const useCase = new RegisterUserUseCase(repository, hasher);
beforeEach(() => vi.clearAllMocks());
it('should hash password before saving', async () => {
repository.findByEmail.mockResolvedValue(null);
hasher.hash.mockResolvedValue('hashed_password');
await useCase.execute({ name: 'John', email: 'john@test.com', password: 'secret' });
expect(hasher.hash).toHaveBeenCalledWith('secret');
expect(repository.save).toHaveBeenCalledWith(
expect.objectContaining({ password: 'hashed_password' })
);
});
it('should reject duplicate emails', async () => {
repository.findByEmail.mockResolvedValue({ id: '1', email: 'john@test.com' });
await expect(
useCase.execute({ name: 'John', email: 'john@test.com', password: 'secret' })
).rejects.toThrow(EmailAlreadyExistsError);
});
});
這就是“一次通過代碼審查”的樣子。
📚 詳細文檔
Corbat強制執行的標準
Corbat在代碼生成之前注入以下規則:
代碼質量
| 規則 |
重要性 |
| 每個方法最多20行 |
函數可讀、可測試且功能單一 |
| 每個類最多200行 |
遵循單一職責原則 |
| 使用有意義的名稱 |
避免使用 data、info、temp、x 等 |
| 避免使用魔法數字 |
使用具有描述性名稱的常量 |
架構
| 規則 |
重要性 |
| 使用接口處理依賴 |
代碼可測試,易於模擬 |
| 分層分離 |
領域邏輯與基礎設施分離 |
| 六邊形/整潔架構模式 |
業務規則與框架無關 |
錯誤處理
| 規則 |
重要性 |
| 使用自定義異常 |
如 UserNotFoundError 而非 Error('not found') |
| 包含錯誤上下文 |
在錯誤中包含ID、值、狀態等信息 |
| 避免空的catch塊 |
處理或傳播每個錯誤 |
安全(根據OWASP Top 10驗證)
| 規則 |
重要性 |
| 輸入驗證 |
在邊界處拒絕無效數據 |
| 不使用硬編碼的秘密 |
僅使用環境變量 |
| 使用參數化查詢 |
防止SQL注入 |
| 輸出編碼 |
防止XSS攻擊 |
基準測試結果v3.0
我們在6種語言的15個實際場景中對Corbat進行了評估。
關鍵洞察
Corbat生成聚焦、可用於生產的代碼 — 而非冗長的樣板代碼:
| 場景 |
使用Corbat |
不使用Corbat |
意義 |
| Kotlin協程 |
236行 |
1,923行 |
相同功能,維護量減少8倍 |
| Java六邊形架構 |
623行 |
2,740行 |
簡潔架構,無冗餘 |
| Go整潔架構 |
459行 |
2,012行 |
地道的Go代碼,而非Java風格的Go代碼 |
| TypeScript NestJS |
395行 |
1,554行 |
正確的模式,合適的規模 |
這並非“為了減少代碼而減少代碼” — 而是採用了正確的抽象,避免過度設計。
價值指標
當我們衡量生產代碼真正重要的指標時:
| 指標 |
結果 |
意義 |
| 代碼減少 |
67% |
減少維護、審查和調試的工作量 |
| 安全性 |
100% |
在所有場景中均無漏洞 |
| 可維護性 |
93%優勢 |
更易於理解和修改 |
| 架構效率 |
87%優勢 |
每行代碼具有更好的模式 |
| 認知負擔 |
-59% |
新開發人員的入職速度更快 |
📊 詳細價值分析
安全:未檢測到漏洞
每個場景都使用模式檢測對OWASP Top 10漏洞進行了分析:
- ✓ 無SQL/NoSQL注入模式
- ✓ 無XSS漏洞
- ✓ 無硬編碼憑證
- ✓ 在所有邊界進行輸入驗證
- ✓ 正確的錯誤消息(不向用戶顯示堆棧跟蹤)
測試的語言和模式
| 語言 |
場景 |
模式 |
| ☕ Java |
5 |
Spring Boot、DDD聚合、六邊形架構、Kafka事件、Saga |
| 📘 TypeScript |
4 |
Express REST、NestJS整潔架構、React組件、Next.js全棧 |
| 🐍 Python |
2 |
FastAPI CRUD、存儲庫模式 |
| 🐹 Go |
2 |
HTTP處理程序、整潔架構 |
| 🦀 Rust |
1 |
Axum與存儲庫特徵 |
| 🟣 Kotlin |
1 |
協程 + 策略模式 |
📖 完整基準測試方法 · 價值分析
內置配置文件
Corbat會自動檢測您的技術棧並應用合適的標準:
| 配置文件 |
技術棧 |
您將獲得 |
java-spring-backend |
Java 21 + Spring Boot 3 |
六邊形 + DDD,TDD覆蓋率80%以上 |
kotlin-spring |
Kotlin + Spring Boot 3 |
協程,Kotest + MockK |
nodejs |
Node.js + TypeScript |
整潔架構,Vitest |
nextjs |
Next.js 14+ |
應用路由模式,服務器組件 |
react |
React 18+ |
鉤子,測試庫,可訪問組件 |
vue |
Vue 3.5+ |
組合式API,Vitest |
angular |
Angular 19+ |
獨立組件,Jest |
python |
Python + FastAPI |
異步模式,pytest |
go |
Go 1.22+ |
地道的Go代碼,表驅動測試 |
rust |
Rust + Axum |
所有權模式,proptest |
csharp-dotnet |
C# 12 + ASP.NET Core 8 |
整潔 + CQRS,xUnit |
flutter |
Dart 3 + Flutter |
BLoC/Riverpod,小部件測試 |
自動檢測:Corbat會讀取 pom.xml、package.json、go.mod、Cargo.toml 等文件。
使用場景
| 使用場景 |
Corbat的幫助 |
| 開始新項目 |
從第一天起就採用正確的架構 |
| 有初級開發者的團隊 |
每個人都能產出高級水平的代碼模式 |
| 嚴格的代碼審查標準 |
AI生成的代碼自動符合您的標準 |
| 受監管的行業 |
保證一致的安全性和文檔 |
| 遺留系統現代化 |
新代碼遵循現代模式 |
何時可能不需要Corbat
- 對質量要求不高的快速原型
- 一次性腳本,用完即棄
- 用於學習的項目,您希望犯錯誤
🔧 技術細節
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ 您的提示 │────▶│ Corbat MCP │────▶│ AI + 規則 │
└─────────────┘ └──────┬──────┘ └─────────────┘
│
┌──────────────┼──────────────┐
▼ ▼ ▼
┌────────────┐ ┌────────────┐ ┌────────────┐
│ 1. 檢測 │ │ 2. 加載 │ │ 3. 注入 │
│ 技術棧 │ │ 配置文件 │ │ 規則 │
└────────────┘ └────────────┘ └────────────┘
pom.xml 六邊形架構 每個方法最多20行
package.json + DDD + 接口
go.mod + SOLID + 自定義錯誤
Corbat不會修改AI的輸出 — 它確保AI在生成代碼之前瞭解您的標準。
重要提示:Corbat為AI提供上下文和指導方針。實際的代碼質量取決於AI模型遵循這些指導方針的程度。在我們的測試中,Claude和GPT - 4等模型始終遵循這些規則。
📄 許可證
本項目採用 MIT許可證。
文檔資源
| 資源 |
描述 |
| 設置指南 |
適用於Cursor、VS Code、JetBrains等25+種工具的安裝說明 |
| 模板 |
現成的 .corbat.json 配置 |
| 兼容性 |
支持的AI工具完整列表 |
| 基準測試分析 |
15個場景的詳細結果 |
| API參考 |
工具、提示和配置選項 |
停止修復AI代碼,開始交付代碼。
添加到您的MCP配置中,即可完成設置:
{ "mcpServers": { "corbat": { "command": "npx", "args": ["-y", "@corbat-tech/coding-standards-mcp"] }}}
您的代碼審查工作會感謝您。
由 corbat-tech 開發