﻿---
title: "PlanetScale MCP 用 mcp.pscale.dev/mcp/planetscale，OAuth 是主路径"
summary: "CLI：codex mcp add planetscale --url https://mcp.pscale.dev/mcp/planetscale，随后浏览器授权。CI 才用 bearer_token_env_var = PLANETSCALE_API_TOKEN。不要抄 REST API 的 id:secret，也不要把已删除的 pscale mcp 当现行路径。"
category: mcp
level: intermediate
surfaces: [cli, app, ide]
tags: ["MCP", "PlanetScale", "OAuth", "HTTP"]
canonical: /tips/mcp-planetscale-remote/
---

# PlanetScale MCP 用 mcp.pscale.dev/mcp/planetscale，OAuth 是主路径

CLI：codex mcp add planetscale --url https://mcp.pscale.dev/mcp/planetscale，随后浏览器授权。CI 才用 bearer_token_env_var = PLANETSCALE_API_TOKEN。不要抄 REST API 的 id:secret，也不要把已删除的 pscale mcp 当现行路径。

PlanetScale **托管**的是远程 Streamable HTTP。官方 Codex 节：

```bash
codex mcp add planetscale --url https://mcp.pscale.dev/mcp/planetscale
```

官方说这条 `add` 会马上弹出浏览器。若没有，再跑 `codex mcp login planetscale`。

```toml
[mcp_servers.planetscale]
url = "https://mcp.pscale.dev/mcp/planetscale"
enabled = true
```

连上之后可以列组织 / 库 / 分支、看 schema、跑 Insights、读查询。写查询会拦没有 `WHERE` 的 `UPDATE` / `DELETE`，也会拦 `TRUNCATE`；DDL 仍要人同意。生产库不要一上来给写权限。

只要 Insights 和 Schema Recommendations、不要执行 SQL 时，换 insights-only 地址。服务器名用下划线，不要把 URL 路径里的连字符抄成表名：

```toml
[mcp_servers.planetscale_insights]
url = "https://mcp.pscale.dev/mcp/planetscale-insights-only"
enabled = true
```

项目只对着一个库时，把组织 / 库 / 分支写进仓库 `AGENTS.md`，少让模型先扫一遍所有组织。

CI 不能开浏览器时，用组织设置里的 service token，走 `bearer_token_env_var`。官方变量名是 `PLANETSCALE_API_TOKEN`，值是 `pscale_tkn_` 开头的**密钥本身**，不要 `Bearer ...`，也不要 PlanetScale REST API 那种 `id:secret`：

```bash
codex mcp add planetscale --url https://mcp.pscale.dev/mcp/planetscale --bearer-token-env-var PLANETSCALE_API_TOKEN
```

```toml
[mcp_servers.planetscale]
url = "https://mcp.pscale.dev/mcp/planetscale"
bearer_token_env_var = "PLANETSCALE_API_TOKEN"
enabled = true
```

变量必须在启动 Codex 的那个进程里。不要和已经 `mcp login` 的 OAuth 写在同一张表。不要把 `Authorization: Bearer` 写进 `http_headers`。工具回 `invalid_token` 多半是把 token ID 或 `id:secret` 塞进去了。

不要做这些：

- 不要抄页上的 `mcpServers` JSON，也不要抄 Claude 的 `--transport http`。
- 不要抄 Claude 的 `/plugin marketplace add planetscale/claude-plugin`。那是 Claude 插件，不是 Codex 命令。
- 不要跑已删除的 `pscale mcp` 本地服务器。
- 不要抄 Claude Code 那条 `--header "Authorization: Bearer …"`：shell 会把密钥展开写进配置。Codex 要的是变量**名**。
- 不要给它 `required = true` 挂全局。
- 不要一上来 `--yolo`，也不要把支付方式的写权限随手授给 token。

网页 Cloud 不读 `~/.codex/config.toml`。改完新开会话。用 `codex mcp get planetscale` 看传输是 streamable_http。会话里 `/mcp` 应显示 Auth: OAuth（或 bearer）。

## 来源

- [PlanetScale · MCP](https://planetscale.com/docs/connect/mcp)
- [PlanetScale · MCP service token](https://planetscale.com/docs/connect/mcp-service-token)
- [OpenAI · Model Context Protocol](https://learn.chatgpt.com/docs/extend/mcp)
