Make Tool.inputSchema nonoptional (#123)
This commit is contained in:
parent
c95d0c0354
commit
f3b9ba4a59
2 changed files with 14 additions and 11 deletions
|
|
@ -14,7 +14,7 @@ public struct Tool: Hashable, Codable, Sendable {
|
||||||
/// The tool description
|
/// The tool description
|
||||||
public let description: String
|
public let description: String
|
||||||
/// The tool input schema
|
/// The tool input schema
|
||||||
public let inputSchema: Value?
|
public let inputSchema: Value
|
||||||
|
|
||||||
/// Annotations that provide display-facing and operational information for a Tool.
|
/// Annotations that provide display-facing and operational information for a Tool.
|
||||||
///
|
///
|
||||||
|
|
@ -86,7 +86,7 @@ public struct Tool: Hashable, Codable, Sendable {
|
||||||
public init(
|
public init(
|
||||||
name: String,
|
name: String,
|
||||||
description: String,
|
description: String,
|
||||||
inputSchema: Value? = nil,
|
inputSchema: Value,
|
||||||
annotations: Annotations = nil
|
annotations: Annotations = nil
|
||||||
) {
|
) {
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
@ -183,7 +183,7 @@ public struct Tool: Hashable, Codable, Sendable {
|
||||||
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.decode(String.self, forKey: .description)
|
||||||
inputSchema = try container.decodeIfPresent(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()
|
||||||
}
|
}
|
||||||
|
|
@ -192,9 +192,7 @@ public struct Tool: Hashable, Codable, Sendable {
|
||||||
var container = encoder.container(keyedBy: CodingKeys.self)
|
var container = encoder.container(keyedBy: CodingKeys.self)
|
||||||
try container.encode(name, forKey: .name)
|
try container.encode(name, forKey: .name)
|
||||||
try container.encode(description, forKey: .description)
|
try container.encode(description, forKey: .description)
|
||||||
if let schema = inputSchema {
|
try container.encode(inputSchema, forKey: .inputSchema)
|
||||||
try container.encode(schema, forKey: .inputSchema)
|
|
||||||
}
|
|
||||||
if !annotations.isEmpty {
|
if !annotations.isEmpty {
|
||||||
try container.encode(annotations, forKey: .annotations)
|
try container.encode(annotations, forKey: .annotations)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -130,7 +130,8 @@ struct ToolTests {
|
||||||
func testToolWithEmptyAnnotations() throws {
|
func testToolWithEmptyAnnotations() throws {
|
||||||
var tool = Tool(
|
var tool = Tool(
|
||||||
name: "test_tool",
|
name: "test_tool",
|
||||||
description: "Test tool description"
|
description: "Test tool description",
|
||||||
|
inputSchema: [:]
|
||||||
)
|
)
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
|
@ -163,7 +164,7 @@ struct ToolTests {
|
||||||
let tool = Tool(
|
let tool = Tool(
|
||||||
name: "test_tool",
|
name: "test_tool",
|
||||||
description: "Test tool description",
|
description: "Test tool description",
|
||||||
inputSchema: nil,
|
inputSchema: [:],
|
||||||
annotations: nil
|
annotations: nil
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -324,8 +325,8 @@ struct ToolTests {
|
||||||
@Test("ListTools result validation")
|
@Test("ListTools result validation")
|
||||||
func testListToolsResult() throws {
|
func testListToolsResult() throws {
|
||||||
let tools = [
|
let tools = [
|
||||||
Tool(name: "tool1", description: "First tool", inputSchema: nil),
|
Tool(name: "tool1", description: "First tool", inputSchema: [:]),
|
||||||
Tool(name: "tool2", description: "Second tool", inputSchema: nil),
|
Tool(name: "tool2", description: "Second tool", inputSchema: [:]),
|
||||||
]
|
]
|
||||||
|
|
||||||
let result = ListTools.Result(tools: tools, nextCursor: "next_page")
|
let result = ListTools.Result(tools: tools, nextCursor: "next_page")
|
||||||
|
|
@ -399,7 +400,11 @@ struct ToolTests {
|
||||||
#expect(request.id == 1)
|
#expect(request.id == 1)
|
||||||
#expect(request.params.cursor == nil)
|
#expect(request.params.cursor == nil)
|
||||||
|
|
||||||
let testTool = Tool(name: "test_tool", description: "Test tool for verification")
|
let testTool = Tool(
|
||||||
|
name: "test_tool",
|
||||||
|
description: "Test tool for verification",
|
||||||
|
inputSchema: [:]
|
||||||
|
)
|
||||||
return ListTools.response(id: request.id, result: ListTools.Result(tools: [testTool]))
|
return ListTools.response(id: request.id, result: ListTools.Result(tools: [testTool]))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue