diff --git a/Docs/migrations/native-backend.md b/Docs/migrations/native-backend.md index 2942a680..8934efa1 100644 --- a/Docs/migrations/native-backend.md +++ b/Docs/migrations/native-backend.md @@ -212,6 +212,7 @@ The current server API is documented in | Public launch-plan/parser/product-metadata types | `XcodeMCPProxyServer.run(...)` for CLI hosting. | | Public installer library APIs | `xcode-mcp-proxy-install` executable; `--dry-run` remains supported. | | `XcodeMCPProxyStdioAdapter` and its configuration | Removed. Connect clients over Streamable HTTP; Swift clients use the [SDK](../../Sources/XcodeMCPKit/README.md). | +| `initializeHandshake` and `XcodeMCPProxyServerConfiguration.InitializeHandshake` | Removed. Hosts always receive the client name `XcodeMCPKit` and no client capabilities. `XcodeMCPProxyKit` no longer depends on the `XcodeMCPKit` product; add that product separately to use `MCPJSONValue` or the client. | | `TimeInterval` request timeout | Positive `Duration?`; `nil` disables it. CLI `--request-timeout 0` also disables it. | | `Status.upstreams`, `Status.Upstream.Health`, `queuedRequestCount`, `proxyInitialized`, `catalogAvailable` | `Status.hosts`: one `Status.Host` per Xcode installation, with its `identifier` (the `hostIdentifier` from `XcodeMCPKitListHosts`), `kind`, `state` (`stopped`, `starting`, `running`), and `activeRequestCount`. Requests queue inside each host, and the catalog is available whenever the server runs. | diff --git a/Package.swift b/Package.swift index 7b495d3f..09b9122a 100644 --- a/Package.swift +++ b/Package.swift @@ -162,7 +162,6 @@ let package = Package( dependencies: [ "XcodeMCPProxyRuntimeContract", "XcodeMCPCore", - "XcodeMCPKit", "XcodeMCPProxyRuntime", "XcodeMCPProxyHTTP", "XcodeMCPPermissionAutomation", diff --git a/Sources/XcodeMCPProxyKit/README.md b/Sources/XcodeMCPProxyKit/README.md index a2a4fef4..4afbeda1 100644 --- a/Sources/XcodeMCPProxyKit/README.md +++ b/Sources/XcodeMCPProxyKit/README.md @@ -57,7 +57,6 @@ may be incomplete, even though the server lifecycle has stopped. - `approvalPolicy`: `.manual` by default. `.automatic` approves MCP connection dialogs for agents connecting directly to GUI Xcode, using macOS Accessibility access. - `maxBodyBytes`: positive maximum HTTP request body size. - `requestTimeout`: a positive `Duration`, or `nil` for no timeout, the default. A client that gives up cancels its request or disconnects, which also ends the work; starting a host stays bounded either way. -- `initializeHandshake`: typed upstream initialization for embedding. - `discovery`: `.disabled`, `.defaultLocation`, or `.file(URL)`. - `prewarmToolsList`: whether discovery begins during startup. @@ -81,22 +80,10 @@ For a standalone headless or generic MCP process, use `XcodeMCPKit`'s explicit `.nativeHost(...)` or `.process(...)` transport. See [native routing migration](../../Docs/migrations/native-backend.md). -```swift -import Foundation -import XcodeMCPKit -import XcodeMCPProxyKit - -let configuration = XcodeMCPProxyServerConfiguration( - initializeHandshake: .init( - clientInfo: .init(name: "EmbeddingClient", version: "1.0"), - capabilities: ["experimental": ["embedding": true]] - ) -) -``` - -The handshake omits `roots`, `sampling`, and `elicitation`: every client -session shares an Xcode host, so no client can answer the host requests those -capabilities allow. +Every host receives the same `initialize` request: the client name +`XcodeMCPKit` and no client capabilities. Initialize parameters from connected +clients do not reach a host. Every client session shares a host, so no client +can answer the host requests that `roots`, `sampling`, or `elicitation` allow. `snapshot()` returns a sanitized read model: lifecycle phase, endpoint, and one entry per owned headless host with its identifier, kind, state, and active diff --git a/Sources/XcodeMCPProxyKit/XcodeMCPProxyServer+PermissionAutomation.swift b/Sources/XcodeMCPProxyKit/XcodeMCPProxyServer+PermissionAutomation.swift index edf69496..57198c86 100644 --- a/Sources/XcodeMCPProxyKit/XcodeMCPProxyServer+PermissionAutomation.swift +++ b/Sources/XcodeMCPProxyKit/XcodeMCPProxyServer+PermissionAutomation.swift @@ -9,8 +9,8 @@ protocol ProxyServerPermissionDialogAutoApprover: Sendable { } extension XcodePermissionDialogAutomation.AutoApprover: ProxyServerPermissionDialogAutoApprover { - static func liveForAllAgents(assistantName: String?) -> Self { - let names = Set(["XcodeMCPKit", "XcodeMCPProxyKit"] + [assistantName].compactMap { $0 }) + static func liveForAllAgents() -> Self { + let names: Set = ["XcodeMCPKit", "XcodeMCPProxyKit"] return Self( configuration: .init( permissionDialogProcessIDs: { diff --git a/Sources/XcodeMCPProxyKit/XcodeMCPProxyServer+Startup.swift b/Sources/XcodeMCPProxyKit/XcodeMCPProxyServer+Startup.swift index 20c338c6..b17143eb 100644 --- a/Sources/XcodeMCPProxyKit/XcodeMCPProxyServer+Startup.swift +++ b/Sources/XcodeMCPProxyKit/XcodeMCPProxyServer+Startup.swift @@ -284,7 +284,7 @@ extension XcodeMCPProxyServer { runtime: runtime, endpoint: boundEndpoint, autoApprover: configuration.approvalPolicy == .automatic - ? dependencies.makeAutoApprover(configuration) : nil + ? dependencies.makeAutoApprover() : nil ) } catch { let operationError = error diff --git a/Sources/XcodeMCPProxyKit/XcodeMCPProxyServer.swift b/Sources/XcodeMCPProxyKit/XcodeMCPProxyServer.swift index b87231b9..1ef0dfc0 100644 --- a/Sources/XcodeMCPProxyKit/XcodeMCPProxyServer.swift +++ b/Sources/XcodeMCPProxyKit/XcodeMCPProxyServer.swift @@ -2,7 +2,6 @@ import XcodeMCPProxyRuntimeContract import XcodeMCPCore import Foundation import Logging -import XcodeMCPKit import XcodeMCPProxyHTTP import XcodeMCPProxyRuntime import XcodeMCPPermissionAutomation @@ -59,49 +58,6 @@ public struct XcodeMCPProxyServerConfiguration: Equatable, Sendable { case automatic } - /// Initialize handshake values sent from the proxy to native helpers. - /// - /// Properties left as `nil` use the built-in defaults. - public struct InitializeHandshake: Equatable, Sendable { - /// Upstream client information for the initialize handshake. - public struct ClientInfo: Equatable, Sendable { - /// Client name to advertise to the native helper. - public var name: String? - - /// Client version to advertise to the native helper. - public var version: String? - - /// Creates upstream client information. - public init(name: String? = nil, version: String? = nil) { - self.name = name - self.version = version - } - } - - /// Protocol version to send in initialize params. - public var protocolVersion: String? - - /// Client info to send in initialize params. - public var clientInfo: ClientInfo? - - /// Capability object to send in initialize params. - /// - /// `roots`, `sampling`, and `elicitation` are not sent: every client session shares an Xcode - /// host, so no client can answer the host requests those capabilities allow. - public var capabilities: [String: MCPJSONValue]? - - /// Creates initialize handshake overrides. - public init( - protocolVersion: String? = nil, - clientInfo: ClientInfo? = nil, - capabilities: [String: MCPJSONValue]? = nil - ) { - self.protocolVersion = protocolVersion - self.clientInfo = clientInfo - self.capabilities = capabilities - } - } - /// HTTP bind address. public var bindAddress: BindAddress @@ -124,9 +80,6 @@ public struct XcodeMCPProxyServerConfiguration: Equatable, Sendable { /// or disconnects, which also ends the work. Starting a host stays bounded either way. public var requestTimeout: Duration? - /// Initialize handshake overrides. `nil` uses the built-in defaults. - public var initializeHandshake: InitializeHandshake? - /// Endpoint discovery policy. public var discovery: Discovery @@ -150,7 +103,6 @@ public struct XcodeMCPProxyServerConfiguration: Equatable, Sendable { /// - discovery: Endpoint discovery policy. /// - approvalPolicy: Xcode MCP connection dialog automation policy. Defaults to `.manual`. /// - prewarmToolsList: Whether to fetch native tool catalogs during startup. - /// - initializeHandshake: Explicit upstream initialize handshake override. /// - enablesDebugEndpoints: Whether to serve the debug endpoints on a loopback listener. Defaults to `false`. public init( bindAddress: BindAddress = .localhost(), @@ -159,7 +111,6 @@ public struct XcodeMCPProxyServerConfiguration: Equatable, Sendable { sharesCompilationCache: Bool = false, maxBodyBytes: Int = 1_048_576, requestTimeout: Duration? = nil, - initializeHandshake: InitializeHandshake? = nil, discovery: Discovery = .defaultLocation, approvalPolicy: ApprovalPolicy = .manual, prewarmToolsList: Bool = true, @@ -172,7 +123,6 @@ public struct XcodeMCPProxyServerConfiguration: Equatable, Sendable { self.approvalPolicy = approvalPolicy self.maxBodyBytes = maxBodyBytes self.requestTimeout = requestTimeout - self.initializeHandshake = initializeHandshake self.discovery = discovery self.prewarmToolsList = prewarmToolsList self.enablesDebugEndpoints = enablesDebugEndpoints @@ -344,7 +294,7 @@ public final class XcodeMCPProxyServer: Sendable { var discoveryClient: DiscoveryClient var processID: @Sendable () -> Int var makeRuntime: @Sendable (ProxyRuntimeConfiguration) throws -> any ProxyRuntimeServing - var makeAutoApprover: @Sendable (XcodeMCPProxyServerConfiguration) -> any ProxyServerPermissionDialogAutoApprover + var makeAutoApprover: @Sendable () -> any ProxyServerPermissionDialogAutoApprover var makeHTTPGateway: @Sendable ( ProxyHTTPConfiguration, @@ -358,10 +308,8 @@ public final class XcodeMCPProxyServer: Sendable { Int(ProcessInfo.processInfo.processIdentifier) }, makeRuntime: @escaping @Sendable (ProxyRuntimeConfiguration) throws -> any ProxyRuntimeServing, - makeAutoApprover: @escaping @Sendable (XcodeMCPProxyServerConfiguration) -> any ProxyServerPermissionDialogAutoApprover = { configuration in - XcodePermissionDialogAutomation.AutoApprover.liveForAllAgents( - assistantName: configuration.initializeHandshake?.clientInfo?.name - ) + makeAutoApprover: @escaping @Sendable () -> any ProxyServerPermissionDialogAutoApprover = { + XcodePermissionDialogAutomation.AutoApprover.liveForAllAgents() }, makeHTTPGateway: @escaping @Sendable ( ProxyHTTPConfiguration, @@ -481,37 +429,13 @@ extension XcodeMCPProxyServerConfiguration { if let requestTimeout, requestTimeout <= .zero { throw XcodeMCPProxyServer.LifecycleError.invalidConfiguration("requestTimeout must be positive; use nil to disable it") } - let configuration = ProxyRuntimeConfiguration( + return ProxyRuntimeConfiguration( nativeHostBundleURL: nativeHostBundleURL, developerDirectoryURL: developerDirectoryURL, sharesCompilationCache: sharesCompilationCache, maxMessageBytes: maxBodyBytes, requestTimeout: requestTimeout, - prewarmToolsList: prewarmToolsList, - initializeParamsOverride: initializeHandshake.map { handshake in - .init( - protocolVersion: handshake.protocolVersion, - clientName: handshake.clientInfo?.name, - clientVersion: handshake.clientInfo?.version, - capabilities: handshake.capabilities?.mapValues(ProxyRuntimeConfiguration.JSONValue.init) - ) - } + prewarmToolsList: prewarmToolsList ) - try configuration.validateModernProtocolConfiguration() - return configuration - } -} - -private extension ProxyRuntimeConfiguration.JSONValue { - init(_ value: MCPJSONValue) { - switch value { - case .object(let object): self = .object(object.mapValues(Self.init)) - case .array(let array): self = .array(array.map(Self.init)) - case .string(let string): self = .string(string) - case .integer(let integer): self = .number(.integer(integer)) - case .double(let double): self = .number(.double(double)) - case .bool(let bool): self = .bool(bool) - case .null: self = .null - } } } diff --git a/Sources/XcodeMCPProxyRuntime/Broker/NativeHostBroker.swift b/Sources/XcodeMCPProxyRuntime/Broker/NativeHostBroker.swift index a1266f83..25d3157c 100644 --- a/Sources/XcodeMCPProxyRuntime/Broker/NativeHostBroker.swift +++ b/Sources/XcodeMCPProxyRuntime/Broker/NativeHostBroker.swift @@ -44,6 +44,13 @@ package final class NativeHostBroker: ProxyRuntimeServing, Sendable { /// Bounds a cleanup close while client requests have no timeout, so a host that never answers /// does not keep the model from being bound again. static let cleanupFallbackTimeout: Duration = .seconds(60) + /// The `initialize` params every host receives. Client sessions share a host, so the handshake + /// advertises no capability that would let the host send requests to a client. + static let initializeParams: JSONValue = .object([ + "protocolVersion": .string(MCP.ProtocolVersion.current), + "capabilities": .object([:]), + "clientInfo": .object(["name": .string("XcodeMCPKit"), "version": .string("dev")]), + ]) /// Bounds a host's initialize handshake even when client requests have no timeout. private static let handshakeTimeoutLimit: Duration = .seconds(60) /// Bounds an internal catalog load even when client requests have no timeout. @@ -96,8 +103,7 @@ package final class NativeHostBroker: ProxyRuntimeServing, Sendable { maxBodyBytes: configuration.maxMessageBytes) let connection = NativeHostConnection( factory: sessionFactory(processConfiguration), - handshake: .object(InitializeHandshakeJSON.resolved( - initializeParamsOverride: configuration.initializeParamsOverride)), + handshake: Self.initializeParams, handshakeTimeout: handshakeTimeout, catalogTimeout: catalogTimeout, prewarmsCatalog: configuration.prewarmToolsList, clock: clock, logger: ProxyLogging.make("native-host"), @@ -123,8 +129,7 @@ package final class NativeHostBroker: ProxyRuntimeServing, Sendable { guard !storage.stopped, storage.resetsInProgress == 0 else { throw CancellationError() } if let connection = storage.guiConnection { return connection } let connection = NativeHostConnection(factory: guiSessionFactory, - handshake: .object(InitializeHandshakeJSON.resolved( - initializeParamsOverride: configuration.initializeParamsOverride)), + handshake: Self.initializeParams, handshakeTimeout: handshakeTimeout, catalogTimeout: catalogTimeout, prewarmsCatalog: false, clock: clock, logger: ProxyLogging.make("mcpbridge"), onEvent: { [weak self] event in self?.receive(event, from: Self.guiHostIdentifier) }) diff --git a/Sources/XcodeMCPProxyRuntime/Configuration/InitializeHandshakeJSON.swift b/Sources/XcodeMCPProxyRuntime/Configuration/InitializeHandshakeJSON.swift deleted file mode 100644 index ea48ac70..00000000 --- a/Sources/XcodeMCPProxyRuntime/Configuration/InitializeHandshakeJSON.swift +++ /dev/null @@ -1,121 +0,0 @@ -import Foundation -import XcodeMCPCore - -enum InitializeHandshakeJSON { - /// Capabilities that let a host send requests to the client. Every client session shares a host, - /// so no client can answer those requests and the handshake does not advertise them. - private static let hostRequestCapabilities: Set = ["roots", "sampling", "elicitation"] - - static func resolved( - initializeParamsOverride: ProxyRuntimeConfiguration.InitializeHandshakeOverride? - ) -> [String: JSONValue] { - let mergedParams = mergeJSONObjects( - defaultParams(), - overriding: jsonObject(from: initializeParamsOverride) ?? [:] - ) - guard InitializeHandshakeParams.hasExplicitClientVersionOverride( - initializeParamsOverride: initializeParamsOverride - ) == false else { - return mergedParams - } - return applyingAutomaticClientVersion(to: mergedParams) - } - - static func defaultParams() -> [String: JSONValue] { - [ - "protocolVersion": .string(MCP.ProtocolVersion.current), - "capabilities": .object([:]), - "clientInfo": .object([ - "name": .string(InitializeHandshakeParams.defaultProxyClientName()), - "version": .string(InitializeHandshakeParams.defaultProxyClientVersion()), - ]), - ] - } - - private static func jsonObject( - from override: ProxyRuntimeConfiguration.InitializeHandshakeOverride? - ) -> [String: JSONValue]? { - guard let override else { return nil } - var params: [String: JSONValue] = [:] - if let protocolVersion = override.protocolVersion { - params["protocolVersion"] = .string(protocolVersion) - } - - var clientInfo: [String: JSONValue] = [:] - if let clientName = override.clientName { - clientInfo["name"] = .string(clientName) - } - if let clientVersion = override.clientVersion { - clientInfo["version"] = .string(clientVersion) - } - if clientInfo.isEmpty == false { - params["clientInfo"] = .object(clientInfo) - } - - if let capabilities = override.capabilities { - params["capabilities"] = .object(capabilities - .filter { !hostRequestCapabilities.contains($0.key) } - .mapValues(jsonValue(from:))) - } - - return params.isEmpty ? nil : params - } - - private static func jsonValue(from value: ProxyRuntimeConfiguration.JSONValue) -> JSONValue { - switch value { - case .object(let object): - return .object(object.mapValues(jsonValue(from:))) - case .array(let array): - return .array(array.map(jsonValue(from:))) - case .string(let string): - return .string(string) - case .number(.integer(let number)): - return .number(.int(number)) - case .number(.double(let number)): - return .number(.double(number)) - case .bool(let bool): - return .bool(bool) - case .null: - return .null - } - } - - private static func applyingAutomaticClientVersion( - to params: [String: JSONValue] - ) -> [String: JSONValue] { - guard case .object(var clientInfo)? = params["clientInfo"], - case .string(let clientName)? = clientInfo["name"] else { - return params - } - - guard let resolvedVersion = InitializeHandshakeParams.xcodeChatClientVersion( - for: clientName - ) else { - return params - } - - clientInfo["version"] = .string(resolvedVersion) - var updated = params - updated["clientInfo"] = .object(clientInfo) - return updated - } - - private static func mergeJSONObjects( - _ base: [String: JSONValue], - overriding override: [String: JSONValue] - ) -> [String: JSONValue] { - var merged = base - for (key, value) in override { - if case .object(let overrideObject) = value, - case .object(let baseObject)? = merged[key] - { - merged[key] = .object( - mergeJSONObjects(baseObject, overriding: overrideObject) - ) - } else { - merged[key] = value - } - } - return merged - } -} diff --git a/Sources/XcodeMCPProxyRuntime/Configuration/InitializeHandshakeParams.swift b/Sources/XcodeMCPProxyRuntime/Configuration/InitializeHandshakeParams.swift deleted file mode 100644 index 1da1afed..00000000 --- a/Sources/XcodeMCPProxyRuntime/Configuration/InitializeHandshakeParams.swift +++ /dev/null @@ -1,115 +0,0 @@ -import Foundation - -/// Session-owned defaults and Xcode chat client version lookup for the -/// initialize params the proxy presents to its native helper. JSON shaping lives with -/// the session runtime, while protocol-version validation remains in -/// the internal MCP runtime. -enum InitializeHandshakeParams { - static func hasExplicitClientVersionOverride( - initializeParamsOverride: ProxyRuntimeConfiguration.InitializeHandshakeOverride? - ) -> Bool { - initializeParamsOverride?.clientVersion != nil - } - - static func defaultClientVersion(for clientName: String) -> String { - xcodeChatClientVersion(for: clientName) ?? defaultProxyClientVersion() - } - - static func defaultProxyClientName() -> String { - "XcodeMCPKit" - } - - static func defaultProxyClientVersion() -> String { - "dev" - } - - static func xcodeChatClientVersion(for clientName: String) -> String? { - let defaults = UserDefaults(suiteName: "com.apple.dt.Xcode")?.dictionaryRepresentation() ?? [:] - return xcodeChatClientVersion(for: clientName, defaults: defaults) - } - - static func xcodeChatClientVersion(for clientName: String, defaults: [String: Any]) -> String? { - let normalizedName = normalizedChatClientName(clientName) - guard !normalizedName.isEmpty else { return nil } - - var exactMatches: [(stem: String, version: String)] = [] - var aliasMatches: [(stem: String, version: String)] = [] - - for (key, value) in defaults { - guard key.hasPrefix("IDEChat"), key.hasSuffix("Version") else { continue } - guard let raw = value as? String, let version = xcodeChatVersionValue(from: raw) else { - continue - } - - let stem = String( - key - .dropFirst("IDEChat".count) - .dropLast("Version".count) - ) - - let normalizedStem = normalizedChatClientName(stem) - if normalizedStem == normalizedName { - exactMatches.append((stem, version)) - continue - } - - if chatClientAliases(forVersionStem: stem).contains(normalizedName) { - aliasMatches.append((stem, version)) - } - } - - let orderedExactMatches = exactMatches.sorted { lhs, rhs in - lhs.stem < rhs.stem - } - if let match = orderedExactMatches.first { - return match.version - } - - let orderedAliasMatches = aliasMatches.sorted { lhs, rhs in - lhs.stem < rhs.stem - } - return orderedAliasMatches.first?.version - } - - static func xcodeChatVersionValue(forDefaultsKey defaultsKey: String) -> String? { - guard let raw = UserDefaults(suiteName: "com.apple.dt.Xcode")?.string(forKey: defaultsKey) else { - return nil - } - return xcodeChatVersionValue(from: raw) - } - - static func xcodeChatVersionValue(from raw: String) -> String? { - guard - let data = raw.data(using: .utf8), - let object = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any], - let version = object["version"] as? String, - !version.isEmpty - else { - return nil - } - return version - } - - static func chatClientAliases(forVersionStem stem: String) -> Set { - var aliases: Set = [] - let normalizedStem = normalizedChatClientName(stem) - if !normalizedStem.isEmpty { - aliases.insert(normalizedStem) - } - - if stem.hasSuffix("Code") { - let baseStem = String(stem.dropLast("Code".count)) - let normalizedBaseStem = normalizedChatClientName(baseStem) - if !normalizedBaseStem.isEmpty { - aliases.insert(normalizedBaseStem) - } - } - - return aliases - } - - static func normalizedChatClientName(_ name: String) -> String { - let scalars = name.unicodeScalars.filter(CharacterSet.alphanumerics.contains) - return String(String.UnicodeScalarView(scalars)).lowercased() - } -} diff --git a/Sources/XcodeMCPProxyRuntime/Configuration/ProxyRuntimeConfiguration.swift b/Sources/XcodeMCPProxyRuntime/Configuration/ProxyRuntimeConfiguration.swift index b5bc2b56..465fa357 100644 --- a/Sources/XcodeMCPProxyRuntime/Configuration/ProxyRuntimeConfiguration.swift +++ b/Sources/XcodeMCPProxyRuntime/Configuration/ProxyRuntimeConfiguration.swift @@ -1,60 +1,6 @@ import Foundation -import XcodeMCPCore package struct ProxyRuntimeConfiguration: Sendable { - package enum ValidationError: Error, CustomStringConvertible { - case unsupportedProtocolVersion(String) - - package var description: String { - switch self { - case .unsupportedProtocolVersion(let protocolVersion): - return - "initializeHandshake.protocolVersion must be \(MCPProtocolVersion.current); " - + "\(protocolVersion) is not supported" - } - } - } - - package indirect enum JSONValue: Equatable, Sendable { - case object([String: JSONValue]) - case array([JSONValue]) - case string(String) - case number(Number) - case bool(Bool) - case null - } - - package enum Number: Equatable, Sendable { - case integer(Int64) - case double(Double) - } - - package struct InitializeHandshakeOverride: Equatable, Sendable { - package var protocolVersion: String? - package var clientName: String? - package var clientVersion: String? - package var capabilities: [String: JSONValue]? - - package init( - protocolVersion: String? = nil, - clientName: String? = nil, - clientVersion: String? = nil, - capabilities: [String: JSONValue]? = nil - ) { - self.protocolVersion = protocolVersion - self.clientName = clientName - self.clientVersion = clientVersion - self.capabilities = capabilities - } - - package var isEmpty: Bool { - protocolVersion == nil - && clientName == nil - && clientVersion == nil - && capabilities == nil - } - } - package var nativeHostBundleURL: URL? package var developerDirectoryURL: URL? package var sharesCompilationCache: Bool @@ -62,7 +8,6 @@ package struct ProxyRuntimeConfiguration: Sendable { /// The limit for one client request, or `nil` for none. package var requestTimeout: Duration? package var prewarmToolsList: Bool - package var initializeParamsOverride: InitializeHandshakeOverride? package init( nativeHostBundleURL: URL? = nil, @@ -70,8 +15,7 @@ package struct ProxyRuntimeConfiguration: Sendable { sharesCompilationCache: Bool = false, maxMessageBytes: Int, requestTimeout: Duration?, - prewarmToolsList: Bool = true, - initializeParamsOverride: InitializeHandshakeOverride? = nil + prewarmToolsList: Bool = true ) { self.nativeHostBundleURL = nativeHostBundleURL self.developerDirectoryURL = developerDirectoryURL @@ -79,15 +23,5 @@ package struct ProxyRuntimeConfiguration: Sendable { self.maxMessageBytes = maxMessageBytes self.requestTimeout = requestTimeout self.prewarmToolsList = prewarmToolsList - self.initializeParamsOverride = initializeParamsOverride - } - - package func validateModernProtocolConfiguration() throws { - guard let protocolVersion = initializeParamsOverride?.protocolVersion else { - return - } - guard MCPProtocolVersion.isSupported(protocolVersion) else { - throw ValidationError.unsupportedProtocolVersion(protocolVersion) - } } } diff --git a/Tests/ProxyCLITests/ServerCommandTests.swift b/Tests/ProxyCLITests/ServerCommandTests.swift index 17c7f8f5..f1c89bf2 100644 --- a/Tests/ProxyCLITests/ServerCommandTests.swift +++ b/Tests/ProxyCLITests/ServerCommandTests.swift @@ -92,7 +92,6 @@ struct ServerCommandTests { "MCP_XCODE_AUTO_APPROVE": "1", "LAZY_INIT": "true", ]) - #expect(config.initializeHandshake == nil) #expect(config.prewarmToolsList) #expect(config.approvalPolicy == .manual) } diff --git a/Tests/ProxyIntegrationTests/ConfigurationRuntimeTests.swift b/Tests/ProxyIntegrationTests/ConfigurationRuntimeTests.swift index 5c33f8a3..9a103d61 100644 --- a/Tests/ProxyIntegrationTests/ConfigurationRuntimeTests.swift +++ b/Tests/ProxyIntegrationTests/ConfigurationRuntimeTests.swift @@ -34,59 +34,14 @@ struct ConfigurationRuntimeTests { return try #require(params.foundationObject as? [String: Any]) } - @Test func hostReceivesTheTypedInitializeHandshake() async throws { + @Test func hostReceivesTheProxyHandshakeRatherThanTheClientParameters() async throws { let params = try await hostInitializeParameters(XcodeMCPProxyServerConfiguration( - requestTimeout: .seconds(5), - initializeHandshake: .init(clientInfo: .init(name: "custom-proxy"), - capabilities: ["roots": true, "sampling": [:], "elicitation": [:], "experimental": [:]]), - prewarmToolsList: false)) - let clientInfo = try #require(params["clientInfo"] as? [String: Any]) - let capabilities = try #require(params["capabilities"] as? [String: Any]) - #expect(params["protocolVersion"] as? String == "2025-06-18") - #expect(clientInfo["name"] as? String == "custom-proxy") - #expect(clientInfo["version"] as? String == InitializeHandshakeParams.defaultProxyClientVersion()) - // A shared host has no single client to answer its requests. - #expect(capabilities.keys.sorted() == ["experimental"]) - } - - @Test func hostReceivesTypedHandshakeValuesUnchanged() async throws { - let params = try await hostInitializeParameters(XcodeMCPProxyServerConfiguration( - initializeHandshake: .init( - protocolVersion: "2025-06-18", - clientInfo: .init(name: "EmbeddingClient", version: "1.2.3"), - capabilities: ["experimental": [ - "enabled": true, "limit": 3, "score": 0.5, "tags": ["swift", "xcode"], "optional": .null, - ]]), - prewarmToolsList: false)) - let client = try #require(params["clientInfo"] as? [String: Any]) - let capabilities = try #require(params["capabilities"] as? [String: Any]) - let experimental = try #require(capabilities["experimental"] as? [String: Any]) - #expect(client["name"] as? String == "EmbeddingClient") - #expect(client["version"] as? String == "1.2.3") - #expect(experimental["enabled"] as? Bool == true) - #expect(experimental["limit"] as? Int == 3) - #expect(experimental["score"] as? Double == 0.5) - #expect(experimental["tags"] as? [String] == ["swift", "xcode"]) - #expect(experimental["optional"] is NSNull) - } - - @Test func hostHandshakeResolvesTheVersionForAConfiguredClientName() async throws { - let params = try await hostInitializeParameters(XcodeMCPProxyServerConfiguration( - requestTimeout: .seconds(5), initializeHandshake: .init(clientInfo: .init(name: "Claude")), - prewarmToolsList: false)) - let clientInfo = try #require(params["clientInfo"] as? [String: Any]) - #expect(clientInfo["name"] as? String == "Claude") - #expect(clientInfo["version"] as? String == InitializeHandshakeParams.defaultClientVersion(for: "Claude")) - } - - @Test func clientInitializeParametersDoNotReachTheHost() async throws { - let params = try await hostInitializeParameters(XcodeMCPProxyServerConfiguration( - requestTimeout: .seconds(5), initializeHandshake: .init(clientInfo: .init(name: "configured-proxy")), - prewarmToolsList: false)) { broker in + requestTimeout: .seconds(5), prewarmToolsList: false)) { broker in let request = try ProxyRuntimeRequest(json: .object([ "jsonrpc": .string("2.0"), "id": .number(.int(1)), "method": .string("initialize"), "params": .object([ - "protocolVersion": .string("2099-01-01"), "capabilities": .object([:]), + "protocolVersion": .string("2099-01-01"), + "capabilities": .object(["roots": .object([:]), "sampling": .object([:])]), "clientInfo": .object(["name": .string("downstream-client"), "version": .string("9.9")]), ]), ])) @@ -95,8 +50,11 @@ struct ConfigurationRuntimeTests { session.close() } let clientInfo = try #require(params["clientInfo"] as? [String: Any]) + let capabilities = try #require(params["capabilities"] as? [String: Any]) #expect(params["protocolVersion"] as? String == "2025-06-18") - #expect(clientInfo["name"] as? String == "configured-proxy") - #expect(clientInfo["version"] as? String == InitializeHandshakeParams.defaultProxyClientVersion()) + // Approval automation matches GUI Xcode connection dialogs by this name. + #expect(clientInfo["name"] as? String == "XcodeMCPKit") + // A shared host has no single client to answer its requests. + #expect(capabilities.isEmpty) } } diff --git a/Tests/ProxyIntegrationTests/XcodeMCPProxyServerTests.swift b/Tests/ProxyIntegrationTests/XcodeMCPProxyServerTests.swift index 0718c2e3..ba87b76c 100644 --- a/Tests/ProxyIntegrationTests/XcodeMCPProxyServerTests.swift +++ b/Tests/ProxyIntegrationTests/XcodeMCPProxyServerTests.swift @@ -201,7 +201,7 @@ struct XcodeMCPProxyServerTests { dependencies: .init( discoveryClient: .testValue, makeRuntime: { _ in StartupTestRuntime() }, - makeAutoApprover: { _ in + makeAutoApprover: { creations.withLockedValue { $0 += 1 } return approver } @@ -286,7 +286,7 @@ struct XcodeMCPProxyServerTests { makeRuntime: { config in try makeServerTestRuntime(config: config, hosts: hosts) }, - makeAutoApprover: { _ in approver } + makeAutoApprover: { approver } ) ) diff --git a/Tests/PublicProductContractTests/PublicProductContractTests.swift b/Tests/PublicProductContractTests/PublicProductContractTests.swift index bf08dea0..ce1469d6 100644 --- a/Tests/PublicProductContractTests/PublicProductContractTests.swift +++ b/Tests/PublicProductContractTests/PublicProductContractTests.swift @@ -1077,36 +1077,13 @@ func compileOnlyProxyConfigurationSurface() { developerDirectoryURL: URL(fileURLWithPath: "/Applications/Xcode.app/Contents/Developer"), maxBodyBytes: 1_048_576, requestTimeout: .seconds(120), - initializeHandshake: .init( - protocolVersion: "2025-06-18", - clientInfo: .init(name: "EmbeddingClient", version: "1.0"), - capabilities: [ - "roots": [ - "listChanged": true, - ], - "experimental": [ - "priority": 1, - "score": 0.5, - "metadata": .null, - ], - ] - ), discovery: .file(URL(fileURLWithPath: "/tmp/xcode-mcp-discovery.json")), approvalPolicy: .automatic, prewarmToolsList: false ) - let typedHandshake = config.initializeHandshake - let typedCapabilities: [String: MCPJSONValue]? = typedHandshake?.capabilities - let metadataIsNull = typedCapabilities?["experimental"]?.objectValue?["metadata"]?.isNull let server = XcodeMCPProxyServer(configuration: config) - _ = ( - config, - typedHandshake, - typedCapabilities, - metadataIsNull, - server - ) + _ = (config, server) } func compileOnlyProxyLaunchSurface() async throws { diff --git a/scripts/verify-proxy-target-boundaries.sh b/scripts/verify-proxy-target-boundaries.sh index 1cdc9b4b..46ef40f3 100755 --- a/scripts/verify-proxy-target-boundaries.sh +++ b/scripts/verify-proxy-target-boundaries.sh @@ -97,6 +97,7 @@ if ! jq -e ' excludes("XcodeMCPProxyRuntimeTestSupport"; ["XcodeMCPKit", "XcodeMCPProxyHTTP", "XcodeMCPProxyKit"]) and excludes("XcodeMCPProxyTestSupport"; ["XcodeMCPKit", "XcodeMCPProxyRuntime", "XcodeMCPProxyHTTP", "XcodeMCPProxyKit"]) and excludes("XcodeMCPProxyHTTPTests"; ["XcodeMCPKit", "XcodeMCPProxyRuntime", "XcodeMCPProxyKit"]) and + excludes("XcodeMCPProxyKit"; ["XcodeMCPKit"]) and directlyUses("XcodeMCPProxyRuntime"; "XcodeMCPCore") and directlyUses("XcodeMCPProxyHTTP"; "XcodeMCPCore") and directlyUses("XcodeMCPProxyHTTP"; "XcodeMCPProxyRuntimeContract") and