GS

gavinaboulhosn/swiftmcp

Developer tools

이 페이지는 AI로 자동 번역되었습니다. 기술적인 세부 사항은 원문을 확인하세요. 원문 보기

11 stars 5 forks 품질 44 트렌드 8MIT

모형 Context 의정서 (MCP) Spec의 신속한 실시

개요

SwiftMCP는 Model Context Protocol (MCP)의 워크 인-progress Swift 구현이며, Swift 애플리케이션에 언어 모델 기능을 통합하기 위해 견고하고 안전한 방법을 제공하는 것을 목표로합니다. ⚠️ 참고 : 이 SDK는 활성 개발 중입니다. API는 TypeScript 구현을 통해 기능 패리티를 변경할 수 있습니다. - 펀 - Swift의 배우 모델과 async/await로 내장 - 모든 MCP 메시지 및 작업을위한 전체 유형 안전 - ↳ - stdio 및 Server-Sent 이벤트 지원 (SSE) - ⚡️ - Timeout 및 retry 지원으로 효율적인 메시지 처리 -  - 자원, 신속한, 도구 및 기타 지원 - ☸ - Swift Package Manager를 통한 쉬운 통합 또는 Xcode 프로젝트에 추가: 1. 파일 > 패키지 의존도를 추가 2. 입력: https://github.com/gavinaboulhosn/SwiftMCP.

개요(AI 번역)

SwiftMCP는 Model Context Protocol (MCP)의 워크 인-progress Swift 구현이며, Swift 애플리케이션에 언어 모델 기능을 통합하기 위해 견고하고 안전한 방법을 제공하는 것을 목표로합니다.

⚠️ 참고: 이 SDK는 활성 개발 중입니다. API는 TypeScript 구현을 통해 기능 패리티를 변경할 수 있습니다.

특징

  • vit **Modern Swift Concurrency ** - Swift의 배우 모델과 async/await로 내장
  • ♣Type-Safe** - 모든 MCP 메시지 및 작업에 대한 전체 유형 안전
  • دMultiple Transports - stdio 및 Server-Sent 이벤트 지원 (SSE)
  • ⚡️Performance - 타임아웃 및 리트리 지원으로 효율적인 메시지 처리
  • Rich Capabilities - 리소스, 프롬프트, 도구 등에 대한 지원 SwiftPM Ready - Swift Package Manager를 통한 간편한 통합

설치

SwiftMCP를 Swift 패키지에 추가하십시오:

또는 Xcode 프로젝트에 추가:

  1. 파일 > 패키지 Dependencies 추가
  2. 입력: https://github.com/gavinaboulhosn/SwiftMCP.git

기본 사용

클라이언트 만들기

호스트

Hosts는 클라이언트 연결을 관리하고 요청 및 알림을 처리하기위한 더 높은 수준의 API를 제공합니다.

기본 설정

이 페이지는 AI로 자동 번역되었습니다. 기술적인 세부 사항은 원문을 확인하세요.

README

원문 README의 일부입니다. 원문 보기.

SwiftMCP

SwiftMCP is a work-in-progress Swift implementation of the Model Context Protocol (MCP), aiming to provide a robust and type-safe way to integrate Language Model capabilities into Swift applications.

⚠️ Note: This SDK is under active development. APIs may change as we work towards feature parity with the TypeScript implementation.

Features

  • 🏃 Modern Swift Concurrency - Built with Swift’s actor model and async/await
  • 🔒 Type-Safe - Full type safety for all MCP messages and operations
  • 🔌 Multiple Transports - Support for stdio and Server-Sent Events (SSE)
  • ⚡️ Performance - Efficient message handling with timeout and retry support
  • 🛠 Rich Capabilities - Support for resources, prompts, tools, and more
  • 📦 SwiftPM Ready - Easy integration through Swift Package Manager

Installation

Add SwiftMCP to your Swift package:

dependencies: [
    .package(url: "https://github.com/gavinaboulhosn/SwiftMCP.git", branch: "main")
]

Or add it to your Xcode project:

  1. File > Add Package Dependencies
  2. Enter: https://github.com/gavinaboulhosn/SwiftMCP.git

Basic Usage

Creating a Client

import SwiftMCP

// Initialize client
let client = MCPClient(
    clientInfo: .init(name: "MyApp", version: "1.0.0"),
    capabilities: .init(
        roots: .init(listChanged: true)  // Enable roots with change notifications
    )
)

// Connect using stdio transport
let transport = StdioTransport(
    options: .init(
        command: "npx",
        arguments: ["-y", "@modelcontextprotocol/server-memory"]
    )
)

// Start the client
try await client.start(transport)

// Make requests
let resources = try await client.listResources()
print("Found \(resources.resources.count) resources")

// Listen for notifications
for await notification in await client.notifications {
    switch notification {
    case let resourceUpdate as ResourceUpdatedNotification:
        print("Resource updated: \(resourceUpdate.params?.uri ?? "")")
    default:
        break
    }
}

Hosts

Hosts are used to manage client connections and provide a higher-level API for handling requests and notifications:

Basic Setup

To get started, you need to create an MCPHost instance and connect to a server using a transport layer:

import SwiftMCP

// Basic host - assumes app name and version via Bundle properties
let host = MCPHost()
// or more advanced configuration
let host = MCPHost(config:
    .init(
        roots: .list([Root(uri: "file:///some/root")]),
        sampling: .init(
            handler: { request in
                /** Use your llm to fulfill the server's sampling request */
GitHub에서 전체 README 보기

설치

This server does not publish a one-line install command.

Open the repository installation guide MCP 초보자라면? mcpskill.org 가이드부터 시작하세요 →