Update inputSchema example usage (#136)
* Update Tool inputSchema in README example usage * Update inputSchema usage in Tool tests
This commit is contained in:
parent
7a76001187
commit
36865fb056
2 changed files with 22 additions and 12 deletions
10
README.md
10
README.md
|
|
@ -434,15 +434,19 @@ server.withMethodHandler(ListTools.self) { _ in
|
||||||
name: "weather",
|
name: "weather",
|
||||||
description: "Get current weather for a location",
|
description: "Get current weather for a location",
|
||||||
inputSchema: .object([
|
inputSchema: .object([
|
||||||
"location": .string("City name or coordinates"),
|
"properties": .object([
|
||||||
"units": .string("Units of measurement, e.g., metric, imperial")
|
"location": .string("City name or coordinates"),
|
||||||
|
"units": .string("Units of measurement, e.g., metric, imperial")
|
||||||
|
])
|
||||||
])
|
])
|
||||||
),
|
),
|
||||||
Tool(
|
Tool(
|
||||||
name: "calculator",
|
name: "calculator",
|
||||||
description: "Perform calculations",
|
description: "Perform calculations",
|
||||||
inputSchema: .object([
|
inputSchema: .object([
|
||||||
"expression": .string("Mathematical expression to evaluate")
|
"properties": .object([
|
||||||
|
"expression": .string("Mathematical expression to evaluate")
|
||||||
|
])
|
||||||
])
|
])
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,9 @@ struct ToolTests {
|
||||||
name: "test_tool",
|
name: "test_tool",
|
||||||
description: "A test tool",
|
description: "A test tool",
|
||||||
inputSchema: .object([
|
inputSchema: .object([
|
||||||
"param1": .string("Test parameter")
|
"properties": .object([
|
||||||
|
"param1": .string("Test parameter")
|
||||||
|
])
|
||||||
])
|
])
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -100,7 +102,9 @@ struct ToolTests {
|
||||||
name: "calculate",
|
name: "calculate",
|
||||||
description: "Performs calculations",
|
description: "Performs calculations",
|
||||||
inputSchema: .object([
|
inputSchema: .object([
|
||||||
"expression": .string("Mathematical expression to evaluate")
|
"properties": .object([
|
||||||
|
"expression": .string("Mathematical expression to evaluate")
|
||||||
|
])
|
||||||
]),
|
]),
|
||||||
annotations: annotations
|
annotations: annotations
|
||||||
)
|
)
|
||||||
|
|
@ -131,23 +135,23 @@ struct ToolTests {
|
||||||
|
|
||||||
do {
|
do {
|
||||||
#expect(tool.annotations.isEmpty)
|
#expect(tool.annotations.isEmpty)
|
||||||
|
|
||||||
let encoder = JSONEncoder()
|
let encoder = JSONEncoder()
|
||||||
let data = try encoder.encode(tool)
|
let data = try encoder.encode(tool)
|
||||||
|
|
||||||
// Verify that empty annotations are not included in the JSON
|
// Verify that empty annotations are not included in the JSON
|
||||||
let jsonString = String(data: data, encoding: .utf8)!
|
let jsonString = String(data: data, encoding: .utf8)!
|
||||||
#expect(!jsonString.contains("\"annotations\""))
|
#expect(!jsonString.contains("\"annotations\""))
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
tool.annotations.title = "Test"
|
tool.annotations.title = "Test"
|
||||||
|
|
||||||
#expect(!tool.annotations.isEmpty)
|
#expect(!tool.annotations.isEmpty)
|
||||||
|
|
||||||
let encoder = JSONEncoder()
|
let encoder = JSONEncoder()
|
||||||
let data = try encoder.encode(tool)
|
let data = try encoder.encode(tool)
|
||||||
|
|
||||||
// Verify that empty annotations are not included in the JSON
|
// Verify that empty annotations are not included in the JSON
|
||||||
let jsonString = String(data: data, encoding: .utf8)!
|
let jsonString = String(data: data, encoding: .utf8)!
|
||||||
#expect(jsonString.contains("\"annotations\""))
|
#expect(jsonString.contains("\"annotations\""))
|
||||||
|
|
@ -179,8 +183,10 @@ struct ToolTests {
|
||||||
name: "test_tool",
|
name: "test_tool",
|
||||||
description: "Test tool description",
|
description: "Test tool description",
|
||||||
inputSchema: .object([
|
inputSchema: .object([
|
||||||
"param1": .string("String parameter"),
|
"properties": .object([
|
||||||
"param2": .int(42),
|
"param1": .string("String parameter"),
|
||||||
|
"param2": .int(42),
|
||||||
|
])
|
||||||
])
|
])
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue