🚀 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 开发