代码标准执行服务器

自动执行团队编码标准的AI辅助开发工具,确保代码一致性并支持多种编程语言。

  • by manasvi-turing
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 manasvi-turing/coding-standards-mcp

使用说明

MCP服务器编码标准

在人工智能辅助开发中自动执行团队编码标准

🎯 这有什么作用

您的AI助手(Cursor、Claude等)在生成代码时将自动遵循团队的编码标准。

优点:

  • ✅ 整个团队的代码一致
  • ✅ 不再提醒AI你的标准
  • ✅ 集中标准-一次更新,适用于所有地方
  • ✅ 适用于Python、Java、Node.js、React等

📖 阅读博客文章:从AI编码混乱到团队标准 -了解基于文件的标准所面临的挑战,以及为什么MCP可能是团队的理想解决方案(截至目前,环境变化非常快)。


🚀 如何使用

步骤1:将MCP服务器添加到游标

编辑 ~/.cursor/mcp.json (如果不存在则创建):

{
  "mcpServers": {
    "coding-standards": {
      "name": "Coding Standards",
      "description": "IMPORTANT: Before generating ANY code, ALWAYS check this server for coding standards. Provides mandatory team coding standards, style guides, best practices, and patterns for Python, Java, Node.js, React/Next.js, JavaScript, general coding, and debugging. Call get_coding_standard() with the language name before writing code to ensure compliance with team standards. And always use the engineering manager ai tool to get the coding standards before writing code.",
      "url": "https://web-production-ad318.up.railway.app/sse"
    }
  }
}

步骤2:重新启动游标

关闭并重新打开游标。就是这样! 🎉


✨ 运作原理

自动模式(推荐):

开始编码吧!AI将:

  1. 检测您正在使用的语言
  2. 自动获取团队的标准
  3. 生成符合您规则的代码

手动模式:

问AI:

  • “向我展示Python编码标准”
  • “列出所有可用的编码标准”
  • “我们的React最佳实践是什么?”

📋 可用标准

服务器提供以下标准:

类别 可用标准
强制性的 代码复杂性(适用于所有代码)
将军 调试、开发过程、服务器操作
python 通用Python、FastAPI
Node.js 通用Node.js、Express.js
反应 React和Next.js

问AI: “列出所有可用的编码标准” 查看带有描述的完整列表。


🔧 可用的MCP工具

AI可以使用这些工具:

  • list_coding_standards() -查看所有标准(强制性与可选性)
  • get_coding_standard(category, name) -获取具体标准
  • get_standards_for_project([languages]) -获得多语言标准

你不需要手动调用这些——人工智能知道什么时候使用它们!


💡 快速提示

想要AI遵循特定的标准吗?

"Use our FastAPI standards to create a new API endpoint"

检查哪些标准适用于您当前的代码?

"What coding standards should I follow for this Python project?"

一次查看所有标准?

"Show me all our team's coding standards"

🔄 标准自动更新

当服务器上的标准更新时,您的AI会自动获取最新版本。无需配置!


👨‍💻 开发指南

对于维护或部署此服务器的开发人员

📁 项目结构

ai-sdlc/
├── server.py                           # MCP server implementation
├── coding-standards/                   # Standards directory
│   ├── code_complexity.md             # Mandatory for all code
│   ├── debugging.md                   # General debugging
│   ├── development_process.md         # Process guidelines
│   ├── server_operations.md           # Server ops
│   ├── python/
│   │   ├── fastapi.md                 # FastAPI standards
│   │   └── general.md                 # Python standards
│   ├── nodejs/
│   │   ├── expressjs.md               # Express.js standards
│   │   └── general.md                 # Node.js standards
│   ├── react_and_nextjs/
│   │   └── general.md                 # React/Next.js standards
│   └── vanilla_js/
│       └── general.md                 # Vanilla JS standards
├── requirements.txt                    # Python dependencies
├── pyproject.toml                     # Python project config
├── uv.lock                            # UV lock file
├── Procfile                           # Railway deployment config
└── railway.json                       # Railway configuration

🚀 地方发展

先决条件

  • Python 3.11+
  • UV(推荐)或pip

设置和运行

选项1:使用紫外线(推荐)

# Clone the repo
git clone <your-repo-url>
cd ai-sdlc

# Run server (UV handles dependencies automatically)
uv run server.py

选项2:使用pip

# Install dependencies
pip install -r requirements.txt

# Run server
python server.py

服务器将于启动 http://localhost:8000/sse

本地MCP配置

对于本地开发,请在 ~/.cursor/mcp.json:

{
  "mcpServers": {
    "coding-standards": {
      "name": "Coding Standards (Local)",
      "description": "Local development coding standards server",
      "url": "http://localhost:8000/sse"
    }
  }
}

📝 添加/编辑标准

标准文件格式

每个标准文件都使用YAML frontmatter:

---
description: Brief description of the standard
status: active
mandatory: false
---

# Your Standard Title

[Your content here...]

前线战场

字段 必填 值 目的
description ✅ text 在列表中显示
status ✅ active /其他 仅 active 标准可见
mandatory ❌ true / false 如果 true,适用于所有代码(默认为 false)

添加新标准

1.创建文件:

# For language-specific standard
mkdir -p coding-standards/golang
touch coding-standards/golang/general.md

# For general standard
touch coding-standards/testing.md

2.增加封面和内容:

---
description: Go coding standards and best practices
status: active
mandatory: false
---

# Go Coding Standards

## Code Organization
...

3.测试:

# Restart server (changes are auto-detected)
# Ask AI: "List all coding standards"

制定强制性标准

编辑封面:

---
description: Must follow for ALL code
status: active
mandatory: true  # ← This makes it mandatory
---

强制性标准出现在“🚨 “强制性标准”表适用于所有代码,无论语言如何。

🧪 测试

手动测试

# Start server
uv run server.py

# In another terminal, test the endpoint
curl http://localhost:8000/sse

MCP检验员测试

# Install and run inspector
npx @modelcontextprotocol/inspector

打开 http://localhost:6274/ 并配置:

  • 运输: SSE
  • 网址: http://localhost:8000/sse
  • 连接类型: Via Proxy

目视测试所有MCP工具!

在游标中测试

  1. 在中配置本地MCP服务器 ~/.cursor/mcp.json
  2. 重新启动游标
  3. 问: “列出所有编码标准”
  4. 验证输出是否与文件匹配

🔍 MCP服务器实现

关键功能

parse_frontmatter(content: str)

  • 从markdown解析YAML frontmatter
  • 将布尔字符串转换为Python布尔值

get_available_standards()

  • 扫描 coding-standards/ 目录
  • 筛选条件 status: active
  • 返回具有通用和特定语言标准的dict

list_coding_standards() (MCP工具)

  • 列出所有活动标准
  • 区分强制性与特定语言
  • 返回格式化的markdown表

get_coding_standard(category, name) (MCP工具)

  • 获取特定标准内容
  • 返回完整的降价内容

get_standards_for_project(languages) (MCP工具)

  • 获取多种语言的标准
  • 始终包括一般标准
  • 返回组合降价

📊 监控

检查服务器运行状况:

# Railway logs
railway logs

# Or visit your app URL
curl https://your-app.railway.app/sse

🐛 故障排除

标准没有出现?

  • 检查 status: active 在前线
  • 验证文件是否在正确的目录中
  • 重新启动服务器

MCP在Cursor中不工作?

  • 验证 ~/.cursor/mcp.json 语法
  • 检查URL是否正确
  • 完全重新启动游标

服务器未启动?

  • 检查Python版本(3.11+)
  • 验证已安装的所有依赖项
  • 检查端口8000是否可用

📚 了解更多

从AI编码混乱到团队标准 -阅读我们从基于文件的标准到MCP的历程,包括:

  • .md和.cursorules代理的挑战
  • 为什么AI代理忽略基于文件的规则
  • MCP如何解决团队级标准执行问题
  • 现实世界实施指南

研究文档 -深入了解我们的发现:


问题? 打开一个问题或请求AI帮助您使用编码标准! 🚀