@@ -125,18 +125,17 @@ object McpToolHelper {
125125 path : String ,
126126 components : Map <String , Schema <* >>?
127127 ): McpTool {
128- val name = operation.operationId ? : " ${httpMethod} _$path "
128+ val name = sanitizeToolName( operation.operationId ? : " ${httpMethod} _$path " )
129129 val description = operation.description ? : (operation.summary ? : " " )
130130 val (parameters, requiredParams) = operationParameters(operation, components)
131131 val requestBody = operationRequestBody(operation, components)
132132 val responseBody = operationResponseBody(operation, components)
133133 val toolAnnotations = if (httpMethod == " GET" )
134134 ToolAnnotations (
135- operation.operationId ,
135+ name ,
136136 readOnlyHint = true ,
137137 destructiveHint = false ,
138- openWorldHint = false
139- ) else ToolAnnotations (operation.operationId, openWorldHint = false )
138+ ) else ToolAnnotations (name)
140139 val toolInput =
141140 if (parameters?.isNotEmpty() == true && requestBody?.isNotEmpty() == true ) {
142141 Tool .Input (
@@ -166,14 +165,27 @@ object McpToolHelper {
166165 Tool .Input ()
167166 }
168167 val tool = Tool (
169- name, description, toolInput, responseBody?.let { Tool .Output (it) }, toolAnnotations
168+ name,
169+ name,
170+ description,
171+ toolInput,
172+ responseBody?.let { Tool .Output (it) },
173+ toolAnnotations
170174 )
171175 val urlTemplate = serverUrl.removeSuffix(" /" ) + " /" + path.removePrefix(" /" )
172176 return McpTool (tool) { request ->
173177 callApi(urlTemplate, httpMethod, request)
174178 }
175179 }
176180
181+ private fun sanitizeToolName (input : String ): String {
182+ return input
183+ .replace(Regex (" [^A-Za-z0-9]" ), " _" )
184+ .replace(Regex (" _+" ), " _" )
185+ .trim(' _' )
186+ }
187+
188+
177189 private suspend fun callApi (
178190 urlTemplate : String ,
179191 httpMethod : String ,
0 commit comments