Skip to content

Commit 4a42963

Browse files
committed
fix: allow description field to be absent from Tool
* description field is not a requried field of Tool
1 parent f1b50e6 commit 4a42963

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

Sources/MCP/Server/Tools.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public struct Tool: Hashable, Codable, Sendable {
182182
public init(from decoder: Decoder) throws {
183183
let container = try decoder.container(keyedBy: CodingKeys.self)
184184
name = try container.decode(String.self, forKey: .name)
185-
description = try container.decode(String.self, forKey: .description)
185+
description = try container.decodeIfPresent(String.self, forKey: .description) ?? ""
186186
inputSchema = try container.decode(Value.self, forKey: .inputSchema)
187187
annotations =
188188
try container.decodeIfPresent(Tool.Annotations.self, forKey: .annotations) ?? .init()

Tests/MCPTests/ToolTests.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,3 +423,20 @@ struct ToolTests {
423423
}
424424
}
425425
}
426+
427+
@Test("Tool with missing description defaults to empty string")
428+
func testToolWithMissingDescription() throws {
429+
let jsonString = """
430+
{
431+
"name": "test_tool",
432+
"inputSchema": {}
433+
}
434+
"""
435+
let jsonData = jsonString.data(using: .utf8)!
436+
437+
let tool = try JSONDecoder().decode(Tool.self, from: jsonData)
438+
439+
#expect(tool.name == "test_tool")
440+
#expect(tool.description == "")
441+
#expect(tool.inputSchema == [:])
442+
}

0 commit comments

Comments
 (0)