cbuntingde/style-guide-mcp-server
GitHub: cbuntingde/style-guide-mcp-server
一个MCP协议服务器,整合了15+编程语言的风格指南和安全实践,为AI助手提供代码规范知识库服务。
Stars: 0 | Forks: 1
# Style Guide MCP Server
[](https://opensource.org/licenses/MIT)
[](https://nodejs.org/)
[](https://www.typescriptlang.org/)
[](https://modelcontextprotocol.io/)
⚡ 轻量快速的 MCP server,通过智能缓存和优化,为 15+ 种语言提供全面的编程风格指南、安全最佳实践和代码分析。
## 🚀 功能特性
### 📚 全面的风格指南
- **支持 15+ 种语言**:TypeScript, JavaScript, Python, C++, Java, Go, Rust, C#, PHP, Ruby, Swift, Kotlin 等
- **多来源**:Google Style Guides、官方文档、社区最佳实践
- **智能缓存**:具有磁盘持久化和 LRU 淘汰机制的高级 HTTP 缓存
- **优化的 SQLite**:启用 WAL 模式和预处理语句的高性能数据库
- **极速**:22ms 启动时间,支持延迟加载和后台更新
### 🔍 强大的搜索与发现
- **全文搜索**:带索引的跨所有指南优化搜索
- **分类过滤**:按主题查找指南(命名、格式化、安全等)
- **来源对比**:比较不同风格指南的建议
- **上下文感知**:根据您的需求获取相关指南
- **批处理**:并行获取和处理以获得更快的结果
### 🛡️ 安全指南
- **28+ 种漏洞类型**:全面的安全漏洞数据库
- **CWE 参考**:链接到 Common Weakness Enumeration
- **特定语言**:针对每种语言量身定制的安全建议
- **框架覆盖**:React, Node.js, Docker, Kubernetes 安全
### 🔧 代码分析
- **模式匹配**:检测常见的风格违规
- **严重程度**:错误、警告和信息级别的建议
- **自动修复**:自动修复常见问题
- **详细报告**:行号、建议和解释
### 📤 导出功能
- **多种格式**:Markdown, HTML, JSON
- **专业样式**:整洁的文档生成
- **带时间戳的文件**:版本控制的导出
### 🏗️ 架构
### 核心组件
- **MCP Server**:具有异步初始化功能的标准 MCP 协议实现
- **优化数据库**:具有 WAL 模式、连接池和预处理语句的高性能 SQLite
- **缓存 HTTP 客户端**:具有重试逻辑、批处理和磁盘持久化的智能缓存
- **优化内容获取器**:具有智能解析和内容分类的并行获取
- **内存管理器**:具有 LRU 淘汰和清理的自动内存管理
- **代码分析器**:具有自动修复功能的基于模式的代码分析
- **导出管理器**:多格式文档生成
### 性能特性
- **22ms 启动**:通过延迟加载实现闪电般的快速启动
- **内存优化**:自动清理和内存监控
- **HTTP 缓存**:智能缓存减少 80% 以上的冗余请求
- **批处理**:并行操作以提高吞吐量
- **连接池**:优化的数据库连接
### 安全特性
- **输入验证**:全面的验证和清理
- **超时保护**:具有指数退避重试的可配置超时
- **错误处理**:具有适当日志记录的优雅错误处理
- **数据加密**:可选的数据库加密支持
- **速率限制**:可配置的速率限制以提供保护
## 🛠️ 安装
### 前置条件
- Node.js 18 或更高版本
- npm 或 yarn
- 推荐 4GB+ RAM(以获得最佳缓存性能)
### 快速开始
1. **克隆仓库:**
```
git clone https://github.com/cbuntingde/style-guide-mcp-server.git
cd style-guide-mcp-server
```
2. **安装依赖:**
```
npm install
```
3. **构建服务器:**
```
npm run build
```
4. **启动服务器:**
```
npm start
```
## ⚙️ 配置
### 环境变量
```
# Server Configuration
SERVER_NAME=style-guide-server
SERVER_VERSION=1.0.0
LOG_LEVEL=info
# Database Configuration
DATABASE_PATH=./data/styleguides.db
DATABASE_BACKUP_ENABLED=true
DATABASE_ENCRYPTION_ENABLED=false
# Security Configuration
RATE_LIMITING_ENABLED=true
RATE_LIMIT_WINDOW_MS=60000
RATE_LIMIT_MAX_REQUESTS=100
MAX_QUERY_LENGTH=1000
MAX_CODE_LENGTH=10000
# Monitoring Configuration
MONITORING_ENABLED=true
METRICS_INTERVAL=60000
HEALTH_CHECK_INTERVAL=30000
# Caching Configuration
CACHING_ENABLED=true
CACHE_TTL=604800000
CACHE_MAX_SIZE=1000
```
### Claude Desktop 配置
添加到您的 Claude Desktop 配置文件:
**macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
```
{
"mcpServers": {
"style-guide": {
"command": "node",
"args": ["/absolute/path/to/style-guide-mcp-server/build/index.js"]
}
}
}
```
**Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
```
{
"mcpServers": {
"style-guide": {
"command": "node",
"args": ["C:\\absolute\\path\\to\\style-guide-mcp-server\\build\\index.js"]
}
}
}
```
## 📖 使用
### MCP 资源
通过 URI 方案直接访问风格指南:
- **`style-guide://{language}`** - 某种语言的完整风格指南
- **`best-practices://{language}`** - 按类别组织的最佳实践
- **`security://all`** - 所有安全指南和漏洞
### MCP 工具
#### 搜索指南
```
{
"name": "search_guidelines",
"arguments": {
"query": "naming conventions",
"language": "typescript"
}
}
```
#### 分析代码
```
{
"name": "analyze_code",
"arguments": {
"code": "var name = 'John';\nlet age = 30;",
"language": "javascript",
"auto_fix": true
}
}
```
#### 检查安全
```
{
"name": "check_security",
"arguments": {
"vulnerability_type": "SQL injection"
}
}
```
#### 导出指南
```
{
"name": "export_guidelines",
"arguments": {
"language": "python",
"format": "html"
}
}
```
#### 添加自定义指南
```
{
"name": "add_custom_guideline",
"arguments": {
"language": "typescript",
"title": "API Response Types",
"content": "All API responses must have explicit return types",
"category": "types"
}
}
```
## 🧪 开发
### 运行测试
```
# Run all tests
npm test
# Run unit tests only
npm run test:unit
# Generate coverage report
npm run test:coverage
```
### 代码质量
```
# Type checking
npm run type-check
# Linting
npm run lint
# Formatting
npm run format:check
# Security audit
npm audit
```
### 构建
```
# Development build
npm run dev
# Production build
npm run build
```
## 📊 支持的语言
### 核心语言
- **TypeScript** - Google Style Guide, Microsoft Guidelines, Best Practices
- **JavaScript** - Google Style Guide, Airbnb Style Guide, MDN Guide
- **Python** - PEP 8, Google Python Style Guide, Best Practices
- **Java** - Google Java Style Guide, Oracle Conventions
- **C++** - Google C++ Style Guide, C++ Core Guidelines
- **Go** - Effective Go, Go Code Review Comments
- **Rust** - Rust API Guidelines, Rust Book
- **C#** - Microsoft C# Coding Conventions
- **PHP** - PHP-FIG Standards, Best Practices
- **Ruby** - Ruby Style Guide, Best Practices
- **Swift** - Swift API Design Guidelines
- **Kotlin** - Kotlin Coding Conventions
### 框架与技术
- **React** - Security Best Practices, Performance Optimization
- **Vue.js** - Style Guide, Best Practices
- **Angular** - Style Guide, Security Best Practices
- **Node.js** - Security Best Practices, Performance
- **Express.js** - Best Practices, Security
- **Django** - Best Practices, Security
- **Flask** - Best Practices, Security
- **Docker** - Security Best Practices
- **Kubernetes** - Security Best Practices
### 安全覆盖
- **OWASP Top 10** - 全面覆盖
- **注入攻击** - SQL, Command, LDAP Injection
- **XSS** - Cross-Site Scripting 变体
- **CSRF** - Cross-Site Request Forgery
- **身份验证** - Broken Authentication, Session Management
- **加密** - Weak Cryptography, Hardcoded Credentials
- **API 安全** - BOLA, Excessive Data Exposure, Rate Limiting
- **现代威胁** - SSRF, XXE, Container Security
## 🔒 安全
### 安全特性
- **输入验证**:全面的验证和清理
- **网络安全**:超时保护,user-agent headers
- **数据保护**:可选的数据库加密
- **错误处理**:安全错误报告,无信息泄露
- **依赖安全**:定期安全审计
### 支持的漏洞类型
该服务器包含针对 28+ 种漏洞类型的详细指南,包括:
- SQL Injection, Command Injection, LDAP Injection
- Cross-Site Scripting (XSS), DOM-based XSS
- Cross-Site Request Forgery (CSRF), Clickjacking
- Insecure Deserialization, Path Traversal
- Broken Authentication, Session Fixation
- Weak Cryptography, Hardcoded Credentials
- API Security 漏洞
- Server-Side Request Forgery (SSRF)
- XML External Entity (XXE)
- Container Escape, Cloud Misconfigurations
## 📁 项目结构
```
style-guide-mcp-server/
├── src/
│ ├── index.ts # Main entry point with optimized startup
│ ├── config/ # Configuration management with environment variables
│ ├── database/ # Optimized database layer with connection pooling
│ │ └── optimized-db.ts # High-performance SQLite implementation
│ ├── http/ # HTTP client with intelligent caching
│ │ └── cached-client.ts # Cached HTTP client with retry logic
│ ├── fetching/ # Content fetching and parsing
│ │ └── optimized-fetcher.ts # Parallel content processing
│ ├── memory/ # Memory management and optimization
│ │ └── memory-manager.ts # LRU cache and cleanup utilities
│ ├── errors/ # Error handling
│ ├── logging/ # Logging utilities
│ ├── monitoring/ # Health checks and metrics
│ ├── rate-limiting/ # Rate limiting implementation
│ └── validation/ # Input validation
├── tests/
│ ├── setup.ts # Test configuration
│ └── unit/ # Unit tests
│ └── validation.test.ts # Validation tests
├── docs/
│ └── API.md # API documentation
├── scripts/ # Setup and utility scripts
│ ├── setup-github.bat # Windows GitHub setup
│ └── setup-github.sh # Unix GitHub setup
├── data/ # Database storage (gitignored)
├── exports/ # Generated exports (gitignored)
├── build/ # Compiled output (gitignored)
├── package.json # Dependencies and scripts
├── tsconfig.json # TypeScript configuration
├── mcp.json # MCP server configuration
├── LICENSE # MIT License
├── CONTRIBUTING.md # Contribution guidelines
├── SECURITY.md # Security policy
├── CODE_OF_CONDUCT.md # Community guidelines
├── MIGRATION.md # Migration guide
├── example-usage.md # Usage examples
└── README.md # This file
```
## 🚀 部署
### 生产部署
1. **配置环境变量**
2. **构建应用程序**:`npm run build`
3. **使用您首选的方法部署**:
- 直接 Node.js 执行
- Docker 容器
- 进程管理器(PM2, systemd)
### Docker 部署
```
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY build/ ./build/
EXPOSE 3000
CMD ["node", "build/index.js"]
```
## 📚 API 文档
完整的 API 文档可在以下地址获取:
- [API 文档](docs/API.md)
- [示例用法](example-usage.md)
## 🤝 贡献
我们欢迎贡献!详情请参阅我们的[贡献指南](CONTRIBUTING.md)。
### 开发流程
1. Fork 本仓库
2. 创建一个功能分支
3. 进行您的更改
4. 为新功能添加测试
5. 确保所有测试通过
6. 提交 pull request
### 代码标准
- 遵循企业编码标准
- 为所有文件添加标头
- 包含全面的测试
- 更新文档
## 📄 许可证
Copyright 2025 Chris Bunting
保留所有权利。
本项目根据 MIT 许可证授权 - 详见 [LICENSE](LICENSE) 文件。
## 🆘 支持
如需支持和提问:
- **文档**:[完整文档](docs/)
- **问题**:[GitHub Issues](https://github.com/cbuntingde/style-guide-mcp-server/issues)
- **示例**:[示例用法](example-usage.md)
- **安全**:[安全策略](SECURITY.md)
## 🗺️ 路线图
- [ ] 增加语言支持(Lua, Dart, Scala)
- [ ] 带 AI 建议的高级代码分析
- [ ] 团队协作功能
- [ ] 用于自定义分析器的插件系统
- [ ] 与风格指南来源的实时同步
- [ ] 多租户支持
- [ ] 高级报告和分析
- [ ] 用于高级集成的 GraphQL API
- [ ] 用于监控和管理的 Web 仪表板
## ✅ 最新改进 (v2.0)
- ⚡ **22ms 启动时间**(从数秒缩短)
- 🧠 **智能内存管理**,具有自动清理功能
- 🌐 **高级 HTTP 缓存**,减少 80% 以上的冗余请求
- 🗄️ **优化的数据库**,具有 WAL 模式和连接池
- 🔄 **重试逻辑**,用于网络请求的指数退避
- 📊 **性能监控**和内存使用跟踪
- 🛡️ **增强的安全性**,具有全面的输入验证
## 🙏 致谢
- Google Style Guides 提供全面的风格指南
- OWASP 提供安全最佳实践
- MCP 社区进行协议开发
- 本项目的所有贡献者和用户
**用 ❤️ 为开发者社区构建**
**仓库**:https://github.com/cbuntingde/style-guide-mcp-server
**问题**:https://github.com/cbuntingde/style-guide-mcp-server/issues
**讨论**:https://github.com/cbuntingde/style-guide-mcp-server/discussions
标签:AI编程辅助, GNU通用公共许可证, Google风格指南, IPv6支持, MCP服务器, MITM代理, Model Context Protocol, Node.js, SQLite, TypeScript, 云安全监控, 代码分析, 代码安全, 代码风格指南, 全文搜索, 凭证管理, 多语言支持, 威胁情报, 安全插件, 安全最佳实践, 安全测试框架, 开发者工具, 横向移动, 漏洞枚举, 缓存优化, 编程规范, 自动化攻击, 请求拦截, 静态分析