Skip to main content
Glama
get-pending-approvals.tsโ€ข2.54 kB
import { ApprovalService } from '../services/approval.js'; export function getPendingApprovalsTool( approvalService: ApprovalService, args: Record<string, unknown> ) { const { duck } = args as { duck?: string; }; try { let approvals = approvalService.getPendingApprovals(); // Filter by duck if specified if (duck) { approvals = approvals.filter(approval => approval.duckName === duck); } if (approvals.length === 0) { return { content: [ { type: 'text', text: 'โœ… No pending MCP tool approvals', }, ], }; } // Format approvals for display const formattedApprovals = approvals.map(approval => { const timeAgo = Math.round((Date.now() - approval.timestamp) / 1000); const expiresIn = Math.round((approval.expiresAt - Date.now()) / 1000); return { id: approval.id, duck: approval.duckName, server: approval.mcpServer, tool: approval.toolName, arguments: approval.arguments, requestedAgo: `${timeAgo}s ago`, expiresIn: expiresIn > 0 ? `${expiresIn}s` : 'expired', }; }); // Create summary text const summaryLines = [ `๐Ÿ”” ${approvals.length} pending MCP approval${approvals.length === 1 ? '' : 's'}:`, '', ]; formattedApprovals.forEach((approval, index) => { summaryLines.push(`${index + 1}. **${approval.duck}** wants to call \`${approval.server}:${approval.tool}\``); summaryLines.push(` ID: \`${approval.id}\``); // Show arguments if they exist and are reasonably sized const argsStr = JSON.stringify(approval.arguments); if (argsStr.length < 100) { summaryLines.push(` Args: \`${argsStr}\``); } else { summaryLines.push(` Args: [${Object.keys(approval.arguments).length} parameters]`); } summaryLines.push(` Requested: ${approval.requestedAgo}, Expires: ${approval.expiresIn}`); summaryLines.push(''); }); summaryLines.push('๐Ÿ’ก Use `approve_mcp_request` to approve or deny requests'); return { content: [ { type: 'text', text: summaryLines.join('\n'), }, ], }; } catch (error: unknown) { return { content: [ { type: 'text', text: `โŒ Failed to get pending approvals: ${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