HTTP Transport for servers

Open
#165 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
swift
Domain
networking

Research direction

Start by reading the HTTPClientTransport entry point and the server.start(transport:) call shown in the issue, then compare them with the HTTP SSE protocol requirement. Confirm whether an HTTP SSE server transport is present and determine what is needed for the example server to connect successfully. Done means the requested HTTP transport behavior is implemented or its absence is clearly resolved.

Written by the indexing model from the issue text.

Description

enhancement

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()
Dominant language
Swift
Stars
1.5k
Forks
243
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from modelcontextprotocol/swift-sdk

All issues in modelcontextprotocol/swift-sdk

Similar issues

More Swift issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.