使用说明
子组MCP服务器
用于Substack与Claude Code和其他MCP兼容AI工具集成的模型上下文协议(MCP)服务器。
特性
- 创建和管理草稿 -以编程方式创建、更新和发布Substack帖子
- 图片上传 -使用适当的元数据将图像上传到Substack的CDN
- 实时博客报道 -带有时间戳的实时帖子更新
- 备注 -将简短内容发布到Substack Notes
- 完全支持ProseMirror -Substack编辑器的正确文档结构
安装
# Clone the repo
git clone https://github.com/acolle/substack-mcp.git
cd substack-mcp
# Install dependencies
pip install -r requirements.txt
测试
python -m unittest discover -s tests
设置
1.获取您的Substack凭据
- 在Chrome/Safari中转到Substack仪表板
- 打开DevTools(Cmd+选项+I或F12)
- 转到“应用程序”选项卡→ Cookie→ your-substack.substack.com
- 找到
substack.sid并复制其值
2.创建凭据文件
# Create ~/.substackrc
cat > ~/.substackrc << 'EOF'
export SUBSTACK_PUBLICATION="your-publication.substack.com"
export SUBSTACK_SID="your-cookie-value-here"
EOF
3.添加到克劳德代码
# Add the MCP server to Claude Code
claude mcp add substack \
--command "bash" \
--args "-c" "source ~/.substackrc && python3 $(pwd)/substack_mcp/server.py"
或手动添加到 ~/.claude.json:
{
"mcpServers": {
"substack": {
"command": "bash",
"args": ["-c", "source ~/.substackrc && python3 /path/to/substack-mcp/substack_mcp/server.py"]
}
}
}
可用工具
| 工具 | 说明 |
|---|---|
substack_create_draft |
创建新的草稿帖子 |
substack_update_draft |
更新现有草稿 |
substack_append_to_draft |
附加内容(用于实时博客) |
substack_add_code_block |
在草稿中添加代码块 |
substack_add_image |
将图像添加到草稿中 |
substack_publish |
发布草稿 |
substack_post_note |
发布一条简短的便条 |
substack_get_drafts |
列出所有草稿 |
substack_get_posts |
列出已发布的帖子 |
substack_live_blog_start |
开始实时博客会话 |
substack_live_blog_end |
结束实时博客会话 |
使用示例
使用Claude Code创建帖子
You: Create a new Substack post about AI tools
Claude: I'll create a draft for you...
[Uses substack_create_draft tool]
Created draft 12345. Edit at: https://your-pub.substack.com/publish/post/12345
上传和嵌入图像
You: Add this diagram to my post [image path]
Claude: I'll upload the image and add it to your draft...
[Uses substack_add_image tool]
Image added successfully.
实时博客报道
You: Start a live blog for the product launch
Claude: Starting live blog session...
[Uses substack_live_blog_start tool]
Live blog started. I'll append updates as they happen.
api参考
Substack客户端
与Substack的API交互的核心客户端。
from substack_client import SubstackClient, SubstackDocument
# rate_limit is seconds between requests; timeout is per-request timeout.
client = SubstackClient(token="your-sid", publication="your-pub.substack.com", rate_limit=0.5, timeout=30.0)
# Upload an image
img = client.upload_image("/path/to/image.png")
# Returns: {"url": "https://...", "width": 800, "height": 600, "bytes": 12345, "contentType": "image/png"}
# Create a document
doc = SubstackDocument()
doc.heading("My Post", level=2)
doc.paragraph("Hello world!")
doc.image(src=img['url'], width=img['width'], height=img['height'],
bytes_size=img['bytes'], content_type=img['contentType'])
# Create and publish
draft = client.create_draft(title="My Post", body=doc)
client.publish_draft(draft.id, send_email=False)
关键技术细节
图像节点结构
Substack使用ProseMirror,并要求图像具有特定属性:
{
"type": "captionedImage",
"content": [{
"type": "image2",
"attrs": {
"src": "https://substack-post-media.s3.amazonaws.com/...",
"width": 800,
"height": 600,
"bytes": 12345,
"type": "image/png",
"internalRedirect": "https://pub.substack.com/i/{draft_id}?img={encoded_url}",
"belowTheFold": false,
"topImage": false,
"isProcessing": false
}
}]
}
这 internalRedirect 字段是 必需的 -没有它,Substack的编辑器将无法呈现文档。
图像处理注意事项
create_draft和update_draft自动添加缺失internalRedirect任何图像节点的值。- 图像标题以单独的斜体段落(不是
imageCaption节点)以避免编辑器渲染问题。 - 为了获得最佳渲染效果,请通过以下方式上传图像
upload_image()并使用返回的元数据。
学分
许可证
麻省理工学院
免责声明
这使用Substack的非官方/内部API,该API可能会在不通知的情况下更改。使用风险自负。