Skip to content

Commit 7e33f68

Browse files
authored
fix(tray): close the 16 findings of the macOS tray UX + settings-parity audit (#1055)
* fix(tray): address the 16 findings of the macOS tray UX + settings-parity audit Menu-bar icon now badges server severity and is labelled for VoiceOver; per-server actions report failure instead of closing silently; a "Needs Attention" row navigates and its remediation lives under its own verb. Agent Tokens and a new global Tools search reach the sidebar, the Servers submenu groups by state, and the settings catalogue regains the three web-only fields behind a full key-coverage parity gate. * test(tray): pin the window- and settings-side audit fixes * fix(tray): tighten query encoding, export filters and the parity gate Cross-model review round 1: escape query values (urlQueryAllowed lets &/=/+ through), carry the sub-call and session filters into the activity export, count only the badged severity in the status-item label, treat a newline-only optional field as unset, and widen the settings parity gate to control/restart/options with comment stripping and duplicate detection. * fix(tray): percent-encode server names in API paths Cross-model review round 2: server names are only validated against ':', so 'my/server' would split the /servers/{id}/... path the menu's enable, disable, restart and sign-in actions all post to. * fix(tray): hand the glance session filter over without a timing race Cross-model review round 3: publish the pending session on AppState so a window created by the click picks it up on appear (a delayed notification lands before ActivityView subscribes), and make the parity gate refuse a non-string-literal field key instead of silently skipping it.
1 parent 829448e commit 7e33f68

17 files changed

Lines changed: 2081 additions & 321 deletions

‎native/macos/MCPProxy/MCPProxy/API/APIClient.swift‎

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -190,24 +190,37 @@ actor APIClient {
190190
return response.servers
191191
}
192192

193+
/// Percent-encode one PATH segment.
194+
///
195+
/// Server names are only validated against `:` (see
196+
/// `internal/config/server_name_validation_test.go`), so `my/server` or
197+
/// `my server` are legal names that would otherwise split the path into
198+
/// extra segments and 404 — or, worse, address a different route. Every
199+
/// `/servers/{id}/…` action the tray menu can fire goes through this.
200+
static func escapePathComponent(_ value: String) -> String {
201+
let unreserved = CharacterSet(
202+
charactersIn: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~")
203+
return value.addingPercentEncoding(withAllowedCharacters: unreserved) ?? ""
204+
}
205+
193206
/// Enable a server via `POST /api/v1/servers/{id}/enable`.
194207
func enableServer(_ id: String) async throws {
195-
try await postAction(path: "/api/v1/servers/\(id)/enable")
208+
try await postAction(path: "/api/v1/servers/\(Self.escapePathComponent(id))/enable")
196209
}
197210

198211
/// Disable a server via `POST /api/v1/servers/{id}/disable`.
199212
func disableServer(_ id: String) async throws {
200-
try await postAction(path: "/api/v1/servers/\(id)/disable")
213+
try await postAction(path: "/api/v1/servers/\(Self.escapePathComponent(id))/disable")
201214
}
202215

203216
/// Restart a server via `POST /api/v1/servers/{id}/restart`.
204217
func restartServer(_ id: String) async throws {
205-
try await postAction(path: "/api/v1/servers/\(id)/restart")
218+
try await postAction(path: "/api/v1/servers/\(Self.escapePathComponent(id))/restart")
206219
}
207220

208221
/// Trigger OAuth login for a server via `POST /api/v1/servers/{id}/login`.
209222
func loginServer(_ id: String) async throws {
210-
try await postAction(path: "/api/v1/servers/\(id)/login")
223+
try await postAction(path: "/api/v1/servers/\(Self.escapePathComponent(id))/login")
211224
}
212225

213226
// MARK: - Profiles (Profiles v2 T5)
@@ -772,10 +785,30 @@ actor APIClient {
772785

773786
// MARK: - Tool Search
774787

775-
/// Search tools across all servers via `GET /api/v1/tools`.
776-
func searchTools(query: String, limit: Int = 20) async throws -> [SearchResult] {
777-
let encoded = query.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) ?? query
778-
let data = try await fetchRaw(path: "/api/v1/tools?q=\(encoded)&limit=\(limit)")
788+
/// Percent-encode one query-string VALUE.
789+
///
790+
/// `.urlQueryAllowed` is the wrong set for a value: it deliberately leaves
791+
/// `&`, `=`, `+` and `?` intact, so a tool search for "a&limit=1" would
792+
/// silently become two parameters, and a `+` in a session id would decode
793+
/// as a space. Only unreserved characters survive here.
794+
static func escapeQueryValue(_ value: String) -> String {
795+
let unreserved = CharacterSet(
796+
charactersIn: "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~")
797+
return value.addingPercentEncoding(withAllowedCharacters: unreserved) ?? ""
798+
}
799+
800+
/// BM25 search across every upstream tool via `GET /api/v1/index/search`.
801+
///
802+
/// This used to call `GET /api/v1/tools?q=…`, which has no `q` parameter:
803+
/// it returns the full catalogue under `tools`, while this function reads
804+
/// `results` — so every call returned an empty array. Nothing consumed it,
805+
/// which is how it stayed broken; `ToolsView` (F16) is the first caller.
806+
///
807+
/// Note the REST contract (#871): `tool.name` here is the BARE tool name
808+
/// with `server_name` alongside — callers assemble `server:tool` themselves.
809+
func searchTools(query: String, limit: Int = 50) async throws -> [SearchResult] {
810+
let encoded = Self.escapeQueryValue(query)
811+
let data = try await fetchRaw(path: "/api/v1/index/search?q=\(encoded)&limit=\(limit)")
779812
let decoder = JSONDecoder()
780813
if let wrapper = try? decoder.decode(APIResponse<SearchToolsResponse>.self, from: data),
781814
let payload = wrapper.data {
@@ -787,6 +820,21 @@ actor APIClient {
787820
return []
788821
}
789822

823+
/// The whole tool catalogue via `GET /api/v1/tools` — what the Tools view
824+
/// shows before anything is typed.
825+
func allTools() async throws -> [SearchTool] {
826+
let data = try await fetchRaw(path: "/api/v1/tools")
827+
let decoder = JSONDecoder()
828+
if let wrapper = try? decoder.decode(APIResponse<SearchToolsResponse>.self, from: data),
829+
let payload = wrapper.data {
830+
return payload.tools ?? []
831+
}
832+
if let direct = try? decoder.decode(SearchToolsResponse.self, from: data) {
833+
return direct.tools ?? []
834+
}
835+
return []
836+
}
837+
790838
// MARK: - Tool Quarantine
791839

792840
/// Fetch tool diff (old vs new description/schema) for a pending/changed tool.

‎native/macos/MCPProxy/MCPProxy/API/Models.swift‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,6 +796,11 @@ struct StatusResponse: Codable {
796796
let routingMode: String?
797797
let upstreamStats: UpstreamStats?
798798
let timestamp: Int64?
799+
/// MCP-2176: the core's built-in default MCP instructions, rendered as the
800+
/// placeholder of the Settings → Advanced instructions field so the shown
801+
/// default never drifts from `resolveInstructions("")`. Optional — a core
802+
/// older than the field simply omits it.
803+
let defaultInstructions: String?
799804

800805
enum CodingKeys: String, CodingKey {
801806
case running
@@ -804,6 +809,7 @@ struct StatusResponse: Codable {
804809
case routingMode = "routing_mode"
805810
case upstreamStats = "upstream_stats"
806811
case timestamp
812+
case defaultInstructions = "default_instructions"
807813
}
808814
}
809815

0 commit comments

Comments
 (0)