中型 MCP(Medium Control Panel)服务器是一个用于管理内容发布和分发的平台。它提供了创建、编辑、发布和调度文章的功能,并支持通过 API 集成到其他系统。
中型 MCP 服务器可助力你轻松管理内容的发布与分发,支持文章的全流程操作,还能通过 API 与其他系统集成。
按照以下步骤快速安装 MCP 服务器:
git clone git@github.com:your-repo/mcp-server.git
npm install
node index.js
所有配置通过环境变量完成,需在 .env
文件中设置以下参数:
变量名 | 描述 | 是否必填 |
---|---|---|
PORT | 服务器端口(默认:3000) | 否 |
MONGODB_URI | MongoDB 连接字符串 | 是 |
REDIS_URL | Redis 连接字符串 | 否 |
JWT_SECRET | JWT 密钥 | 是 |
MEDIUM_CLIENT_ID | Medium API 客户端 ID | 是 |
MEDIUM_CLIENT_SECRET | Medium API 客户端密钥 | 是 |
MEDIUM_REDIRECT_URI | OAuth 回调 URL | 是 |
FRONTEND_URL | 前端 URL | 是 |
const axios = require('axios');
async function createDraft() {
try {
const response = await axios.post('http://localhost:3000/api/posts', {
title: '我的第一篇文章',
content: '# 欢迎使用 MCP 服务器\n这是我的第一篇通过 API 发布的文章。',
contentFormat: 'markdown',
tags: ['MCP', '教程', 'API'],
publishStatus: 'draft'
}, {
headers: {
'Authorization': `Bearer ${TOKEN}`
}
});
console.log('草稿创建成功:', response.data);
} catch (error) {
console.error('创建草稿失败:', error.response?.data || error.message);
}
}
createDraft();
async function publishArticle(postId) {
try {
const response = await axios.post(`http://localhost:3000/api/posts/${postId}/publish`, {}, {
headers: {
'Authorization': `Bearer ${TOKEN}`
}
});
console.log('文章已发布:', response.data);
} catch (error) {
console.error('发布失败:', error.response?.data || error.message);
}
}
// 调用示例
publishArticle('647f5d3b0c87e5a9c23b1aa1');
async function listArticles(status = 'all', page = 1, limit = 10) {
try {
const response = await axios.get(`http://localhost:3000/api/posts?status=${status}&page=${page}&limit=${limit}`, {
headers: {
'Authorization': `Bearer ${TOKEN}`
}
});
console.log('文章列表:', response.data);
} catch (error) {
console.error('获取文章失败:', error.response?.data || error.message);
}
}
// 示例调用
listArticles('draft', 1, 20);
const scheduledPost = {
title: '明天的文章',
content: '# 明天见\n这是一篇预定发布的内容。',
publishStatus: 'draft',
scheduledAt: '2023-10-10T15:00:00Z'
};
async function scheduleArticle() {
try {
const response = await axios.post('http://localhost:3000/api/posts', scheduledPost, {
headers: {
'Authorization': `Bearer ${TOKEN}`
}
});
console.log('文章已调度:', response.data);
} catch (error) {
console.error('调度失败:', error.response?.data || error.message);
}
}
scheduleArticle();
所有需要认证的 API 请求都需要在头中添加 Authorization
字段,格式如下:
Bearer
确保 JWT_SECRET
和其他敏感配置不被泄露。建议使用环境变量或密钥管理工具来存储这些信息。
状态码 | 描述 |
---|---|
401 | 未授权 |
403 | 禁止访问 |
500 | 内部服务器错误 |
某些旧的 API 接口可能已弃用,建议更新到最新版本。
# Dockerfile
FROM node:16-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install --production
COPY . .
CMD ["node", "index.js"]
如需反馈或技术支持,请访问我们的 GitHub 仓库 或发送邮件至 support@yourdomain.com。
感谢使用 MCP 服务器!