A Cloudflare Worker that serves as an MCP (Model Context Protocol) server for code explanation. It analyzes and explains code with a comprehensive breakdown of structure and functionality.
A Cloudflare Worker that serves as an MCP (Model Context Protocol) server for code explanation. It analyzes and explains code with a comprehensive breakdown of structure and functionality.
The Code Explainer analyzes source code using a combination of techniques:
All processing happens within the Cloudflare Worker with no external dependencies.
Clone this repository:
git clone https://github.com/BillDuke13/code-explainer-mcp.git
cd code-explainer-mcp
Install dependencies:
npm install
Configure your secret key:
wrangler.jsonc
and replace YOUR_SECRET_KEY_HERE
with your chosen secret key, orwrangler secret put SHARED_SECRET
Deploy to Cloudflare Workers:
npm run deploy
Send a POST request to your worker URL with the following JSON body:
{
"method": "explainCode",
"params": ["your code here", "programming language"]
}
Include the Authorization header with your secret key:
Authorization: Bearer YOUR_SECRET_KEY_HERE
The response will be a JSON object with a result
field containing the code analysis:
{
"result": "# Code Analysis for JavaScript Code\n\n## Architecture Diagram\n...\n\n## Core Functionality\n..."
}
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));
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)
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));
Clone the repository and install dependencies:
git clone https://github.com/BillDuke13/code-explainer-mcp.git
cd code-explainer-mcp
npm install
Run the development server:
wrangler dev
Test the endpoint locally:
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"]}'
This project is licensed under the Apache License 2.0 - see the LICENSE{:target=“_blank”} file for details.
Ragie Mcp Server
Ragie Model Context Protocol Server
Mcp Snapshot Server
A MCP server for Snapshot
Perplexity Mcp Server
This Model Context Protocol (MCP) server enables LLMs like Claude to perform internet research using the Perplexity API. It provides real-time, up-to-date information with source citations.
An MCP (Model Context Protocol) tool that provides real-time weather data, forecasts, and historical weather information using the OpenWeatherMap API, specifically designed for Claude Desktop.
An MCP server implementation for managing marginalia and annotations
An MCP tool server that provides a stateful terminal.