dsh-mcp 1.13.0 → 1.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,166 @@
1
+ /**
2
+ * Operating-system CA trust for HTTPS MCP endpoints.
3
+ *
4
+ * Node ships its own bundled root store (Mozilla's), so an HTTPS server whose
5
+ * certificate chains to a root that only exists in the operating system store
6
+ * — a corporate CA, an MDM/Zscaler/proxy root, a self-signed internal PKI —
7
+ * fails with `UNABLE_TO_VERIFY_LEAF_SIGNATURE` / `DEPTH_ZERO_SELF_SIGNED_CERT`
8
+ * even though every browser and curl on the machine accepts it. The MCP
9
+ * transport, its OAuth discovery/registration/token calls, and the connection
10
+ * probe all go through the process-wide `fetch`, so the fix is to merge the
11
+ * system anchors into the process default trust store once.
12
+ *
13
+ * `tls.getCACertificates('system')` is the accurate cross-platform source
14
+ * (macOS/Windows/Linux, Node >= 24.9); when the API is absent or returns
15
+ * nothing, the well-known OS bundle files are read as a fallback. The merge is
16
+ * additive — Node's bundled roots stay trusted — and idempotent.
17
+ */
18
+
19
+ import { readFileSync } from "node:fs";
20
+ import { createRequire } from "node:module";
21
+ import tls from "node:tls";
22
+
23
+ /**
24
+ * Well-known OS bundle files, used when `tls.getCACertificates('system')` is
25
+ * unavailable (Node < 24.9) or empty.
26
+ */
27
+ const OS_CA_FILES = [
28
+ "/etc/ssl/cert.pem",
29
+ "/etc/ssl/certs/ca-certificates.crt",
30
+ "/etc/pki/tls/certs/ca-bundle.crt",
31
+ "/etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem",
32
+ ];
33
+
34
+ /** Split a PEM bundle into individual certificates, tolerating junk between them. */
35
+ function splitPem(text) {
36
+ return String(text).match(/-----BEGIN CERTIFICATE-----[\s\S]*?-----END CERTIFICATE-----/g) ?? [];
37
+ }
38
+
39
+ /**
40
+ * Certificates installed in the operating-system trust store.
41
+ * @returns an array of PEM strings (possibly empty).
42
+ */
43
+ export function systemCaCertificates() {
44
+ const certificates = [];
45
+ if (typeof tls.getCACertificates === "function") {
46
+ try {
47
+ certificates.push(...(tls.getCACertificates("system") ?? []));
48
+ } catch {
49
+ /* the API throws when the OS store is unreadable — fall back to files */
50
+ }
51
+ }
52
+ for (const file of OS_CA_FILES) {
53
+ try {
54
+ certificates.push(...splitPem(readFileSync(file, "utf8")));
55
+ } catch {
56
+ /* an absent bundle file is not an error */
57
+ }
58
+ }
59
+ return [...new Set(certificates)];
60
+ }
61
+
62
+ /** Memoized result of the last {@link ensureSystemCaTrust} call. */
63
+ let trustState;
64
+
65
+ /**
66
+ * Merge the operating-system CA roots into the process-wide default TLS trust
67
+ * store, once per process. Every HTTPS client that uses Node's defaults —
68
+ * global `fetch` (undici), `node:https`, and therefore the MCP SDK's transport
69
+ * and OAuth calls — then trusts exactly what the OS trusts.
70
+ *
71
+ * Safe to call from any host path: repeated calls are a no-op, and a host
72
+ * whose Node lacks the API simply keeps its previous behaviour.
73
+ * @param options - test/override hooks (not used by the plugin).
74
+ * @param options.refresh - recompute instead of returning the memoized state.
75
+ * @param options.systemCertificates - explicit system roots (tests, callers that already resolved them).
76
+ * @returns a summary of what happened, for logging.
77
+ */
78
+ export function ensureSystemCaTrust(options = {}) {
79
+ if (trustState !== undefined && options.refresh !== true) return trustState;
80
+ const canSetDefault =
81
+ typeof tls.getCACertificates === "function" && typeof tls.setDefaultCACertificates === "function";
82
+ if (!canSetDefault) {
83
+ trustState = { applied: false, added: 0, system: 0, reason: "node-api-unavailable" };
84
+ return trustState;
85
+ }
86
+ let defaults;
87
+ try {
88
+ defaults = tls.getCACertificates("default") ?? [];
89
+ } catch {
90
+ trustState = { applied: false, added: 0, system: 0, reason: "default-store-unreadable" };
91
+ return trustState;
92
+ }
93
+ let system;
94
+ try {
95
+ system = options.systemCertificates ?? systemCaCertificates();
96
+ } catch {
97
+ system = [];
98
+ }
99
+ if (system.length === 0) {
100
+ trustState = { applied: false, added: 0, system: 0, reason: "no-system-ca" };
101
+ return trustState;
102
+ }
103
+ const merged = [...new Set([...defaults, ...system])];
104
+ if (merged.length === defaults.length) {
105
+ trustState = { applied: false, added: 0, system: system.length, reason: "already-trusted" };
106
+ return trustState;
107
+ }
108
+ try {
109
+ tls.setDefaultCACertificates(merged);
110
+ } catch {
111
+ trustState = { applied: false, added: 0, system: system.length, reason: "set-failed" };
112
+ return trustState;
113
+ }
114
+ trustState = { applied: true, added: merged.length - defaults.length, system: system.length };
115
+ return trustState;
116
+ }
117
+
118
+ /** Test hook: forget the memoized state (the trust store itself is left as is). */
119
+ export function resetSystemCaTrustState() {
120
+ trustState = undefined;
121
+ scopedFetch = undefined;
122
+ }
123
+
124
+ /** Memoized scoped fetch (see {@link systemFetch}). */
125
+ let scopedFetch;
126
+
127
+ /**
128
+ * A `fetch` that verifies HTTPS against the operating-system roots, usable on
129
+ * every supported Node:
130
+ *
131
+ * - On Node >= 24.9 (Electron 44 ships 24.18) {@link ensureSystemCaTrust}
132
+ * patches the process default store, which global `fetch` already uses, so
133
+ * this returns the global fetch.
134
+ * - On older Node the default store cannot be patched; when the `undici`
135
+ * package is resolvable (it always is inside a DSH installation, and plain
136
+ * Node's own fetch is undici), this returns a fetch bound to an Agent whose
137
+ * `ca` is Node's bundled roots plus the OS roots.
138
+ * - Otherwise it returns global fetch unchanged, so the caller never breaks.
139
+ *
140
+ * @returns a fetch function (never undefined).
141
+ */
142
+ export function systemFetch() {
143
+ if (scopedFetch !== undefined) return scopedFetch;
144
+ const summary = ensureSystemCaTrust();
145
+ if (summary.applied) {
146
+ scopedFetch = fetch;
147
+ return scopedFetch;
148
+ }
149
+ const certificates = systemCaCertificates();
150
+ if (certificates.length === 0) {
151
+ scopedFetch = fetch;
152
+ return scopedFetch;
153
+ }
154
+ try {
155
+ const require = createRequire(import.meta.url);
156
+ const { Agent, fetch: undiciFetch } = require("undici");
157
+ const ca = [...new Set([...(tls.rootCertificates ?? []), ...certificates])];
158
+ const agent = new Agent({ connect: { ca } });
159
+ scopedFetch = (input, init) => undiciFetch(input, { ...init, dispatcher: agent });
160
+ } catch {
161
+ // No undici in reach (or an older API): stay on the global fetch rather
162
+ // than failing the connection.
163
+ scopedFetch = fetch;
164
+ }
165
+ return scopedFetch;
166
+ }
package/lib/transport.js CHANGED
@@ -1,9 +1,21 @@
1
1
  import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
