@@ -493,23 +493,42 @@ async def invoke_tool(self, db: Session, name: str, arguments: Dict[str, Any]) -
493
493
headers .update (credentials )
494
494
495
495
# Build the payload based on integration type.
496
- payload = arguments
496
+ payload = arguments .copy ()
497
+
498
+ # Handle URL path parameter substitution
499
+ final_url = tool .url
500
+ if '{' in tool .url and '}' in tool .url :
501
+ # Extract path parameters from URL template and arguments
502
+ import re
503
+ url_params = re .findall (r'\{(\w+)\}' , tool .url )
504
+ url_substitutions = {}
505
+
506
+ for param in url_params :
507
+ if param in payload :
508
+ url_substitutions [param ] = payload .pop (param ) # Remove from payload
509
+ final_url = final_url .replace (f'{{{ param } }}' , str (url_substitutions [param ]))
510
+ else :
511
+ raise ToolInvocationError (f"Required URL parameter '{ param } ' not found in arguments" )
497
512
498
513
# Use the tool's request_type rather than defaulting to POST.
499
514
method = tool .request_type .upper ()
500
515
if method == "GET" :
501
- response = await self ._http_client .get (tool . url , params = payload , headers = headers )
516
+ response = await self ._http_client .get (final_url , params = payload , headers = headers )
502
517
else :
503
- response = await self ._http_client .request (method , tool . url , json = payload , headers = headers )
518
+ response = await self ._http_client .request (method , final_url , json = payload , headers = headers )
504
519
response .raise_for_status ()
505
- result = response .json ()
506
-
507
- if response .status_code not in [200 , 201 , 202 , 204 , 206 ]:
520
+
521
+ # Handle 204 No Content responses that have no body
522
+ if response .status_code == 204 :
523
+ tool_result = ToolResult (content = [TextContent (type = "text" , text = "Request completed successfully (No Content)" )])
524
+ elif response .status_code not in [200 , 201 , 202 , 206 ]:
525
+ result = response .json ()
508
526
tool_result = ToolResult (
509
527
content = [TextContent (type = "text" , text = str (result ["error" ]) if "error" in result else "Tool error encountered" )],
510
528
is_error = True ,
511
529
)
512
530
else :
531
+ result = response .json ()
513
532
filtered_response = extract_using_jq (result , tool .jsonpath_filter )
514
533
tool_result = ToolResult (content = [TextContent (type = "text" , text = json .dumps (filtered_response , indent = 2 ))])
515
534
0 commit comments