@@ -94,7 +94,9 @@ object McpToolHelper {
9494
9595    fun  toTools (
9696        openAPI :  OpenAPI ,
97-         openAPIOperationFilter :  OpenAPIOperationFilter ?  = null
97+         openAPIOperationFilter :  OpenAPIOperationFilter ?  = null,
98+         queryParams :  Map <String , String >?  = null,
99+         headers :  Map <String , String >?  = null,
98100    ): List <McpTool > {
99101        logger.info(" Create tools with filter {}" 
100102        val  serverUrl =  openAPI.servers.first().url
@@ -114,7 +116,15 @@ object McpToolHelper {
114116            logger.info(" Use {} operations after filtering" 
115117        }
116118        return  operations?.map {
117-             toTool(serverUrl, it.operation, it.httpMethod, it.path, components)
119+             toTool(
120+                 serverUrl,
121+                 it.operation,
122+                 it.httpMethod,
123+                 it.path,
124+                 components,
125+                 queryParams,
126+                 headers
127+             )
118128        } ? :  listOf ()
119129    }
120130
@@ -123,7 +133,9 @@ object McpToolHelper {
123133        operation :  Operation ,
124134        httpMethod :  String ,
125135        path :  String ,
126-         components :  Map <String , Schema <* >>? 
136+         components :  Map <String , Schema <* >>? ,
137+         queryParams :  Map <String , String >?  = null,
138+         headers :  Map <String , String >?  = null,
127139    ): McpTool  {
128140        val  name =  sanitizeToolName(operation.operationId ? :  " ${httpMethod} _$path " 
129141        val  description =  operation.description ? :  (operation.summary ? :  " " 
@@ -174,7 +186,7 @@ object McpToolHelper {
174186        )
175187        val  urlTemplate =  serverUrl.removeSuffix(" /" +  " /" +  path.removePrefix(" /" 
176188        return  McpTool (tool) { request -> 
177-             callApi(urlTemplate, httpMethod, request)
189+             callApi(urlTemplate, httpMethod, request, queryParams, headers )
178190        }
179191    }
180192
@@ -189,20 +201,36 @@ object McpToolHelper {
189201    private  suspend  fun  callApi (
190202        urlTemplate :  String ,
191203        httpMethod :  String ,
192-         request :  CallToolRequest 
204+         request :  CallToolRequest ,
205+         queryParams :  Map <String , String >?  = null,
206+         extraHeaders :  Map <String , String >?  = null,
193207    ): CallToolResult  {
194208        return  httpClient.request {
195-             url(
196-                 parseUrl(expandUriTemplate(urlTemplate, request.arguments))
197-                     ? :  throw  RuntimeException (" Invalid url" 
198-             )
209+             url {
210+                 takeFrom(
211+                     parseUrl(expandUriTemplate(urlTemplate, request.arguments))
212+                         ? :  throw  RuntimeException (" Invalid url" 
213+                 )
214+                 queryParams?.let  { params -> 
215+                     params.forEach { (k, v) -> 
216+                         parameters.append(k, v)
217+                     }
218+                 }
219+             }
199220            method =  when  (httpMethod) {
200221                " PUT" ->  HttpMethod .Put 
201222                " POST" ->  HttpMethod .Post 
202223                " PATCH" ->  HttpMethod .Patch 
203224                " DELETE" ->  HttpMethod .Delete 
204225                else  ->  HttpMethod .Get 
205226            }
227+             extraHeaders?.let  {
228+                 it.forEach { (k, v) -> 
229+                     headers.append(k, v)
230+                 }
231+             }
232+             contentType(ContentType .Application .Json )
233+             setBody(request.arguments)
206234        }.bodyAsText().let  { text -> 
207235            CallToolResult (listOf (TextContent (text)))
208236        }
0 commit comments