Skip to content

Commit 093002d

Browse files
Update admin.js as per issue #352 (#487)
* Update admin.js as per issue #352 Signed-off-by: Shoumi <[email protected]> * Ran npx prettier mcpgateway/static/admin.js --write Signed-off-by: Mihai Criveti <[email protected]> --------- Signed-off-by: Shoumi <[email protected]> Signed-off-by: Mihai Criveti <[email protected]> Co-authored-by: Mihai Criveti <[email protected]>
1 parent 777a2b2 commit 093002d

File tree

1 file changed

+48
-13
lines changed

1 file changed

+48
-13
lines changed

mcpgateway/static/admin.js

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,24 @@ function validateInputName(name, type = "input") {
9191
return { valid: true, value: cleaned };
9292
}
9393

94+
/**
95+
* Extracts content from various formats with fallback
96+
*/
97+
function extractContent(content, fallback = "") {
98+
if (typeof content === "object" && content !== null) {
99+
if (content.text !== undefined && content.text !== null) {
100+
return content.text;
101+
} else if (content.blob !== undefined && content.blob !== null) {
102+
return content.blob;
103+
} else if (content.content !== undefined && content.content !== null) {
104+
return content.content;
105+
} else {
106+
return JSON.stringify(content, null, 2);
107+
}
108+
}
109+
return String(content || fallback);
110+
}
111+
94112
/**
95113
* SECURITY: Validate URL inputs
96114
*/
@@ -1527,10 +1545,18 @@ async function viewResource(resourceUri) {
15271545
const contentPre = document.createElement("pre");
15281546
contentPre.className =
15291547
"mt-1 bg-gray-100 p-2 rounded overflow-auto max-h-80 dark:bg-gray-800 dark:text-gray-100";
1530-
contentPre.textContent =
1531-
typeof content === "object"
1532-
? JSON.stringify(content, null, 2)
1533-
: String(content); // Safe text content
1548+
1549+
// Handle content display - extract actual content from object if needed
1550+
let contentStr = extractContent(
1551+
content,
1552+
resource.description || "No content available",
1553+
);
1554+
1555+
if (!contentStr.trim()) {
1556+
contentStr = resource.description || "No content available";
1557+
}
1558+
1559+
contentPre.textContent = contentStr;
15341560
contentDiv.appendChild(contentPre);
15351561
container.appendChild(contentDiv);
15361562

@@ -1621,7 +1647,6 @@ async function editResource(resourceUri) {
16211647
const data = await response.json();
16221648
const resource = data.resource;
16231649
const content = data.content;
1624-
16251650
const isInactiveCheckedBool = isInactiveChecked("resources");
16261651
let hiddenField = safeGetElement("edit-resource-show-inactive");
16271652
if (!hiddenField) {
@@ -1665,19 +1690,29 @@ async function editResource(resourceUri) {
16651690
mimeField.value = resource.mimeType || "";
16661691
}
16671692
if (contentField) {
1668-
const contentStr =
1669-
typeof content === "object"
1670-
? JSON.stringify(content, null, 2)
1671-
: String(content);
1693+
let contentStr = extractContent(
1694+
content,
1695+
resource.description || "No content available",
1696+
);
1697+
1698+
if (!contentStr.trim()) {
1699+
contentStr = resource.description || "No content available";
1700+
}
1701+
16721702
contentField.value = contentStr;
16731703
}
16741704

16751705
// Update CodeMirror editor if it exists
16761706
if (window.editResourceContentEditor) {
1677-
const contentStr =
1678-
typeof content === "object"
1679-
? JSON.stringify(content, null, 2)
1680-
: String(content);
1707+
let contentStr = extractContent(
1708+
content,
1709+
resource.description || "No content available",
1710+
);
1711+
1712+
if (!contentStr.trim()) {
1713+
contentStr = resource.description || "No content available";
1714+
}
1715+
16811716
window.editResourceContentEditor.setValue(contentStr);
16821717
window.editResourceContentEditor.refresh();
16831718
}

0 commit comments

Comments
 (0)