# ChatGPT

通过托管的 Streamable HTTP MCP 和浏览器 OAuth 连接 ChatGPT，具有 memory:read 和 memory:write 范围。

- Canonical: https://docs.xmemo.dev/zh/docs/mcp/chatgpt
- Locale: zh-CN
- Content-Locale: zh-CN
- Canonical-Content-Digest: 0a34bc1a4a60d47cc1fcab5b55616f0d81c50ddc2815030f687094efa4fdc4a5
- Edition-Digest: 1b14f9e5ba897e233d4d81e96c57167f9a9e86ab7f9cfaec65a9a30da1b71704
- Source-Revision: sha256:9bc37480fb26a371846f25bf5ea25d86ddd8bd3808e3df34131ef15403069090

## 前置条件

使用支持远程 MCP 服务器和托管的 Streamable HTTP 端点的 OpenAI 应用程序配置。运行时与前置条件：

- 具体接口：ChatGPT Web 和桌面客户端 (OpenAI Apps / Actions)。
- 端点：https://xmemo.dev/mcp。
- 传输：Streamable HTTP (streamable-http)。
- 认证模式：具有 memory:read 和 memory:write 范围的 OAuth。
- 账户：在 https://xmemo.dev 拥有有效的 XMemo 账户。

## 安装 / 设置

在 ChatGPT 客户端或 OpenAI 平台仪表板中，注册远程连接的托管 MCP URL 和 OAuth 元数据：

- 在应用仪表板中配置托管的 MCP URL：https://xmemo.dev/mcp。
- 在同意时请求 memory:read 和 memory:write。
- 不要在应用列表中添加承载令牌。

## 设置凭据

无需密钥 — 完成浏览器 OAuth。ChatGPT 通过 OAuth 授权接收凭据；不要设置 XMEMO_KEY 或添加 Authorization 标头：

```text
No XMEMO_KEY
Complete browser OAuth in ChatGPT
```

## 生成 / 确认 XMEMO_AGENT_INSTANCE_ID

经过审查的 ChatGPT OAuth 列表没有客户端身份标头。不要在应用配置中编造或粘贴 XMEMO_AGENT_INSTANCE_ID；确认此客户端路径的归属由 OAuth 授权管理。

## 保留现有配置块

使用经过审查的 ChatGPT 配置块。保留其托管 URL、OAuth 模式和请求的范围；仅更改客户端所需的本地仪表板值：

```json
{
  "servers": {
    "xmemo": {
      "type": "http",
      "url": "https://xmemo.dev/mcp"
    }
  }
}
```

## 重启客户端

保存应用配置，关闭所有陈旧的 MCP 连接，然后重新打开 ChatGPT 应用或对话，以便加载当前的 OAuth 元数据。

## 使用真实的召回调用进行测试

使第一次 MCP 调用为只读。这是实际的召回调用，而不是健康检查占位符，并且它不会写入记忆。

```text
recall({ query: "connection check", limit: 1 })
```

## 预期响应（字面形态）

成功的调用将返回以下公开的排序文本形态；引用和内容是来自授权记忆空间的真实值。

```text
### XMemo Memory Results:
1. Reference: <opaque-memory-id> | Location: <location>
   > <memory content>
```

## 首个实用任务：合成记忆生命周期

在 ChatGPT 内演练完整的合成记忆任务：

- 1. 保存合成事实：要求 ChatGPT 调用 remember，内容为 "Demo project timestamps use UTC."，路径为 "projects/demo-onboarding/conventions"。
- 2. 无状态转换：在 ChatGPT 中打开一个全新的聊天会话，以确保不保留对话内的记忆。
- 3. 带溯源归属的召回：要求 ChatGPT 召回 "demo project timestamp format"。确认返回的 Reference 和 Location。
- 4. 修正记忆：要求 ChatGPT 使用有效 ID 调用 update_memory，将规范更新为 ISO 8601 格式。
- 5. 可选清理：测试结束后，要求 ChatGPT 使用记忆 ID 调用 forget。

## 功能与配置文件工具

ChatGPT 可以访问 MCP 文档契约中为 chatgpt-public 配置文件定义的限定工具：

- 核心记忆工具：remember, recall, update_memory, forget, read_memory, explain_memory, search_memory, recall_context。
- 项目与上下文工具：get_mcp_identity, get_project_summary, project, todo, update_state, record_event, restore_memory, analyze_memory_text, memory_overview。
- 交互式工作区：open_project_workspace, open_todo_board, open_ledger, ledger。

## 限制与边界

ChatGPT 集成的操作边界与约束：

- 工作区边界：记忆访问严格限制在授权用户的工作区内。
- Skill 支持：ChatGPT 远程运行工具调用，不执行独立的本地 Node.js skills。
- OAuth 会话：非活动 OAuth 会话可能会定期过期，需要一键式浏览器重新授权。

## 常见错误

ChatGPT 特定的 OAuth 失败映射到真实的令牌端点响应：

- invalid_grant — 授权码无效或已过期，或已被使用：重新连接 ChatGPT 并再次授权。
- invalid_target — OAuth 资源与此 MCP 服务器不匹配：使用 https://xmemo.dev/mcp 作为资源重新启动连接。
- 403 insufficient_scope — 授权不包括 memory:read 或 memory:write：批准所请求的范围并重新连接。

## 更新与移除

ChatGPT 的维护流程：

- 更新：更新 ChatGPT 客户端或重新进行身份验证以刷新工具定义。
- 移除：在 ChatGPT Settings -> Connected Accounts / MCP 中移除 XMemo 连接。

## ChatGPT / OpenAI Apps SDK

OAuth marketplace lane: configure the hosted MCP URL and OAuth metadata in the OpenAI app dashboard; never paste XMEMO_KEY or Bearer tokens into the listing.

```
{
  "mcpServers": {
    "XMemo": {
      "url": "https://xmemo.dev/mcp",
      "transport": "streamable-http",
      "auth": {
        "type": "oauth2",
        "resource": "https://xmemo.dev/mcp",
        "scopes": ["memory:read", "memory:write"]
      }
    }
  }
}
```
