1. Conduid
  2. AI
  3. Swift Context Protocol
MCP server · AI

Swift Context Protocol

swift-context-protocol is a Swift-based implementation of the Model Context Protocol (MCP) for AI contexts. It leverages Swift’s distributed actor model to enable type-safe, asynchronous remote invocation of tools, resources, and prompts.

Unclaimed last commit a year ago modelcontextprotocolaiswift
46Fair

Scored 5 months ago · breakdown

About Swift Context Protocol

Swift Context Protocol is an MCP server published by 1amageek in the AI category: swift-context-protocol is a Swift-based implementation of the Model Context Protocol (MCP) for AI contexts. It leverages Swift’s distributed actor model to enable type-safe, asynchronous remote invocation of tools, resources, and prompts.

The repository has 11 stars and 1 forks, with the last commit a year ago. Six months or more without a commit doesn't mean the server is broken, but check the open issues before depending on it in production.

Install

From source
git clone https://github.com/1amageek/swift-context-protocol

This server has no ConduID identity, so agent calls to it are not receipted. Pin the version you install and review the source before granting it credentials.

Ask AI

✦

Ask AI about Swift Context Protocol

Powered by Claude · Grounded in docs

I know everything about Swift Context Protocol. Ask me about installation, configuration, usage, or troubleshooting.

Security checks

Static checks derived from the repository 5 days ago. Heuristics on the source, not an audit.

  • ✓README presentThe repository ships documentation.
  • !License declaredNo license file. Legally you have no right to use it in a product.
  • ✓Tests presentA test suite exists in the repository.
  • !Dependencies pinnedNo lockfile. Installs can pull different code over time.
  • !Scoped permissionsDoesn't declare a permission scope. Assume it can do anything its process can.

1 check has not been run yet.

README

swift-context-protocol

Swift Version License

A distributed context protocol implementation for Swift.

swift-context-protocol is a Swift-based implementation of the Model Context Protocol (MCP) for AI contexts. It leverages Swift’s distributed actor model to enable type-safe, asynchronous remote invocation of tools, resources, and prompts.

Features

  • Distributed Context Protocol
    Define a common interface (ContextProtocol) for operations like ping, initialize, complete, set logging level, resource reading, tool calling, and prompt execution.

  • Tool, Resource, and Prompt Protocols
    Provide standardized protocols for:

    • Tool: Executes a specific operation using JSON schema validated inputs.
    • Resource: Represents a resource identified by a URI, supporting asynchronous read operations.
    • Prompt: Generates prompt templates or responses based on input parameters.
  • JSON Schema Support
    Input and output formats can be validated and described using JSONSchema.

  • Distributed Actors
    Leverages Swift’s new distributed actor model (with WebSocketActorSystem) to allow remote invocation of protocol methods.

  • Capability Negotiation & Initialization
    Exchange client and server information along with supported capabilities during the initialization handshake.

Installation

Add the following dependency to your Package.swift:

dependencies: [
    .package(url: "https://github.com/1amageek/swift-context-protocol.git", from: "1.0.0")
]

Then add "swift-context-protocol" to your target dependencies.

Usage

Creating a Custom Tool

Implement the Tool protocol to create a custom tool. For example, here's a simple echo tool that returns the input string:

import Foundation
import JSONSchema
import ContextProtocol

/// A simple tool that echoes the provided input.
public struct EchoTool: Tool {
    
    public typealias Input = Envelop<String>
    public typealias Output = String
    
    public var name: String = "echo"
    public var description: String = "A tool that echoes the provided input."
    public var inputSchema: JSONSchema? = .string()
    
    public var guide: String? = """
    # Tool Name
    EchoTool
    
    ## Description
    This tool echoes back the input string provided to it.
    
    ## Parameters
    - `input`: The string to be echoed.
      - **Type**: `String`
      - **Description**: The input text that will be returned as output.
    
    ## Usage
    Provide a valid string as input.
    
    ## Example
    ```swift
    let input = "Hello, world!"
    // EchoTool returns: "Hello, world!"
    ```
    """
    
    public func run(_ input: Envelop<String>) async throws -> String {
        return input.data
    }
}

Registering Components and Starting the Server

Create a distributed actor (e.g., ContextActor) that implements the ContextProtocol and registers your tools, resources, and prompts.

import Foundation
import Distributed
import WebSocketActors
import ContextProtocol

@main
struct Boot {
    
    static func main() async throws {
        let server = ContextServer()
        server.setTools([ EchoTool() ])
        try await server.start()
    }
}

Connecting a Client

You can connect to the server using a client wrapper like ContextClient:

import Foundation
import Distributed
import ContextProtocol

@main
struct ClientBoot {
    static func main() async throws {
        let client = try await ContextClient.connectServer()
        let data = Envelop(data: "Hello, World!")
        let parameters = try JSONEncoder().encode(data)
        let toolResponse = try await client.session.callTool(
            name: "echo",
            parameters: parameters
        )
        print(toolResponse)
    }
}

During connection, the client performs an initialization handshake where it sends its information and capabilities and receives server details and instructions. A cool connection banner is printed on success.

API Overview

ContextProtocol

The distributed actor protocol defines methods for:

  • initialize: Handshake with client info and capabilities.
  • ping: Simple connectivity check.
  • complete: Trigger completion logic.
  • setLoggingLevel: Adjust logging level.
  • getPrompt: Request a prompt.
  • listPrompts: List available prompt templates.
  • listResources: Retrieve a list of resources.
  • readResource: Read resource content (returns a ResourceContentData enum).
  • subscribeResource / unsubscribeResource: Manage resource subscriptions.
  • callTool: Call a tool and receive its output as a ResourceContentData enum.
  • listTools: Retrieve a list of tools.
  • sendRootsListChanged: Notify changes in the root resource list.

Domain Types

  • ServerInfo / ClientInfo: Exchange basic identity and versioning information.
  • CapabilityConfig: Key-value settings indicating supported capabilities.
  • ResourceContentData: An enum (e.g., .text(String) or .binary(Data)) to represent resource contents.
  • ToolResponse / PromptResponse / ResourceResponse: DTOs used to list available tools, prompts, and resources.
  • ListResponse<T>: A generic wrapper for lists.

Contributing

Contributions are welcome! Please open issues or pull requests on GitHub.

License

This project is licensed under the MIT License.

README fetched from the repository 5 days ago. The original is authoritative.

Questions

About Swift Context Protocol

How do I install Swift Context Protocol?

No package has been published for this server, so install it from source: clone the repository and follow its README.

Is Swift Context Protocol safe to use with an AI agent?

Its trust score is 46 out of 100 (fair). It passes 2 of the 5 static security checks run so far; the failures are listed above. It has no ConduID identity yet, so agent calls to it are not receipted.

Is Swift Context Protocol still maintained?

The last commit was a year ago and 1 open issues. That's long enough that you should check whether the maintainer is responding to issues before depending on it.