Repair Toolbox navigation, chat web lookup, and model discovery
This commit is contained in:
+44
-19
@@ -232,6 +232,7 @@ struct MCPSettings: View {
|
||||
@State private var profiles: [String: MCPServerConfiguration] = [:]
|
||||
@State private var importingConfig = false
|
||||
@State private var configStatus = ""
|
||||
@State private var profileErrors: [String: String] = [:]
|
||||
|
||||
private var profile: MCPServerConfiguration? { profiles[selectedProfile] }
|
||||
private var local: Bool { profile.map { $0.command != nil } ?? (transport == "stdio") }
|
||||
@@ -268,19 +269,37 @@ struct MCPSettings: View {
|
||||
Button("Edit File") { NSWorkspace.shared.open(URL(fileURLWithPath: configPath)) }
|
||||
}
|
||||
}
|
||||
if !profiles.isEmpty {
|
||||
Picker("Server", selection: $selectedProfile) {
|
||||
Text("Manual connection").tag("")
|
||||
ForEach(profiles.keys.sorted(), id: \.self) { name in Text(name).tag(name) }
|
||||
ForEach(profiles.keys.sorted(), id: \.self) { serverName in
|
||||
if let entry = profiles[serverName] {
|
||||
VStack(alignment: .leading, spacing: 6) {
|
||||
HStack {
|
||||
Label(serverName, systemImage: entry.command == nil ? "network" : "terminal")
|
||||
.font(.headline)
|
||||
Spacer()
|
||||
if studio.activeToolset?.profileName == serverName {
|
||||
Text("\(tools.count) tools · Connected").font(.caption).foregroundStyle(.green)
|
||||
Button("Disconnect") { resetConnection() }.disabled(busy)
|
||||
} else {
|
||||
Button(busy && selectedProfile == serverName ? "Connecting…" : "Connect") {
|
||||
selectedProfile = serverName
|
||||
if entry.command != nil { confirmingStartup = true; confirm = true }
|
||||
else { discover() }
|
||||
}.disabled(busy)
|
||||
}
|
||||
}
|
||||
Text(entry.command == nil ? "Streamable HTTP" : "Local stdio")
|
||||
.font(.caption).foregroundStyle(.secondary)
|
||||
if let error = profileErrors[serverName] {
|
||||
Text(error).font(.caption).foregroundStyle(.red).textSelection(.enabled)
|
||||
}
|
||||
}
|
||||
.padding(.vertical, 3)
|
||||
}
|
||||
}
|
||||
if !configStatus.isEmpty { Text(configStatus).foregroundStyle(.secondary).textSelection(.enabled) }
|
||||
}
|
||||
Section("MCP server") {
|
||||
if let profile {
|
||||
LabeledContent("Transport", value: local ? "Local stdio" : "Streamable HTTP")
|
||||
LabeledContent("Target", value: profile.target)
|
||||
} else {
|
||||
Section("Manual Connection") {
|
||||
DisclosureGroup("Configure a manual connection") {
|
||||
Picker("Transport", selection: $transport) {
|
||||
Text("Streamable HTTP").tag("http")
|
||||
Text("Local stdio").tag("stdio")
|
||||
@@ -294,12 +313,13 @@ struct MCPSettings: View {
|
||||
}
|
||||
}
|
||||
HStack {
|
||||
Button(local ? "Start Server and Discover…" : "Discover Tools") {
|
||||
if local { confirmingStartup = true; confirm = true }
|
||||
Button("Connect Manually") {
|
||||
selectedProfile = ""
|
||||
if transport == "stdio" { confirmingStartup = true; confirm = true }
|
||||
else { discover() }
|
||||
}
|
||||
.disabled(busy || target.isEmpty)
|
||||
if client != nil {
|
||||
.disabled(busy || (transport == "stdio" ? executable.isEmpty : endpoint.isEmpty))
|
||||
if studio.activeToolset?.profileName == nil && client != nil && !(client is BuiltInWebTools) {
|
||||
Button("Disconnect") { resetConnection() }.disabled(busy)
|
||||
}
|
||||
if busy { Button("Cancel") { operation?.cancel() } }
|
||||
@@ -349,7 +369,6 @@ struct MCPSettings: View {
|
||||
if !configPath.isEmpty { loadConfig(URL(fileURLWithPath: configPath), disconnect: false) }
|
||||
if !tools.contains(where: { $0.name == name }) { name = tools.first?.name ?? "" }
|
||||
}
|
||||
.onChange(of: selectedProfile) { _, _ in resetConnection() }
|
||||
.onChange(of: endpoint) { _, _ in resetConnection() }
|
||||
.onChange(of: token) { _, _ in resetConnection() }
|
||||
.onChange(of: name) { _, _ in arguments = "{}" }
|
||||
@@ -388,6 +407,7 @@ struct MCPSettings: View {
|
||||
let file = try MCPServerConfiguration.File.read(url)
|
||||
if disconnect { resetConnection() }
|
||||
profiles = file.mcpServers
|
||||
profileErrors = [:]
|
||||
configPath = url.path
|
||||
if profiles[selectedProfile] == nil && (disconnect || !selectedProfile.isEmpty) {
|
||||
let names = profiles.keys.sorted()
|
||||
@@ -403,8 +423,9 @@ struct MCPSettings: View {
|
||||
}
|
||||
|
||||
private func discover() {
|
||||
run {
|
||||
resetConnection(cancel: false)
|
||||
let profileName = profile == nil ? nil : selectedProfile
|
||||
if let profileName { profileErrors[profileName] = nil }
|
||||
run(profileName: profileName) {
|
||||
let server: any MCPToolClient
|
||||
if let profile {
|
||||
server = try profile.makeClient()
|
||||
@@ -417,7 +438,7 @@ struct MCPSettings: View {
|
||||
let discovered = try await server.listTools()
|
||||
try Task.checkCancellation()
|
||||
studio.activeToolset = ActiveToolset(name: profile == nil ? target : selectedProfile,
|
||||
client: server, tools: discovered)
|
||||
client: server, tools: discovered, profileName: profileName)
|
||||
name = discovered.first?.name ?? ""
|
||||
result = discovered.isEmpty ? "This server has no exposed tools." : "\(discovered.count) tools discovered."
|
||||
}
|
||||
@@ -445,7 +466,7 @@ struct MCPSettings: View {
|
||||
result = ""
|
||||
}
|
||||
|
||||
private func run(_ work: @escaping @MainActor () async throws -> Void) {
|
||||
private func run(profileName: String? = nil, _ work: @escaping @MainActor () async throws -> Void) {
|
||||
guard !busy else { return }
|
||||
busy = true
|
||||
result = ""
|
||||
@@ -453,7 +474,10 @@ struct MCPSettings: View {
|
||||
operation = Task {
|
||||
defer { busy = false; operation = nil }
|
||||
do { try await work() }
|
||||
catch { result = Task.isCancelled ? "Cancelled" : error.localizedDescription }
|
||||
catch {
|
||||
if let profileName, !Task.isCancelled { profileErrors[profileName] = error.localizedDescription }
|
||||
else { result = Task.isCancelled ? "Cancelled" : error.localizedDescription }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -780,6 +804,7 @@ struct ActiveToolset {
|
||||
let name: String
|
||||
let client: any MCPToolClient
|
||||
let tools: [MCPTool]
|
||||
var profileName: String? = nil
|
||||
}
|
||||
|
||||
struct BuiltInWebTools: MCPToolClient {
|
||||
|
||||
Reference in New Issue
Block a user