Skip to content

Commit fd7ea14

Browse files
Nuno Miguel AguiarNuno Miguel Aguiar
authored andcommitted
feat(mcp): add function to show MCP server information
1 parent b773a63 commit fd7ea14

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

mini-a-mcptest.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,37 @@ function listMCPTools(mcpClient, showElapsed) {
106106
}
107107
}
108108

109+
// Show MCP server info
110+
function showMCPServerInfo(mcpClient, showElapsed) {
111+
try {
112+
var startTime = now()
113+
var toolsResult = mcpClient.listTools()
114+
if (showElapsed) {
115+
printElapsedTime(startTime, "Get MCP server info")
116+
}
117+
118+
var serverInfo = __
119+
if (isDef(mcpClient.getInfo)) {
120+
serverInfo = mcpClient.getInfo()
121+
}
122+
123+
print("\n" + ansiColor("BOLD", "🖥️ MCP Server Information:"))
124+
print(ansiColor("FAINT", "──────────────────────────"))
125+
126+
if (isUnDef(serverInfo)) {
127+
print(ansiColor("FAINT", "No server information available from this MCP server."))
128+
} else if (isString(serverInfo)) {
129+
print(serverInfo)
130+
} else {
131+
print(printTree(serverInfo))
132+
}
133+
print()
134+
} catch(e) {
135+
print(ansiColor("ITALIC,FG(196)", "!!") + ansiColor("FG(196)", " Failed to get server info: " + e.message))
136+
print()
137+
}
138+
}
139+
109140
// Show tool details
110141
function showToolDetails(tool) {
111142
print("\n" + ansiColor("BOLD,FG(41)", "Tool: " + tool.name))
@@ -539,6 +570,7 @@ function mainMCPTest(args) {
539570
// Connected
540571
_options = [
541572
"📋 List tools",
573+
"🖥️ Show MCP server info",
542574
"🔧 Call a tool",
543575
"🔍 Show tool details",
544576
"🔌 New connection",
@@ -595,6 +627,12 @@ function mainMCPTest(args) {
595627
} else {
596628
listMCPTools(_mcpClient, sessionOptions.showtimeelapsed)
597629
}
630+
} else if (optionText.indexOf("Show MCP server info") >= 0) {
631+
if (isUnDef(_mcpClient)) {
632+
print(ansiColor("ITALIC," + errorColor, "!!") + colorifyText(" No MCP connection. Please create a new connection first.", errorColor) + "\n")
633+
} else {
634+
showMCPServerInfo(_mcpClient, sessionOptions.showtimeelapsed)
635+
}
598636
} else if (optionText.indexOf("Call a tool") >= 0) {
599637
if (isUnDef(_mcpClient)) {
600638
print(ansiColor("ITALIC," + errorColor, "!!") + colorifyText(" No MCP connection. Please create a new connection first.", errorColor) + "\n")

0 commit comments

Comments
 (0)