Allow params field to be omitted in requests for methods that don't require them (#17)

* Allow `params` field to be omitted in requests for methods with empty parameters

* Add ping request to roundtrip test

* Generalize decoding of non-required parameters
This commit is contained in:
Mattt 2025-03-17 05:26:47 -07:00 • committed by GitHub
commit 6f1f65a392
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -142,6 +142,36 @@ struct PromptTests {
let emptyParams = ListPrompts.Parameters()
#expect(emptyParams.cursor == nil)
}
@Test("ListPrompts request decoding with omitted params")
func testListPromptsRequestDecodingWithOmittedParams() throws {
// Test decoding when params field is omitted
let jsonString = """
{"jsonrpc":"2.0","id":"test-id","method":"prompts/list"}
"""
let data = jsonString.data(using: .utf8)!
let decoder = JSONDecoder()
let decoded = try decoder.decode(Request<ListPrompts>.self, from: data)
#expect(decoded.id == "test-id")
#expect(decoded.method == ListPrompts.name)
}
@Test("ListPrompts request decoding with null params")
func testListPromptsRequestDecodingWithNullParams() throws {
// Test decoding when params field is null
let jsonString = """
{"jsonrpc":"2.0","id":"test-id","method":"prompts/list","params":null}
"""
let data = jsonString.data(using: .utf8)!
let decoder = JSONDecoder()
let decoded = try decoder.decode(Request<ListPrompts>.self, from: data)
#expect(decoded.id == "test-id")
#expect(decoded.method == ListPrompts.name)
}
@Test("ListPrompts result validation")
func testListPromptsResult() throws {