* Support 2025-06-18 Spec (#167) * Support OpenAI _meta for Tool * Update init * Add title and outputSchema * Concurreny issue * General fields * Add Generate Fields to Server elements * 4 tab spacing * Update Version * Elicitation * Format * More tests and inits * Elicitation in README * Fix orphaned test * Add title to more structs * Public init * Fix meta validation and make tests more generic * Format and make Result properties public again * Revert more visibility changes * feat: 2025-11-25 phase 1, includes Version, Icon, Progress (#181) * chore: fixed unit tests * feat: added icon and progess base structs * feat: added progress notification and meta to callTool * feat: added tests * feat: simplified RequestMeta encoding/decoding * tests: added unit test to track progress * chore: rebased v0.11.x * feat: implemented cancellation * feat: added overloaded callTool method * fix: encoding Response _meta fix * chore: added old version to the versions list * feat: 2025-11-25 phase 2; added Logging and Completions (#196) * feat: added Logging and Completions * feat: updated EmbeddedResource for the latest spec * chore: changed encoding of meta in Prompts to encodeIfPresent * feat: compliance tests + http server transport (#197) * feat: http server transport * feat: added http server transport * feat: removed unused files * feat: added conformance tests * feat: improved conformace testing * chore: removed redundant files * feat/2025-11-25: sampling, elicitation, roots (#198) * feat: Roots implementation * feat: added unit testing * feat: improved unit tests and fixed NetworkTransport crash * feat: implemented sampling and elicitation * feat: improved sampling tests * feat: improved elicitation tests * feat: improved confirmance tests * feat: improved Prompts unit tests * feat: removed test code * feat: updated conformance tests * chore: removed redundant commas * chore: removed 6.0.3 swift version from ci * chore: improved unit tests a little bit * chore: update README.md * chore: add server progress tracking example to README.md * chore: updated README.md * chore: updated transports table formatting * chore: updated MockNetworkConnection --------- Co-authored-by: Austin Evans <austinjevans@me.com> Co-authored-by: yehorsobko <yehorsobko@macpaw.com>
93 lines
4 KiB
Swift
93 lines
4 KiB
Swift
/// The initialization phase MUST be the first interaction between client and server.
|
|
/// During this phase, the client and server:
|
|
/// - Establish protocol version compatibility
|
|
/// - Exchange and negotiate capabilities
|
|
/// - Share implementation details
|
|
///
|
|
/// - SeeAlso: https://spec.modelcontextprotocol.io/specification/2024-11-05/basic/lifecycle/#initialization
|
|
public enum Initialize: Method {
|
|
public static let name: String = "initialize"
|
|
|
|
public struct Parameters: Hashable, Codable, Sendable {
|
|
public let protocolVersion: String
|
|
public let capabilities: Client.Capabilities
|
|
public let clientInfo: Client.Info
|
|
|
|
public init(
|
|
protocolVersion: String = Version.latest,
|
|
capabilities: Client.Capabilities,
|
|
clientInfo: Client.Info
|
|
) {
|
|
self.protocolVersion = protocolVersion
|
|
self.capabilities = capabilities
|
|
self.clientInfo = clientInfo
|
|
}
|
|
|
|
private enum CodingKeys: String, CodingKey {
|
|
case protocolVersion, capabilities, clientInfo
|
|
}
|
|
|
|
public init(from decoder: Decoder) throws {
|
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
protocolVersion =
|
|
try container.decodeIfPresent(String.self, forKey: .protocolVersion)
|
|
?? Version.latest
|
|
capabilities =
|
|
try container.decodeIfPresent(Client.Capabilities.self, forKey: .capabilities)
|
|
?? .init()
|
|
clientInfo =
|
|
try container.decodeIfPresent(Client.Info.self, forKey: .clientInfo)
|
|
?? .init(name: "unknown", version: "0.0.0")
|
|
}
|
|
}
|
|
|
|
public struct Result: Hashable, Codable, Sendable {
|
|
public let protocolVersion: String
|
|
public let capabilities: Server.Capabilities
|
|
public let serverInfo: Server.Info
|
|
public let instructions: String?
|
|
public var _meta: Metadata?
|
|
|
|
public init(
|
|
protocolVersion: String,
|
|
capabilities: Server.Capabilities,
|
|
serverInfo: Server.Info,
|
|
instructions: String? = nil,
|
|
_meta: Metadata? = nil
|
|
) {
|
|
self.protocolVersion = protocolVersion
|
|
self.capabilities = capabilities
|
|
self.serverInfo = serverInfo
|
|
self.instructions = instructions
|
|
self._meta = _meta
|
|
}
|
|
|
|
private enum CodingKeys: String, CodingKey, CaseIterable {
|
|
case protocolVersion, capabilities, serverInfo, instructions, _meta
|
|
}
|
|
|
|
public func encode(to encoder: Encoder) throws {
|
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
|
try container.encode(protocolVersion, forKey: .protocolVersion)
|
|
try container.encode(capabilities, forKey: .capabilities)
|
|
try container.encode(serverInfo, forKey: .serverInfo)
|
|
try container.encodeIfPresent(instructions, forKey: .instructions)
|
|
try container.encodeIfPresent(_meta, forKey: ._meta)
|
|
}
|
|
|
|
public init(from decoder: Decoder) throws {
|
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
|
protocolVersion = try container.decode(String.self, forKey: .protocolVersion)
|
|
capabilities = try container.decode(Server.Capabilities.self, forKey: .capabilities)
|
|
serverInfo = try container.decode(Server.Info.self, forKey: .serverInfo)
|
|
instructions = try container.decodeIfPresent(String.self, forKey: .instructions)
|
|
_meta = try container.decodeIfPresent(Metadata.self, forKey: ._meta)
|
|
}
|
|
}
|
|
}
|
|
|
|
/// After successful initialization, the client MUST send an initialized notification to indicate it is ready to begin normal operations.
|
|
/// - SeeAlso: https://spec.modelcontextprotocol.io/specification/2024-11-05/basic/lifecycle/#initialization
|
|
public struct InitializedNotification: Notification {
|
|
public static let name: String = "notifications/initialized"
|
|
}
|