Skip to main content
Glama
gcorroto

Asterisk S2S MCP Server

by gcorroto

phone_get_metrics

Retrieve system metrics and statistics for automated phone call operations within the Asterisk S2S MCP Server to monitor and analyze telephony performance.

Instructions

Obtener métricas y estadísticas del sistema telefónico

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • index.ts:98-112 (registration)
    Registers the 'phone_get_metrics' MCP tool with empty input schema and an inline handler that fetches metrics via phoneTools.getCallMetrics() and returns formatted text output.
    server.tool(
      "phone_get_metrics",
      "Obtener métricas y estadísticas del sistema telefónico",
      {},
      async () => {
        const result = await phoneTools.getCallMetrics();
    
        return {
          content: [{ 
            type: "text", 
            text: `📊 **Métricas del Sistema Telefónico**\n\n**Total de llamadas:** ${result.totalCalls}\n**Llamadas exitosas:** ${result.successfulCalls}\n**Llamadas fallidas:** ${result.failedCalls}\n**Tasa de éxito:** ${result.successRate}%\n**Duración promedio:** ${Math.round(result.averageDuration)} segundos\n\n**Top propósitos:**\n${result.topPurposes.map(p => `- ${p.proposito}: ${p.count} llamadas`).join('\n')}`
          }],
        };
      }
    );
  • Core implementation of getCallMetrics(): computes comprehensive phone call metrics from in-memory activeCalls and conversationHistory, including totals, success/failure counts, average duration, daily stats, and top purposes.
    export function getCallMetrics(): CallMetrics {
      const now = new Date();
      const calls = Array.from(activeCalls.values()).concat(
        conversationHistory.map(h => ({
          callId: h.callId,
          status: 'completed' as const,
          lastUpdate: now.toISOString(),
          usuario: '',
          telefono: '',
          proposito: ''
        }))
      );
      
      const totalCalls = calls.length;
      const successfulCalls = calls.filter(c => c.status === 'completed').length;
      const failedCalls = calls.filter(c => c.status === 'failed').length;
      
      const durations = calls.filter(c => c.duration).map(c => c.duration!);
      const averageDuration = durations.length > 0 
        ? durations.reduce((a, b) => a + b, 0) / durations.length 
        : 0;
      
      const callsByStatus = calls.reduce((acc, call) => {
        acc[call.status] = (acc[call.status] || 0) + 1;
        return acc;
      }, {} as Record<CallStatus['status'], number>);
      
      // Stats diarias (últimos 7 días)
      const dailyStats = [];
      for (let i = 6; i >= 0; i--) {
        const date = new Date(now);
        date.setDate(date.getDate() - i);
        const dateStr = date.toISOString().split('T')[0];
        
        const dayCalls = calls.filter(c => 
          c.lastUpdate.startsWith(dateStr)
        );
        
        const dayDurations = dayCalls.filter(c => c.duration).map(c => c.duration!);
        const dayAvgDuration = dayDurations.length > 0 
          ? dayDurations.reduce((a, b) => a + b, 0) / dayDurations.length 
          : 0;
        
        dailyStats.push({
          date: dateStr,
          calls: dayCalls.length,
          successRate: dayCalls.length > 0 
            ? dayCalls.filter(c => c.status === 'completed').length / dayCalls.length * 100 
            : 0,
          averageDuration: dayAvgDuration
        });
      }
      
      // Top propósitos
      const purposeCounts: Record<string, number> = {};
      calls.forEach(call => {
        if (call.proposito) {
          purposeCounts[call.proposito] = (purposeCounts[call.proposito] || 0) + 1;
        }
      });
      
      const topPurposes = Object.entries(purposeCounts)
        .map(([proposito, count]) => ({ proposito, count }))
        .sort((a, b) => b.count - a.count)
        .slice(0, 5);
      
      return {
        totalCalls,
        successfulCalls,
        failedCalls,
        averageDuration,
        callsByStatus,
        dailyStats,
        topPurposes
      };
    }
  • Helper wrapper getCallMetrics() that invokes the operations-level getCallMetrics() and adds successRate calculation to the returned metrics.
    export async function getCallMetrics(): Promise<{
      totalCalls: number;
      successfulCalls: number;
      failedCalls: number;
      averageDuration: number;
      successRate: number;
      dailyStats: Array<{
        date: string;
        calls: number;
        successRate: number;
        averageDuration: number;
      }>;
      topPurposes: Array<{
        proposito: string;
        count: number;
      }>;
    }> {
      const metrics = phoneOps.getCallMetrics();
      
      const successRate = metrics.totalCalls > 0 
        ? (metrics.successfulCalls / metrics.totalCalls) * 100 
        : 0;
    
      return {
        ...metrics,
        successRate: Math.round(successRate * 100) / 100
      };
    }
Install Server

Other Tools

Related Tools

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/gcorroto/mcp-s2s-asterisk'

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