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>
This commit is contained in:
parent
ac90e679cd
commit
fb6fffbecd
2 changed files with 18 additions and 1 deletions
|
|
@ -182,7 +182,7 @@ public struct Tool: Hashable, Codable, Sendable {
|
||||||
public init(from decoder: Decoder) throws {
|
public init(from decoder: Decoder) throws {
|
||||||
let container = try decoder.container(keyedBy: CodingKeys.self)
|
let container = try decoder.container(keyedBy: CodingKeys.self)
|
||||||
name = try container.decode(String.self, forKey: .name)
|
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)
|
inputSchema = try container.decode(Value.self, forKey: .inputSchema)
|
||||||
annotations =
|
annotations =
|
||||||
try container.decodeIfPresent(Tool.Annotations.self, forKey: .annotations) ?? .init()
|
try container.decodeIfPresent(Tool.Annotations.self, forKey: .annotations) ?? .init()
|
||||||
|
|
|
||||||
|
|
@ -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 == [:])
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue