Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions Sources/MCP/Base/Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,22 @@ import Foundation
@preconcurrency import SystemPackage
#endif

/// Top-level namespace for backward compatibility
///
/// This is provided to allow existing code that uses `MCP.Error` to continue
/// to work without modification.
///
/// The MCPError type is now the recommended way to handle errors in MCP.
///
/// @warning This namespace is deprecated and will be removed in a future version.
public enum MCP {
/// Deprecated type alias for MCPError
@available(*, deprecated, renamed: "MCPError", message: "Use MCPError instead of MCP.Error")
public typealias Error = MCPError
}

// MARK: -

/// A model context protocol error.
public enum MCPError: Error, Sendable {
// Standard JSON-RPC 2.0 errors (-32700 to -32603)
Expand Down
12 changes: 8 additions & 4 deletions Tests/MCPTests/Helpers/MockTransport.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import Foundation
import class Foundation.JSONEncoder
import class Foundation.JSONDecoder
import struct Foundation.Data
import struct Foundation.POSIXError
Comment on lines +1 to +4
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why someone might need to fully-qualify MCP.Method or MCP.Notification is to fix a different namespace collision with Foundation.

As a workaround, you can import individual declarations as needed. Apologies in advance for any inconvenience this causes 🙇


import Logging

@testable import MCP
Expand Down Expand Up @@ -76,7 +80,7 @@ actor MockTransport: Transport {
shouldFailSend = shouldFail
}

func queue<M: MCP.Method>(request: Request<M>) throws {
func queue<M: Method>(request: Request<M>) throws {
let data = try encoder.encode(request)
if let continuation = dataStreamContinuation {
continuation.yield(data)
Expand All @@ -85,12 +89,12 @@ actor MockTransport: Transport {
}
}

func queue<M: MCP.Method>(response: Response<M>) throws {
func queue<M: Method>(response: Response<M>) throws {
let data = try encoder.encode(response)
dataToReceive.append(data)
}

func queue<N: MCP.Notification>(notification: Message<N>) throws {
func queue<N: Notification>(notification: Message<N>) throws {
let data = try encoder.encode(notification)
dataToReceive.append(data)
}
Expand Down