Skip to main content
Glama
Carl-jcc

Code Review Workflow MCP Server

by Carl-jcc

Code Review Workflow — MCP 端到端代码审查流水线

基于 MCP(Model Context Protocol)协议的代码审查工作流,演示如何用标准化协议构建 AI 工具流水线。

架构

用户请求 "检查代码" 
    │
    ▼
┌──────────────┐     ┌──────────────────────────┐
│ code_reader  │     │ code_checker             │
│ MCP Server   │     │ MCP Server               │
├──────────────┤     ├──────────────────────────┤
│ read_code    │ →  │ check_style   检查规范    │
│ 读取代码文件  │     │ generate_report 生成报告  │
└──────────────┘     └──────────────────────────┘
    │                        │
    └────────┬───────────────┘
             ▼
      端到端流水线:读文件 → 检查 → 报告

Related MCP server: Teams Guide MCP

项目结构

code-review-workflow/
├── shared/                    # 共享 MCP 协议栈
│   ├── jsonrpc.js             # JSON-RPC 2.0 编解码
│   ├── dispatcher.js          # 消息路由
│   ├── framing.js             # stdio 字节流分帧
│   ├── session.js             # 生命周期状态机
│   ├── registry.js            # 工具注册表
│   └── errors.js              # 统一错误处理
│
├── code_reader/               # MCP Server 1:代码读取
│   └── server.js
│       └── read_code          接收文件路径 → 返回文件内容
│
├── code_checker/              # MCP Server 2:代码检查
│   └── server.js
│       ├── check_style        接收代码文本 → 检查规范问题
│       └── generate_report    接收检查结果 → 生成格式化报告
│
└── README.md

快速开始

环境要求

  • Node.js 20+

测试 Server 1:code_reader

cd code-review-workflow
node -e "
import { spawn } from 'child_process';
import { createFramer } from './shared/framing.js';
import { encodeRequest, encodeNotification, decode, MessageType } from './shared/jsonrpc.js';
import { Session, PROTOCOL_VERSION } from './shared/session.js';
import { fileURLToPath } from 'url';

// ... (完整测试代码见 examples/end_to_end_test.js)
"

检查规则

规则

说明

console.log 检测

生产代码不应保留调试输出

TODO/FIXME 检测

待完成事项需要跟踪

行长检测

超过 100 字符的行影响可读性

技术栈

  • 协议: MCP (Model Context Protocol) + JSON-RPC 2.0

  • 传输: stdio (stdin/stdout)

  • 运行时: Node.js (纯 JavaScript,零依赖)

  • 协议栈: 基于 mcp-from-scratch 的 6 层架构

面试要点

这个项目展示了:

  1. 标准化: 两个 MCP Server 通过统一的 JSON-RPC 协议通信

  2. 端到端: 读文件 → 检查规范 → 生成报告,完整流水线

  3. 工具开发: 手写 MCP 工具定义(inputSchema)+ 执行函数(handler)

  4. 协议理解: 底层掌握 handshake / tools/list / tools/call 全流程

License

MIT

Related MCP Connectors

Related MCP Servers

  • F
    license
    A
    quality
    D
    maintenance
    Enables Claude to perform thorough code reviews by integrating with Codex and Gemini CLIs to provide senior-level feedback on code quality, security, performance, and best practices. Supports reviewing code snippets, individual files, or entire directories with automatic detection of available review tools.
    4
    -
  • A
    license
    Not graded
    quality
    C
    maintenance
    Enables AI-powered, zero-trust code review with multiple models, supporting single files, git diffs, and multiple files, with security, performance, and architecture checks across 10+ languages.
    13
    MIT
  • F
    license
    Not graded
    quality
    C
    maintenance
    Enables AI agents to scan codebases for TODO/FIXME/XXX patterns and get prioritized results over MCP, supporting CI gates and multiple output formats.
    -