Skip to content

Commit fb6fffb

Browse files
abcsnowwolfmattt
andauthored
fix: allow description field to be absent from Tool (#159)
* fix: allow description field to be absent from `Tool` * description field is not a requried field of Tool * Apply suggestions from code review * Update Tests/MCPTests/ToolTests.swift --------- Co-authored-by: Mattt <mattt@me.com>
1 parent ac90e67 commit fb6fffb

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

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")
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 == nil)
441+
#expect(tool.inputSchema == [:])
442+
}

0 commit comments

Comments
 (0)