﻿---
title: "MCP 登录 scopes：先 CLI，再 config，最后才是广告值"
summary: "顺序是 --scopes、mcp_servers.NAME.scopes、scopes_supported、空列表。Learn 页写成广告优先，和源码相反。只对 streamable HTTP。"
category: mcp
level: advanced
surfaces: [cli, app]
tags: ["scopes", "OAuth", "MCP"]
canonical: /tips/mcp-oauth-scopes/
---

# MCP 登录 scopes：先 CLI，再 config，最后才是广告值

顺序是 --scopes、mcp_servers.NAME.scopes、scopes_supported、空列表。Learn 页写成广告优先，和源码相反。只对 streamable HTTP。

streamable HTTP 的 MCP 若要 OAuth 范围，写在该服务器表里：

```toml
[mcp_servers.docs]
url = "https://mcp.example.com/mcp"
scopes = ["read:docs"]
```

这一次登录也可以带旗标：

```bash
codex mcp login docs --scopes read:docs,search
```

CLI 参考里 `--scopes` 是逗号分隔；TOML 里是字符串数组。不要把逗号列表写进 TOML。

源码 `resolve_oauth_scopes` 的顺序是：

1. 这次命令的 `--scopes`（显式列表）
2. config 里的 `mcp_servers.NAME.scopes`
3. 服务器广告的 `scopes_supported`
4. 都没有就发空列表

Learn 的 MCP 页目前写成「广告值优先于 config」。那是过时摘要。广告值**不会**盖住你已经写进 TOML 的 `scopes`，也不会回写进 config。想用服务器广告的范围，就不要在 TOML 里写 `scopes`，也别带 `--scopes`。

这**不是** `oauth_resource`。后者往授权 URL 附加 RFC 8707 `resource`，不管权限范围。stdio 服务器没有 OAuth login，写 `scopes` 不会发起授权。

改范围之后必须重新 `codex mcp login`。旧令牌不会按新列表自动缩权。第三方继续 `auth = "oauth"`，不要靠 `auth = "chatgpt"` 去要范围。

## 来源

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