Skip to content

Commit bd425df

Browse files
authored
Merge pull request #121 from thongnbui/thong/id_patch
(1) Allow id in API /a/b/c/{id} (2) Allow PATCH for REST and handle 204
2 parents 026e368 + 29145df commit bd425df

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

mcpgateway/services/tool_service.py

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -493,23 +493,42 @@ async def invoke_tool(self, db: Session, name: str, arguments: Dict[str, Any]) -
493493
headers.update(credentials)
494494

495495
# 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")
497512

498513
# Use the tool's request_type rather than defaulting to POST.
499514
method = tool.request_type.upper()
500515
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)
502517
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)
504519
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()
508526
tool_result = ToolResult(
509527
content=[TextContent(type="text", text=str(result["error"]) if "error" in result else "Tool error encountered")],
510528
is_error=True,
511529
)
512530
else:
531+
result = response.json()
513532
filtered_response = extract_using_jq(result, tool.jsonpath_filter)
514533
tool_result = ToolResult(content=[TextContent(type="text", text=json.dumps(filtered_response, indent=2))])
515534

mcpgateway/static/admin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ document.addEventListener("DOMContentLoaded", function () {
319319

320320
const requestTypeMap = {
321321
MCP: ["SSE", "STDIO"],
322-
REST: ["GET", "POST", "PUT", "DELETE"],
322+
REST: ["GET", "POST", "PUT", "PATCH", "DELETE"],
323323
};
324324

325325

@@ -1754,7 +1754,7 @@ function closeModal(modalId, clearId=null) {
17541754

17551755
const integrationRequestMap = {
17561756
MCP: ["SSE", "STDIO"],
1757-
REST: ["GET", "POST", "PUT", "DELETE"],
1757+
REST: ["GET", "POST", "PUT", "PATCH", "DELETE"],
17581758
};
17591759

17601760
function updateRequestTypeOptions(preselectedValue = null) {

0 commit comments

Comments
 (0)