emlog博客系统
基于模型上下文协议(MCP)的Emlog博客系统集成服务,允许AI助手通过标准化接口与Emlog博客进行交互。
MCP 服务配置
复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用
{
"mcpServers": {
"emlog": {
"args": [
"emlog-mcp"
],
"command": "npx",
"env": {
"EMLOG_API_KEY": "your_api_key_here",
"EMLOG_API_URL": "https://your-emlog-site.com"
}
}
}
}
该服务需要配置环境变量:EMLOG_API_KEY、EMLOG_API_URL
服务介绍
Emlog MCP 服务器
基于模型上下文协议(MCP)的Emlog博客系统集成服务,允许AI助手通过标准化接口与Emlog博客进行交互。
功能
资源
- 博客文章 (
emlog://articles) - 获取所有博客文章列表 - 分类 (
emlog://categories) - 获取所有分类信息 - 评论 (
emlog://comments) - 获取评论列表(基于最新文章) - 微记 (
emlog://notes) - 获取微记列表 - 草稿文章 (
emlog://drafts) - 获取所有草稿文章列表 - 用户信息 (
emlog://user) - 获取当前用户信息
工具
- create_article - 创建新的博客文章
- update_article - 更新现有的博客文章
- get_article - 获取特定文章详情
- search_articles - 搜索文章(支持关键词、标签、分类过滤)
- like_article - 点赞文章
- add_comment - 添加评论
- get_comments - 获取特定文章的评论列表
- create_note - 创建微记
- upload_file - 上传文件(图片及其他媒体资源)
- get_user_info - 获取用户信息
- get_draft_list - 获取草稿文章列表
- get_draft_detail - 获取特定草稿的详细信息
技术栈
- TypeScript - 类型安全的JavaScript超集
- Node.js - JavaScript运行时环境
- MCP SDK - Model Context Protocol TypeScript SDK
- Axios - HTTP客户端库
- Zod - 面向TypeScript的模式验证库
- form-data - 多部分表单数据处理
安装与配置
方法1:直接使用(推荐)
在Claude Desktop配置中直接使用emlog-mcp,无需本地安装。跳转至MCP客户端配置部分。
方法2:本地开发安装
1. 克隆项目
git clone https://github.com/eraincc/emlog-mcp.git
cd emlog-mcp
2. 安装依赖
npm install
3. 环境变量配置
复制示例配置文件并编辑:
cp .env.example .env
在.env文件中设置以下环境变量:
# Emlog API base URL (required)
EMLOG_API_URL=https://your-emlog-site.com
# Emlog API key (required)
EMLOG_API_KEY=your_api_key_here
获取API密钥:
- 登录您的Emlog后台管理系统
- 进入“设置” → “API接口”
- 启用API功能并生成API密钥
- 将生成的密钥复制到
.env文件中
4. 构建项目
npm run build
5. 运行服务
npm start
或开发模式:
npm run dev
MCP客户端配置
Claude Desktop配置
添加到Claude Desktop配置文件中(通常位于~/Library/Application Support/Claude/claude_desktop_config.json):
{
"mcpServers": {
"emlog": {
"command": "npx",
"args": ["emlog-mcp"],
"env": {
"EMLOG_API_URL": "https://your-emlog-site.com",
"EMLOG_API_KEY": "your_api_key_here"
}
}
}
}
注意: 此配置现在直接使用已发布的npm包emlog-mcp,无需本地安装或编译。npx将自动下载并运行最新版本。
该项目还提供了一个示例配置文件claude-desktop-config.json供参考。
其他MCP客户端
对于其他支持MCP的客户端,请参阅其各自的文档以了解stdio传输配置。
API接口文档
此服务基于Emlog的REST API构建,支持以下主要操作:
文章管理
GET /api/article_list- 获取文章列表GET /api/article_view- 获取特定文章详情POST /api/article_save- 创建/更新文章POST /api/article_like- 点赞文章
草稿管理
GET /api/draft_list- 获取草稿列表-GET /api/draft_detail- 获取特定草稿详情
分类管理
GET /api/sort_list- 获取分类列表
评论管理
GET /api/comment_list- 获取评论列表POST /api/comment_save- 发布评论
微笔记
GET /api/note_list- 获取微笔记列表POST /api/note_save- 发布微笔记
文件上传
POST /api/upload- 上传文件
用户管理
GET /api/userinfo- 获取用户信息
使用示例
创建博客文章
// Through MCP tool call
{
"name": "create_article",
"arguments": {
"title": "My New Article",
"content": "This is the article content, supporting HTML and Markdown formats.",
"sort_id": 1,
"tag": "technology,programming,MCP",
"is_private": "n",
"allow_comment": "y"
}
}
搜索文章
// Search articles containing keywords
{
"name": "search_articles",
"arguments": {
"keyword": "technology",
"page": 1,
"count": 10
}
}
获取文章列表
// Through MCP resource access
{
"uri": "emlog://articles"
}
获取草稿列表
// Get draft list
{
"name": "get_draft_list",
"arguments": {
"count": 10
}
}
获取草稿详情
// Get detailed information of specific draft
{
"name": "get_draft_detail",
"arguments": {
"id": 123
}
}
上传文件
// Upload image file
{
"name": "upload_file",
"arguments": {
"file_path": "/path/to/image.jpg"
}
}
创建微笔记
// Publish micro note
{
"name": "create_note",
"arguments": {
"content": "This is a micro note",
"is_private": false
}
}
错误处理
服务包括全面的错误处理机制:
- 网络错误 - 自动重试和超时处理
- API 错误 - 返回详细的错误信息
- 认证错误 - API 密钥验证失败提示
- 参数错误 - 输入参数验证和提示
开发与调试
可用脚本
# Build project
npm run build
# Start service
npm start
# Development mode (auto restart)
npm run dev
# Watch mode (auto compile)
npm run watch
# Run tests
npm test
日志输出
服务将运行时状态信息输出到 stderr 以便调试:
Emlog MCP server running on stdio
测试服务
项目包含一个简单的测试脚本 test-server.js,用于验证服务是否正常工作:
node test-server.js
安全注意事项
- API 密钥保护 - 确保 API 密钥不被泄露,使用环境变量存储
- HTTPS 连接 - 建议在生产环境中使用 HTTPS 连接到 Emlog API
- 权限控制 - 确保 API 密钥具有适当的权限范围
- 输入验证 - 所有用户输入都经过验证和清理
故障排除
常见问题
-
连接失败
- 检查
EMLOG_API_URL是否正确 - 确认 Emlog 站点可访问
- 检查
-
认证失败
- 验证
EMLOG_API_KEY是否有效 - 检查 API 密钥权限
- 验证
-
工具调用失败
- 在错误消息中检查具体原因
- 确认参数格式正确
项目结构
emlog-mcp/
├── src/ # Source code directory
│ ├── index.ts # MCP service main entry
│ └── emlog-client.ts # Emlog API client
├── dist/ # Compiled output directory
├── docs/ # Documentation directory
│ └── api_doc.md # Detailed Emlog API documentation
├── .env.example # Environment variable example file
├── .gitignore # Git ignore file configuration
├── claude-desktop-config.json # Claude Desktop configuration example
├── test-server.js # Test script
├── package.json # Project configuration and dependencies
├── tsconfig.json # TypeScript configuration
└── README.md # Project documentation
贡献
欢迎提交 Issues 和 Pull Requests 来改进此项目。在提交代码之前,请确保:
- 代码通过 TypeScript 编译检查
- 遵循项目代码风格
- 添加适当的错误处理
- 更新相关文档
许可证
MIT 许可证