From 96cee49bef450f0d370f619e93b2cb659ff6724d Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Fri, 20 Nov 2026 14:43:54 -0800 Subject: [PATCH] feat(mobile): sign in to an agent's MCP server from its notice On mobile, an MCP sign-in notice opens a sheet: Open sign-in page starts the sign-in and opens the browser, then the user pastes the address it lands on and taps Finish sign-in. The row ends in Sign in, then Signed in. The whole row is the button because iOS hides a button nested in a pressable row from VoiceOver. Co-Authored-By: Claude Opus 5.5 --- .../src/features/threads/McpSignInSheet.tsx | 167 ++++++++++++++++++ .../src/features/threads/thread-work-log.tsx | 73 +++++++- apps/mobile/src/i18n/translations/de.json | 8 + apps/mobile/src/i18n/translations/en.json | 8 + apps/mobile/src/i18n/translations/es.json | 8 + apps/mobile/src/i18n/translations/fr.json | 8 + apps/mobile/src/i18n/translations/ja.json | 8 + apps/mobile/src/i18n/translations/ko.json | 8 + apps/mobile/src/i18n/translations/pt-BR.json | 8 + apps/mobile/src/i18n/translations/ru.json | 8 + apps/mobile/src/i18n/translations/sv.json | 8 + apps/mobile/src/i18n/translations/zh.json | 8 + docs/user/providers-claude.md | 2 +- docs/user/providers-codex.md | 10 +- 14 files changed, 319 insertions(+), 13 deletions(-) create mode 100644 apps/mobile/src/features/threads/McpSignInSheet.tsx diff --git a/apps/mobile/src/features/threads/McpSignInSheet.tsx b/apps/mobile/src/features/threads/McpSignInSheet.tsx new file mode 100644 index 000000000000..8053fe4a32b6 --- /dev/null +++ b/apps/mobile/src/features/threads/McpSignInSheet.tsx @@ -0,0 +1,167 @@ +import type { EnvironmentId, ProviderThreadId, ThreadId } from "@t3tools/contracts"; +import { errorDisplayMessage } from "@t3tools/client-runtime/errors"; +import { + type AtomCommandResult, + isAtomCommandInterrupted, + squashAtomCommandFailure, +} from "@t3tools/client-runtime/state/runtime"; +import * as Haptics from "expo-haptics"; +import { msg, T, useGT, useMessages } from "gt-react-native"; +import { useState } from "react"; +import { ScrollView } from "react-native"; +import { useSafeAreaInsets } from "react-native-safe-area-context"; + +import { AppText as Text, AppTextInput as TextInput } from "../../components/ui/AppText"; +import { Button } from "../../components/ui/Button"; +import { Sheet } from "../../components/ui/Sheet"; +import { tryOpenExternalUrl } from "../../lib/openExternalUrl"; +import { threadEnvironment } from "../../state/threads"; +import { useAtomCommand } from "../../state/use-atom-command"; + +export interface McpSignInTarget { + readonly threadId: ThreadId; + readonly providerThreadId: ProviderThreadId; + readonly server: string; +} + +/** + * Signs an agent's MCP server in from the notice that says it needs one. The + * agent keeps the credential; the user approves in a browser, then pastes back + * the address it lands on, which is often a localhost page on another machine. + */ +export function McpSignInSheet(props: { + readonly environmentId: EnvironmentId; + readonly target: McpSignInTarget; + readonly onClose: () => void; +}) { + const gt = useGT(); + const m = useMessages(); + const insets = useSafeAreaInsets(); + const { server } = props.target; + const start = useAtomCommand(threadEnvironment.mcpSignInStart, { + label: "start MCP sign-in", + reportFailure: false, + reportDefect: false, + }); + const complete = useAtomCommand(threadEnvironment.mcpSignInComplete, { + label: "finish MCP sign-in", + reportFailure: false, + reportDefect: false, + }); + const [url, setUrl] = useState(null); + const [callbackUrl, setCallbackUrl] = useState(""); + const [busy, setBusy] = useState(false); + const [error, setError] = useState(null); + + const failed = (result: AtomCommandResult & { readonly _tag: "Failure" }) => { + if (isAtomCommandInterrupted(result)) return; + setError( + errorDisplayMessage(squashAtomCommandFailure(result), m) ?? + m(msg("The sign-in couldn't continue. Try again.")), + ); + }; + // The command marks the server signed in for the thread, which every notice about it shows. + const signedIn = () => { + void Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success); + props.onClose(); + }; + const openSignInPage = async () => { + setBusy(true); + setError(null); + let page = url; + if (page === null) { + const result = await start({ environmentId: props.environmentId, input: props.target }); + if (result._tag === "Failure") { + setBusy(false); + failed(result); + return; + } + if (result.value.authorizationUrl === null) { + setBusy(false); + signedIn(); + return; + } + page = result.value.authorizationUrl; + setUrl(page); + } + setBusy(false); + if (!(await tryOpenExternalUrl(page, "provider-auth"))) { + setError(gt("Could not open the sign-in page.")); + } + }; + const finish = async () => { + const pasted = callbackUrl.trim(); + if (pasted.length === 0) return; + setBusy(true); + setError(null); + const result = await complete({ + environmentId: props.environmentId, + input: { ...props.target, callbackUrl: pasted }, + }); + setBusy(false); + if (result._tag === "Success") signedIn(); + else failed(result); + }; + + return ( + + + + + Approve access in your browser. It then opens a page that may not load: copy that page's + address and paste it here. + + +