使用模型上下文协议(Model Context Protocol)分析并生成React代码文档。基于react-analyzer库。
此工具分析React组件文件(JSX/TSX),提取组件及其属性的信息。
# 克隆仓库
git clone https://github.com/azer/react-analyzer-mcp.git
cd react-analyzer-mcp
# 安装依赖
npm install
# 更新 src/index.ts 文件中的 PROJECT_ROOT。
vim src/index.ts
# 构建
npm run build
{
"react-analyzer-mcp": {
"command": "node",
"args": [
"/Users/azer/code/sandbox/react-analyzer-mcp/build/index.js"
]
}
}
使用Claude Shell连接到你的MCP服务器。
直接在Claude对话中使用这些工具:
分析我“ui”文件夹中的React组件。
或者:
我在项目中有哪些React组件?
输入:
你能分析一下我的“foobar”文件夹中的组件吗?
输出:
# 组件
## 按钮
### 属性
| 属性 | 类型 | 可选 | 默认值 |
|------|------|------|--------|
| `variant` | `string` | ✓ | `primary` |
| `size` | `string` | ✓ | `md` |
| `onClick` | `function` | ✓ | |
...
MIT </中文翻译>