README 生成器 MCP 服务器
📝 描述
一个模型上下文协议(MCP)服务器,它使大型语言模型(LLMs)能够自动分析项目结构并生成全面、格式良好的README文件。该服务器提供了智能项目分析、技术检测和README生成功能,帮助开发者快速创建专业文档。
🛠️ 使用的技术
- Node.js
- TypeScript
- MCP SDK(@modelcontextprotocol/sdk)
✨ 特点/功能
- 自动技术检测识别Node.js、TypeScript、Python、Rust、Go、Java、Docker等
- 智能项目分析从 package.json、依赖项、脚本和配置文件中提取元数据
- 目录结构扫描递归遍历,支持可配置深度和智能忽略模式
- 丰富的README生成创建带有徽章、表情符号、适当部分和代码块的专业README文件
- 灵活的模板系统预定义结构,包含必填和可选部分
- 多语言支持支持多种编程语言和框架
📦 安装
npm install🔧 设置
1. 构建服务器
npm run build2. 配置Claude桌面版
将此服务器添加到您的Claude Desktop配置文件中:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json Windows: %APPDATA%\Claude\claude_desktop_config.json Linux: ~/.config/Claude/claude_desktop_config.json
{
"mcpServers": {
"readme-generator": {
"command": "node",
"args": ["/absolute/path/to/mcp/build/index.js"]
}
}
}3. 重启Claude桌面版
添加配置后,重启 Claude Desktop 以加载 MCP 服务器。
克劳德代码CLI
要将此MCP服务器添加到Claude Code CLI中:
# With node (after build)
claude mcp add readme-generator --scope user -- node
/build/index.js
# With npx and TypeScript (development mode)
claude mcp add readme-generator --scope user -- npx -y tsx
/src/index.ts替换 包含此MCP服务器的绝对路径。
范围选项:
--scope user在您的所有项目中均可使用(推荐)--scope project通过(某种方式)与项目中的所有人共享.mcp.json--scope local仅限当前项目
有用的命令:
claude mcp list # Show all configured servers
claude mcp remove readme-generator # Remove the server
/mcp # Show server status in Claude CodeGemini 命令行界面 (CLI)
要将此MCP服务器添加到Gemini CLI,请编辑配置文件:
文件位置: ~/.config/gemini/settings.json
添加服务器配置:
{
"mcpServers": {
"readme-generator": {
"command": "node",
"args": ["
/build/index.js"]
}
}
}替换 带有此MCP服务器的绝对路径。
使用 TypeScript 的替代方案(开发模式):
{
"mcpServers": {
"readme-generator": {
"command": "npx",
"args": ["-y", "tsx", "
/src/index.ts"]
}
}
}🚀 使用方法
可用脚本
npm run build编译TypeScript并生成可执行文件
npm run watch监控变化并自动重新编译
npm run prepare在npm发布前自动运行构建
可用的MCP工具
该服务器为大型语言模型(LLMs)提供了四种工具:
1. read_project_structure
读取项目的目录结构并返回一个树状结构。
示例:
{
"path": "/home/user/my-project",
"maxDepth": 3
}2. read_file
读取特定文件的内容。
示例:
{
"path": "/home/user/my-project/package.json"
}3. analyze_project
分析项目目录并返回结构化数据,包括检测到的技术、依赖项、脚本和目录结构。
示例:
{
"projectPath": "/home/user/my-project"
}4. generate_readme
为项目自动生成一个完整、专业的README.md文件。
示例:
{
"projectPath": "/home/user/my-project"
}💡 使用示例
快速生成README文件
一旦在Claude Desktop中配置好MCP服务器,只需询问:
"Generate a README for my project at /home/user/my-awesome-app"服务器将:
- 分析项目目录
- 检测技术(Node.js、Python、Rust 等)
- 从配置文件中提取元数据
- 生成一个包含适当部分的专业README文件
项目详细分析
为了对过程拥有更多控制权:
"Analyze the project at /home/user/my-awesome-app and show me what you found"审查分析结果,然后提出请求:
"Now generate a README emphasizing the API documentation and deployment sections"分步工作流程
对于需要定制的复杂项目:
- 探索结构:
"Read the project structure of /home/user/my-app with depth 4"- 审查特定文件:
"Read the package.json and show me the available scripts"- 获取全面分析:
"Analyze the entire project and tell me what technologies you detected"- 生成自定义的README文件:
"Create a README with extra focus on the testing and contribution guidelines"现实世界中的例子
User: "I have a TypeScript Express API project at /home/user/projects/api-server.
Can you create a README for it?"
Claude: [Uses the MCP server to analyze the project]
"I've analyzed your project and found:
- TypeScript with Express.js
- PostgreSQL database integration
- Jest for testing
- Docker configuration
I'll create a comprehensive README with sections for setup,
API endpoints, database configuration, and deployment."生成的 README 文件将自动包含:
- 适用于TypeScript、Node.js等的合适徽章。
- 基于 package.json 的安装说明
- 所有可用的 npm 脚本及其描述
- 项目结构可视化
- 依赖项和开发依赖项
- API使用示例(如检测到)
- Docker 部署说明(如果存在 Dockerfile)
📁 项目结构
mcp/
package-lock.json
package.json
src/
index.ts
tsconfig.json🎨 定制化
修改README模板
编辑 README_TEMPLATE 在 src/index.ts:12-66 自定义部分:
const README_TEMPLATE = {
sections: [
{
name: "Project Title",
description: "The main title/name of the project",
required: true,
},
{
name: "Your Custom Section",
description: "Description of what this section should contain",
required: false,
},
// Add more sections as needed
],
};添加技术检测
延长/扩展 analyzeProject 函数 in src/index.ts:126-214 检测其他框架:
if (files.includes("docker-compose.yml")) {
detectedTechnologies.push("Docker Compose");
configFiles.push("docker-compose.yml");
}修改后,重新构建:
npm run build📚 依赖项
- @modelcontextprotocol/sdk(可译为):“模型上下文协议SDK”或“模型上下文协议开发工具包”
🔧 开发依赖
- @types/node 翻译成中文是:“Node.js 类型定义”
- TypeScript
📖 工作原理
- 项目扫描递归读取项目目录(忽略 node_modules、.git、dist、build)
- 技术检测基于配置文件(如 package.json、tsconfig.json、Cargo.toml 等)识别技术
- 元数据提取从 package.json 中提取信息,包括脚本、依赖项、作者、许可证
- 模板应用使用预定义的模板结构,包含必填和可选部分
- README文件生成创建一个带有徽章、适当章节、代码块和专业样式的格式化README文件
🤝 贡献
欢迎投稿!投稿方式:
- 为仓库创建分支(或:克隆仓库)
- 创建一个特性分支:
git checkout -b feature/my-feature - 进行你的更改并测试它们
- 提交您的更改:
git commit -m 'Add my feature' - 推送至分支:
git push origin feature/my-feature - 提交拉取请求
📄 许可证
此项目采用ISC许可证授权。
______________________________________________________________________
*这个README文件是使用README生成器MCP服务器本身生成的! 🎉*
