From 3e628db6d89a5860bf83d96a885d6fe0fbac4524 Mon Sep 17 00:00:00 2001 From: Mattt Date: Mon, 17 Mar 2025 04:35:03 -0700 Subject: [PATCH] Update capabilities to be expressible by Boolean literals (#16) * Conform Server.Capabilities types to ExpressibleByBooleanLiteral * Conform Client.Capabilities types to ExpressibleByBooleanLiteral * Use Boolean literatls for capabilities in tests * Update README --- README.md | 8 +++----- Sources/MCP/Client/Client.swift | 14 ++++++++++++++ Sources/MCP/Server/Server.swift | 26 ++++++++++++++++++++++++++ Tests/MCPTests/RoundtripTests.swift | 6 +++--- 4 files changed, 46 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 2a3a130..fc1e179 100644 --- a/README.md +++ b/README.md @@ -51,11 +51,9 @@ let server = Server( name: "MyServer", version: "1.0.0", capabilities: .init( - prompts: .init(), - resources: .init( - subscribe: true - ), - tools: .init() + prompts: true, + resources: true, + tools: true ) ) diff --git a/Sources/MCP/Client/Client.swift b/Sources/MCP/Client/Client.swift index e910ac8..8f9fa24 100644 --- a/Sources/MCP/Client/Client.swift +++ b/Sources/MCP/Client/Client.swift @@ -408,3 +408,17 @@ public actor Client { return value } } + +// MARK: - ExpressibleByBooleanLiteral + +extension Client.Capabilities.Roots: ExpressibleByBooleanLiteral { + public init(booleanLiteral value: Bool) { + self.init() + } +} + +extension Client.Capabilities.Sampling: ExpressibleByBooleanLiteral { + public init(booleanLiteral value: Bool) { + self.init() + } +} diff --git a/Sources/MCP/Server/Server.swift b/Sources/MCP/Server/Server.swift index 168b062..5f07ade 100644 --- a/Sources/MCP/Server/Server.swift +++ b/Sources/MCP/Server/Server.swift @@ -408,3 +408,29 @@ public actor Server { self.isInitialized = true } } + +// MARK: - ExpressibleByBooleanLiteral + +extension Server.Capabilities.Logging: ExpressibleByBooleanLiteral { + public init(booleanLiteral value: Bool) { + self.init() + } +} + +extension Server.Capabilities.Prompts: ExpressibleByBooleanLiteral { + public init(booleanLiteral value: Bool) { + self.init() + } +} + +extension Server.Capabilities.Resources: ExpressibleByBooleanLiteral { + public init(booleanLiteral value: Bool) { + self.init() + } +} + +extension Server.Capabilities.Tools: ExpressibleByBooleanLiteral { + public init(booleanLiteral value: Bool) { + self.init() + } +} diff --git a/Tests/MCPTests/RoundtripTests.swift b/Tests/MCPTests/RoundtripTests.swift index 681c77e..282794e 100644 --- a/Tests/MCPTests/RoundtripTests.swift +++ b/Tests/MCPTests/RoundtripTests.swift @@ -34,9 +34,9 @@ struct RoundtripTests { name: "TestServer", version: "1.0.0", capabilities: .init( - prompts: .init(), - resources: .init(), - tools: .init() + prompts: true, + resources: true, + tools: true ) ) await server.withMethodHandler(ListTools.self) { _ in