blogger-cli-mcp
MCP server for managing Blogger posts: create, update, retrieve posts, and upload images to GCS via natural language.
README
Blogger Post CLI Script
A Python utility to create and publish posts on Blogger using the Google Blogger API v3 from the command line.
Features
- Title and Content Specification: Create posts by passing raw HTML content strings or specifying a path to an HTML file.
- Draft or Live Status: Save as a draft or publish immediately to your blog.
- Labels Management: Attach comma-separated labels (tags) to your posts.
- OAuth 2.0 Authentication: Automatically handles authorization via web browser and securely caches tokens locally.
- Update and History Tracking: Update existing posts using
blogger_update.py. Post history is automatically saved topost_history.json. - Fetch Post Information: Retrieve current live status, content, and other metadata of existing posts directly from Blogger using
blogger_get.py. Output can be dynamically filtered by specific fields. - Module Support: Import modules into other Python scripts to programmatically create or update posts.
- Multi-Blog Support: Dynamically route posts to different blogs based on genre or alias using the
--target_blogparameter. - MCP Server Support: Includes
Blogger_mcp_server.py(FastMCP) allowing AI assistants to post or update articles directly.
Setup Instructions
1. Install Dependencies
Create a Python 3.x virtual environment and install the required packages:
# Create virtual environment
python3 -m venv venv
# Activate virtual environment
source venv/bin/activate
# Install required packages
pip install -r requirements.txt
2. Configure Environment Variables and Credentials
To run this tool, you need to set up two configuration files in the script directory:
-
.envFile Create a.envfile in the same directory as the script with the following content:BLOG_ID=YOUR_DEFAULT_BLOG_ID BLOG_ID_SITE1=YOUR_SITE1_BLOG_ID (Optional: links with --target_blog site1) BLOG_ID_SITE2=YOUR_SITE2_BLOG_ID (Optional: links with --target_blog site2) GCS_BUCKET_NAME=YOUR_GCS_BUCKET_NAME GCP_PROJECT_ID=YOUR_GCP_PROJECT_ID -
client_secret.jsonFile Download your Desktop Application OAuth 2.0 client credentials JSON file from the Google Cloud Console, rename it toclient_secret.json, and place it in the script directory. -
GCS Authentication for Image Uploads (ADC) To use the image upload feature (
image_post.py), run the following command locally and complete the browser authentication for Application Default Credentials (ADC):gcloud auth application-default login
[!WARNING] For security,
.env,client_secret.json, and the auto-generatedtoken.jsonare excluded from Git commits via.gitignore. Be careful not to expose your credentials.
Usage
Make sure your virtual environment is activated before running the script.
Create a Post (Save as Draft)
Provide a title and HTML string content to save a draft post:
python blogger_post.py \
--title "My First API Post" \
--content "<h1>Hello World</h1><p>This is a test post from Blogger API.</p>"
Read from HTML File and Publish (Live Status)
Specify an HTML file path using --file and set --status live to publish the post immediately:
python blogger_post.py \
--title "Article Loaded from HTML File" \
--file "path/to/article.html" \
--status live
Add Labels to Your Post
Pass labels as a comma-separated string using the --labels option:
python blogger_post.py \
--title "Post with Labels" \
--content "<p>Testing Blogger API v3 labels.</p>" \
--labels "Python, Blogger API, Test"
Route Post to a Specific Blog (Multi-Blog Support)
If you have configured multiple blog IDs in your .env (e.g., BLOG_ID_SITE1), use the --target_blog argument to dynamically switch the destination:
python blogger_post.py \
--title "Site 1 News" \
--content "<p>This goes to the site1 blog.</p>" \
--target_blog "site1"
Update an Existing Post
Use blogger_update.py to update an existing post by its post_id:
python blogger_update.py \
--post_id 1234567890123456789 \
--title "Updated Title" \
--content "<p>Updated content.</p>" \
--status live
Note: Successful posts and updates are automatically recorded in post_history.json.
Fetch Post Information
Use blogger_get.py to retrieve the current status, content, or other metadata of a specific post_id. You can extract only specific fields using the --fields argument.
Available Fields (--fields):
id: The ID of the posttitle: The title of the poststatus: The publication status (e.g.,LIVE,DRAFT,SCHEDULED)url: The public URL of the postlabels: A list of labels (tags) attached to the postcontent: The HTML content of the postpublished: The time the post was publishedupdated: The time the post was last updatedreplies: Comment informationauthor: Information about the author
python blogger_get.py \
--post_id 1234567890123456789 \
--fields "title,status,url"
Use as a Module
You can also import the script into other Python projects:
from blogger_post import post_article
try:
url = post_article(
title="My API Post",
content="<p>This is posted via Python module.</p>",
labels=["Python", "Module"],
status="draft"
)
print(f"Posted successfully: {url}")
except Exception as e:
print(f"Failed to post: {e}")
Use as an MCP Server
The included Blogger_mcp_server.py script runs a FastMCP server. By configuring your AI assistant (e.g., Claude) to use this script as an MCP server, it exposes the following tools:
post_to_blogger: Publish or draft new articles and automatically save the history locally. Acceptstarget_blogto route posts dynamically.update_blogger_post: Update existing articles by theirpost_idand sync the local history. Also acceptstarget_blog.upload_image_to_gcs: Uploads a single local image to GCS (automatically converts to WebP and resizes) and returns the public URL.replace_html_images_with_gcs: Reads local image links within an HTML document, uploads all of them to GCS, and returns a new HTML string with replaced image URLs.get_blogger_post: Retrieves the current information of a specific post directly from the Blogger API. You can specify which fields (e.g., status, url) to extract.
Note: Ensure the mcp, google-cloud-storage, Pillow, and beautifulsoup4 packages are installed (pip install -r requirements.txt) before running the MCP server.
Error Handling
If any issue occurs, the script catches the exception and outputs localized troubleshooting advice:
- File Errors: Warns you if the HTML file is missing, lacks read permissions, or is not UTF-8 encoded.
- Network Connection Errors: Catches failures when there is no internet connection, Google servers are unreachable, or the request times out (maximum 30-second socket timeout to prevent hanging).
- HTTP Errors (403, 404, 500, etc.): Suggests causes and fixes depending on the status code (e.g. check Blogger API enablement for 403, verify BLOG_ID for 404, or wait for Google servers for 500).
- Authentication Errors: Guides you if credentials are invalid or expired. This includes a 120-second timeout for the local browser OAuth flow; if it times out (common when your Google Cloud project is in "Testing" mode and the current account is not registered as a "Test User"), the script will abort and print steps to configure test users in Google Cloud Console.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Disclaimer
- This script is provided "AS IS", without warranty of any kind.
- The authors are not responsible for any damage, data loss, or API quota consumption caused by using this software.
- Please comply with Google's API terms of service when using this tool.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。