diff --git a/Sources/MCP/Base/Lifecycle.swift b/Sources/MCP/Base/Lifecycle.swift index 2e451e90..e02315b8 100644 --- a/Sources/MCP/Base/Lifecycle.swift +++ b/Sources/MCP/Base/Lifecycle.swift @@ -4,7 +4,15 @@ /// - Exchange and negotiate capabilities /// - Share implementation details /// -/// - SeeAlso: https://spec.modelcontextprotocol.io/specification/2024-11-05/basic/lifecycle/#initialization +/// `initialize` exists only in the handshake revisions (``Version/handshake``). 2026-07-28 removes +/// it ([SEP-2575](https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2575)): each +/// request carries its protocol version and client capabilities in `_meta`, and `server/discover` +/// advertises what the server supports. A server that serves stateless requests answers a stateless +/// `initialize` with -32601 (method not found). A client in ``Client/ProtocolMode/automatic`` mode +/// sends `server/discover` first and falls back to `initialize` on the signals that mode lists. +/// +/// - SeeAlso: https://modelcontextprotocol.io/specification/2025-11-25/basic/lifecycle#initialization +/// - SeeAlso: https://modelcontextprotocol.io/specification/2026-07-28/changelog public enum Initialize: Method { public static let name: String = "initialize" @@ -101,7 +109,14 @@ public enum Initialize: Method { } /// 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 +/// +/// Like ``Initialize``, `notifications/initialized` exists only in the handshake revisions; +/// 2026-07-28 removes it +/// ([SEP-2575](https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2575)). A client +/// sends it only after an `initialize` exchange. +/// +/// - SeeAlso: https://modelcontextprotocol.io/specification/2025-11-25/basic/lifecycle#initialization +/// - SeeAlso: https://modelcontextprotocol.io/specification/2026-07-28/changelog public struct InitializedNotification: Notification { public static let name: String = "notifications/initialized" } diff --git a/Sources/MCP/Base/Transports/HTTPClientTransport.swift b/Sources/MCP/Base/Transports/HTTPClientTransport.swift index 58e3e613..a14f8fe2 100644 --- a/Sources/MCP/Base/Transports/HTTPClientTransport.swift +++ b/Sources/MCP/Base/Transports/HTTPClientTransport.swift @@ -9,7 +9,7 @@ import Logging /// An implementation of the MCP Streamable HTTP transport protocol for clients. /// -/// This transport implements the [Streamable HTTP transport](https://spec.modelcontextprotocol.io/specification/2025-11-25/basic/transports#streamable-http) +/// This transport implements the [Streamable HTTP transport](https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#streamable-http) /// of the Model Context Protocol. On stateless (2026-07-28) connections it /// also sends the `Mcp-Method`, `Mcp-Name` and `Mcp-Param-*` request headers. /// diff --git a/Sources/MCP/Base/Utilities/Cancellation.swift b/Sources/MCP/Base/Utilities/Cancellation.swift index ce604ed3..b0a3d1cb 100644 --- a/Sources/MCP/Base/Utilities/Cancellation.swift +++ b/Sources/MCP/Base/Utilities/Cancellation.swift @@ -1,13 +1,19 @@ import Foundation /// The Model Context Protocol supports cancellation of requests through -/// notification messages. Either side can send a cancellation notification -/// to indicate that a previously-issued request should be cancelled. +/// notification messages. +/// +/// In the handshake revisions either side sends it to cancel a request it +/// sent. At 2026-07-28 a client sends it on every transport except Streamable +/// HTTP, where closing the request's response stream cancels the request, and +/// a server sends it only to tear down a `subscriptions/listen` stream the +/// client opened. /// /// Cancellation is advisory: the receiver should make a best-effort attempt /// to cancel the operation, but may not always be able to do so. /// /// - SeeAlso: https://modelcontextprotocol.io/specification/2025-11-25/basic/utilities/cancellation +/// - SeeAlso: https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/cancellation public struct CancelledNotification: Notification { public static let name: String = "notifications/cancelled" diff --git a/Sources/MCP/Base/Utilities/Ping.swift b/Sources/MCP/Base/Utilities/Ping.swift index e526ad4e..e4bb84f2 100644 --- a/Sources/MCP/Base/Utilities/Ping.swift +++ b/Sources/MCP/Base/Utilities/Ping.swift @@ -1,5 +1,12 @@ /// The Model Context Protocol includes an optional ping mechanism that allows either party to verify that their counterpart is still responsive and the connection is alive. -/// - SeeAlso: https://spec.modelcontextprotocol.io/specification/2024-11-05/basic/utilities/ping +/// +/// `ping` exists only in the revisions that use the `initialize` handshake. 2026-07-28 removes it +/// ([SEP-2575](https://github.com/modelcontextprotocol/modelcontextprotocol/pull/2575)): a server that +/// serves stateless requests answers a stateless `ping` with -32601 (method not found), and +/// ``Client/ping()`` sends `server/discover` instead on a stateless connection. +/// +/// - SeeAlso: https://modelcontextprotocol.io/specification/2025-11-25/basic/utilities/ping +/// - SeeAlso: https://modelcontextprotocol.io/specification/2026-07-28/changelog public enum Ping: Method { public static let name: String = "ping" } diff --git a/Sources/MCP/Base/Utilities/Progress.swift b/Sources/MCP/Base/Utilities/Progress.swift index 6c1b2d0b..763ed6f1 100644 --- a/Sources/MCP/Base/Utilities/Progress.swift +++ b/Sources/MCP/Base/Utilities/Progress.swift @@ -5,9 +5,12 @@ import Foundation /// The sender (either client or server) that issued the original request may /// include a progress token in the request's `_meta` field. If the receiver /// supports progress reporting, it can send progress notifications -/// containing that token to indicate how the operation is proceeding. +/// containing that token to indicate how the operation is proceeding. At +/// 2026-07-28, which has no server-to-client requests, only the server sends +/// them, for requests the client issued. /// /// - SeeAlso: https://modelcontextprotocol.io/specification/2025-11-25/basic/utilities/progress +/// - SeeAlso: https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/progress public struct ProgressNotification: Notification { public static let name: String = "notifications/progress" @@ -97,6 +100,7 @@ public enum ProgressToken: Hashable, Codable, Sendable { /// which can contain a progress token for receiving progress notifications. /// /// - SeeAlso: https://modelcontextprotocol.io/specification/2025-11-25/basic/utilities/progress +/// - SeeAlso: https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/progress public struct Metadata: Hashable, Codable, Sendable { /// The field for `key`, or `nil` when it is absent. public subscript(_ key: String) -> Value? { diff --git a/Sources/MCP/Base/Utilities/RequestContext.swift b/Sources/MCP/Base/Utilities/RequestContext.swift index fc73642a..5de64408 100644 --- a/Sources/MCP/Base/Utilities/RequestContext.swift +++ b/Sources/MCP/Base/Utilities/RequestContext.swift @@ -1,12 +1,15 @@ import Foundation -/// A context object that wraps a pending request, providing both the request ID -/// and a Task handle for the asynchronous operation. +/// A request the client sent: its ID and the task that awaits its response. /// -/// This allows you to track and cancel in-flight requests by sending -/// a CancelledNotification to the receiver (client or server). +/// Cancel the request with `Client.cancelRequest(_:reason:)` or by cancelling +/// the task that awaits ``value``. How the cancellation reaches the server +/// depends on the revision and transport: at 2026-07-28 over Streamable HTTP +/// the client closes the request's response stream; otherwise it sends +/// `notifications/cancelled`. /// /// - SeeAlso: https://modelcontextprotocol.io/specification/2025-11-25/basic/utilities/cancellation +/// - SeeAlso: https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/cancellation#transport-specific-cancellation public struct RequestContext: Sendable { /// The unique identifier for this request. public let requestID: ID diff --git a/Sources/MCP/Client/Client.swift b/Sources/MCP/Client/Client.swift index 7380a697..b71089b8 100644 --- a/Sources/MCP/Client/Client.swift +++ b/Sources/MCP/Client/Client.swift @@ -1113,8 +1113,8 @@ public actor Client { /// Send a request and return a RequestContext that wraps both the request ID and the Task. /// - /// This allows you to track and cancel the request by sending a CancelledNotification - /// to the server using the requestID. + /// Cancel the request with ``cancelRequest(_:reason:)``, passing the + /// context's `requestID`, or by cancelling the task that awaits its `value`. /// /// Example: /// ```swift @@ -1129,6 +1129,7 @@ public actor Client { /// - Returns: A RequestContext containing the request ID and Task /// - Throws: MCPError if the client is not connected /// - SeeAlso: https://modelcontextprotocol.io/specification/2025-11-25/basic/utilities/cancellation + /// - SeeAlso: https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/cancellation#transport-specific-cancellation public func send(_ request: Request) throws -> RequestContext { let first = try dispatch(request) return RequestContext(requestID: request.id, requestTask: withRoundTrips(request, first: first)) @@ -1631,7 +1632,12 @@ public actor Client { listenAcknowledgements[id]?.yield(.success(notifications)) } - /// Cancel a request by sending a CancelledNotification to the server. + /// Cancels a request the client sent. + /// + /// At 2026-07-28 over Streamable HTTP, this closes the request's response + /// stream, which is the cancellation signal there, and `reason` is not + /// sent. Otherwise it sends `notifications/cancelled` carrying `reason`. + /// A request not yet sent is never sent, and the server is told nothing. /// /// According to the MCP specification, cancellation is advisory: /// - The server SHOULD stop processing and free resources @@ -1647,6 +1653,7 @@ public actor Client { /// - reason: An optional human-readable reason for the cancellation /// - Throws: MCPError if the notification cannot be sent /// - SeeAlso: https://modelcontextprotocol.io/specification/2025-11-25/basic/utilities/cancellation + /// - SeeAlso: https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/cancellation#transport-specific-cancellation public func cancelRequest(_ requestID: ID, reason: String? = nil) async throws { // A request in a multi round-trip exchange: stop its rounds, which // cancels running input handlers, and cancel its current round. diff --git a/Sources/MCP/Server/Server.swift b/Sources/MCP/Server/Server.swift index 543b997e..05482605 100644 --- a/Sources/MCP/Server/Server.swift +++ b/Sources/MCP/Server/Server.swift @@ -1679,7 +1679,7 @@ public actor Server { /// response is the teardown, so nothing is sent there; nor after a /// stream the client cancelled. /// - /// - SeeAlso: https://modelcontextprotocol.io/specification/2026-07-28/basic/utilities/cancellation + /// - SeeAlso: https://modelcontextprotocol.io/specification/2026-07-28/basic/patterns/cancellation private func sendListenTeardown(_ id: ID) async { guard !isSessionless, let connection else { return } let cancelled = CancelledNotification.message(.init(requestId: id, reason: "Subscription closed")) diff --git a/Sources/MCP/Server/Tools.swift b/Sources/MCP/Server/Tools.swift index a40f034d..c065885d 100644 --- a/Sources/MCP/Server/Tools.swift +++ b/Sources/MCP/Server/Tools.swift @@ -742,7 +742,7 @@ extension CallTool.Result: InputRequiringResult { } /// When the list of available tools changes, servers that declared the listChanged capability SHOULD send a notification: -/// - SeeAlso: https://spec.modelcontextprotocol.io/specification/2025-06-18/server/tools/#list-changed-notification +/// - SeeAlso: https://modelcontextprotocol.io/specification/2025-11-25/server/tools#list-changed-notification public struct ToolListChangedNotification: Notification { public static let name: String = "notifications/tools/list_changed" }