Skip to content

Conversation

@mattt
Copy link
Contributor

@mattt mattt commented Feb 27, 2025

This PR adds a NetworkTransport implementation to the MCP Swift SDK, providing network-based communication capabilities alongside the existing StdioTransport.

Features

  • Implements the Transport protocol using Apple's Network framework
  • Handles connection establishment, message sending and receiving over network connections
  • Properly manages connection state with async/await patterns
  • Includes robust error handling and logging
  • Works with any NWConnection instance, allowing flexibility in network configuration

Example Usage

import Network
import MCP

// Create a TCP connection to a server
let connection = NWConnection(
    host: "example.com", 
    port: 8080, 
    using: .tcp
)

// Create the transport with the connection
let transport = NetworkTransport(connection: connection)

// Use with MCP client
let client = Client(name: "MyApp", version: "1.0.0")
try await client.connect(transport: transport)

Model Context Protocol currently supports only stdio and SSE interfaces. However, NetworkTransport can be helpful when proxying traffic from stdio over a network interface.

@mattt mattt merged commit 1367621 into main Feb 27, 2025
1 check passed
@mattt mattt deleted the mattt/network-transport branch February 27, 2025 22:50
devyhan pushed a commit to devyhan/swift-sdk that referenced this pull request Apr 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants