Skip to content

Every agent's model. One place. Codex on DeepSeek, Claude Code on Kimi, from the menu bar.

mcpauth: a firewall's 403 says it turned the request away, not "says nothing of a sign-in"

yetonec83f8d4bbe66
diff --git a/internal/gui/assets/i18n.js b/internal/gui/assets/i18n.js
index daed4393f..c16e8ee1b 100644
--- a/internal/gui/assets/i18n.js
+++ b/internal/gui/assets/i18n.js
@@ -2028,6 +2028,7 @@ const I18N = {
"Sign-in": "登录",
"this server already works without signing in, so there is nothing to sign in to: the agents given it can use it as it is. A key it takes goes in Headers; a server that signs in at another address (as Exa's ?login) needs that URL": "此服务器无需登录即可使用,分配到它的 agent 可直接使用。所需密钥填在请求头中;需在另一地址登录的服务器(如 Exa 的 ?login)请填该 URL",
"this server's sign-in admits only the apps it lists and turned magpie away, so magpie can't sign in for the agents. The agents given it still have the server's own address: sign in from each agent itself (in Claude Code, run /mcp and pick the server)": "此服务器的登录只接受它列出的应用,拒绝了 magpie,所以 magpie 无法替 agent 登录。分配到它的 agent 拿到的仍是服务器自己的地址:请在各个 agent 里自行登录(Claude Code 中运行 /mcp 并选中该服务器)",
+ "a firewall in front of this server turned magpie's request away (403) before the server could offer a sign-in. It judges the network the request came from: try again on another network, or give magpie a proxy in Settings": "服务器前面的防火墙拦下了 magpie 的请求(403),服务器还没来得及提供登录。它是按请求来自的网络判断的:换一个网络再试,或在设置里给 magpie 配一个代理",
"1 tool": "1 个工具",
"needs sign-in": "需要登录",
"can't start": "无法启动",
@@ -6016,6 +6017,7 @@ const I18N = {
"Sign-in": "登入",
"this server already works without signing in, so there is nothing to sign in to: the agents given it can use it as it is. A key it takes goes in Headers; a server that signs in at another address (as Exa's ?login) needs that URL": "此伺服器無需登入即可使用,分配到它的 agent 可直接使用。所需金鑰填在請求頭中;需在另一位址登入的伺服器(如 Exa 的 ?login)請填該 URL",
"this server's sign-in admits only the apps it lists and turned magpie away, so magpie can't sign in for the agents. The agents given it still have the server's own address: sign in from each agent itself (in Claude Code, run /mcp and pick the server)": "此伺服器的登入只接受它列出的應用,拒絕了 magpie,所以 magpie 無法替 agent 登入。分配到它的 agent 拿到的仍是伺服器自己的位址:請在各個 agent 裡自行登入(Claude Code 中執行 /mcp 並選取該伺服器)",
+ "a firewall in front of this server turned magpie's request away (403) before the server could offer a sign-in. It judges the network the request came from: try again on another network, or give magpie a proxy in Settings": "伺服器前面的防火牆攔下了 magpie 的請求(403),伺服器還沒來得及提供登入。它是依請求來自的網路判斷的:換一個網路再試,或在設定裡給 magpie 設一個代理",
"1 tool": "1 個工具",
"needs sign-in": "需要登入",
"can't start": "無法啟動",
@@ -9981,6 +9983,7 @@ const I18N = {
"Sign-in": "サインイン",
"this server already works without signing in, so there is nothing to sign in to: the agents given it can use it as it is. A key it takes goes in Headers; a server that signs in at another address (as Exa's ?login) needs that URL": "このサーバーはサインインなしで既に使えるため、サインインする対象がありません。割り当てられたエージェントはそのまま使えます。必要なキーはヘッダーに入れてください。別のアドレスでサインインするサーバー(Exa の ?login など)はその URL が必要です",
"this server's sign-in admits only the apps it lists and turned magpie away, so magpie can't sign in for the agents. The agents given it still have the server's own address: sign in from each agent itself (in Claude Code, run /mcp and pick the server)": "このサーバーのサインインは登録済みのアプリしか受け付けず、magpie を拒否したため、magpie はエージェントの代わりにサインインできません。割り当てられたエージェントにはサーバー自身のアドレスが渡されています。各エージェントから直接サインインしてください(Claude Code では /mcp を実行してサーバーを選択)",
+ "a firewall in front of this server turned magpie's request away (403) before the server could offer a sign-in. It judges the network the request came from: try again on another network, or give magpie a proxy in Settings": "サーバーの前にあるファイアウォールが magpie のリクエストを拒否しました(403)。サーバーがサインインを示す前です。リクエスト元のネットワークで判断しているため、別のネットワークで試すか、設定で magpie にプロキシを指定してください",
"1 tool": "1 個のツール",
"needs sign-in": "サインインが必要",
"can't start": "起動できません",
@@ -13976,6 +13979,7 @@ const I18N = {
"Sign-in": "Anmeldung",
"this server already works without signing in, so there is nothing to sign in to: the agents given it can use it as it is. A key it takes goes in Headers; a server that signs in at another address (as Exa's ?login) needs that URL": "dieser Server funktioniert bereits ohne Anmeldung, es gibt also nichts anzumelden: Die zugewiesenen Agenten können ihn direkt nutzen. Ein Schlüssel, den er erwartet, gehört unter Header; ein Server, der sich an einer anderen Adresse anmeldet (wie Exa mit ?login), braucht diese URL",
"this server's sign-in admits only the apps it lists and turned magpie away, so magpie can't sign in for the agents. The agents given it still have the server's own address: sign in from each agent itself (in Claude Code, run /mcp and pick the server)": "die Anmeldung dieses Servers lässt nur die von ihm gelisteten Apps zu und hat magpie abgewiesen, daher kann magpie sich nicht für die Agenten anmelden. Die zugewiesenen Agenten erhalten weiterhin die eigene Adresse des Servers: Melden Sie sich in jedem Agenten selbst an (in Claude Code /mcp ausführen und den Server wählen)",
+ "a firewall in front of this server turned magpie's request away (403) before the server could offer a sign-in. It judges the network the request came from: try again on another network, or give magpie a proxy in Settings": "Eine Firewall vor diesem Server hat die Anfrage von magpie abgewiesen (403), bevor der Server eine Anmeldung anbieten konnte. Sie beurteilt das Netzwerk, aus dem die Anfrage kommt: Versuche es in einem anderen Netzwerk oder gib magpie in den Einstellungen einen Proxy",
"1 tool": "1 Tool",
"needs sign-in": "Anmeldung nötig",
"can't start": "Start nicht möglich",
diff --git a/internal/gui/tests/mcp-signin.test.cjs b/internal/gui/tests/mcp-signin.test.cjs
index b2602e670..6a22fda84 100644
--- a/internal/gui/tests/mcp-signin.test.cjs
+++ b/internal/gui/tests/mcp-signin.test.cjs
@@ -22,6 +22,7 @@ const base = () => ({
{ name: "neon", transport: "http", url: "https://mcp.neon.tech/mcp", agents: ["codex", "claude"], signIn: { signedIn: false } },
{ name: "exa", transport: "http", url: "https://mcp.exa.ai/mcp", agents: ["codex"], signIn: { signedIn: false } },
{ name: "figma", transport: "http", url: "https://mcp.figma.com/mcp", agents: ["claude"], signIn: { signedIn: false } },
+ { name: "sofa", transport: "http", url: "https://agents.stackoverflow.com/mcp", agents: ["claude"], signIn: { signedIn: false } },
],
});
// mcpauth.ErrNoSignIn, as the API says it
@@ -29,6 +30,10 @@ const noSignIn = "this server already works without signing in, so there is noth
// mcpauth.ErrClientRefused: Figma's registration 403s any app it doesn't list (#1619)
const refused = "this server's sign-in admits only the apps it lists and turned magpie away, so magpie can't sign in for the agents. The agents given it still have the server's own address: sign in from each agent itself (in Claude Code, run /mcp and pick the server)";
+// mcpauth.ErrTurnedAway: a firewall's 403 page in front of the server
+// (fremontdango on Discord, Cloudflare at agents.stackoverflow.com)
+const turnedAway = "a firewall in front of this server turned magpie's request away (403) before the server could offer a sign-in. It judges the network the request came from: try again on another network, or give magpie a proxy in Settings";
+
function server(lang, calls) {
const lib = base();
let polls = 0;
@@ -46,6 +51,7 @@ function server(lang, calls) {
const s = lib.servers.find((x) => x.name === name);
if (s.url === "https://mcp.exa.ai/mcp") return route.fulfill({ status: 400, json: { error: noSignIn } });
if (s.url === "https://mcp.figma.com/mcp") return route.fulfill({ status: 400, json: { error: refused } });
+ if (s.url === "https://agents.stackoverflow.com/mcp") return route.fulfill({ status: 400, json: { error: turnedAway } });
polls = 0;
// no url: the test's browser opens no window
return route.fulfill({ json: { id: "s-" + name, server: name, state: "waiting" } });
@@ -81,8 +87,8 @@ function server(lang, calls) {
}
const words = {
- en: { signIn: "Sign in", signOut: "Sign out", signed: "Signed in", label: "Sign-in", done: "Signed in to neon — the agents given it use magpie's sign-in", out: "Signed out of neon — the agents are given the server's own address again", exaDone: "Signed in to exa — the agents given it use magpie's sign-in", noSignIn: "already works without signing in", refused: "admits only the apps it lists", saveSignIn: "Save and sign in" },
- zh: { signIn: "登录", signOut: "退出登录", signed: "已登录", label: "登录", done: "已登录 neon,分配到它的 agent 共用 magpie 的登录", out: "已退出 neon,agent 改回使用服务器自身的地址", exaDone: "已登录 exa,分配到它的 agent 共用 magpie 的登录", noSignIn: "无需登录即可使用", refused: "只接受它列出的应用", saveSignIn: "保存并登录" },
+ en: { signIn: "Sign in", signOut: "Sign out", signed: "Signed in", label: "Sign-in", done: "Signed in to neon — the agents given it use magpie's sign-in", out: "Signed out of neon — the agents are given the server's own address again", exaDone: "Signed in to exa — the agents given it use magpie's sign-in", noSignIn: "already works without signing in", refused: "admits only the apps it lists", turnedAway: "a firewall in front of this server", saveSignIn: "Save and sign in" },
+ zh: { signIn: "登录", signOut: "退出登录", signed: "已登录", label: "登录", done: "已登录 neon,分配到它的 agent 共用 magpie 的登录", out: "已退出 neon,agent 改回使用服务器自身的地址", exaDone: "已登录 exa,分配到它的 agent 共用 magpie 的登录", noSignIn: "无需登录即可使用", refused: "只接受它列出的应用", turnedAway: "服务器前面的防火墙拦下了", saveSignIn: "保存并登录" },
};
for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium", "webkit"])) {
@@ -172,6 +178,16 @@ for (const engine of (process.env.BROWSER ? [process.env.BROWSER] : ["chromium",
assert.deepEqual(calls.slice(6), ["start figma"]);
await page.keyboard.press("Escape");
await page.locator("#modal .lib-editor").waitFor({ state: "detached" });
+
+ // a firewall's 403 says it was the firewall, judging the network,
+ // in the reader's language, not "says nothing of a sign-in"
+ await row("sofa").click();
+ const sofa = page.locator("#modal .lib-signin");
+ await sofa.getByRole("button", { name: w.signIn, exact: true }).click();
+ await sofa.locator(".lib-signin-err", { hasText: w.turnedAway }).waitFor();
+ assert.deepEqual(calls.slice(7), ["start sofa"]);
+ await page.keyboard.press("Escape");
+ await page.locator("#modal .lib-editor").waitFor({ state: "detached" });
assert.equal(await scrolled(), before, "no click moved the page");
await ctx.close();
});
diff --git a/internal/mcpauth/mcpauth.go b/internal/mcpauth/mcpauth.go
index 2883287c4..c26b0731c 100644
--- a/internal/mcpauth/mcpauth.go
+++ b/internal/mcpauth/mcpauth.go
@@ -26,6 +26,7 @@ import (
"html"
"io"
"io/fs"
+ "mime"
"net"
"net/http"
"net/url"
@@ -83,6 +84,14 @@ var ErrNoSignIn = errors.New("this server already works without signing in, so t
// each agent signs in there itself. The GUI has it in every language.
var ErrClientRefused = errors.New("this server's sign-in admits only the apps it lists and turned magpie away, so magpie can't sign in for the agents. The agents given it still have the server's own address: sign in from each agent itself (in Claude Code, run /mcp and pick the server)")
+// ErrTurnedAway is a server whose address answered 403 with a web page
+// rather than the server's own reply: a firewall in front of it (Cloudflare's,
+// as agents.stackoverflow.com has) judged the network the request came from
+// and stopped it before the server could offer a sign-in (fremontdango on
+// Discord, where magpie said only "answered 403 and says nothing of a
+// sign-in"). The GUI has it in every language.
+var ErrTurnedAway = errors.New("a firewall in front of this server turned magpie's request away (403) before the server could offer a sign-in. It judges the network the request came from: try again on another network, or give magpie a proxy in Settings")
+
// ErrNoRegistration is a server whose sign-in doesn't let an app register
// itself (GitHub's, 新v学员 on Discord): magpie signs in to it only as an
// OAuth app of the user's own, made with the server's vendor, as Claude
@@ -638,11 +647,24 @@ func discover(ctx context.Context, serverURL string) (meta, error) {
return meta{}, fmt.Errorf("couldn't read the metadata of %s, the server's authorization server", issuer)
}
if resp.StatusCode != http.StatusUnauthorized && !found && !got {
+ if turnedAway(resp) {
+ return meta{}, ErrTurnedAway
+ }
return meta{}, fmt.Errorf("the server answered %d and says nothing of a sign-in", resp.StatusCode)
}
return m, nil
}
+// turnedAway is a 403 from a firewall rather than the MCP server: a web page
+// to a JSON-RPC request, or Cloudflare saying it stopped it.
+func turnedAway(resp *http.Response) bool {
+ if resp.StatusCode != http.StatusForbidden {
+ return false
+ }
+ ct, _, _ := mime.ParseMediaType(resp.Header.Get("Content-Type"))
+ return ct == "text/html" || resp.Header.Get("Cf-Mitigated") != ""
+}
+
// withOffline asks for offline_access too when the authorization server
// offers it. An OpenID provider gives a refresh token only to a sign-in that
// asks for it (Vercel's: the server names only "openid", and without
diff --git a/internal/mcpauth/mcpauth_test.go b/internal/mcpauth/mcpauth_test.go
index 165820f7d..d3501202b 100644
--- a/internal/mcpauth/mcpauth_test.go
+++ b/internal/mcpauth/mcpauth_test.go
@@ -2,6 +2,9 @@ package mcpauth_test
import (
"errors"
+ "io"
+ "net/http"
+ "net/http/httptest"
"net/url"
"os"
"path/filepath"
@@ -334,3 +337,42 @@ func TestSignInAsksForOfflineAccess(t *testing.T) {
t.Errorf("scope %q", u.Query().Get("scope"))
}
}
+
+// A firewall's 403 page in front of a server is said to be one: it judged
+// the network, and the server never got to offer a sign-in. A 403 the
+// server gives in its own words is not (fremontdango on Discord: Cloudflare
+// at agents.stackoverflow.com, told as "says nothing of a sign-in").
+func TestFirewallTurnedAway(t *testing.T) {
+ home(t)
+ for _, c := range []struct {
+ name string
+ header map[string]string
+ body string
+ away bool
+ }{
+ {"cloudflare page", map[string]string{"Content-Type": "text/html; charset=UTF-8", "Server": "cloudflare"}, "<title>Attention Required! | Cloudflare</title>", true},
+ {"cloudflare challenge", map[string]string{"Content-Type": "text/plain", "Cf-Mitigated": "challenge"}, "", true},
+ {"server's own 403", map[string]string{"Content-Type": "application/json"}, `{"error":"forbidden"}`, false},
+ } {
+ t.Run(c.name, func(t *testing.T) {
+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ for k, v := range c.header {
+ w.Header().Set(k, v)
+ }
+ w.WriteHeader(http.StatusForbidden)
+ io.WriteString(w, c.body)
+ }))
+ defer srv.Close()
+ _, err := mcpauth.Start(t.Context(), "sofa", srv.URL+"/mcp")
+ if err == nil {
+ t.Fatal("signed in past a 403")
+ }
+ if got := errors.Is(err, mcpauth.ErrTurnedAway); got != c.away {
+ t.Fatalf("turned away %v, want %v: %v", got, c.away, err)
+ }
+ if !c.away && !strings.Contains(err.Error(), "answered 403") {
+ t.Fatalf("error %v", err)
+ }
+ })
+ }
+}