Skip to main content
Glama

clear_cache

Idempotent

Clear stored data cache in Metabase to resolve outdated information issues. Supports targeted clearing for specific cache types like dashboards, cards, or databases.

Instructions

Clear the internal cache for stored data. Useful for debugging or when you know the data has changed. Supports granular cache clearing for both individual items and list caches.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cache_typeNoType of cache to clear: "all" (default - clears all cache types), individual item caches ("cards", "dashboards", "tables", "databases", "collections", "fields"), list caches ("cards-list", "dashboards-list", "tables-list", "databases-list", "collections-list"), or bulk operations ("all-lists", "all-individual")all

Implementation Reference

  • The handleClearCache function that executes the clear_cache tool. Validates cache_type input and calls appropriate apiClient cache clearing methods based on the specified type (individual items, lists, or all). Returns structured JSON response with confirmation and cache status information.
    export function handleClearCache(
      request: CallToolRequest,
      apiClient: MetabaseApiClient,
      logInfo: (message: string, data?: unknown) => void,
      logWarn: (message: string, data?: unknown, error?: Error) => void,
      logError: (message: string, error: unknown) => void
    ) {
      const requestId = 'clearCache'; // Generate a simple request ID for logging
    
      // Validate cache_type parameter with case insensitive handling
      const validCacheTypes = [
        'all',
        'cards',
        'dashboards',
        'tables',
        'databases',
        'collections',
        'fields',
        'cards-list',
        'dashboards-list',
        'tables-list',
        'databases-list',
        'collections-list',
        'all-lists',
        'all-individual',
      ] as const;
    
      const cacheType = validateEnumValue(
        request.params?.arguments?.cache_type || 'all',
        validCacheTypes,
        'cache_type',
        requestId,
        logWarn
      );
    
      try {
        let message = '';
        let cacheStatus = '';
    
        switch (cacheType) {
          case 'cards':
            apiClient.clearCardsCache();
            message = 'Cards cache cleared successfully (individual items only)';
            cacheStatus = 'cards_cache_empty';
            break;
    
          case 'dashboards':
            apiClient.clearDashboardsCache();
            message = 'Dashboards cache cleared successfully (individual items only)';
            cacheStatus = 'dashboards_cache_empty';
            break;
    
          case 'tables':
            apiClient.clearTablesCache();
            message = 'Tables cache cleared successfully (individual items only)';
            cacheStatus = 'tables_cache_empty';
            break;
    
          case 'databases':
            apiClient.clearDatabasesCache();
            message = 'Databases cache cleared successfully (individual items only)';
            cacheStatus = 'databases_cache_empty';
            break;
    
          case 'collections':
            apiClient.clearCollectionsCache();
            message = 'Collections cache cleared successfully (individual items only)';
            cacheStatus = 'collections_cache_empty';
            break;
    
          case 'fields':
            apiClient.clearFieldsCache();
            message = 'Fields cache cleared successfully';
            cacheStatus = 'fields_cache_empty';
            break;
    
          case 'cards-list':
            apiClient.clearCardsListCache();
            message = 'Cards list cache cleared successfully';
            cacheStatus = 'cards_list_cache_empty';
            break;
    
          case 'dashboards-list':
            apiClient.clearDashboardsListCache();
            message = 'Dashboards list cache cleared successfully';
            cacheStatus = 'dashboards_list_cache_empty';
            break;
    
          case 'tables-list':
            apiClient.clearTablesListCache();
            message = 'Tables list cache cleared successfully';
            cacheStatus = 'tables_list_cache_empty';
            break;
    
          case 'databases-list':
            apiClient.clearDatabasesListCache();
            message = 'Databases list cache cleared successfully';
            cacheStatus = 'databases_list_cache_empty';
            break;
    
          case 'collections-list':
            apiClient.clearCollectionsListCache();
            message = 'Collections list cache cleared successfully';
            cacheStatus = 'collections_list_cache_empty';
            break;
    
          case 'all-lists':
            apiClient.clearListCaches();
            message =
              'All list caches cleared successfully (cards, dashboards, tables, databases, collections)';
            cacheStatus = 'all_list_caches_empty';
            break;
    
          case 'all-individual':
            apiClient.clearCardsCache();
            apiClient.clearDashboardsCache();
            apiClient.clearTablesCache();
            apiClient.clearDatabasesCache();
            apiClient.clearCollectionsCache();
            apiClient.clearFieldsCache();
            message =
              'All individual item caches cleared successfully (cards, dashboards, tables, databases, collections, fields)';
            cacheStatus = 'all_individual_caches_empty';
            break;
    
          case 'all':
          default:
            apiClient.clearAllCache();
            message =
              'All caches cleared successfully (individual items and lists for cards, dashboards, tables, databases, collections, and fields)';
            cacheStatus = 'all_caches_empty';
            break;
        }
    
        logInfo(message);
    
        return {
          content: [
            {
              type: 'text',
              text: formatJson({
                message,
                cache_type: cacheType,
                cache_status: cacheStatus,
                next_fetch_will_be: 'fresh from API',
                cache_info: {
                  cache_explanation:
                    'Unified cache system with separate individual item and list caches for optimal performance',
                  cache_types: {
                    individual:
                      'Cache for specific items accessed by ID (cards, dashboards, tables, databases, collections, fields)',
                    lists:
                      'Cache for bulk list operations (cards-list, dashboards-list, tables-list, databases-list, collections-list)',
                  },
                },
              }),
            },
          ],
        };
      } catch (error: any) {
        throw handleApiError(error, { operation: 'Clear cache' }, logError);
      }
    }
  • Tool schema definition for 'clear_cache' including name, description, annotations, and inputSchema with cache_type enum and descriptions.
    {
      name: 'clear_cache',
      description:
        'Clear the internal cache for stored data. Useful for debugging or when you know the data has changed. Supports granular cache clearing for both individual items and list caches.',
      annotations: {
        readOnlyHint: false,
        destructiveHint: false,
        idempotentHint: true,
        openWorldHint: false,
      },
      inputSchema: {
        type: 'object',
        properties: {
          cache_type: {
            type: 'string',
            enum: [
              'all',
              'cards',
              'dashboards',
              'tables',
              'databases',
              'collections',
              'fields',
              'cards-list',
              'dashboards-list',
              'tables-list',
              'databases-list',
              'collections-list',
              'all-lists',
              'all-individual',
            ],
            description:
              'Type of cache to clear: "all" (default - clears all cache types), individual item caches ("cards", "dashboards", "tables", "databases", "collections", "fields"), list caches ("cards-list", "dashboards-list", "tables-list", "databases-list", "collections-list"), or bulk operations ("all-lists", "all-individual")',
            default: 'all',
          },
        },
        required: [],
      },
    },
  • src/server.ts:556-565 (registration)
    Registration of the clear_cache handler in the CallToolRequestSchema switch statement, dispatching calls to handleClearCache with appropriate parameters.
    case 'clear_cache':
      return safeCall(() =>
        handleClearCache(
          request,
          this.apiClient,
          this.logInfo.bind(this),
          this.logWarn.bind(this),
          this.logError.bind(this)
        )
      );
  • Re-export of handleClearCache from clearCache.js for use in server.ts.
    export { handleClearCache } from './clearCache.js';
