@@ -129,7 +129,7 @@ public struct MCPToolMacro: PeerMacro {
129129
130130 // Extract parameter information
131131 var parameterString = " "
132- var parameterInfos : [ ( name: String , type: String , defaultValue: String ? ) ] = [ ]
132+ var parameterInfos : [ ( name: String , label : String , type: String , defaultValue: String ? ) ] = [ ]
133133
134134 // Extract return type information from the syntax tree
135135 let returnTypeString : String
@@ -143,7 +143,9 @@ public struct MCPToolMacro: PeerMacro {
143143 }
144144
145145 for param in funcDecl. signature. parameterClause. parameters {
146- let paramName = param. firstName. text
146+ // Get the parameter name (secondName) and label (firstName)
147+ let paramName = param. secondName? . text ?? param. firstName. text
148+ let paramLabel = param. firstName. text
147149 let paramType = param. type. description. trimmingCharacters ( in: . whitespacesAndNewlines)
148150
149151 // Store parameter info for wrapper function generation
@@ -225,10 +227,10 @@ public struct MCPToolMacro: PeerMacro {
225227 parameterString += " , "
226228 }
227229
228- parameterString += " MCPToolParameterInfo(name: \" \( paramName) \" , type: \" \( paramType) \" , description: \( paramDescription) , defaultValue: \( defaultValue) ) "
230+ parameterString += " MCPToolParameterInfo(name: \" \( paramName) \" , label: \" \( paramLabel ) \" , type: \" \( paramType) \" , description: \( paramDescription) , defaultValue: \( defaultValue) ) "
229231
230232 // Store parameter info for wrapper function generation
231- parameterInfos. append ( ( name: paramName, type: paramType, defaultValue: defaultValueStr) )
233+ parameterInfos. append ( ( name: paramName, label : paramLabel , type: paramType, defaultValue: defaultValueStr) )
232234 }
233235
234236 // Create a registration statement using string interpolation for simplicity
@@ -256,6 +258,7 @@ public struct MCPToolMacro: PeerMacro {
256258 // Add parameter extraction code
257259 for param in parameterInfos {
258260 let paramName = param. name
261+ let paramLabel = param. label
259262 let paramType = param. type
260263
261264 // If it has a default value, use conditional binding
@@ -322,7 +325,7 @@ public struct MCPToolMacro: PeerMacro {
322325 } else {
323326 actualType = " nil "
324327 }
325- throw MCPToolError.invalidArgumentType(parameterName: " \( paramName) " , expectedType: " \( paramType) " , actualType: actualType)
328+ throw MCPToolError.invalidArgumentType(parameterName: " \( paramLabel ) \( paramName) " , expectedType: " \( paramType) " , actualType: actualType)
326329 }
327330 """
328331 } else if param. type == " Int " {
@@ -343,7 +346,7 @@ public struct MCPToolMacro: PeerMacro {
343346 } else {
344347 actualType = " nil "
345348 }
346- throw MCPToolError.invalidArgumentType(parameterName: " \( paramName) " , expectedType: " \( paramType) " , actualType: actualType)
349+ throw MCPToolError.invalidArgumentType(parameterName: " \( paramLabel ) \( paramName) " , expectedType: " \( paramType) " , actualType: actualType)
347350 }
348351 """
349352 } else {
@@ -357,15 +360,15 @@ public struct MCPToolMacro: PeerMacro {
357360 } else {
358361 actualType = " nil "
359362 }
360- throw MCPToolError.invalidArgumentType(parameterName: " \( paramName) " , expectedType: " \( paramType) " , actualType: actualType)
363+ throw MCPToolError.invalidArgumentType(parameterName: " \( paramLabel ) \( paramName) " , expectedType: " \( paramType) " , actualType: actualType)
361364 }
362365 """
363366 }
364367 }
365368 }
366369
367370 // Add the function call
368- let parameterList = parameterInfos. map { " \( $0. name ) : \( $0. name) " } . joined ( separator: " , " )
371+ let parameterList = parameterInfos. map { " \( $0. label ) : \( $0. name) " } . joined ( separator: " , " )
369372 let isThrowing = funcDecl. signature. effectSpecifiers? . throwsClause? . throwsSpecifier != nil
370373 let isAsync = funcDecl. signature. effectSpecifiers? . asyncSpecifier != nil
371374
0 commit comments