@@ -14,14 +14,12 @@ import SwiftMCP
1414func testEnrichArguments( ) throws {
1515 let calculator = Calculator ( )
1616
17- // Get the add tool from the calculator
18- guard let tool = calculator. mcpTools. first ( where: { $0. name == " add " } ) else {
19- throw TestError ( " Could not find add tool " )
20- }
17+ // Get the add tool metadata from the calculator
18+ let metadata = unwrap ( calculator. mcpToolMetadata ( for: " add " ) )
2119
2220 // Test enriching arguments
2321 let arguments : [ String : Sendable ] = [ " a " : 2 , " b " : 3 ]
24- let enrichedArguments = try tool . enrichArguments ( arguments, forObject : calculator as Any )
22+ let enrichedArguments = try metadata . enrichArguments ( arguments)
2523
2624 // Check that the arguments were not changed
2725 #expect( enrichedArguments. count == 2 )
@@ -33,14 +31,12 @@ func testEnrichArguments() throws {
3331func testEnrichArgumentsWithExplicitFunctionName( ) throws {
3432 let calculator = Calculator ( )
3533
36- // Get the add tool from the calculator
37- guard let tool = calculator. mcpTools. first ( where: { $0. name == " add " } ) else {
38- throw TestError ( " Could not find add tool " )
39- }
34+ // Get the add tool metadata from the calculator
35+ let metadata = unwrap ( calculator. mcpToolMetadata ( for: " add " ) )
4036
4137 // Test enriching arguments with explicit function name
4238 let arguments : [ String : Sendable ] = [ " a " : 2 , " b " : 3 ]
43- let enrichedArguments = try tool . enrichArguments ( arguments, forObject : calculator as Any )
39+ let enrichedArguments = try metadata . enrichArguments ( arguments)
4440
4541 // Check that the arguments were not changed
4642 #expect( enrichedArguments. count == 2 )
@@ -52,14 +48,12 @@ func testEnrichArgumentsWithExplicitFunctionName() throws {
5248func testEnrichArgumentsWithNoDefaults( ) throws {
5349 let calculator = Calculator ( )
5450
55- // Get a tool from the calculator
56- guard let tool = calculator. mcpTools. first ( where: { $0. name == " add " } ) else {
57- throw TestError ( " Could not find add tool " )
58- }
51+ // Get the add tool metadata from the calculator
52+ let metadata = unwrap ( calculator. mcpToolMetadata ( for: " add " ) )
5953
6054 // Test enriching arguments with no default values
6155 let arguments : [ String : Sendable ] = [ " a " : 2 , " b " : 3 ]
62- let enrichedArguments = try tool . enrichArguments ( arguments, forObject : calculator as Any )
56+ let enrichedArguments = try metadata . enrichArguments ( arguments)
6357
6458 // Check that the arguments were not changed
6559 #expect( enrichedArguments. count == 2 )
@@ -71,29 +65,25 @@ func testEnrichArgumentsWithNoDefaults() throws {
7165func testEnrichArgumentsWithMissingRequiredArgument( ) throws {
7266 let calculator = Calculator ( )
7367
74- // Get a tool from the calculator
75- guard let tool = calculator. mcpTools. first ( where: { $0. name == " add " } ) else {
76- throw TestError ( " Could not find add tool " )
77- }
68+ // Get the add tool metadata from the calculator
69+ let metadata = unwrap ( calculator. mcpToolMetadata ( for: " add " ) )
7870
7971 // Test enriching arguments with a missing required argument
8072 #expect( throws: MCPToolError . self, " Should notice missing parameter " ) {
81- try tool . enrichArguments ( [ " a " : 2 ] , forObject : calculator )
73+ try metadata . enrichArguments ( [ " a " : 2 ] )
8274 }
8375}
8476
8577@Test
8678func testEnrichArgumentsWithTypeConversion( ) throws {
8779 let calculator = Calculator ( )
8880
89- // Get a tool from the calculator
90- guard let tool = calculator. mcpTools. first ( where: { $0. name == " add " } ) else {
91- throw TestError ( " Could not find add tool " )
92- }
81+ // Get the add tool metadata from the calculator
82+ let metadata = unwrap ( calculator. mcpToolMetadata ( for: " add " ) )
9383
9484 // Test enriching arguments with string values that need to be converted
9585 let arguments : [ String : Sendable ] = [ " a " : " 2 " , " b " : " 3 " ]
96- let enrichedArguments = try tool . enrichArguments ( arguments, forObject : calculator as Any )
86+ let enrichedArguments = try metadata . enrichArguments ( arguments)
9787
9888 // Check that the arguments were not changed (enrichArguments doesn't do type conversion)
9989 #expect( enrichedArguments. count == 2 )
@@ -105,23 +95,21 @@ func testEnrichArgumentsWithTypeConversion() throws {
10595func testSubtractArguments( ) throws {
10696 let calculator = Calculator ( )
10797
108- // Get a tool from the calculator
109- guard let tool = calculator. mcpTools. first ( where: { $0. name == " subtract " } ) else {
110- throw TestError ( " Could not find subtract tool " )
111- }
98+ // Get the subtract tool metadata from the calculator
99+ let metadata = unwrap ( calculator. mcpToolMetadata ( for: " subtract " ) )
112100
113101 // Test with no arguments - should throw missing required parameter
114102 #expect( throws: MCPToolError . self, " Should notice missing parameter " ) {
115- try tool . enrichArguments ( [ : ] , forObject : calculator )
103+ try metadata . enrichArguments ( [ : ] )
116104 }
117105
118106 // Test with partial arguments - should throw missing required parameter
119107 #expect( throws: MCPToolError . self, " Should notice missing parameter " ) {
120- try tool . enrichArguments ( [ " b " : 5 ] , forObject : calculator )
108+ try metadata . enrichArguments ( [ " b " : 5 ] )
121109 }
122110
123111 // Test with all arguments - no defaults should be added
124- let allArgs = try tool . enrichArguments ( [ " a " : 20 , " b " : 5 ] , forObject : calculator )
112+ let allArgs = try metadata . enrichArguments ( [ " a " : 20 , " b " : 5 ] )
125113 #expect( allArgs. count == 2 )
126114 #expect( allArgs [ " a " ] as? Int == 20 )
127115 #expect( allArgs [ " b " ] as? Int == 5 )
@@ -131,23 +119,21 @@ func testSubtractArguments() throws {
131119func testMultiplyArguments( ) throws {
132120 let calculator = Calculator ( )
133121
134- // Get a tool from the calculator
135- guard let tool = calculator. mcpTools. first ( where: { $0. name == " multiply " } ) else {
136- throw TestError ( " Could not find multiply tool " )
137- }
122+ // Get the multiply tool metadata from the calculator
123+ let metadata = unwrap ( calculator. mcpToolMetadata ( for: " multiply " ) )
138124
139125 // Test with no arguments - should throw missing required parameter
140126 #expect( throws: MCPToolError . self, " Should notice missing parameter " ) {
141- try tool . enrichArguments ( [ : ] , forObject : calculator )
127+ try metadata . enrichArguments ( [ : ] )
142128 }
143129
144130 // Test with partial arguments - should throw missing required parameter
145131 #expect( throws: MCPToolError . self, " Should notice missing parameter " ) {
146- try tool . enrichArguments ( [ " b " : 5 ] , forObject : calculator )
132+ try metadata . enrichArguments ( [ " b " : 5 ] )
147133 }
148134
149135 // Test with all arguments - no defaults should be added
150- let allArgs = try tool . enrichArguments ( [ " a " : 20 , " b " : 5 ] , forObject : calculator )
136+ let allArgs = try metadata . enrichArguments ( [ " a " : 20 , " b " : 5 ] )
151137 #expect( allArgs. count == 2 )
152138 #expect( allArgs [ " a " ] as? Int == 20 )
153139 #expect( allArgs [ " b " ] as? Int == 5 )
0 commit comments