Jotley / app / macOS / Views / SettingsView+MCPDesktopSetup.swift
| 1 | import AppKit |
| 2 | import SwiftUI |
| 3 | |
| 4 | extension SettingsView { |
| 5 | var mcpDesktopSetup: some View { |
| 6 | VStack(alignment: .leading, spacing: 20) { |
| 7 | Text("Choose your Mac app").font(.headline) |
| 8 | Picker("Connect to", selection: $mcpClient) { |
| 9 | Text("Claude Code app").tag("Claude Code app") |
| 10 | Text("Codex app").tag("Codex app") |
| 11 | Text("Claude chat · advanced").tag("Claude chat") |
| 12 | }.pickerStyle(.segmented).labelsHidden() |
| 13 | .onChange(of: mcpClient) { _, _ in mcpCopiedItem = nil; mcpSetupMessage = nil } |
| 14 | |
| 15 | if mcpClient == "Claude Code app" { |
| 16 | mcpSetupStep(1, title: "Save a connection in your project", detail: "Choose the folder you work in. Jotley adds its entry to that folder’s .mcp.json and preserves other servers. The connection uses this copy of Jotley, with no access token in the project file.") { |
| 17 | Button("Save project connection…") { |
| 18 | guard let configuration = JotleyMCPDesktopSetup.projectConfiguration else { return } |
| 19 | runMCPSetup { try JotleyMCPDesktopSetup.saveProject(configuration: configuration) } |
| 20 | }.disabled(!mcp.enabled).accessibilityIdentifier("mcpSaveClaudeProject") |
| 21 | } |
| 22 | mcpSetupStep(2, title: "Open Claude’s Code tab", detail: "In the Claude Mac app, select Code. Start a new local session on This computer and choose that same project folder. Review Claude’s project MCP trust prompt.") { |
| 23 | Button("Open Claude") { openMCPClient("com.anthropic.claudefordesktop", name: "Claude") } |
| 24 | } |
| 25 | mcpSetupStep(3, title: "Check Connectors in the local session", detail: "Open the session’s Connectors panel and check Jotley. If the project was already open, start a new session. Regular Claude chat uses the separate Claude chat setup here.") { mcpTryPrompt } |
| 26 | Link("Claude Code desktop guide", destination: URL(string: "https://code.claude.com/docs/en/desktop#connect-external-tools")!) |
| 27 | } else if mcpClient == "Codex app" { |
| 28 | mcpSetupStep(1, title: "Add an MCP server in Codex", detail: "Open Codex for Mac. Go to Settings → MCP servers → Add server. Name the server jotley and choose STDIO.") { |
| 29 | Button("Open Codex") { openMCPClient("com.openai.codex", name: "Codex") } |
| 30 | } |
| 31 | mcpSetupStep(2, title: "Paste the two connection fields", detail: "Paste Command as a path, without extra quotes. Add one Argument and paste its value below. Leave Environment variables empty. Jotley’s bundled bridge handles the connection; no separate runtime or token is needed.") { |
| 32 | VStack(alignment: .leading, spacing: 10) { |
| 33 | mcpCopyField("Command", value: JotleyMCPDesktopSetup.command, item: "commandPath") |
| 34 | mcpCopyField("Argument", value: JotleyMCPDesktopSetup.argument, item: "argument") |
| 35 | } |
| 36 | } |
| 37 | mcpSetupStep(3, title: "Save, restart and check", detail: "Click Save, then Restart for the server. Start a local chat and type /mcp to check Jotley. Some current versions label the desktop app ChatGPT. Keep Jotley open and in its current location.") { mcpTryPrompt } |
| 38 | Link("Codex desktop MCP guide", destination: URL(string: "https://learn.chatgpt.com/docs/extend/mcp?surface=desktop")!) |
| 39 | } else { |
| 40 | mcpSetupStep(1, title: "Save the Claude chat extension", detail: "This is for regular Claude chat in the Mac app. Claude supplies the runtime, so there is nothing to install in Terminal. The saved extension contains no access token.") { |
| 41 | Button("Save Claude extension…") { runMCPSetup { try JotleyMCPDesktopSetup.saveClaudeExtension(endpoint: mcp.endpoint) } } |
| 42 | .disabled(!mcp.enabled).accessibilityIdentifier("mcpSaveClaudeExtension") |
| 43 | } |
| 44 | mcpSetupStep(2, title: "Install it in Claude’s local extensions", detail: "Open Claude → Settings → Desktop app → Extensions → Manage → Advanced settings → Install Extension…. Choose Jotley.mcpb and follow the prompts. Older versions start at Settings → Extensions.") { |
| 45 | Button("Open Claude") { openMCPClient("com.anthropic.claudefordesktop", name: "Claude") } |
| 46 | } |
| 47 | mcpSetupStep(3, title: "Paste your token and connect", detail: "In the extension’s Jotley access token field, paste the token copied here and save. Start a new chat and check Jotley under + → Connectors. Keep Jotley open.") { |
| 48 | Button(mcpCopiedItem == "token" ? "Token copied ✓" : "Copy access token") { copyMCP(mcp.accessToken, item: "token") } |
| 49 | .disabled(!mcp.enabled).accessibilityIdentifier("mcpCopyAccessToken") |
| 50 | mcpTryPrompt |
| 51 | } |
| 52 | Text("Use a local extension, rather than Claude’s remote connector URL field: cloud connections cannot reach this Mac-only server.") |
| 53 | .font(.caption).foregroundStyle(.secondary) |
| 54 | Link("Claude local extension guide", destination: URL(string: "https://support.claude.com/en/articles/10949351-getting-started-with-local-mcp-servers-on-claude-desktop")!) |
| 55 | } |
| 56 | if let message = mcpSetupMessage { |
| 57 | Text(message).font(.callout).foregroundStyle(.secondary).textSelection(.enabled) |
| 58 | .accessibilityIdentifier("mcpSetupMessage") |
| 59 | } |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | private var mcpTryPrompt: some View { |
| 64 | VStack(alignment: .leading, spacing: 8) { |
| 65 | Text("Ask your agent").font(.caption.bold()) |
| 66 | Text("Search my Jotley notes for release planning and tell me who owns each action.") |
| 67 | .font(.callout).textSelection(.enabled) |
| 68 | Button(mcpCopiedItem == "question" ? "Copied ✓" : "Copy request") { |
| 69 | copyMCP("Search my Jotley notes for release planning and tell me who owns each action.", item: "question") |
| 70 | }.disabled(!mcp.enabled) |
| 71 | if mcp.allowsWriting { |
| 72 | Text("Then try: “Find that note, rename it Launch checklist, and rewrite its summary as a checklist. Keep the transcript unchanged.” Open it in Jotley to see the saved change.") |
| 73 | .font(.caption).foregroundStyle(.secondary).textSelection(.enabled) |
| 74 | } |
| 75 | Text("Jotley’s Last agent seen and Last successful request above confirm actual client activity.") |
| 76 | .font(.caption).foregroundStyle(.secondary) |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | private func mcpCopyField(_ label: String, value: String, item: String) -> some View { |
| 81 | HStack { |
| 82 | VStack(alignment: .leading, spacing: 3) { |
| 83 | Text(label).font(.caption.bold()) |
| 84 | Text(value).font(.system(.caption, design: .monospaced)).textSelection(.enabled) |
| 85 | } |
| 86 | Spacer() |
| 87 | Button(mcpCopiedItem == item ? "Copied ✓" : "Copy \(label)") { copyMCP(value, item: item) } |
| 88 | .disabled(!mcp.enabled) |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | private func runMCPSetup(_ operation: () throws -> String?) { |
| 93 | do { mcpSetupMessage = try operation() } |
| 94 | catch { mcpSetupMessage = "Setup could not finish. \(error.localizedDescription)" } |
| 95 | } |
| 96 | |
| 97 | private func openMCPClient(_ bundleID: String, name: String) { |
| 98 | if !JotleyMCPDesktopSetup.openClient(bundleID) { |
| 99 | // The unified desktop app can register the ChatGPT bundle instead. |
| 100 | if bundleID == "com.openai.codex", JotleyMCPDesktopSetup.openClient("com.openai.chat") { return } |
| 101 | mcpSetupMessage = "\(name) could not be found. Open it from Applications after installing it." |
| 102 | } |
| 103 | } |
| 104 | } |