使用说明
micropub-mcp
MCP服务器,允许AI代理(Claude Code、Cursor等)创建、更新、删除和查询任何帖子 Micropub-兼容的博客。通过以下方式进行身份验证 印度 使用PKC。
建于 包子 +TypeScript。
快速开始
1.安装
git clone https://github.com/rmdes/micropub-mcp.git
cd micropub-mcp
bun install
2.添加到克劳德代码
添加到您的 .mcp.json (项目或全球):
{
"mcpServers": {
"micropub": {
"command": "bun",
"args": ["run", "/path/to/micropub-mcp/src/index.ts"]
}
}
}
3.身份验证
告诉克劳德: “通过我的博客进行身份验证https://yourblog.com"
这叫 micropub_auth,其中:
- 发现您博客的IndieAuth端点
- 打开浏览器进入授权页面
- 您批准访问,回调服务器将捕获令牌
- 令牌保存到
~/.config/micropub-mcp/<domain>.json
身份验证在会话之间持续存在。你只需要做一次。
4.开始发布
"Create a note saying Hello from my MCP client!"
"Write an article titled 'My Setup' about my development environment"
"Syndicate a note to Bluesky and Mastodon about the IndieWeb"
工具
micropub_auth
通过IndieAuth+PKCE与Micropub兼容的博客进行身份验证。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
site_url |
string | 是 | 您的博客URL(例如。, https://yourblog.com) |
scope |
string | 否 | OAuth作用域(默认值: create update delete media) |
microub_create
创建新帖子(注释、文章、照片、书签等)。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
content |
string | 否 | 发布内容(文本或HTML) |
type |
string | 否 | 帖子类型: entry (默认), event |
name |
string | 否 | 标题(使其成为文章) |
summary |
string | 否 | 帖子摘要 |
category |
string[] | 否 | 标签/类别 |
syndicate_to |
string[] | 否 | 联合目标UID |
in_reply_to |
string | 否 | 正在回复的URL |
like_of |
string | 否 | 正在被点赞的URL |
repost_of |
string | 否 | 正在转发的URL |
photo |
string[] | 否 | 照片URL |
slug |
string | 否 | URL段符 |
post_status |
string | 否 | published 或 draft |
published |
string | 否 | ISO 8601日期 |
ai_text_level |
string | 否 | AI文本参与: 0 (无), 1 (社论), 2 (共同起草), 3 (人工智能生成) |
ai_code_level |
string | 否 | AI代码参与: 0 (人类), 1 (人工智能辅助), 2 (主要是AI) |
ai_tools |
string | 否 | 使用的AI工具(例如。 "Claude", "ChatGPT, Copilot") |
ai_description |
string | 否 | AI使用的自由文本描述 |
示例:
Create a note: { content: "Hello world" }
Create an article: { name: "My Title", content: "Article body..." }
Create a bookmark: { like_of: "https://example.com/post" }
Create a reply: { in_reply_to: "https://example.com/post", content: "Great post!" }
Syndicate: { content: "Cross-posted!", syndicate_to: ["https://brid.gy/publish/bluesky"] }
With AI metadata: { content: "AI-assisted post", ai_text_level: "2", ai_tools: "Claude" }
微插件更新
更新现有帖子。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
url |
string | 是 | 要更新的帖子的URL |
replace |
object | 否 | 要替换的属性(值是数组) |
add |
object | 否 | 要添加的属性 |
delete_properties |
string[] | 否 | 要删除的属性名称 |
例子: { url: "https://blog.com/notes/abc", replace: { content: ["Updated text"] }, add: { category: ["new-tag"] } }
微孔板
删除帖子。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
url |
string | 是 | 要删除的帖子的URL |
微型潜艇
恢复以前删除的帖子。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
url |
string | 是 | 要还原的帖子的URL |
微子查询
查询Micropub服务器的配置、帖子或元数据。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
q |
string | Yes | 查询类型(见下文) |
url |
string | 否 | 帖子URL(用于 source 查询) |
properties |
string[] | 否 | 要返回的属性 |
limit |
number | 否 | 最大结果 |
offset |
number | No | 分页偏移 |
查询类型:
config--服务器功能、联合目标、帖子类型source--获取帖子的属性(需要url)syndicate-to--可用的联合目标post-types--支持的帖子类型category--可用类别/标签channel--可用频道
Micropub上传
将媒体文件上载到服务器的媒体端点。
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
file_path |
string | 是 | 文件的绝对路径 |
返回上传文件的URL,可用于 photo, video,或 audio 参数 micropub_create.
AI透明度元数据
帖子可以选择性地携带披露人工智能参与的元数据。这些字段作为标准Micropub mf2属性发送(ai-text-level, ai-code-level, ai-tools, ai-description).
所有字段都是可选的。 如果你的Micropub服务器不知道它们,它只会将它们存储为额外的属性或忽略它们——不需要特殊的服务器端支持。这适用于任何标准的Micropub端点。
| 级别 | ai_text_level |
ai_code_level |
|---|---|---|
| 0 | 无-一切都是人类写的 | 人类写的 |
| 1 | 编辑协助(语法、拼写) | AI辅助 |
| 2 | 共同起草(人工指导,人工智能编写) | 主要由人工智能生成 |
| 3 | 人工智能生成(人工审查) | -- |
如果您的服务器确实支持这些字段(例如。, 印度人 随着 @rmdes/indiekit-endpoint-posts),它们可以显示在帖子表单UI中,用于过滤或标记帖子。
身份验证的工作原理
┌─────────┐ ┌──────────────┐ ┌─────────────┐ ┌──────────┐
│ Claude │────>│ MCP Server │────>│ Browser │────>│ Blog │
│ Code │ │ (this tool) │ │ │ │ Server │
└─────────┘ └──────────────┘ └─────────────┘ └──────────┘
│ │ │ │
│ micropub_auth │ │ │
│───────────────>│ │ │
│ │ discover endpoints │ │
│ │────────────────────────────────────────>│
│ │ start callback │ │
│ │ server :19750 │ │
│ │ open browser ──────>│ │
│ │ │ authorize ────────>│
│ "open browser"│ │ │
│<───────────────│ │<── redirect with │
│ │ │ auth code │
│ │<── callback ────────│ │
│ │ exchange code ─────────────────────────>│
│ │<── access token ────────────────────────│
│ │ save token │ │
│ │ ~/.config/... │ │
回调服务器运行在 localhost:19750 并且是一个进程级单例——它在MCP工具调用中持续存在,并在收到回调后关闭。
令牌存储
令牌保存到 ~/.config/micropub-mcp/<domain>.json 包括:
- 访问令牌
- 刷新令牌(如果提供)
- 过期时间
- 已发现的端点(micropub、媒体、令牌)
如果有可用的刷新令牌,过期的令牌将自动刷新。
需求
- 包子 1.0+
- 支持Micropub+IndieAuth的博客(例如。, 印度人, 带有IndieWeb插件的WordPress, 微博客)
Indiekit特定注释
如果你的博客在nginx后面运行Indiekit,请确保:
-
内容安全策略
form-action:The/auth位置必须允许form-action *(或至少http://localhost:*)因此OAuth同意书可以重定向到本地回调服务器。如果没有这个,点击“允许”什么也不做(日志中的HTTP 499)。 -
重定向验证:Indiekit的上游重定向正则表达式(
/^\/[\w&/=?]*$/)拒绝路径中的连字符,如/auth/new-password如果你击中ForbiddenError: Invalid redirect attempted,补丁lib/indieauth.js使用扩展的正则表达式。
发展
# Run tests
bun test
# Start the MCP server (stdio)
bun run src/index.ts
建筑
src/
├── index.ts Entry point — creates MCP server, connects stdio transport
├── tools.ts 7 MCP tool definitions with Zod schemas
├── auth.ts IndieAuth + PKCE flow, token storage, non-blocking callback server
├── client.ts Micropub HTTP client (create/update/delete/query/upload)
└── discovery.ts Endpoint discovery from Link headers + HTML + indieauth-metadata
许可证
麻省理工学院