Expose built-in web tools in MCP Toolbox
This commit is contained in:
@@ -571,3 +571,32 @@ final class WebToolsTests: XCTestCase {
|
||||
XCTAssertTrue(page.reference.contains(result.url.absoluteString))
|
||||
}
|
||||
}
|
||||
|
||||
final class BuiltInToolsetTests: XCTestCase {
|
||||
func testDiscoveryAndSetupErrorWithoutExternalServer() async throws {
|
||||
let client = BuiltInWebTools(searchEndpoint: "")
|
||||
let tools = try await client.listTools()
|
||||
XCTAssertEqual(tools.map(\.name), ["retrieve_page", "web_search"])
|
||||
do {
|
||||
_ = try await client.callTool("web_search", argumentsJSON: Data(#"{"query":"tides"}"#.utf8))
|
||||
XCTFail("Expected a configuration error")
|
||||
} catch let error as StudioError {
|
||||
XCTAssertTrue(error.message.contains("SearXNG"))
|
||||
}
|
||||
}
|
||||
|
||||
func testBuiltInToolsReturnSourcesThroughMCPInterface() async throws {
|
||||
guard let endpoint = ProcessInfo.processInfo.environment["AISTUDIO_TEST_WEB_URL"] else {
|
||||
throw XCTSkip("Run Scripts/test.sh to configure the web fixture.")
|
||||
}
|
||||
let client: any MCPToolClient = BuiltInWebTools(searchEndpoint: endpoint)
|
||||
let result = try await client.callTool("web_search", argumentsJSON: Data(#"{"query":"tides & moon"}"#.utf8))
|
||||
let items = try XCTUnwrap(JSONSerialization.jsonObject(with: result) as? [[String: String]])
|
||||
let address = try XCTUnwrap(items.first?["url"])
|
||||
let args = try JSONEncoder().encode(["url": address])
|
||||
let response = try await client.callTool("retrieve_page", argumentsJSON: args)
|
||||
let page = try XCTUnwrap(JSONSerialization.jsonObject(with: response) as? [String: String])
|
||||
XCTAssertEqual(page["url"], address)
|
||||
XCTAssertEqual(page["text"], "Moon and tides\nTest passage.")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user