@@ -111,7 +111,7 @@ struct ToolTests {
111111 let emptyParams = ListTools . Parameters ( )
112112 #expect( emptyParams. cursor == nil )
113113 }
114-
114+
115115 @Test ( " ListTools request decoding with omitted params " )
116116 func testListToolsRequestDecodingWithOmittedParams( ) throws {
117117 // Test decoding when params field is omitted
@@ -126,7 +126,7 @@ struct ToolTests {
126126 #expect( decoded. id == " test-id " )
127127 #expect( decoded. method == ListTools . name)
128128 }
129-
129+
130130 @Test ( " ListTools request decoding with null params " )
131131 func testListToolsRequestDecodingWithNullParams( ) throws {
132132 // Test decoding when params field is null
@@ -205,4 +205,37 @@ struct ToolTests {
205205 func testToolListChangedNotification( ) throws {
206206 #expect( ToolListChangedNotification . name == " notifications/tools/list_changed " )
207207 }
208+
209+ @Test ( " ListTools handler invocation without params " )
210+ func testListToolsHandlerWithoutParams( ) async throws {
211+ let jsonString = """
212+ { " jsonrpc " : " 2.0 " , " id " :1, " method " : " tools/list " }
213+ """
214+ let jsonData = jsonString. data ( using: . utf8) !
215+
216+ let anyRequest = try JSONDecoder ( ) . decode ( AnyRequest . self, from: jsonData)
217+
218+ let handler = TypedRequestHandler < ListTools > { request in
219+ #expect( request. method == ListTools . name)
220+ #expect( request. id == 1 )
221+ #expect( request. params. cursor == nil )
222+
223+ let testTool = Tool ( name: " test_tool " , description: " Test tool for verification " )
224+ return ListTools . response ( id: request. id, result: ListTools . Result ( tools: [ testTool] ) )
225+ }
226+
227+ let response = try await handler ( anyRequest)
228+
229+ if case . success( let value) = response. result {
230+ let encoder = JSONEncoder ( )
231+ let decoder = JSONDecoder ( )
232+ let data = try encoder. encode ( value)
233+ let result = try decoder. decode ( ListTools . Result. self, from: data)
234+
235+ #expect( result. tools. count == 1 )
236+ #expect( result. tools [ 0 ] . name == " test_tool " )
237+ } else {
238+ #expect( Bool ( false ) , " Expected success result " )
239+ }
240+ }
208241}
0 commit comments