Skip to main content
Glama

get_metrics

Retrieve server performance metrics to monitor system health and optimize resource allocation for memory management operations.

Instructions

獲取服務器性能指標

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Handler function for the 'get_metrics' MCP tool. It executes the tool logic by calling globalMetrics.getMetrics() to retrieve comprehensive server performance metrics.
    async handler() {
      return globalMetrics.getMetrics();
    }
  • src/index.js:186-194 (registration)
    Registration of the 'get_metrics' tool in the tool registry. Includes name, description, empty input schema (no parameters), system scope, and inline handler.
    registerTool({
      name: 'get_metrics',
      description: '獲取服務器性能指標',
      inputSchema: z.object({}),
      scope: 'system',
      async handler() {
        return globalMetrics.getMetrics();
      }
    }, 'system');
  • Zod input schema for the 'get_metrics' tool: empty object schema indicating no input parameters are required.
    inputSchema: z.object({}),
  • Core implementation of getMetrics() method in MetricsCollector class. Computes and returns detailed performance metrics: uptime, request counts/error rates, latency percentiles (p50/p95/p99), cache statistics, memory usage, and tool-specific stats.
    getMetrics() {
      const now = Date.now();
      const uptime = now - this.startTime;
      const uptimeSeconds = Math.floor(uptime / 1000);
    
      // 計算請求率
      const requestsPerSecond = this.requestCount / (uptimeSeconds || 1);
    
      // 計算錯誤率
      const errorRate = this.requestCount > 0
        ? (this.errorCount / this.requestCount * 100).toFixed(2)
        : 0;
    
      // 計算持續時間統計
      const avgDuration = this.durations.length > 0
        ? this.durations.reduce((sum, d) => sum + d, 0) / this.durations.length
        : 0;
    
      // 計算緩存命中率
      const totalCacheAccess = this.cacheHits + this.cacheMisses;
      const cacheHitRate = totalCacheAccess > 0
        ? (this.cacheHits / totalCacheAccess * 100).toFixed(2)
        : 0;
    
      // 獲取最新內存使用
      const latestMemory = this.memorySnapshots.length > 0
        ? this.memorySnapshots[this.memorySnapshots.length - 1]
        : process.memoryUsage();
    
      return {
        uptime: {
          ms: uptime,
          seconds: uptimeSeconds,
          human: this.formatUptime(uptimeSeconds)
        },
        requests: {
          total: this.requestCount,
          success: this.successCount,
          error: this.errorCount,
          errorRate: `${errorRate}%`,
          requestsPerSecond: requestsPerSecond.toFixed(2)
        },
        latency: {
          avg: avgDuration.toFixed(2),
          p50: percentile(this.durations, 0.50).toFixed(2),
          p95: percentile(this.durations, 0.95).toFixed(2),
          p99: percentile(this.durations, 0.99).toFixed(2),
          max: this.durations.length > 0 ? Math.max(...this.durations).toFixed(2) : 0,
          unit: 'ms'
        },
        cache: {
          hits: this.cacheHits,
          misses: this.cacheMisses,
          total: totalCacheAccess,
          hitRate: `${cacheHitRate}%`
        },
        memory: {
          rss: `${(latestMemory.rss / 1024 / 1024).toFixed(2)} MB`,
          heapTotal: `${(latestMemory.heapTotal / 1024 / 1024).toFixed(2)} MB`,
          heapUsed: `${(latestMemory.heapUsed / 1024 / 1024).toFixed(2)} MB`,
          external: `${(latestMemory.external / 1024 / 1024).toFixed(2)} MB`
        },
        toolStats: this.getToolStats()
      };
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. While '獲取' (get) implies a read operation, it doesn't disclose important behavioral aspects: whether this requires authentication, what format the metrics are returned in, if there are rate limits, whether it's real-time or historical data, or what happens if the server is unavailable. For a monitoring tool with zero annotation coverage, this is insufficient.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient phrase that communicates the core purpose without unnecessary words. It's appropriately sized for a simple tool and front-loads the essential information. Every character earns its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given this is a performance monitoring tool with no annotations and no output schema, the description is incomplete. It doesn't explain what metrics are returned, in what format, or how to interpret them. With 18 sibling tools including similar 'get_' operations, more context about this tool's specific domain (server vs memory vs cache metrics) would be helpful for an agent to use it correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool has 0 parameters with 100% schema description coverage, so the baseline is 4. The description doesn't need to explain parameters since none exist, and it correctly doesn't mention any. This meets expectations for a parameterless tool.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose3/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description '獲取服務器性能指標' (Get server performance metrics) states a clear verb ('獲取' - get) and resource ('服務器性能指標' - server performance metrics), but it's vague about scope and doesn't differentiate from sibling tools like 'get_cache_stats' or 'get_memory_stats'. It provides basic purpose but lacks specificity about what metrics are included or how this differs from other get_* tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. With multiple sibling tools that retrieve different types of data (cache stats, memory stats, health check), there's no indication of when server performance metrics are appropriate versus other monitoring tools. No prerequisites, exclusions, or complementary tools are mentioned.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/win10ogod/memory-mcp-server'

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