Skip to main content
Glama
mcp-status.tsโ€ข4.18 kB
import { MCPClientManager } from '../services/mcp-client-manager.js'; import { ApprovalService } from '../services/approval.js'; import { FunctionBridge } from '../services/function-bridge.js'; export async function mcpStatusTool( mcpManager: MCPClientManager, approvalService: ApprovalService, functionBridge: FunctionBridge, _args: Record<string, unknown> ) { try { // Get MCP server status const serverStatus = mcpManager.getStatus(); const connectedServers = mcpManager.getConnectedServers(); // Get available tools const allTools = await mcpManager.listAllTools(); const toolsByServer = allTools.reduce((acc, tool) => { if (!acc[tool.serverName]) { acc[tool.serverName] = []; } acc[tool.serverName].push(tool); return acc; }, {} as Record<string, Array<{name: string; serverName: string}>>); // Get approval statistics const approvalStats = approvalService.getStats(); // Get function bridge statistics const bridgeStats = functionBridge.getStats(); // Build status report const statusLines = [ '๐Ÿฆ† **MCP Bridge Status**', '', '๐Ÿ“Š **Overview:**', `- Connected Servers: ${connectedServers.length}`, `- Available Tools: ${allTools.length}`, `- Trusted Tools: ${bridgeStats.trustedToolCount}`, '', ]; // Server details if (Object.keys(serverStatus).length > 0) { statusLines.push('๐Ÿ–ฅ๏ธ **MCP Servers:**'); for (const [serverName, status] of Object.entries(serverStatus)) { const toolCount = toolsByServer[serverName]?.length || 0; const statusIcon = status.status === 'connected' ? '๐ŸŸข' : status.status === 'connecting' ? '๐ŸŸก' : '๐Ÿ”ด'; statusLines.push(`${statusIcon} **${serverName}** (${status.type})`); statusLines.push(` Status: ${status.status}`); if (toolCount > 0) { statusLines.push(` Tools: ${toolCount}`); // Show first few tools as examples const tools = toolsByServer[serverName]; if (tools && tools.length <= 3) { statusLines.push(` Available: ${tools.map(t => t.name).join(', ')}`); } else if (tools && tools.length > 3) { statusLines.push(` Available: ${tools.slice(0, 3).map(t => t.name).join(', ')} +${tools.length - 3} more`); } } statusLines.push(''); } } else { statusLines.push('๐Ÿ–ฅ๏ธ **No MCP servers configured**'); statusLines.push(''); } // Approval statistics statusLines.push('๐Ÿ“‹ **Approval Statistics:**'); statusLines.push(`- Total Requests: ${approvalStats.total}`); statusLines.push(`- Pending: ${approvalStats.pending}`); statusLines.push(`- Approved: ${approvalStats.approved}`); statusLines.push(`- Denied: ${approvalStats.denied}`); statusLines.push(`- Expired: ${approvalStats.expired}`); // Show pending approvals if any if (approvalStats.pending > 0) { const pendingApprovals = approvalService.getPendingApprovals(); statusLines.push(''); statusLines.push('โณ **Pending Approvals:**'); pendingApprovals.forEach(approval => { const timeAgo = Math.round((Date.now() - approval.timestamp) / 1000); statusLines.push(`- ${approval.duckName} โ†’ ${approval.mcpServer}:${approval.toolName} (${timeAgo}s ago)`); }); } // Configuration hints statusLines.push(''); statusLines.push('๐Ÿ’ก **Commands:**'); statusLines.push('- `get_pending_approvals` - View pending approval requests'); statusLines.push('- `approve_mcp_request` - Approve or deny requests'); statusLines.push('- `ask_duck` - Chat with ducks (MCP functions auto-enabled)'); return { content: [ { type: 'text', text: statusLines.join('\n'), }, ], }; } catch (error: unknown) { return { content: [ { type: 'text', text: `โŒ Failed to get MCP status: ${error instanceof Error ? error.message : String(error)}`, }, ], isError: true, }; } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/nesquikm/mcp-rubber-duck'

If you have feedback or need assistance with the MCP directory API, please join our Discord server