Skip to content

Commit 3e628db

Browse files
authored
Update capabilities to be expressible by Boolean literals (modelcontextprotocol#16)
* Conform Server.Capabilities types to ExpressibleByBooleanLiteral * Conform Client.Capabilities types to ExpressibleByBooleanLiteral * Use Boolean literatls for capabilities in tests * Update README
1 parent 4ed52bc commit 3e628db

File tree

4 files changed

+46
-8
lines changed

4 files changed

+46
-8
lines changed

README.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,9 @@ let server = Server(
5151
name: "MyServer",
5252
version: "1.0.0",
5353
capabilities: .init(
54-
prompts: .init(),
55-
resources: .init(
56-
subscribe: true
57-
),
58-
tools: .init()
54+
prompts: true,
55+
resources: true,
56+
tools: true
5957
)
6058
)
6159

Sources/MCP/Client/Client.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,3 +408,17 @@ public actor Client {
408408
return value
409409
}
410410
}
411+
412+
// MARK: - ExpressibleByBooleanLiteral
413+
414+
extension Client.Capabilities.Roots: ExpressibleByBooleanLiteral {
415+
public init(booleanLiteral value: Bool) {
416+
self.init()
417+
}
418+
}
419+
420+
extension Client.Capabilities.Sampling: ExpressibleByBooleanLiteral {
421+
public init(booleanLiteral value: Bool) {
422+
self.init()
423+
}
424+
}

Sources/MCP/Server/Server.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,3 +408,29 @@ public actor Server {
408408
self.isInitialized = true
409409
}
410410
}
411+
412+
// MARK: - ExpressibleByBooleanLiteral
413+
414+
extension Server.Capabilities.Logging: ExpressibleByBooleanLiteral {
415+
public init(booleanLiteral value: Bool) {
416+
self.init()
417+
}
418+
}
419+
420+
extension Server.Capabilities.Prompts: ExpressibleByBooleanLiteral {
421+
public init(booleanLiteral value: Bool) {
422+
self.init()
423+
}
424+
}
425+
426+
extension Server.Capabilities.Resources: ExpressibleByBooleanLiteral {
427+
public init(booleanLiteral value: Bool) {
428+
self.init()
429+
}
430+
}
431+
432+
extension Server.Capabilities.Tools: ExpressibleByBooleanLiteral {
433+
public init(booleanLiteral value: Bool) {
434+
self.init()
435+
}
436+
}

Tests/MCPTests/RoundtripTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ struct RoundtripTests {
3434
name: "TestServer",
3535
version: "1.0.0",
3636
capabilities: .init(
37-
prompts: .init(),
38-
resources: .init(),
39-
tools: .init()
37+
prompts: true,
38+
resources: true,
39+
tools: true
4040
)
4141
)
4242
await server.withMethodHandler(ListTools.self) { _ in

0 commit comments

Comments
 (0)