GitHub项目文档化服务

一个基于Node.js的MCP服务器,用于自动化将GitHub项目文档化为博客文章。

  • by Melfelf
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 Melfelf/MCP4All

使用说明

MCP4All(可翻译为“面向所有人的MCP”或根据具体语境调整,如“MCP全民计划”等,但直接翻译为“面向所有人的MCP”较为通用)

项目描述

这个项目展示了在Node.js中实现的MCP服务器(模型上下文协议)。其目标是自动化地将GitHub项目文档化为博客文章。

安装

  1. 安装 Node.js(如果尚未安装)
  2. 安装依赖项:
    npm install
    

示例代码

MCP服务器已处于 server.js 已实现:

const express = require('express');
const axios = require('axios');
const fs = require('fs');
const path = require('path');

const app = express();
app.use(express.json());

app.post('/mcp', async (req, res) => {
	const { repo, token, blog_path = './blog_content' } = req.body;
	if (!repo || !token) {
		return res.status(400).json({ error: 'repo und token sind erforderlich.' });
	}
	try {
		const url = `https://api.github.com/repos/${repo}/readme`;
		const response = await axios.get(url, {
			headers: {
				Authorization: `token ${token}`,
				'User-Agent': 'MCP-Server-Node'
			}
		});
		const content = Buffer.from(response.data.content, 'base64').toString('utf-8');
		fs.mkdirSync(blog_path, { recursive: true });
		const filename = path.join(blog_path, `${repo.replace('/', '_')}.md`);
		fs.writeFileSync(filename, content, 'utf-8');
		res.json({ success: true, file: filename });
	} catch (err) {
		res.status(500).json({ error: err.message });
	}
});

app.get('/', (req, res) => {
	res.send('MCP4All Node.js Server läuft!');
});

const PORT = process.env.PORT || 5000;
app.listen(PORT, () => {
	console.log(`Server läuft auf Port ${PORT}`);
});

使用

启动服务器:

npm start

发送一个请求(例如,使用 curl):

curl -X POST http://localhost:5000/mcp \
	-H "Content-Type: application/json" \
	-d '{"repo":"username/repo","token":"<dein_github_token>"}'

回答:

{"success": true, "file": "blog_content/username_repo.md"}

许可证

参见LICENSE(许可证)。

发送一个请求(例如,使用 curl):

curl -X POST http://localhost:5000/mcp -H "Content-Type: application/json" -d '{"input": "Was ist MCP?"}'

回答:

{"response": "Du hast gefragt: Was ist MCP?. MCP antwortet: Hallo Welt!"}

许可证

请参阅LICENSE。 测试