一个与Medium API集成的Model Context Protocol (MCP)服务器,使外部应用程序能够无缝地发布内容和管理用户账户。Model Context Protocol提供了一种标准化的方式,让AI模型与外部服务和API进行交互,使得这个服务器可以作为AI助手与Medium发布平台之间的桥梁。
身份验证及用户管理
内容发布
媒体管理
可靠性及性能
克隆仓库:
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
http://your-domain.com/api/auth/medium/callback.env文件中POST /api/auth/register
请求体:
{
"email": "user@example.com",
"name": "John Doe"
}
响应:
{
"message": "用户注册成功",
"token": "jwt_token_here",
"user": {
"userId": "user_id",
"email": "user@example.com",
"name": "John Doe"
}
}
POST /api/auth/login
请求体:
{
"email": "user@example.com"
}
响应:
{
"message": "登录成功",
"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": "我的新文章",
"content": "# Markdown 内容\n\n这是我的文章内容。",
"contentFormat": "markdown",
"tags": ["编程", "教程"],
"publishStatus": "草稿",
"publicationId": "可选的出版物ID"
}
响应:
{
"_id": "post_id",
"userId": "user_id",
"title": "我的新文章",
"content": "# Markdown 内容\n\n这是我的文章内容。",
"contentFormat": "markdown",
"tags": ["编程", "教程"],
"publishStatus": "草稿",
"createdAt": "2025-03-16T07:00:00.000Z",
updatedAt": "2025-03-16T07:00:00.000Z"
}
POST /api/posts/:postId/publish
头部信息:
Authorization: Bearer jwt_token_here
响应:
{
"message": "文章发布成功",
"post": {
"_id": "post_id",
"mediumPostId": "medium_post_id",
"title": "我的新文章",
"published": true,
...
}
}
GET /api/posts?status=draft&page=1&limit=10
头部信息:
Authorization: Bearer jwt_token_here
响应:
{
"posts": [
{
"_id": "post_id",
"title": "我的新文章",
...
}
],
"total": 15,
"page": 1,
"pages": 2
}
POST /api/media/upload
头部信息:
Authorization: Bearer jwt_token_here
Content-Type: multipart/form-data
表单数据:
image: [file]
响应:
{
"message": "文件上传成功",
"filePath": "/uploads/filename.jpg",
"fileName": "filename.jpg",
"originalName": "my-image.jpg",
"mimeType": "image/jpeg",
"size": 12345
}
const axios = require('axios');
const API_URL = 'http://your-domain.com';
const TOKEN = 'your_jwt_token';
async function publishPost() {
try {
// 创建草稿文章
const post = await axios.post(`${API_URL}/api/posts`, {
title: '我的精彩文章',
content: '# Hello Medium\n\n这是通过MCP API发布的我的第一篇文章。',
contentFormat: 'markdown',
tags: ['api', 'medium', '教程'],
publishStatus: '草稿'
}, {
headers: {
'Authorization': `Bearer ${TOKEN}`
}
});
// 将文章发布到Medium
const published = await axios.post(`${API_URL}/api/posts/${post.data._id}/publish`, {}, {
headers: {
'Authorization': `Bearer ${TOKEN}`
}
});
console.log('文章发布成功!', published.data);
} catch (error) {
console.error('发布文章时出错:', error.response?.data || error.message);
}
}
publishPost();
服务器支持为未来的发布安排文章。在创建或更新文章时,包括一个带有ISO时间戳的scheduledAt字段:
{
"title": "定时发布的文章",
"content": "这将在指定的时间自动发布。",
"scheduledAt": "2025-03-20T12:00:00.000Z"
}
如果配置了Redis,服务器将在指定的时间自动发布文章。
所有配置都是通过环境变量完成的:
| 变量 | 描述 | 必需 |
|---|---|---|
| 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 | 是 |
MIT
欢迎贡献!请随时提交Pull Request。
git checkout -b feature/amazing-feature)git commit -m '添加一些精彩的功能')git push origin feature/amazing-feature)