2
2
  import { StreamableHTTPClientTransport } from "@modelcontextprotocol/client";
3
3
  import { scrubbedParentEnv } from "@deepseek-ai/dsh-subprocess";
4
+ import { ensureSystemCaTrust, systemFetch } from "./system-ca.js";
4
5
  function buildChildEnv(extra) {
5
6
  return { ...scrubbedParentEnv(), ...extra };
6
7
  }
8
+ /**
9
+ * HTTPS servers are verified against the operating-system trust store in
10
+ * addition to Node's bundled roots (see lib/system-ca.js): internal/corporate
11
+ * endpoints are usually signed by a CA that only the OS knows.
12
+ */
13
+ function trustSystemCaFor(url) {
14
+ try {
15
+ if (new URL(url).protocol === "https:") ensureSystemCaTrust();
16
+ } catch {
17
+ }
18
+ }
7
19
  function createTransport(config) {
8
20
  switch (config.transport) {
9
21
  case "stdio":
@@ -14,10 +26,14 @@ function createTransport(config) {
14
26
  cwd: config.cwd
15
27
  });
16
28
  case "streamable-http":
29
+ trustSystemCaFor(config.url);
17
30
  return new StreamableHTTPClientTransport(
18
31
  new URL(config.url),
19
32
  {
20
33
  requestInit: { headers: config.headers },
34
+ // HTTPS verification trusts the OS store (corporate/internal roots);
35
+ // the SDK reuses this fetch for its OAuth discovery/token calls.
36
+ fetch: systemFetch(),
21
37
  ...(config.authProvider === void 0 ? {} : { authProvider: config.authProvider })
22
38
  }
23
39
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-mcp",
3
- "version": "1.13.0",
3
+ "version": "1.14.0",
4
4
  "description": "MCP 管理界面 + tool search:可视化配置/启停/刷新 MCP 服务器与工具勾选,按需检索(tool search)热注入;工具列表稳定命中缓存、不撑爆上下文。DeepSeek Harness plugin: MCP management UI + tool search — stable tool list, cache-friendly, no context bloat.",
5
5
  "type": "module",
6
6
  "main": "lib/index.js",
@@ -41,7 +41,7 @@
41
41
  "url": "https://github.com/ArvinQi/dsh-mcp/issues"
42
42
  },
43
43
  "dsh": {
44
- "supported": "0.1.6-alpha.2",
44
+ "supported": "0.2.0-rc.2",
45
45
  "bundle": {
46
46
  "patch": "./cordis.patch.yml"
47
47
  },
package/scripts/test.mjs CHANGED
@@ -27,6 +27,7 @@ const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..')
27
27
  /** Test files that require the DSH module closure at import time. */
28
28
  const NEEDS_DSH_CLOSURE = new Set([
29
29
  'cordis-servers.test.mjs',
30
+ 'oauth-flow.test.mjs',
30
31
  'patch-writer.test.mjs',
31
32
  'stdio-env.test.mjs',
32
33
  'takeover.test.mjs',
@@ -218,6 +218,27 @@ button:disabled {
218
218
  color: var(--dsw-alias-brand-primary);
219
219
  }
220
220
 
221
+ .badge.oauth {
222
+ background: color-mix(in srgb, var(--dsw-alias-state-warn-primary) 14%, transparent);
223
+ color: var(--dsw-alias-state-warn-primary);
224
+ }
225
+
226
+ .badge.oauthMiss {
227
+ background: color-mix(in srgb, var(--dsw-alias-state-error-primary) 12%, transparent);
228
+ color: var(--dsw-alias-state-error-primary);
229
+ }
230
+
231
+ /* The authorization button of an unauthorized OAuth server: red, so the
232
+ missing authorization is visible without any warning text. */
233
+ .dangerButton {
234
+ border-color: var(--dsw-alias-state-error-primary);
235
+ color: var(--dsw-alias-state-error-primary);
236
+ }
237
+
238
+ .dangerButton:hover {
239
+ background: color-mix(in srgb, var(--dsw-alias-state-error-primary) 12%, transparent);
240
+ }
241
+
221
242
  .note {
222
243
  margin: 6px 0 0;
223
244
  color: var(--dsw-alias-label-secondary);
@@ -4,7 +4,7 @@ import type {
4
4
  McpToolInjectionMode, McpToolsState, McpToolView,
5
5
  } from './types.ts'
6
6
  import type { InjectFace, PropsLocale, PropsRuntime, PropsStore } from '@deepseek-ai/dsh-client-ui-slots'
7
- import { McpServerForm, type McpServerFormRemote } from './ServerForm.tsx'
7
+ import { McpServerForm, OAUTH_POLL_MS, type McpServerFormRemote } from './ServerForm.tsx'
8
8
  import { ServersJsonEditor, type ServersJsonEntry } from './ServersJsonEditor.tsx'
9
9
  import { GlobalEnvEditor, type GlobalEnvRemote } from './GlobalEnvEditor.tsx'
10
10
  import type { McpToolControlRemote } from './ToolControlSection.tsx'
@@ -84,7 +84,7 @@ function viewToDraft(server: McpServerView): McpDraft {
84
84
  * per-server tool-binding list, or the editor when a draft is open.
85
85
  */
86
86
  export function McpSettingsSection(props: McpSettingsSectionProps): ReactNode {
87
- const { list, save, remove, test, adopt, release } = props
87
+ const { list, save, remove, test, adopt, release, oauthStart, oauthStatus } = props
88
88
  const state = props.useStore(snapshot => snapshot)
89
89
  const { setLoadState, setServers, beginCreate, beginEdit, cancelEdit, updateDraft, setBusy, setTestRunning, setTest } = props.actions
90
90
  const t = props.t
@@ -98,9 +98,22 @@ export function McpSettingsSection(props: McpSettingsSectionProps): ReactNode {
98
98
  const [jsonOpen, setJsonOpen] = useState(false)
99
99
  const [envOpen, setEnvOpen] = useState(true)
100
100
  const [adopting, setAdopting] = useState<ReadonlySet<string>>(new Set())
101
+ const [oauthWaiting, setOauthWaiting] = useState<ReadonlySet<string>>(new Set())
102
+ const [oauthStarting, setOauthStarting] = useState<ReadonlySet<string>>(new Set())
103
+ const [oauthLinks, setOauthLinks] = useState<ReadonlyMap<string, string>>(() => new Map())
104
+ const [oauthErrors, setOauthErrors] = useState<ReadonlyMap<string, string>>(() => new Map())
105
+ const [oauthIncomplete, setOauthIncomplete] = useState<ReadonlySet<string>>(new Set())
101
106
  const [actionError, setActionError] = useState<string | null>(null)
102
107
  const [actionNotice, setActionNotice] = useState<string | null>(null)
103
108
  const timersRef = useRef<number[]>([])
109
+ /** Servers whose flow died (no listener, no tokens): stop polling them. */
110
+ const oauthStoppedRef = useRef<Set<string>>(new Set())
111
+ // The injected face is re-created on every render; the poller reads it
112
+ // through a ref so its interval is not restarted by unrelated renders.
113
+ const oauthStatusRef = useRef(oauthStatus)
114
+ oauthStatusRef.current = oauthStatus
115
+ const tRef = useRef(t)
116
+ tRef.current = t
104
117
  let inlineForm: ReactNode | null = null
105
118
 
106
119
  useEffect(() => () => {
@@ -213,6 +226,97 @@ export function McpSettingsSection(props: McpSettingsSectionProps): ReactNode {
213
226
  })
214
227
  }
215
228
 
229
+ /**
230
+ * Servers the Host itself reports as awaiting authorization: a mount that
231
+ * only failed because the user still has to authorize, or an interactive
232
+ * flow the mount opened (`allowBrowserOnMount`). They are polled too, so a
233
+ * browser authorization completed while the page sat open is noticed within
234
+ * one poll interval instead of needing a manual refresh. A server whose flow
235
+ * already died (no listener, no tokens) stops being polled until the user
236
+ * clicks its button again.
237
+ */
238
+ const hostPendingOAuth = state.servers
239
+ .filter(server => server.oauth === true
240
+ && server.status.oauthRequired === true
241
+ && server.oauthAuthorized !== true
242
+ && !oauthStoppedRef.current.has(server.serverName))
243
+ .map(server => server.serverName)
244
+ const pollKey = [...new Set([...oauthWaiting, ...hostPendingOAuth])].sort().join(',')
245
+
246
+ /**
247
+ * Poll the authorization state of every pending flow every 5s. Nothing
248
+ * renders as failed before the host reports tokens; a completed
249
+ * authorization refreshes the list (the host remounts the server when the
250
+ * credentials update lands), and a flow that is gone stops being polled.
251
+ */
252
+ useEffect(() => {
253
+ if (pollKey.length === 0) return
254
+ const names = pollKey.split(',')
255
+ let cancelled = false
256
+ const tick = async (): Promise<void> => {
257
+ const results = await Promise.all(names.map(async (name) => {
258
+ try {
259
+ return { name, status: await oauthStatusRef.current(name) }
260
+ } catch (error) {
261
+ console.error('[dsh-mcp] oauthStatus failed:', error)
262
+ return { name, status: null }
263
+ }
264
+ }))
265
+ if (cancelled) return
266
+ const authorized = results
267
+ .filter(entry => entry.status?.authorized === true)
268
+ .map(entry => entry.name)
269
+ // A flow that reported a failure (`access_denied`, token exchange, ...)
270
+ // or that lost its listener is not going to complete on its own: stop
271
+ // polling it, remember the outcome, and let the user retry.
272
+ const failed = results
273
+ .filter(entry => entry.status !== null && !entry.status.authorized && entry.status.error !== undefined)
274
+ .map(entry => ({ name: entry.name, error: entry.status?.error ?? '' }))
275
+ const gone = results
276
+ .filter(entry => entry.status !== null && !entry.status.authorized && entry.status.error === undefined && !entry.status.pending)
277
+ .map(entry => entry.name)
278
+ for (const entry of failed) {
279
+ oauthStoppedRef.current.add(entry.name)
280
+ setOauthErrors(prev => new Map(prev).set(entry.name, entry.error))
281
+ }
282
+ for (const name of gone) {
283
+ oauthStoppedRef.current.add(name)
284
+ setOauthIncomplete(prev => new Set(prev).add(name))
285
+ }
286
+ const finished = new Set([
287
+ ...authorized,
288
+ ...failed.map(entry => entry.name),
289
+ ...gone,
290
+ ])
291
+ if (finished.size === 0) return
292
+ setOauthWaiting((prev) => {
293
+ const next = new Set(prev)
294
+ for (const name of finished) next.delete(name)
295
+ return next
296
+ })
297
+ if (authorized.length === 0) return
298
+ setOauthErrors((prev) => {
299
+ const next = new Map(prev)
300
+ for (const name of authorized) next.delete(name)
301
+ return next
302
+ })
303
+ setOauthIncomplete((prev) => {
304
+ const next = new Set(prev)
305
+ for (const name of authorized) next.delete(name)
306
+ return next
307
+ })
308
+ setActionError(null)
309
+ setActionNotice(tRef.current('oauthAuthorized'))
310
+ refreshServer('')
311
+ }
312
+ void tick()
313
+ const timer = window.setInterval(() => { void tick() }, OAUTH_POLL_MS)
314
+ return () => {
315
+ cancelled = true
316
+ window.clearInterval(timer)
317
+ }
318
+ }, [pollKey])
319
+
216
320
  const runAdopt = async (server: McpServerView): Promise<void> => {
217
321
  const giveBack = server.adopted === true
218
322
  // Giving a declaration back to a composition that cannot authenticate it
@@ -240,6 +344,45 @@ export function McpSettingsSection(props: McpSettingsSectionProps): ReactNode {
240
344
  }
241
345
  }
242
346
 
347
+ /**
348
+ * Row-level authorization: ask the Host to start (or reuse) the server's
349
+ * flow. The Host opens the system browser itself — a client-side
350
+ * `window.open` is denied inside the DSH shell and only flashes a blank tab
351
+ * — and the row keeps the URL as a manual fallback link. The 5s poller above
352
+ * then reports "authorizing…", the failure reason, or success.
353
+ */
354
+ const runOAuth = async (server: McpServerView): Promise<void> => {
355
+ setActionError(null)
356
+ setActionNotice(null)
357
+ oauthStoppedRef.current.delete(server.serverName)
358
+ setOauthErrors(prev => {
359
+ const next = new Map(prev)
360
+ next.delete(server.serverName)
361
+ return next
362
+ })
363
+ setOauthIncomplete(prev => {
364
+ const next = new Set(prev)
365
+ next.delete(server.serverName)
366
+ return next
367
+ })
368
+ setOauthStarting(prev => new Set(prev).add(server.serverName))
369
+ try {
370
+ const url = await oauthStart({ id: server.id, serverName: server.serverName })
371
+ setOauthLinks(prev => new Map(prev).set(server.serverName, url))
372
+ setOauthWaiting(prev => new Set(prev).add(server.serverName))
373
+ } catch (error) {
374
+ // A missing Host method (a client/host version mismatch before the next
375
+ // restart) is the one failure this path can hit; say what to do.
376
+ setActionError(`${tRef.current('oauthStartFailed')}: ${String((error instanceof Error ? error.message : error) ?? error)}`)
377
+ } finally {
378
+ setOauthStarting(prev => {
379
+ const next = new Set(prev)
380
+ next.delete(server.serverName)
381
+ return next
382
+ })
383
+ }
384
+ }
385
+
243
386
  const toggleEnabled = async (server: McpServerView): Promise<void> => {
244
387
  const target = !server.enabled
245
388
  const draft = viewToDraft(server)
@@ -297,7 +440,7 @@ export function McpSettingsSection(props: McpSettingsSectionProps): ReactNode {
297
440
  test={state.test}
298
441
  t={t}
299
442
  actions={actions}
300
- injected={{ save, remove, test, list }}
443
+ injected={{ save, remove, test, list, oauthStart, oauthStatus }}
301
444
  onSaved={() => {
302
445
  // Mounting is asynchronous: refresh again after the connection
303
446
  // settles so the badge and tool count reflect the live state without
@@ -416,6 +559,31 @@ export function McpSettingsSection(props: McpSettingsSectionProps): ReactNode {
416
559
  // Declared servers are mounted by the composition, so this page
417
560
  // only views them: no enable/disable, no refresh, no editor.
418
561
  const declared = server.source === 'cordis'
562
+ // OAuth state of a managed row: unauthorized rows carry the red
563
+ // button (and never the raw authorization-link error), a pending
564
+ // flow reads as "awaiting authorization", and once tokens are
565
+ // stored the button disappears.
566
+ const oauthManaged = !declared && server.oauth === true
567
+ const oauthAuthorized = server.oauthAuthorized === true
568
+ const oauthNeedsAuth = oauthManaged && !oauthAuthorized
569
+ // A server that is live and serving tools does not need the red
570
+ // "not authorized" alarm even without OAuth tokens (its static
571
+ // headers may be enough): keep a plain button, drop the alarm.
572
+ const oauthUsable = server.status.phase === 'live' && server.status.tools.length > 0
573
+ const oauthBlocks = oauthNeedsAuth && !oauthUsable
574
+ const oauthPending = oauthNeedsAuth && server.status.oauthRequired === true
575
+ const oauthInFlight = oauthNeedsAuth
576
+ && (oauthStarting.has(server.serverName) || oauthWaiting.has(server.serverName))
577
+ // The mount's "authorization required" error embeds the link (and
578
+ // only that error does); it is recognized across host versions so
579
+ // the row shows the button hint instead of the raw link text.
580
+ const oauthLinkError = oauthNeedsAuth
581
+ && typeof server.status.error === 'string'
582
+ && server.status.error.includes('response_type=code')
583
+ /** Manual fallback for the authorization page (the Host opens the browser itself). */
584
+ const oauthLink = oauthLinks.get(server.serverName)
585
+ const oauthError = oauthErrors.get(server.serverName)
586
+ const oauthIncompleteHere = oauthIncomplete.has(server.serverName)
419
587
  const card = (
420
588
  <li key={server.id} className={css.card}>
421
589
  <div className={css.row}>
@@ -430,6 +598,12 @@ export function McpSettingsSection(props: McpSettingsSectionProps): ReactNode {
430
598
  <span className={`${css.badge} ${css.cordis}`}>{t('pendingBadge')}</span>
431
599
  ) : server.conflict ? (
432
600
  <span className={`${css.badge} ${css.cordis}`}>{t('conflictBadge')}</span>
601
+ ) : oauthPending ? (
602
+ /* A flow is waiting for the user: the pending state,
603
+ never a pre-authorization failure. */
604
+ <span className={`${css.badge} ${css.oauth}`}>{t('oauthBadgeWaiting')}</span>
605
+ ) : oauthBlocks ? (
606
+ <span className={`${css.badge} ${css.oauthMiss}`}>{t('oauthBadgeUnauthorized')}</span>
433
607
  ) : (
434
608
  <span className={`${css.badge} ${css[server.status.phase]}`}>{t(phaseKey(server.status.phase))}</span>
435
609
  )}
@@ -445,7 +619,30 @@ export function McpSettingsSection(props: McpSettingsSectionProps): ReactNode {
445
619
  ) : null}
446
620
  {server.conflict ? <p className={css.warn}>{t('conflictDeclared')}</p> : null}
447
621
  {server.needsPlugin ? <p className={css.warn}>{t('needsPluginHint')}</p> : null}
448
- {server.status.error ? <p className={css.warn}>{server.status.error}</p> : null}
622
+ {/* The authorization outcome, always visible: authorizing
623
+ (with a manual link), the failure reason reported by the
624
+ authorization server, "did not complete", or the short
625
+ "click the button" hint. Only non-authorization failures
626
+ keep the raw mount error. */}
627
+ {oauthInFlight || (oauthPending && oauthLink !== undefined) ? (
628
+ <p className={css.note}>
629
+ {t('oauthInProgress')}
630
+ {oauthLink !== undefined ? (
631
+ <>
632
+ {' · '}
633
+ <a href={oauthLink} target="_blank" rel="noreferrer">{t('oauthOpenManual')}</a>
634
+ </>
635
+ ) : null}
636
+ </p>
637
+ ) : oauthError !== undefined ? (
638
+ <p className={css.warn}>{t('oauthFailed')}: {oauthError}</p>
639
+ ) : oauthIncompleteHere ? (
640
+ <p className={css.note}>{t('oauthNotCompleted')}</p>
641
+ ) : oauthPending || oauthBlocks ? (
642
+ <p className={css.note}>{t('oauthRequiredHint')}</p>
643
+ ) : oauthLinkError && !oauthUsable ? (
644
+ <p className={css.note}>{t('oauthRequiredHint')}</p>
645
+ ) : server.status.error ? <p className={css.warn}>{server.status.error}</p> : null}
449
646
  {declared ? <p className={css.note}>{t('readOnlyHint')}</p> : null}
450
647
  {server.stale ? <p className={css.note}>{t('staleMirror')}</p> : null}
451
648
  {server.skipReason === 'js-expression' ? <p className={css.warn}>{t('skipJsExpr')}</p> : null}
@@ -458,6 +655,20 @@ export function McpSettingsSection(props: McpSettingsSectionProps): ReactNode {
458
655
  {server.enabled ? t('disable') : t('enabled')}
459
656
  </button>
460
657
  )}
658
+ {/* Unauthorized OAuth servers keep the button; it is red
659
+ only when the missing authorization actually blocks the
660
+ server (not live with tools). It reads "authorizing…"
661
+ from the click on and the 5s poll hides it once tokens
662
+ land. */}
663
+ {oauthNeedsAuth && !server.conflict && !server.pendingTakeover ? (
664
+ <button
665
+ type="button"
666
+ className={oauthBlocks ? css.dangerButton : undefined}
667
+ onClick={() => void runOAuth(server)}
668
+ >
669
+ {oauthInFlight ? t('oauthInProgress') : t('oauthAuthorize')}
670
+ </button>
671
+ ) : null}
461
672
  {declared ? null : (
462
673
  <button type="button" disabled={isRefreshing} onClick={() => refreshServer(server.serverName)}>
463
674
  {isRefreshing ? t('refreshing') : t('refresh')}
@@ -142,6 +142,25 @@ button:disabled {
142
142
  color: var(--dsw-alias-state-error-primary);
143
143
  }
144
144
 
145
+ .oauthWaiting {
146
+ font-size: 12px;
147
+ line-height: 18px;
148
+ color: var(--dsw-alias-state-warn-primary);
149
+ }
150
+
151
+ .oauthOk {
152
+ font-size: 12px;
153
+ line-height: 18px;
154
+ color: var(--dsw-alias-state-success-primary);
155
+ }
156
+
157
+ .oauthRequired {
158
+ margin: 0;
159
+ font-size: 13px;
160
+ line-height: 20px;
161
+ color: var(--dsw-alias-state-warn-primary);
162
+ }
163
+
145
164
  .actions {
146
165
  display: flex;
147
166
  justify-content: flex-end;