规则集MCP
人工智能车轮上的重量:让每个代理人都遵守你的项目规则。
RulesetMCP是一个模型上下文协议(MCP)服务器,它为AI代理提供了一个项目感知规则手册。每次打开新的AI会话时,您都可以在版本控制文件中定义它们,而不是解释您的编码标准、SQL约定或流程指南。RulesetMCP读取这些文件,并公开用于列出、汇总和将规则应用于特定任务和代码段的工具。
问题
现在你可能:
- ✋ 每次会话对AI重复相同的上下文(“SQL关键字使用大写字母”)
- 📝 维护人工智能无法轻易查询的分散文档
- 🔄 重新解释不同AI工具的架构决策
- ⚠️ 希望AI能记住你的项目惯例
解决方案
RulesetMCP就像人工智能助手的“车轮上的重量”开关:一旦你的规则被加载,每个动作都以它们为基础。这使您的重写、重构和新功能与您已经做出的架构和流程决策保持一致。
特性
- 🔍 项目发现 通过
list_projects - 📋 结构化规则 来自Markdown和YAML
- 🎯 上下文查询 随着
get_rules(按区域、标签、严重程度过滤) - 📊 以任务为导向的总结 随着
summarize_rules_for_task - ✅ 代码段验证 随着
validate_snippet - 🔄 热重载 规则与
reload_rules - 🌐 通用兼容性 通过MCP协议(适用于Claude Code、Claude Desktop和任何兼容MCP的客户端)
快速开始
1.安装
npm install -g rulesetmcp或者克隆并在本地构建:
git clone https://github.com/n8daniels/RulesetMCP.git
cd RulesetMCP
npm install
npm run build2.创建配置
创建 rulesetmcp.config.json 在您的工作空间中:
{
"projects": [
{
"id": "my-api",
"name": "My API Project",
"paths": ["/path/to/my-api"],
"rulesPaths": ["rules/", "docs/rules/"]
}
],
"defaultProjectId": "my-api"
}3.添加规则
创建 rules/RULES.md 在您的项目中:
# My API - Coding Standards
## [api-naming-001] RESTful endpoint naming
**Area:** api
**Severity:** warn
**Tags:** api, rest, naming
**Description:**
All REST endpoints must use plural nouns and follow `/api/v1/{resource}` pattern.
**Good Example:**GET/api/v1/用户 POST/api/v1/订单
**Bad Example:**GET/api/getUser POST/api/创建订单
4.配置您的MCP客户端
克劳德桌面(claude_desktop_config.json):
{
"mcpServers": {
"rulesetmcp": {
"command": "rulesetmcp",
"args": ["--config", "/path/to/rulesetmcp.config.json"]
}
}
}克劳德代码(.claude/settings.json):
{
"mcp": {
"rulesetmcp": {
"command": "rulesetmcp",
"args": ["--config", "/path/to/rulesetmcp.config.json"]
}
}
}5.使用它!
现在,当你使用AI时:
You: "Refactor this SQL stored procedure to pull more data from the users table"
AI: [Calls get_rules for project="my-api", area="sql"]
AI: "Based on your project's SQL rules, I'll ensure:
- All keywords are UPPER-CASE
- Identifiers use lower_case
- Proper indexing hints are included
Here's the refactored procedure..."规则格式
RulesetMCP支持多种格式:
Markdown(RULES.md)
## [rule-id] Rule Title
**Area:** sql
**Severity:** error
**Tags:** formatting, style
**Description:** What the rule requires
**Rationale:** Why this matters
**Good Example:**SELECT * FROM users;
**坏例子:**
select * from Users;
YAML (rules/*.yaml)
- id: sql-format-001
project: my-api
area: sql
title: SQL casing convention
description: All SQL must use UPPER-CASE keywords and lower_case identifiers
severity: warn
tags: [sql, style, formatting]
examples:
good: |
SELECT u.user_id FROM users u;
bad: |
select UserID from Users;
appliesTo:
- "*.sql"
- "procedures/*"MCP工具
list_projects
发现可用项目及其规则集。
get_rules
按项目、区域、标签或严重性查询规则。
validate_snippet
根据项目规则验证代码/SQL/config并获取修复建议。
summarize_rules_for_task
在开始工作之前,对相关规则进行任务导向的总结。
reload_rules
编辑磁盘上的文件后的热重新加载规则。
哲学
RulesetMCP体现了 “车轮上的重量” 原则:就像飞机一旦停飞就不能忽视物理一样,一旦RulesetMCP启用,人工智能代理也不应该忽视项目的规则。
这不仅仅是文件 -它是:
- ✅ 机器可读和可查询
- ✅ 版本由您的代码控制
- ✅ 可通过验证工具执行
- ✅ 适用于所有MCP兼容的AI工具
例子
请参阅 examples/ 完整示例项目的目录:
nodejs-api/-使用TypeScript标准的REST APIpython-django/-具有安全规则的Django项目dotnet-webapi/- .NET API的体系结构模式
用例
SQL标准化
- id: sql-format-001
area: sql
title: SQL keyword casing
description: All SQL keywords UPPER-CASE, identifiers lower_case
severity: warn安全护栏
- id: security-001
area: security
title: No hardcoded secrets
description: Use environment variables or secure vaults
severity: blocker体系结构模式
- id: arch-http-001
area: architecture
title: Use HttpClientFactory
description: Never instantiate HttpClient directly
severity: error迁移规则
- id: migration-001
area: migration
title: Preserve backward compatibility
description: When refactoring API endpoints, maintain old routes with redirects
severity: blocker路线图
- \[x\] 第一阶段:配备基本工具的核心MCP服务器
- \[x\] 第二阶段:多格式规则加载(Markdown、YAML)
- \[\]第3阶段:使用模式匹配进行高级验证
- \[\]第4阶段:LLM辅助规则违规检测
- \[\]第5阶段:用于内联提示的VSCode扩展
- \[\]第6阶段:预提交挂钩和CI/CD集成
- \[\]社区规则包(OWASP、谷歌风格指南等)
贡献
欢迎投稿!请看 贡献.md 作为指导方针。
从源头构建
npm install
npm run build
npm start许可证
MIT许可证-请参阅 许可证
支持
- 问题: https://github.com/n8daniels/RulesetMCP/issues
- 讨论: https://github.com/n8daniels/RulesetMCP/discussions
- MCP社区: https://discord.gg/anthropic
______________________________________________________________________
内置于❤️ 对于厌倦了向人工智能重复自己的开发人员
*“停止解释。开始执行。”*
