🦀 MCP上下文锈蚀
用Rust编写的多语言模型上下文协议(MCP)服务器,为AI助手提供智能上下文分析和代码模式训练。支持Rust、Node.js、Python、Go、Java、PHP和。NET项目。
   
______________________________________________________________________
📋 项目状态
这是一个功能强大的MCP服务器,用于Claude Desktop的上下文强化和代码模式训练。 ✅ 阶段0完成: 安全强化,符合MCP协议,通过42项测试。 该项目探索了人工智能助理的高级上下文管理模式和培训机制。将其用作MCP实现的参考,或将概念适应您自己的项目。 📊 诚实评价: 这真的能节省时间吗? | 🛣️ 未来计划: 见路线图
✨ 特性
核心功能
- 🌐 多语言支持:用7+种语言分析项目
- 锈 (Cargo.toml) - actix-web, axum, 东京 - Node.js (package.json)-React、Vue、Next.js、Express、Svelte - python (pyproject.toml)-Django、Flask、FastAPI - 去 (go.mod)-杜松子酒,纤维 - Java (pom.xml)-Spring,Gradle - PHP程序 (composer.json)-Laravel、Symfony、WordPress - .NET (.csproj)-访问字符串,ASP。NET核心
- 🔍 深度代码分析:解析项目文件,使用树状图分析代码,检测依赖关系
- 📚 27+内置图案:各种发展方案的最佳做法
- 🔄 生命周期(6种模式) - ⚡ 性能(5种模式) - 🌐 JavaScript互操作(4种模式) - 📡 数据和API(4种模式) - 🔒 安全(4种模式) - 💉 依赖注入(2种模式) - 📦 状态管理(2种模式)
- 🎓 模式训练:增量学习系统-添加自己的模式
- 🎯 上下文感知:基于项目分析的智能建议
- 🦀 防锈性能:比Python等效程序快10倍
- 🔌 MCP本地:与Claude Desktop和其他MCP客户端配合使用
安全与质量
- 🔒 自动安全扫描:货物审计与RustSec数据库集成(861条建议)
- ✅ 零已知漏洞:已验证159个依赖关系,未发现任何问题
- 🔍 不安全代码检测:CI/CD中的货物盖革监测
- 📋 持续集成:GitHub Actions工作流,包括安全、lint、格式和测试检查
- 📊 代码质量:简洁迂腐的lints,通过42项测试,结构化跟踪日志记录
- 🛡️ 输入验证:路径遍历保护,经过净化的输入
🦀 为什么是Rust?
| 特性 | Rust实现 | Python等效 |
|---|---|---|
| 启动时间 | 50ms | 300ms |
| 分析时间 | 120ms | 1.2s |
| 内存使用量 | 8MB | 45MB |
| 二进制大小 | 3MB | 40MB+数据 |
- ⚡ 快10倍 比Python实现
- 🔒 内存安全 -零碰撞或泄漏
- 📦 单一二进制 -无运行时依赖关系
- 🚀 并发 -高效的异步请求处理
- 🎯 本地解析 -树保姆集成
🚀 快速开始
先决条件
- 锈蚀1.70+ (安装Rust)
安装
# Clone the repository
git clone https://github.com/scopweb/mcp-context-rust.git
cd mcp-context-rust
# Build release binary
cargo build --release
# Binary location:
# Windows: target/release/mcp-context-rust.exe
# Linux/Mac: target/release/mcp-context-rustClaude桌面配置
视窗
编辑: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"context-rust": {
"command": "C:\\path\\to\\mcp-context-rust\\target\\release\\mcp-context-rust.exe",
"args": [],
"env": {
"MCP_PATTERNS_PATH": "C:\\path\\to\\mcp-context-rust\\data\\patterns"
}
}
}
}Linux/Mac
编辑: ~/.config/Claude/claude_desktop_config.json
{
"mcpServers": {
"context-rust": {
"command": "/path/to/mcp-context-rust/target/release/mcp-context-rust",
"args": [],
"env": {
"MCP_PATTERNS_PATH": "/path/to/mcp-context-rust/data/patterns"
}
}
}
}重要提示: 在配置中使用绝对路径。
重新启动克劳德桌面
关闭并重新打开Claude Desktop以加载MCP服务器。
______________________________________________________________________
📖 用法
分析项目
You: Analyze my project at C:\Projects\MyLaravelApp
Claude → calls analyze-project tool
Server → detects PHP/Laravel, parses composer.json, finds Vue frontend
Claude → shows structure, dependencies, framework-specific suggestions支持的项目:
- Rust、Node.js、Python、Go、Java、PHP。网
- 自动检测框架(Laravel、React、Django、Spring等)
获取代码模式
You: Show me lifecycle patterns
Claude → calls get-patterns tool
Server → returns relevant patterns with code examples
Claude → explains best practices搜索模式
You: Find patterns for async initialization
Claude → calls search-patterns tool
Server → intelligent search with scoring
Claude → shows most relevant patterns培养新模式
You: Save this as a best practice for error handling:
[your code example]
Claude → calls train-pattern tool
Server → stores pattern with metadata
Claude → confirms pattern saved获取统计信息
You: Show pattern database stats
Claude → calls get-statistics tool
Server → returns total patterns, categories, frameworks______________________________________________________________________
🛠️ 可用工具
| 工具 | 说明 | 参数 |
|---|---|---|
analyze-project | 分析任何项目(Rust、Node、Python、Go、Java、PHP、.NET) | project_path (字符串) |
get-patterns | 按框架/类别获取模式 | framework (字符串), category (可选) |
search-patterns | 高级模式搜索 | query, framework, category, tags, min_score |
train-pattern | 添加自定义图案 | id, category, framework, title, description, code, tags |
get-statistics | 数据库统计 | 无 |
______________________________________________________________________
🏗️ 建筑
mcp-context-rust/
├── src/
│ ├── main.rs # Entry point
│ ├── lib.rs # Library root (clippy lints, exports)
│ ├── config.rs # Configuration
│ ├── types.rs # Shared types (Project, Dependency, etc.)
│ ├── error.rs # Custom error types (McpError, TrainingError)
│ ├── utils/
│ │ └── mod.rs # Utility functions (hash, truncate)
│ ├── analyzer/
│ │ ├── mod.rs # Analyzer module
│ │ ├── detector.rs # Project type detection
│ │ ├── generic.rs # Multi-language analyzer
│ │ ├── project.rs # Legacy .NET analyzer
│ │ └── csharp.rs # C# tree-sitter parser
│ ├── context/ # Context generation
│ ├── training/ # Pattern management
│ │ └── mod.rs # Training system
│ └── mcp/ # MCP protocol
│ └── mod.rs # Server implementation
├── data/
│ └── patterns/ # Built-in patterns (JSON)
├── tests/ # Integration tests (42 tests)
├── docs/ # Technical documentation
├── Cargo.toml
├── README.md
├── CHANGELOG.md
└── LICENSE______________________________________________________________________
🧪 测试
# Run all tests
cargo test
# Run specific test module
cargo test analyzer
# Test with output
cargo test -- --nocapture
# Manual test (stdio)
echo '{"jsonrpc":"2.0","method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}},"id":1}' | cargo run --release______________________________________________________________________
📚 文档
设置和使用
发展
- 开发指南 -项目架构和开发工作流程
- 使用Rust创建MCP -构建MCP服务器的完整指南
- 图案目录 -所有27+内置图案
- 更新日志 -版本历史
项目状态和规划
______________________________________________________________________
🔒 安全状态
该项目实施了全面的安全扫描:
✅ Automated dependency scanning with cargo-audit
✅ 159 dependencies verified against 861 RustSec advisories
✅ Zero known vulnerabilities found
✅ Continuous monitoring on every push (GitHub Actions)
✅ Daily security checks (2 AM UTC)
✅ Unsafe code detection with cargo-geiger
✅ Code quality enforcement (clippy, fmt)
✅ Comprehensive CI/CD pipeline看 安全_审计_报告.md 查看详细结果。
______________________________________________________________________
🤝 贡献
欢迎投稿!拜托:
- 克隆该仓库
- 创建要素分支(
git checkout -b feature/amazing-feature) - 提交您的更改(
git commit -m 'Add amazing feature') - 推到分支(
git push origin feature/amazing-feature) - 打开拉取请求
添加图案
要贡献新模式:
- 将JSON文件添加到
data/patterns/ - 遵循模式模式
- 测试用
get-statistics工具 - 提交带有图案细节的PR
______________________________________________________________________
📝 许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
______________________________________________________________________
🙏 致谢
______________________________________________________________________
🐛 故障排除
服务器未连接
- 检查克劳德桌面日志:
%APPDATA%\Claude\logs\mcp-server-context-rust.log - 验证可执行路径是否为绝对路径
- 确保
MCP_PATTERNS_PATH指向正确的目录 - 尝试重建:
cargo clean && cargo build --release
未加载图案
# Check patterns directory exists
ls data/patterns/*.json
# Verify environment variable
echo $MCP_PATTERNS_PATH # Linux/Mac
echo %MCP_PATTERNS_PATH% # Windows解析错误
- 检查文件是否采用UTF-8编码
- 验证项目结构是否正确
有关更多帮助,请参阅 MCP_SETUP_GUIDE.md 或者打开一个问题。
______________________________________________________________________
📬 联系
- 问题:
- 讨论:
______________________________________________________________________
由...制作🦀 锈
⭐ 标记此存储库 如果你觉得它有用的话!
