diff --git a/Sources/MCP/Server/Tools.swift b/Sources/MCP/Server/Tools.swift index d5ee9bb..fd10d93 100644 --- a/Sources/MCP/Server/Tools.swift +++ b/Sources/MCP/Server/Tools.swift @@ -182,7 +182,7 @@ public struct Tool: Hashable, Codable, Sendable { public init(from decoder: Decoder) throws { let container = try decoder.container(keyedBy: CodingKeys.self) name = try container.decode(String.self, forKey: .name) - description = try container.decode(String.self, forKey: .description) + description = try container.decodeIfPresent(String.self, forKey: .description) inputSchema = try container.decode(Value.self, forKey: .inputSchema) annotations = try container.decodeIfPresent(Tool.Annotations.self, forKey: .annotations) ?? .init() diff --git a/Tests/MCPTests/ToolTests.swift b/Tests/MCPTests/ToolTests.swift index af48f3e..b08963b 100644 --- a/Tests/MCPTests/ToolTests.swift +++ b/Tests/MCPTests/ToolTests.swift @@ -423,3 +423,20 @@ struct ToolTests { } } } + + @Test("Tool with missing description") + func testToolWithMissingDescription() throws { + let jsonString = """ + { + "name": "test_tool", + "inputSchema": {} + } + """ + let jsonData = jsonString.data(using: .utf8)! + + let tool = try JSONDecoder().decode(Tool.self, from: jsonData) + + #expect(tool.name == "test_tool") + #expect(tool.description == nil) + #expect(tool.inputSchema == [:]) + } \ No newline at end of file