# Codex Desktop 接入 SunAI 论坛 MCP：复制提示词即可配置

**URL:** <https://www.sunai.net/t/topic/1443>\
**Category:** IT\
**Tags:** 教程, codex, ai, mcp, discourse\
**Created:** [2026 年7 月 4 日 18:15 UTC](https://www.sunai.net/t/topic/1443 "2026-07-04T18:15:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

作者： ![Logos](https://www.sunai.net/user_avatar/www.sunai.net/logos/32/2077_2.png) [@Logos](https://www.sunai.net/u/Logos)\
发布日期： [2026 年7 月 4 日 18:15 UTC](https://www.sunai.net/t/topic/1443/1 "2026-07-04T18:15:07Z")

</div>

我刚把 Codex Desktop 接到了 SunAI 论坛的 Discourse MCP。接好以后，Codex 就可以直接搜索论坛、读帖子、发回复、创建主题，适合用来整理资料、同步教程、维护论坛内容。

大多数人只需要复制下面的提示词发给自己的 Codex。后半部分是给想手动配置、排错或了解原理的人看的。

# 快速开始：复制这段提示词

把下面这段提示词复制给你的 Codex Desktop。Codex 会根据你的本机环境自动检查 Node.js、创建 profile、修改配置文件，并提示你重启。

```plaintext
请帮我在 Codex Desktop 里接入 SunAI 论坛的官方 Discourse MCP。

目标：让当前 Codex 可以使用 mcp__discourse 工具访问 https://www.sunai.net。

请按下面要求配置：

1. 使用官方 MCP 包 @discourse/mcp@latest。
2. 不要把 Discourse API Key 写进命令行参数，也不要写进项目仓库。
3. 创建本地 profile JSON 保存站点、认证和写入开关，推荐放在：%APPDATA%\SunAI\discourse-mcp-profile.json。
4. 修改 %USERPROFILE%\.codex\config.toml，新增 [mcp_servers.discourse]。
5. 优先使用本机 PATH 里的 node；如果 npx.cmd 在 Codex MCP 启动时不稳定，就定位 npm 的 npx-cli.js，用 node 去运行它。
6. 配置完成后提醒我重启 Codex Desktop。
7. 重启后用 tool_search 搜索 discourse，确认出现 mcp__discourse 工具。
8. 最后只做一次 discourse_search 只读测试，不要直接执行发帖、改帖、删帖等写操作。

我会提供 SunAI 的 Discourse 用户名和 API Key。如果我还没有 API Key，请停止配置，并提醒我到教程帖下面留言申请。

```

如果你还没有 SunAI 的 Discourse API Key，请直接在本帖下面留言。管理员确认账号和用途后，可以协助你生成或配置合适权限的 key。

# 手动配置与排错原理

## 它做了什么

Codex Desktop 通过 MCP server 调用 Discourse API。这里使用的是官方包：

```plaintext
@discourse/mcp@latest

```

关键点是：API Key 不放在命令行参数里，而是放进本机 profile 文件。这样任务管理器或进程命令行里看不到 key，也不容易误提交到项目仓库。

## 检查 Node.js

本机需要有 Node.js：

```powershell
node -v

```

如果能输出版本号，就可以继续。若 `node` 已经在环境变量里，Codex 配置里可以直接写：

```toml
command = "node"

```

## 创建 profile 文件

推荐把密钥放在本机用户配置目录，不要放项目目录，也不要写进命令行。

建议路径：

```plaintext
%APPDATA%\SunAI\discourse-mcp-profile.json

```

profile 大致长这样：

```json
{
  "site": "https://www.sunai.net",
  "read_only": false,
  "allow_writes": true,
  "auth_pairs": [
    {
      "username": "你的论坛用户名",
      "api_key": "你的 API Key"
    }
  ]
}

```

只想先让 Codex 读论坛，可以先设成：

```json
{
  "site": "https://www.sunai.net",
  "read_only": true,
  "allow_writes": false,
  "auth_pairs": [
    {
      "username": "你的论坛用户名",
      "api_key": "你的 API Key"
    }
  ]
}

```

等需要发帖、回复、编辑时再打开写权限。

## 修改 Codex 配置

打开：

```plaintext
%USERPROFILE%\.codex\config.toml

```

加入：

```toml
[mcp_servers.discourse]
command = "node"
args = [
  "C:\\path\\to\\npm\\bin\\npx-cli.js",
  "-y",
  "@discourse/mcp@latest",
  "--profile",
  "C:\\Users\\你的用户名\\AppData\\Roaming\\SunAI\\discourse-mcp-profile.json"
]
startup_timeout_sec = 120

```

其中 `C:\\path\\to\\npm\\bin\\npx-cli.js` 要换成本机真实路径。可以让 Codex 帮你找；如果你用的是 Codex Desktop 自带 Node 运行时，也可以用它自带的 `npx-cli.js`。

有些环境可以直接这样写：

```toml
[mcp_servers.discourse]
command = "npx.cmd"
args = [
  "-y",
  "@discourse/mcp@latest",
  "--profile",
  "C:\\Users\\你的用户名\\AppData\\Roaming\\SunAI\\discourse-mcp-profile.json"
]
startup_timeout_sec = 120

```

但 Windows 下不同启动方式对 `.cmd` 的处理不完全一致。如果 `npx.cmd` 方式没有加载出工具，就换回 `node + npx-cli.js`。

## 重启并验证

保存配置后，重启 Codex Desktop。

然后问 Codex：

```plaintext
你现在有 discourse MCP 工具了吗？用 tool_search 检查一下。

```

正常会看到 `mcp__discourse` 命名空间。再做一次只读测试：

```plaintext
用 discourse_search 搜索 SunAI，max_results 设为 1。

```

能返回主题结果，就说明 MCP、profile 和认证都通了。

## 安全建议

- API Key 不要写在 `args` 里。
- profile 不要放进项目仓库。
- 不要把 profile 提交到 Git。
- 不要把高权限 key 发给不可信工具或不可信项目。
- 写权限打开以后，发帖、改帖、创建用户这类操作最好让 Codex 先复述计划，再确认执行。
