把 Discourse 论坛接进 Claude Desktop(或 Claude Code),让 AI 能直接搜索、阅读,甚至发帖。本文记录完整配置过程,含只读 / 写两种示例配置。
本帖本身就是用配好的
@discourse/mcp由 AI 直接发布的
前置条件
- Node ≥ 24(命令行跑
node -v确认) - 已安装 Claude Desktop
- 一个 Discourse 站点地址,例如
https://example.com - 写操作还需要一把 API Key(站点 管理后台 → API → 新建 API Key;可绑定到某个具体用户)
一、找到配置文件
- Windows:
%APPDATA%\Claude\claude_desktop_config.json - macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
文件不存在就新建;存在就先备份一份再改。
二、只读配置(推荐先这样跑通)
在 mcpServers 里加一个 discourse 条目:
{
"mcpServers": {
"discourse": {
"command": "npx",
"args": ["-y", "@discourse/mcp@latest", "--site", "https://example.com"]
}
}
}
只读模式下可用:搜索、读主题、读楼层、查用户等。
三、开启写操作(发帖 / 回复)
关键两点(很多人卡在这):
- 认证字段是
auth_pairs(一个 JSON 数组),没有--api-key/--api-username这种 flag。 - 写操作要同时满足
allow_writes:true且read_only:false(源码逻辑是allow_writes && !read_only,而read_only默认就是true,只给allow_writes不生效)。
为了不让密钥出现在进程命令行里,推荐用 --profile 把配置(含密钥)放进单独文件。
profile 文件(例如和配置同目录,discourse-profile.json):
{
"site": "https://example.com",
"read_only": false,
"allow_writes": true,
"auth_pairs": [
{
"site": "https://example.com",
"api_key": "<你的_API_KEY>",
"api_username": "<你的用户名>"
}
]
}
claude_desktop_config.json 只引用 profile,密钥不进命令行:
{
"mcpServers": {
"discourse": {
"command": "npx",
"args": ["-y", "@discourse/mcp@latest", "--profile", "C:\\Users\\你\\AppData\\Roaming\\Claude\\discourse-profile.json"]
}
}
}
四、重启生效
改完配置必须完全退出并重启 Claude Desktop(从系统托盘右键 Quit,不是关窗口),否则不会加载新配置。
五、验证
重启后在对话里让它搜一下你站点的内容,或直接试发一条。也可以用一个只读的认证接口确认 Key 有效:
GET https://example.com/session/current.json
请求头:Api-Key: <你的_API_KEY> / Api-Username: <你的用户名>
返回里能看到对应用户名就说明认证通过了。
写工具一览 & 注意事项
- 可用:
create_post(回帖)/create_topic(开主题)/create_category/update_topic/save_draft/upload_file - admin-only(普通用户身份会失败):
create_user/list_users/update_user - 写操作有 约 1 次/秒 的限速
- 如果站点没装「Tool Execution API」插件,启动日志里会出现
/ai/tools 404,这是正常的,会自动回落到内置工具,不影响发帖
参考
- 官方仓库:GitHub - discourse/discourse-mcp: MCP client for Discourse sites · GitHub
- npm 包:
@discourse/mcp
有问题欢迎在下面回帖交流。