コード解説者MCP
コード解説のためのMCP(Model Context Protocol)サーバーとして機能するCloudflare Worker。コードの構造と機能を包括的に分析・解説します。
特徴
アーキテクチャ ダイアグラム: 全体的な構造、コンポーネント間の関係、およびデータ フローを示す ASCII ダイアグラムを生成します。
コア機能分析: パターン認識に基づいてコードの主な目的を識別し、説明します。
コンポーネントの内訳: すべての主要なクラスと関数を、その役割の簡単な説明とともに一覧表示します。
多言語サポート: JavaScript、TypeScript、Python、Java、C# など、さまざまなプログラミング言語のコードを分析します。
JSDoc/Docstring 認識: コード内の既存のドキュメントを抽出して利用します。
セキュア API : エンドポイントを保護するためのベアラー トークン認証。
Related MCP server: Remote MCP Server for Website Analysis
仕組み
Code Explainer は、次のような技術を組み合わせてソース コードを分析します。
パターン認識: コード構造と共通パターンを識別します
関係分析: コンポーネント間の依存関係をマッピングします
ドキュメント抽出: 既存のドキュメントコメントを優先します
アーキテクチャの視覚化: コード構造のASCIIダイアグラムを作成します
コンポーネントの説明: 関数とクラスの意味的な説明を提供します
すべての処理は外部依存なしに Cloudflare Worker 内で行われます。
インストール
前提条件
設定
このリポジトリをクローンします:
git clone https://github.com/BillDuke13/code-explainer-mcp.git cd code-explainer-mcp依存関係をインストールします:
npm install秘密鍵を設定します:
wrangler.jsoncを編集し、YOUR_SECRET_KEY_HEREを選択した秘密鍵に置き換えるか、Cloudflare シークレットを使用する (本番環境では推奨):
wrangler secret put SHARED_SECRET
Cloudflare Workers にデプロイする:
npm run deploy
使用法
APIエンドポイント
次の JSON 本文を含む POST リクエストをワーカー URL に送信します。
{
"method": "explainCode",
"params": ["your code here", "programming language"]
}秘密キーを含む Authorization ヘッダーを追加します。
Authorization: Bearer YOUR_SECRET_KEY_HERE応答フォーマット
応答は、コード分析を含むresultフィールドを持つ JSON オブジェクトになります。
{
"result": "# Code Analysis for JavaScript Code\n\n## Architecture Diagram\n...\n\n## Core Functionality\n..."
}使用例
JavaScript(ブラウザ)
async function explainCode(code, language) {
const response = await fetch('https://your-worker-url.workers.dev', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_SECRET_KEY_HERE',
},
body: JSON.stringify({
method: "explainCode",
params: [code, language]
}),
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
return data.result;
}
// Example usage
const jsCode = `function add(a, b) { return a + b; }`;
explainCode(jsCode, "javascript")
.then(explanation => console.log(explanation))
.catch(error => console.error('Error:', error));Python(リクエスト)
import requests
import json
def explain_code(code, language, api_url, secret_key):
headers = {
'Content-Type': 'application/json',
'Authorization': f'Bearer {secret_key}'
}
payload = {
'method': 'explainCode',
'params': [code, language]
}
response = requests.post(api_url, headers=headers, json=payload)
response.raise_for_status()
return response.json()['result']
# Example usage
code = "def hello(): print('Hello, world!')"
explanation = explain_code(code, "python", "https://your-worker-url.workers.dev", "YOUR_SECRET_KEY_HERE")
print(explanation)Node.js(アクシオス)
const axios = require('axios');
async function explainCode(code, language) {
try {
const response = await axios.post('https://your-worker-url.workers.dev', {
method: 'explainCode',
params: [code, language]
}, {
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer YOUR_SECRET_KEY_HERE'
}
});
return response.data.result;
} catch (error) {
console.error('Error:', error.response ? error.response.data : error.message);
throw error;
}
}
// Example usage
const codeToAnalyze = `
class Person {
constructor(name) {
this.name = name;
}
sayHello() {
return \`Hello, my name is \${this.name}\`;
}
}
`;
explainCode(codeToAnalyze, 'javascript')
.then(explanation => console.log(explanation))
.catch(err => console.error('Failed to explain code:', err));地域開発
リポジトリをクローンし、依存関係をインストールします。
git clone https://github.com/BillDuke13/code-explainer-mcp.git cd code-explainer-mcp npm install開発サーバーを実行します。
wrangler devエンドポイントをローカルでテストします。
curl -X POST http://localhost:8787 \ -H "Content-Type: application/json" \ -H "Authorization: Bearer YOUR_SECRET_KEY_HERE" \ -d '{"method":"explainCode","params":["function hello() { return \"Hello World\"; }","javascript"]}'
開発ガイドライン
TypeScriptのベストプラクティスに従う
複雑なロジックにコメントを追加する
公開APIの変更に関するドキュメントの更新
新機能のテストを追加する
安全
APIはベアラートークン認証で保護されています
本番環境で共有シークレットを保存するには環境シークレットを使用します
実際の秘密鍵をバージョン管理にコミットしないでください
本番環境での導入にはレート制限が推奨されます
ライセンス
このプロジェクトは、Apache License 2.0 に基づいてライセンスされています。詳細については、 LICENSEファイルを参照してください。
This server cannot be installed
Resources
Looking for Admin?
Admins can modify the Dockerfile, update the server description, and track usage metrics. If you are the server author, to access the admin panel.