Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ let sseTransport = SSEClientTransport(
endpoint: URL(string: "http://localhost:8080/sse")! // Ensure endpoint is SSE-specific if needed
)
try await client.connect(transport: sseTransport)
try await client.initialize()
Copy link
Contributor

Choose a reason for hiding this comment

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

This is no longer required, as of #100

Suggested change
try await client.initialize()

```

### Tools
Expand Down Expand Up @@ -773,4 +774,4 @@ see the [GitHub Releases page](https://github.com/modelcontextprotocol/swift-sdk
This project is licensed under the MIT License.

[mcp]: https://modelcontextprotocol.io
[mcp-spec-2025-03-26]: https://modelcontextprotocol.io/specification/2025-03-26
[mcp-spec-2025-03-26]: https://modelcontextprotocol.io/specification/2025-03-26
13 changes: 12 additions & 1 deletion Sources/MCP/Base/Transports/SSEClientTransport.swift
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,18 @@ import Logging

// For relative paths, preserve the scheme, host, and port
let pathToUse = path.starts(with: "/") ? path : "/\(path)"
components.path = pathToUse

// Parse the path to separate path and query components
if let pathComponents = URLComponents(string: pathToUse) {
components.path = pathComponents.path
// Preserve any query parameters from the endpoint path
if let queryItems = pathComponents.queryItems {
components.queryItems = queryItems
}
} else {
components.path = pathToUse
}

Comment on lines +421 to +430
Copy link
Contributor

Choose a reason for hiding this comment

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

Slightly more comprehensive version:

Suggested change
if let pathComponents = URLComponents(string: pathToUse) {
components.path = pathComponents.path
// Preserve any query parameters from the endpoint path
if let queryItems = pathComponents.queryItems {
components.queryItems = queryItems
}
} else {
components.path = pathToUse
}
// For relative paths, preserve the scheme, host, and port.
let pathToUse = path.starts(with: "/") ? path : "/\(path)"
if let relativeComponents = URLComponents(string: pathToUse) {
// Set path (prefer percentEncodedPath if present to avoid double-encoding)
if let percentEncodedPath = relativeComponents.percentEncodedPath.isEmpty
? nil : relativeComponents.percentEncodedPath
{
components.percentEncodedPath = percentEncodedPath
} else {
components.path = relativeComponents.path
}
// Set query via queryItems to ensure correct percent-encoding
if let queryItems = relativeComponents.queryItems, !queryItems.isEmpty {
components.queryItems = queryItems
} else {
components.queryItems = nil
}
// Preserve fragment if provided
components.fragment = relativeComponents.fragment
} else {
// Fallback: set path directly if components parsing fails
components.path = pathToUse
}

return components.url
}
}
Expand Down