中型MCP API服务器
模型上下文协议(MCP)服务器,与Medium的API集成,实现来自外部应用程序的无缝内容发布和用户帐户管理。模型上下文协议为人工智能模型与外部服务和API交互提供了一种标准化的方式,使该服务器成为人工智能助手和Medium发布平台之间的桥梁。
🚀 特性
- 身份验证和用户管理
- Secure Medium OAuth集成 - 基于JWT的身份验证 - 用户配置文件管理
- 内容发布
- 支持Markdown和HTML内容格式 - 草稿创建和管理 - 岗位安排 - 出版物集成 - 标签和类别支持
- 媒体管理
- 图像上传和存储 - 内容格式化实用程序
- 可靠性和性能
- 基于Redis的缓存 - 发布后的作业安排 - 全面的错误处理 - 速率限制
📋 需求
- Node.js 16+
- MongoDB
- Redis(可选,但建议用于调度)
- 中等API证书
🛠️ 安装
使用Docker(推荐)
- 克隆存储库:
git clone https://github.com/jignesh88/medium-mcp-api.git
cd medium-mcp-api- 创建一个
.env基于示例的文件:
cp .env.example .env- 更新
.env使用您的凭据文件:
MEDIUM_CLIENT_ID=your_medium_client_id
MEDIUM_CLIENT_SECRET=your_medium_client_secret
MEDIUM_REDIRECT_URI=http://your-domain.com/api/auth/medium/callback
JWT_SECRET=your_strong_secret_key- 使用Docker Compose启动服务:
docker-compose up -d手动安装
- 克隆存储库:
git clone https://github.com/jignesh88/medium-mcp-api.git
cd medium-mcp-api- 安装依赖项:
npm install- 创建和配置您的
.env文件
- 启动MongoDB和Redis服务器
- 启动应用程序:
npm start🔐 中等API设置
- 在以下位置创建Medium开发人员应用程序https://medium.com/me/applications
- 将回调URL设置为
http://your-domain.com/api/auth/medium/callback - 将您的客户ID和客户密码复制到您的
.env文件
📚 API文档
身份验证端点
注册新用户
POST /api/auth/register请求正文:
{
"email": "user@example.com",
"name": "John Doe"
}答复:
{
"message": "User registered successfully",
"token": "jwt_token_here",
"user": {
"userId": "user_id",
"email": "user@example.com",
"name": "John Doe"
}
}登录
POST /api/auth/login请求正文:
{
"email": "user@example.com"
}答复:
{
"message": "Login successful",
"token": "jwt_token_here",
"user": {
"userId": "user_id",
"email": "user@example.com",
"name": "John Doe",
"mediumConnected": true
}
}连接中型帐户
GET /api/auth/medium标题:
Authorization: Bearer jwt_token_here答复:
{
"authUrl": "https://medium.com/m/oauth/authorize?client_id=..."
}内容管理端点
创建帖子
POST /api/posts标题:
Authorization: Bearer jwt_token_here请求正文:
{
"title": "My New Post",
"content": "# Markdown Content\n\nThis is my post content.",
"contentFormat": "markdown",
"tags": ["programming", "tutorial"],
"publishStatus": "draft",
"publicationId": "optional_publication_id"
}答复:
{
"_id": "post_id",
"userId": "user_id",
"title": "My New Post",
"content": "# Markdown Content\n\nThis is my post content.",
"contentFormat": "markdown",
"tags": ["programming", "tutorial"],
"publishStatus": "draft",
"createdAt": "2025-03-16T07:00:00.000Z",
"updatedAt": "2025-03-16T07:00:00.000Z"
}将帖子发布到Medium
POST /api/posts/:postId/publish标题:
Authorization: Bearer jwt_token_here答复:
{
"message": "Post published successfully",
"post": {
"_id": "post_id",
"mediumPostId": "medium_post_id",
"title": "My New Post",
"published": true,
...
}
}获取用户帖子
GET /api/posts?status=draft&page=1&limit=10标题:
Authorization: Bearer jwt_token_here答复:
{
"posts": [
{
"_id": "post_id",
"title": "My New Post",
...
}
],
"total": 15,
"page": 1,
"pages": 2
}媒体管理
上传图片
POST /api/media/upload标题:
Authorization: Bearer jwt_token_here
Content-Type: multipart/form-data表格数据:
image: [file]答复:
{
"message": "File uploaded successfully",
"filePath": "/uploads/filename.jpg",
"fileName": "filename.jpg",
"originalName": "my-image.jpg",
"mimeType": "image/jpeg",
"size": 12345
}🔄 与MCP服务器集成
示例:使用Node.js发布帖子
const axios = require('axios');
const API_URL = 'http://your-domain.com';
const TOKEN = 'your_jwt_token';
async function publishPost() {
try {
// Create a draft post
const post = await axios.post(`${API_URL}/api/posts`, {
title: 'My Awesome Article',
content: '# Hello Medium\n\nThis is my first post published via the MCP API.',
contentFormat: 'markdown',
tags: ['api', 'medium', 'tutorial'],
publishStatus: 'draft'
}, {
headers: {
'Authorization': `Bearer ${TOKEN}`
}
});
// Publish the post to Medium
const published = await axios.post(`${API_URL}/api/posts/${post.data._id}/publish`, {}, {
headers: {
'Authorization': `Bearer ${TOKEN}`
}
});
console.log('Post published successfully!', published.data);
} catch (error) {
console.error('Error publishing post:', error.response?.data || error.message);
}
}
publishPost();📅 计划发布
服务器支持为将来的发布安排帖子。在创建或更新帖子时,请包含 scheduledAt 带有ISO时间戳的字段:
{
"title": "Scheduled Post",
"content": "This will be published automatically.",
"scheduledAt": "2025-03-20T12:00:00.000Z"
}如果配置了Redis,服务器将在指定时间自动发布帖子。
🛡️ 安全考虑
- 在生产环境中始终使用HTTPS
- 定期轮换JWT机密
- 设置适当的监控和记录
- 将敏感数据存储在环境变量或安全保管库中
- 实施适当的CORS策略
🔧 配置
所有配置都是通过环境变量完成的:
| 变量 | 描述 | 必填 |
|---|---|---|
| PORT | 服务器端口(默认值:3000) | 否 |
| MONGODB_URI | MONGODB连接字符串 | 是 |
| REDIS_URL | REDIS连接字符串 | 否 |
| JWT_SECRET | JWT令牌的秘密 | 是 |
| MEDIUM_CLIENT_ID | 中等API客户端ID | 是 |
| MEDIUM_CLIENT_SECRET | 中等API客户端机密 | 是 |
| MEDIUM_REDIRECT_URI | OAuth回调URL | 是 |
| FRONTEND_URL | 前端重定向的URL | 是 |
📜 许可证
麻省理工学院
🤝 贡献
欢迎投稿!请随时提交拉取请求。
- 分叉存储库
- 创建功能分支(
git checkout -b feature/amazing-feature) - 提交您的更改(
git commit -m 'Add some amazing feature') - 推到分支(
git push origin feature/amazing-feature) - 打开拉取请求
