Skip to main content
Glama
olibuijr

Iceland News MCP Server

by olibuijr

cache_stats

Monitor cache performance by retrieving hit/miss rates and entry counts. Optionally clear the cache after viewing statistics to manage data freshness.

Instructions

Get cache statistics including hit/miss rates and entry counts. Useful for monitoring performance.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
clearCacheNoIf true, clears the cache after returning stats

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
hitsYes
missesYes
entriesYes
hitRateYes
ttlMinutesYes
newestEntryAgeYes
oldestEntryAgeYes

Implementation Reference

  • The handler function for the 'cache_stats' MCP tool. It calls getCacheStats(), computes additional metrics like hit rate and ages, generates markdown table, and optionally clears the cache.
    async ({ clearCache: shouldClear }) => {
      const stats = getCacheStats();
      const now = Date.now();
    
      const hitRate = stats.hits + stats.misses > 0
        ? (stats.hits / (stats.hits + stats.misses)) * 100
        : 0;
    
      const oldestAge = stats.oldestEntry ? Math.round((now - stats.oldestEntry) / 1000) : null;
      const newestAge = stats.newestEntry ? Math.round((now - stats.newestEntry) / 1000) : null;
    
      const cacheStatsResult = {
        hits: stats.hits,
        misses: stats.misses,
        hitRate: Math.round(hitRate * 100) / 100,
        entries: stats.entries,
        ttlMinutes: CACHE_TTL / 60000,
        oldestEntryAge: oldestAge,
        newestEntryAge: newestAge,
      };
    
      let markdown = `# Cache Statistics\n\n`;
      markdown += `| Metric | Value |\n|--------|-------|\n`;
      markdown += `| Cache Hits | ${stats.hits} |\n`;
      markdown += `| Cache Misses | ${stats.misses} |\n`;
      markdown += `| Hit Rate | ${cacheStatsResult.hitRate}% |\n`;
      markdown += `| Cached Entries | ${stats.entries} |\n`;
      markdown += `| TTL | ${CACHE_TTL / 60000} minutes |\n`;
      markdown += `| Oldest Entry Age | ${oldestAge !== null ? `${oldestAge}s` : "N/A"} |\n`;
      markdown += `| Newest Entry Age | ${newestAge !== null ? `${newestAge}s` : "N/A"} |\n`;
    
      if (shouldClear) {
        clearCache();
        markdown += `\n*Cache has been cleared.*\n`;
      }
    
      return {
        content: [{ type: "text" as const, text: markdown }],
        structuredContent: cacheStatsResult,
      };
    }
  • Zod schema defining the structured output for the cache_stats tool.
    const CacheStatsSchema = z.object({
      hits: z.number(),
      misses: z.number(),
      hitRate: z.number(),
      entries: z.number(),
      ttlMinutes: z.number(),
      oldestEntryAge: z.number().nullable(),
      newestEntryAge: z.number().nullable(),
    });
  • src/index.ts:1001-1054 (registration)
    Registration of the 'cache_stats' tool with the MCP server using server.registerTool, specifying name, description, input/output schemas, and handler function.
    server.registerTool(
      "cache_stats",
      {
        description: "Get cache statistics including hit/miss rates and entry counts. Useful for monitoring performance.",
        inputSchema: {
          clearCache: z
            .boolean()
            .default(false)
            .describe("If true, clears the cache after returning stats"),
        },
        outputSchema: CacheStatsSchema,
      },
      async ({ clearCache: shouldClear }) => {
        const stats = getCacheStats();
        const now = Date.now();
    
        const hitRate = stats.hits + stats.misses > 0
          ? (stats.hits / (stats.hits + stats.misses)) * 100
          : 0;
    
        const oldestAge = stats.oldestEntry ? Math.round((now - stats.oldestEntry) / 1000) : null;
        const newestAge = stats.newestEntry ? Math.round((now - stats.newestEntry) / 1000) : null;
    
        const cacheStatsResult = {
          hits: stats.hits,
          misses: stats.misses,
          hitRate: Math.round(hitRate * 100) / 100,
          entries: stats.entries,
          ttlMinutes: CACHE_TTL / 60000,
          oldestEntryAge: oldestAge,
          newestEntryAge: newestAge,
        };
    
        let markdown = `# Cache Statistics\n\n`;
        markdown += `| Metric | Value |\n|--------|-------|\n`;
        markdown += `| Cache Hits | ${stats.hits} |\n`;
        markdown += `| Cache Misses | ${stats.misses} |\n`;
        markdown += `| Hit Rate | ${cacheStatsResult.hitRate}% |\n`;
        markdown += `| Cached Entries | ${stats.entries} |\n`;
        markdown += `| TTL | ${CACHE_TTL / 60000} minutes |\n`;
        markdown += `| Oldest Entry Age | ${oldestAge !== null ? `${oldestAge}s` : "N/A"} |\n`;
        markdown += `| Newest Entry Age | ${newestAge !== null ? `${newestAge}s` : "N/A"} |\n`;
    
        if (shouldClear) {
          clearCache();
          markdown += `\n*Cache has been cleared.*\n`;
        }
    
        return {
          content: [{ type: "text" as const, text: markdown }],
          structuredContent: cacheStatsResult,
        };
      }
    );
  • Core helper function that computes raw cache statistics: hits, misses, entry count, and timestamps of oldest/newest entries.
    function getCacheStats(): CacheStats {
      let oldestEntry: number | null = null;
      let newestEntry: number | null = null;
    
      for (const entry of cache.values()) {
        if (oldestEntry === null || entry.createdAt < oldestEntry) {
          oldestEntry = entry.createdAt;
        }
        if (newestEntry === null || entry.createdAt > newestEntry) {
          newestEntry = entry.createdAt;
        }
      }
    
      return {
        hits: cacheHits,
        misses: cacheMisses,
        entries: cache.size,
        oldestEntry,
        newestEntry,
      };
    }
  • TypeScript interface defining the structure of raw CacheStats used by getCacheStats.
    interface CacheStats {
      hits: number;
      misses: number;
      entries: number;
      oldestEntry: number | null;
      newestEntry: number | null;
    }
