﻿---
title: "MCP 的 auth=chatgpt 只给 ChatGPT 同源，不是任意 HTTP 服务器"
summary: "bearer 和显式头优先。oauth 用存好的 MCP 令牌；chatgpt 只把当前 ChatGPT 会话交给与 chatgpt_base_url 同源的主机。第三方仍要 mcp login。"
category: mcp
level: advanced
surfaces: [cli, app, ide]
tags: ["mcp_servers.auth", "chatgpt", "OAuth"]
canonical: /tips/mcp-http-auth-chatgpt/
---

# MCP 的 auth=chatgpt 只给 ChatGPT 同源，不是任意 HTTP 服务器

bearer 和显式头优先。oauth 用存好的 MCP 令牌；chatgpt 只把当前 ChatGPT 会话交给与 chatgpt_base_url 同源的主机。第三方仍要 mcp login。

Streamable HTTP 服务器在配完 bearer / 请求头之后，才看 `auth`：

```toml
[mcp_servers.docs]
url = "https://mcp.example.com/mcp"
auth = "oauth"
# 仅当 url 与 chatgpt_base_url 同源时才写 auth = "chatgpt"
```

- `oauth`（默认）：用 `codex mcp login` 存下的 MCP OAuth 令牌
- `chatgpt`：用当前 ChatGPT 登录态，失败再回退到存好的 MCP OAuth

`chatgpt` **不是**「所有 MCP 都能免登录」。官方会核对服务器 URL 的 HTTP(S) 源是否和 `chatgpt_base_url` 相同；不同源的配置在启动前会被拿掉这项能力，第三方 GitHub / Linear 不会拿到你的 ChatGPT access token。旧讨论里的 `use_chatgpt_auth = true` 已经改成这个枚举，不要再抄布尔键。

显式 `bearer_token_env_var`、`http_headers`、`env_http_headers` 或 `http_headers_helper` 打出的 `Authorization` 优先于会话。stdio 服务器没有 `auth`。两边都解析不到凭据时，仍可能无鉴权连上——不要靠这个当安全边界。第三方继续 `codex mcp login docs`。

## 来源

- [OpenAI · Model Context Protocol](https://learn.chatgpt.com/docs/extend/mcp)
- [OpenAI · Configuration reference](https://developers.openai.com/codex/config-reference)
- [openai/codex#29733](https://github.com/openai/codex/pull/29733)
