Skip to content

HTTP Transport for servers #165

Open

Description

@Cclleemm

I'm trying to build a very simple MCP Server base on HTTP SSE protocol (not STDIO).
This feature is implemented or not ? The MCP doesn't seem to be connected.

import Foundation
import Logging

// Configure Logger
LoggingSystem.bootstrap { label in
    var handler = StreamLogHandler.standardOutput(label: label)
    handler.logLevel = .trace
    return handler
}

// Create logger
let logger = Logger(label: "com.example.mcp")


let server = Server(
    name: "Swift Version Server",
    version: "1.0.0",
    capabilities: .init(tools: .init(listChanged: false))
)

let transport = HTTPClientTransport(
    endpoint: URL(string: "http://localhost:8080")!,
    logger:logger
)
try await server.start(transport: transport)


let tool = Tool(name: "swift_version",
                description: "Returns the current Swift version",
                inputSchema: .object([
                    "type": .string("object")
                ]))

await server.withMethodHandler(ListTools.self) { params in
    ListTools.Result(tools: [tool])
}

await server.withMethodHandler(CallTool.self) { params in
    guard params.name == tool.name else {
        throw MCPError.invalidParams("Wrong tool name: \(params.name)")
    }
    return CallTool.Result(content: [.text(swiftVersion() ?? "No version")])
}

func swiftVersion() -> String? {
    let process = Process()
    process.executableURL = URL(fileURLWithPath: "/usr/bin/env")
    process.arguments = ["swift", "--version"]

    let outputPipe = Pipe()
    process.standardOutput = outputPipe

    do {
        try process.run()
        process.waitUntilExit()

        let data = outputPipe.fileHandleForReading.readDataToEndOfFile()
        return String(data: data, encoding: .utf8)
    } catch {
        return "Error running swift-version: \(error)"
    }
}

await server.waitUntilCompleted()

Activity

  1. sebsto commented on Oct 8, 2025

    @sebsto
    Contributor

    Hello Clement,

    There is no MCPHTTPServerTransport to implement a server in this library.
    You need to create your own HTTP endpoint, using Vapor or Hummingbird, your own custom transport for it and bind the pieces together.

    @stallent has a reasonably working implementation in his fork's branch.
    Look at the thread here
    #110

    Based on his work, I created a minimal HTTP server with Hummingbird. I use it for request / responses. I haven't try streamable events yet. You can look at the code, but it's a heavy work in progress.
    https://github.com/sebsto/agentkit (the README is not updated, look at the Example directory instead)

  2. realmtai commented on Nov 15, 2025

    @realmtai

    What's the purpose of NetworkTransport actor? should the following code work?

            /// // Create a TCP connection to a server
            let connection = NWConnection(
                host: NWEndpoint.Host("192.168.1.034"),
                port: NWEndpoint.Port(23232),
                using: .tcp
            )
    
            // Initialize the transport with the connection
            let transport = NetworkTransport(connection: connection)
    
            try await server.start(transport: transport)
    
            await server.waitUntilCompleted()
  3. DePasqualeOrg commented on Jan 4, 2026

    @DePasqualeOrg

    I've implemented this functionality in my PR #175. I'd love to hear your feedback if you're able to test it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions