🚀 BestPractices MCP Server
このModel Context Protocol (MCP) サーバーは、複数のプログラミング言語とフレームワークにまたがる開発のベストプラクティス、セキュリティガイドライン、およびコーディング標準にAIエージェントがアクセスできるようにするものです。
✨ 主な機能
- プラグインアーキテクチャ:新しい言語やフレームワークを追加できる拡張可能なシステム
- メモリ内ストレージ:即時クエリを可能にする高速なメモリ内データストア
- 動的CSV読み込み:プラグインのデータディレクトリからすべてのCSVファイルを自動的に読み込む
- 284以上のコーディング標準:セキュリティ、アクセシビリティ、パフォーマンス、およびベストプラクティスを網羅
- MCPツール:標準をクエリするための4つのツール
get_standards:カテゴリ、サブカテゴリ、および重要度でフィルタリング
search_standards:すべての標準を対象とした全文検索
get_categories:利用可能なすべてのカテゴリをリスト表示
get_standard_by_id:特定の標準の詳細情報を取得
📦 インストール
- リポジトリをクローンします:
git clone https://github.com/abderrahimghazali/bestpractices_mcp.git
cd bestpractices_mcp
- 仮想環境を作成してアクティブ化します:
python -m venv venv
source venv/bin/activate
- 依存関係をインストールします:
pip install -r requirements.txt
- 環境設定をコピーします:
cp .env.example .env
💻 使用例
基本的な使用法
サーバーの起動
スタンドアロン実行形式
./bestpractices-server
Pythonモジュール経由
source venv/bin/activate
python -m src.server
テストの実行
python -m pytest tests/ -v
MCPクライアントの設定
Claude Desktop
Claude Desktopの設定ファイル (macOSの場合は~/Library/Application Support/Claude/claude_desktop_config.json) に以下を追加します:
{
"mcpServers": {
"bestpractices": {
"command": "/path/to/bestpractices_mcp/bestpractices-server"
}
}
}
設定を追加した後、Claude Desktopを再起動します。
VSCode with Continue.dev
Continue.dev はMCPサーバーをサポートするVSCode用のAIコーディングアシスタントです。
- VSCodeにContinue拡張機能をインストールします。
- Continueの設定 (
~/.continue/config.json) を開きます。
- MCPサーバーの設定を追加します:
{
"models": [...],
"mcpServers": {
"bestpractices": {
"command": "/path/to/bestpractices_mcp/bestpractices-server"
}
}
}
Cursor Editor
CursorはAI設定を通じてMCPサーバーをサポートしています。
- Cursorの設定 (macOSではCmd+,) を開きます。
- "AI" → "Model Context Protocol" に移動します。
- サーバー設定を追加します:
{
"bestpractices": {
"command": "/path/to/bestpractices_mcp/bestpractices-server",
"description": "Drupal coding standards and best practices"
}
}
Zed Editor
AIアシスタント機能を備えたZedエディタの場合:
- Zedの設定 (
~/.config/zed/settings.json) を開きます。
- アシスタント設定に追加します:
{
"assistant": {
"mcp_servers": {
"bestpractices": {
"command": "/path/to/bestpractices_mcp/bestpractices-server"
}
}
}
}
汎用MCPクライアントの設定
MCP互換のクライアントでは、以下の設定を使用します:
- コマンド:
/path/to/bestpractices_mcp/bestpractices-server
- プロトコル:stdio (標準入出力)
- トランスポート:stdioを介したJSON-RPC
- 初期化:特別なパラメータは必要ありません
Pythonスクリプトでの使用
import subprocess
import json
proc = subprocess.Popen(
["/path/to/bestpractices_mcp/bestpractices-server"],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
text=True
)
request = {
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "get_standards",
"arguments": {
"category": "drupal_security",
"severity": "critical"
}
},
"id": 1
}
proc.stdin.write(json.dumps(request) + "\n")
proc.stdin.flush()
response = json.loads(proc.stdout.readline())
print(response)
高度な使用法
新しい標準の追加
既存のプラグインに追加
プラグインのデータディレクトリ (data/{plugin_name}/*.csv) 内の任意のCSVファイルを作成または編集します。プラグインはすべてのCSVファイルを自動的に読み込みます:
id,category,subcategory,title,description,severity,examples,references,tags,rationale,fix_guidance
NEW001,drupal_security,new_issue,New Security Issue,Description here,high,"{""good"": ""example"", ""bad"": ""example""}","[""https://example.com""]",security|new,Why this matters,How to fix it
注意:Drupalプラグインは data/drupal/ からすべてのCSVファイルを動的に読み込むため、標準を複数のファイル (例: security_standards.csv, performance_standards.csv など) に整理することができます。
新しいプラグインの作成
src/plugins/ に新しいプラグインファイルを作成します:
from .base import StandardsPlugin, Standard
class MyPlugin(StandardsPlugin):
@property
def name(self) -> str:
return "myplugin"
- データディレクトリとCSVファイルを作成します:
mkdir data/myplugin
📚 ドキュメント
含まれる標準
サーバーには現在、以下のカテゴリにまたがる284以上のコーディング標準が含まれています:
Drupal標準 (263の標準)
- コーディング標準 (130以上の標準):PHP標準、PSR-4準拠、命名規則、コード組織、ドキュメント化
- セキュリティ (70の標準):SQLインジェクション、XSS、CSRF、アクセス制御、ファイルアップロード、認証、入力検証
- ベストプラクティス (16の標準):Field API、依存性注入、設定管理、エンティティ処理
- フロントエンド (11の標準):テーマ開発、レスポンシブデザイン、CSS/JS集約、Twigテンプレート
- アクセシビリティ (8の標準):WCAG準拠、ARIA属性、セマンティックHTML、キーボードナビゲーション
- テスト (7の標準):PHPUnit、Behat、機能テスト、テストカバレッジ、モッキング
- ドキュメント化 (7の標準):コードコメント、READMEファイル、APIドキュメント、DocBlocks
- API (6の標準):REST、JSON:API、GraphQLのベストプラクティス、HTTPメソッド
- ビルド (6の標準):ビルドプロセス、最適化、アセット管理
- DevOps (6の標準):CI/CD、デプロイメント、環境管理、GitHub Actions
- データベース (5の標準):スキーマ設計、マイグレーション、クエリ最適化、Database API
- 統合 (5の標準):サードパーティ統合、外部サービス、API
- Git (4の標準):Gitワークフロー、コミットメッセージ、ブランチング戦略
- JavaScript (3の標準):Drupalビヘイビア、最新のJSパターン、最適化
- 設定 (1の標準):設定管理
- フォーム (1の標準):Form APIと処理
- フック (1の標準):フックの実装
- Twig (1の標準):テンプレートのベストプラクティス
OWASP標準 (20の標準)
- OWASP Top 10 2021:アクセス制御の破壊、暗号化の失敗、インジェクション攻撃、不安全な設計、セキュリティ設定の誤り、脆弱なコンポーネント、識別の失敗、ソフトウェアの整合性の失敗、ロギングの失敗、およびサーバーサイドリクエスト偽造などの重大なセキュリティ脆弱性
利用可能なMCPツール
接続後、AIエージェントは以下のツールを利用できます:
1. get_standards
フィルターを使用してコーディング標準をクエリします:
- category:カテゴリでフィルター (例: "drupal_security", "drupal_performance")
- subcategory:サブカテゴリでフィルター (例: "sql_injection", "xss")
- severity:重要度レベルでフィルター ("critical", "high", "medium", "low", "info")
- limit:最大結果数 (デフォルト: 50)
例のクエリ:"Show me all critical security standards for Drupal"
2. search_standards
すべての標準を対象とした全文検索を行います:
- query:検索テキスト (必須)
- categories:検索対象のカテゴリのリスト (オプション)
- tags:フィルターするタグのリスト (オプション)
- limit:最大結果数 (デフォルト: 50)
例のクエリ:"Search for standards about SQL injection"
3. get_categories
説明と件数を含むすべての利用可能なカテゴリをリスト表示します。
例のクエリ:"What categories of standards are available?"
4. get_standard_by_id
特定の標準の詳細情報を取得します:
- standard_id:一意の識別子 (例: "DS001", "SEC001")
例のクエリ:"Show me details for standard DS001"
AIエージェント用の例のプロンプト
このサーバーとMCPクライアントを使用する場合、以下のような質問をすることができます:
- "What are the critical security standards I should follow for Drupal?"
- "Show me best practices for Drupal forms"
- "Search for standards about caching and performance"
- "How should I handle user input to prevent XSS attacks?"
- "What's the proper way to use Drupal's Database API?"
- "List all accessibility standards"
- "Show me examples of good vs bad code for SQL queries"
- "What are the OWASP Top 10 2021 vulnerabilities and how to prevent them?"
- "Show me critical security standards across all categories"
- "Search for standards about broken access control"
トラブルシューティング
問題が発生した場合:
- ログを確認:ほとんどのMCPクライアントはデバッグログを提供しています。
- 手動でテスト:
echo '{"jsonrpc":"2.0","method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"1.0"}},"id":1}' | ./bestpractices-server を実行します。
- パスを確認:実行可能ファイルのパスが正しいこと、およびファイルが実行可能であることを確認します (
chmod +x bestpractices-server)。
- Python環境:サーバーは独自の仮想環境を使用するため、アクティブ化する必要はありません。
🔧 技術詳細
プロジェクト構造
bestpractices_mcp/
├── src/
│ ├── server.py # MCPサーバーの実装
│ ├── config.py # 設定管理
│ ├── plugins/ # プラグインシステム
│ │ ├── base.py # ベースプラグインクラス
│ │ ├── manager.py # プラグインマネージャー
│ │ └── drupal.py # Drupal標準プラグイン
│ └── data/ # データストレージ層
│ ├── database.py # 互換性ラッパー
│ └── memory_store.py # メモリ内データストア
├── data/ # 標準データファイル
│ ├── drupal/
│ │ └── drupal_standards.csv
│ └── owasp/
│ ├── owasp_top10_2021.csv
│ └── OWASP_RESOURCES.md
├── tests/ # テストスイート
├── requirements.txt # Python依存関係
└── README.md # このファイル
🤝 コントリビュート
- リポジトリをフォークします。
- 機能ブランチを作成します。
- 変更を加えます。
- テストを書きます。
- プルリクエストを送信します。
📄 ライセンス
MITライセンス - 詳細はLICENSEファイルを参照してください。