Behavior4/5

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

The description adds valuable behavioral context beyond annotations: it explains that clearing is 'granular' for both individual items and list caches, which helps the agent understand the tool's capabilities. While annotations cover idempotency and non-destructive nature, the description provides practical usage context that complements them without contradiction.

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 perfectly concise with three sentences that each add distinct value: stating the core purpose, providing usage context, and explaining granular capabilities. No wasted words, and information is front-loaded with the primary function stated first.

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?

For a single-parameter tool with comprehensive annotations and full schema coverage, the description provides adequate context about purpose, usage scenarios, and behavioral characteristics. The main gap is the lack of output schema information, but given the tool's relative simplicity and good annotation coverage, the description is mostly complete.

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?

With 100% schema description coverage, the input schema already fully documents the single parameter's purpose, enum values, and default. The description mentions 'granular cache clearing for both individual items and list caches' which aligns with but doesn't significantly expand upon the schema's detailed enum descriptions.

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

Purpose5/5

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

The description clearly states the specific action ('Clear') and target resource ('internal cache for stored data'), distinguishing it from sibling tools like list, retrieve, or search. It provides additional context about what the cache contains (stored data) and the granularity of clearing operations.

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

Usage Guidelines4/5

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

The description provides explicit guidance on when to use the tool ('Useful for debugging or when you know the data has changed'), giving clear context for its application. However, it doesn't specify when NOT to use it or mention alternatives among the sibling tools.

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/jerichosequitin/metabase-mcp'

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