Behavior3/5

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

No annotations are provided, so the description carries the full burden. It discloses the tool's purpose and utility but lacks details on behavioral traits like permissions needed, rate limits, error conditions, or what the output looks like (though an output schema exists). The description doesn't contradict annotations (none provided), but it's minimal beyond the basic operation.

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 appropriately sized and front-loaded: the first sentence states the core purpose, and the second adds context without redundancy. Every sentence earns its place by providing essential information efficiently, with zero waste.

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

Completeness4/5

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

Given the tool's low complexity (1 parameter, no nested objects), high schema coverage (100%), and the presence of an output schema, the description is reasonably complete. It covers the purpose and utility, though it could benefit from more behavioral context (e.g., performance implications). The output schema reduces the need to explain return values, making this adequate.

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

Parameters3/5

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

The description adds no parameter semantics beyond what the input schema provides. The schema has 100% description coverage for its single parameter ('clearCache'), clearly explaining its effect. With high schema coverage, the baseline is 3, as the description doesn't need to compensate but also doesn't add value regarding parameters.

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

Purpose4/5

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

The description clearly states the tool's purpose with specific verbs ('Get cache statistics') and resources ('cache statistics including hit/miss rates and entry counts'). It distinguishes itself from sibling tools (which are about feeds/news) by focusing on cache monitoring. However, it doesn't explicitly differentiate from potential cache-related siblings if they existed.

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

Usage Guidelines3/5

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

The description provides implied usage guidance with 'Useful for monitoring performance,' suggesting when this tool might be appropriate. However, it doesn't explicitly state when to use it versus alternatives, nor does it mention any prerequisites or exclusions. The sibling tools are unrelated (feeds/news), so no comparative guidance is needed.

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/olibuijr/iceland-news-mcp'

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