Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions mcpgateway/static/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -1991,16 +1991,22 @@ async function editTool(toolId) {
window.editToolSchemaEditor.refresh();
}

// Trigger change event for integration type
// Prefill integration type from DB and set request types accordingly
if (typeField) {
const event = new Event("change");
typeField.dispatchEvent(event);
typeField.value = tool.integrationType || "REST";
updateEditToolRequestTypes(tool.requestType || null); // preselect from DB
}

// Set Request Type field
// Request Type field handling (disable for MCP)
const requestTypeField = safeGetElement("edit-tool-request-type");
if (requestTypeField) {
requestTypeField.value = tool.requestType || "SSE";
if ((tool.integrationType || "REST") === "MCP") {
requestTypeField.value = "";
requestTypeField.disabled = true; // disabled -> not submitted
} else {
requestTypeField.disabled = false;
requestTypeField.value = tool.requestType || ""; // keep DB verb or blank
}
}

// Set auth type field
Expand Down Expand Up @@ -3560,6 +3566,7 @@ function createParameterForm(parameterCount) {

const integrationRequestMap = {
REST: ["GET", "POST", "PUT", "PATCH", "DELETE"],
MCP: [],
};

function updateRequestTypeOptions(preselectedValue = null) {
Expand Down Expand Up @@ -3593,26 +3600,31 @@ function updateRequestTypeOptions(preselectedValue = null) {
function updateEditToolRequestTypes(selectedMethod = null) {
const editToolTypeSelect = safeGetElement("edit-tool-type");
const editToolRequestTypeSelect = safeGetElement("edit-tool-request-type");

if (!editToolTypeSelect || !editToolRequestTypeSelect) {
return;
}

const selectedType = editToolTypeSelect.value;
const allowedMethods = integrationRequestMap[selectedType] || [];

// Clear existing options
editToolRequestTypeSelect.innerHTML = "";
// If this integration has no HTTP verbs (MCP), clear & disable the control
if (allowedMethods.length === 0) {
editToolRequestTypeSelect.innerHTML = "";
editToolRequestTypeSelect.value = "";
editToolRequestTypeSelect.disabled = true;
return;
}

// Populate new options
// Otherwise populate and enable
editToolRequestTypeSelect.disabled = false;
editToolRequestTypeSelect.innerHTML = "";
allowedMethods.forEach((method) => {
const option = document.createElement("option");
option.value = method;
option.textContent = method;
editToolRequestTypeSelect.appendChild(option);
});

// Set the pre-selected method, if valid
if (selectedMethod && allowedMethods.includes(selectedMethod)) {
editToolRequestTypeSelect.value = selectedMethod;
}
Expand Down Expand Up @@ -6287,8 +6299,6 @@ function setupIntegrationTypeHandlers() {

const editToolTypeSelect = safeGetElement("edit-tool-type");
if (editToolTypeSelect) {
editToolTypeSelect.value = "REST";
updateEditToolRequestTypes("PUT");
editToolTypeSelect.addEventListener("change", () =>
updateEditToolRequestTypes(),
);
Expand Down
114 changes: 90 additions & 24 deletions mcpgateway/templates/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -963,18 +963,39 @@ <h3 class="text-lg font-bold mb-4 dark:text-gray-200">
</h3>
<form id="add-tool-form">
<div class="grid grid-cols-1 gap-6">
<div>
<label
class="block text-sm font-medium text-gray-700 dark:text-gray-400"
>Name</label
>
<input
type="text"
name="name"
required
class="mt-1 block w-full rounded-md border border-gray-300 dark:border-gray-700 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-900 dark:placeholder-gray-300 dark:text-gray-300"
/>
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div>
<label class="block text-sm font-medium text-gray-700 dark:text-gray-400">
Gateway Name
</label>
<input
type="text"
name="gateway_name"
id="add-tool-gateway-name"
placeholder="e.g., local-gateway"
class="mt-1 block w-full rounded-md border border-gray-300 dark:border-gray-700 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-900 dark:placeholder-gray-300 dark:text-gray-300"
/>
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400">
Optional for REST tools; populated for MCP-imported tools.
</p>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 dark:text-gray-400">
Original Name
</label>
<input
type="text"
name="original_name"
id="add-tool-original-name"
placeholder="e.g., list-files"
class="mt-1 block w-full rounded-md border border-gray-300 dark:border-gray-700 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-900 dark:placeholder-gray-300 dark:text-gray-300"
/>
<p class="mt-1 text-xs text-gray-500 dark:text-gray-400">
Tool's name as provided by the gateway.
</p>
</div>
</div>

<div>
<label
class="block text-sm font-medium text-gray-700 dark:text-gray-400"
Expand Down Expand Up @@ -2635,19 +2656,32 @@ <h3 class="text-lg font-medium text-gray-900 dark:text-gray-100">
<div class="mt-4">
<form id="edit-tool-form" method="POST">
<div class="grid grid-cols-1 gap-6">
<div>
<label
class="block text-sm font-medium text-gray-700 dark:text-gray-300"
>Name</label
>
<input
type="text"
name="name"
required
id="edit-tool-name"
class="mt-1 block w-full rounded-md border border-gray-300 dark:border-gray-600 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-900 dark:placeholder-gray-300 dark:text-gray-300"
/>

<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300">
Gateway Name
</label>
<input
type="text"
name="gateway_name"
id="edit-tool-gateway-name"
class="mt-1 block w-full rounded-md border border-gray-300 dark:border-gray-600 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-900 dark:placeholder-gray-300 dark:text-gray-300"
/>
</div>
<div>
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300">
Original Name
</label>
<input
type="text"
name="original_name"
id="edit-tool-original-name"
class="mt-1 block w-full rounded-md border border-gray-300 dark:border-gray-600 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-900 dark:placeholder-gray-300 dark:text-gray-300"
/>
</div>
</div>

<div>
<label
class="block text-sm font-medium text-gray-700 dark:text-gray-300"
Expand Down Expand Up @@ -2681,9 +2715,11 @@ <h3 class="text-lg font-medium text-gray-900 dark:text-gray-100">
name="integrationType"
id="edit-tool-type"
class="mt-1 block w-full rounded-md border border-gray-300 dark:border-gray-600 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-900 dark:placeholder-gray-300 dark:text-gray-300"
onchange="handleEditIntegrationTypeChange()"
>

<option value="REST">REST</option>
<option value="MCP">MCP</option>
</select>
</div>
<div>
Expand All @@ -2696,7 +2732,7 @@ <h3 class="text-lg font-medium text-gray-900 dark:text-gray-100">
id="edit-tool-request-type"
class="mt-1 block w-full rounded-md border border-gray-300 dark:border-gray-600 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 dark:bg-gray-900 dark:placeholder-gray-300 dark:text-gray-300"
>
<!-- Will be populated dynamically -->

</select>
</div>
<div>
Expand Down Expand Up @@ -3846,5 +3882,35 @@ <h3 class="text-lg font-medium text-gray-900 dark:text-gray-100">
});
});
</script>
<script>
function handleEditIntegrationTypeChange() {
const typeSel = document.getElementById('edit-tool-type');
const reqSel = document.getElementById('edit-tool-request-type');
if (!typeSel || !reqSel) return;

const isREST = typeSel.value === 'REST';
// For REST tools, enable HTTP verbs; for MCP, disable & clear to avoid bad values.
reqSel.disabled = !isREST;
if (!isREST) {
reqSel.value = '';
}
}

// When the Edit modal is shown, re-evaluate enable/disable based on prefilled value.
(function () {
const modal = document.getElementById('tool-edit-modal');
if (!modal) return;

const observer = new MutationObserver(() => {
const isOpen = !modal.classList.contains('hidden');
if (isOpen) {
// Defer one tick so existing JS can prefill values first.
setTimeout(handleEditIntegrationTypeChange, 0);
}
});
observer.observe(modal, { attributes: true, attributeFilter: ['class'] });
})();
</script>

</body>
</html>
Loading