Skip to main content
Glama
FosterG4

Code Reference Optimizer MCP Server

by FosterG4

get_cached_context

Retrieve cached code context for a specified file path to optimize AI assistant token usage. Supports TypeScript, JavaScript, Python, Go, and Rust with minimal, relevant context extraction.

Instructions

Retrieve cached code context for a file

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cacheKeyNoOptional cache key for specific context
filePathYesPath to the source file

Implementation Reference

  • The MCP tool handler for 'get_cached_context'. Extracts parameters from args, logs the call, delegates to CodeReferenceOptimizer.getCachedContext, and returns the result as JSON-formatted text content.
    private async handleGetCachedContext(args: any) {
      const { filePath, cacheKey } = args;
      
      this.logger.info(`get_cached_context: filePath=${filePath} cacheKey=${cacheKey ?? ''}`);
      const result = await this.optimizer.getCachedContext(filePath, cacheKey);
    
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(result, null, 2),
          },
        ],
      };
    }
  • src/index.ts:125-142 (registration)
    Tool registration in ListToolsRequestSchema handler, including name, description, and input schema definition.
    {
      name: 'get_cached_context',
      description: 'Retrieve previously extracted and cached code context for a file. Provides fast access to analyzed code structures without re-parsing. Useful for repeated queries on the same file or when working with large codebases where re-analysis would be expensive.',
      inputSchema: {
        type: 'object',
        properties: {
          filePath: {
            type: 'string',
            description: 'Path to the source file for which to retrieve cached context. Must match the path used in previous extract_code_context calls.',
          },
          cacheKey: {
            type: 'string',
            description: 'Optional specific cache key to retrieve a particular cached analysis. If omitted, returns the most recent cached context for the file.',
          },
        },
        required: ['filePath'],
      },
    },
  • Core implementation of getCachedContext in CodeReferenceOptimizer class. Retrieves specific cached context by key or the most recent/relevant one for the filePath from cacheManager.
    async getCachedContext(filePath: string, cacheKey?: string): Promise<CodeContext | null> {
      if (cacheKey) {
        return await this.cacheManager.get(cacheKey);
      }
      
      // Find most relevant cached context for the file
      const allCached = await this.cacheManager.getByFilePath(filePath);
      if (allCached.length === 0) {
        return null;
      }
      
      // Return the most recent and relevant cached context
      const sortedCached = (allCached || []).sort((a, b) => {
        const scoreA = a.relevanceScore * (1 - this.getAgeWeight(a.timestamp));
        const scoreB = b.relevanceScore * (1 - this.getAgeWeight(b.timestamp));
        return scoreB - scoreA;
      });
      return sortedCached.length > 0 ? (sortedCached[0] as CodeContext) : null;
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the action is to 'retrieve' cached context, implying a read-only operation, but doesn't clarify if this requires specific permissions, what happens if the cache is missing, or any rate limits. This leaves significant gaps in understanding the tool's behavior.

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, clear sentence with no wasted words. It's front-loaded with the core action and resource, making it efficient and easy to parse for an AI agent.

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

Completeness3/5

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

Given the tool's moderate complexity (2 parameters, no output schema, no annotations), the description is minimally adequate. It explains what the tool does but lacks details on behavioral traits, usage context, and output format, which are important for a retrieval operation. This leaves room for improvement without being incomplete.

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?

Schema description coverage is 100%, so the input schema already documents both parameters ('cacheKey' and 'filePath') with descriptions. The description adds no additional meaning beyond implying that 'filePath' is the primary identifier for retrieving context, which aligns with the schema but doesn't provide extra value. This meets the baseline for high schema coverage.

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 verb 'retrieve' and the resource 'cached code context for a file', making the purpose specific and understandable. However, it doesn't explicitly differentiate from sibling tools like 'extract_code_context' or 'analyze_code_diff', which might involve similar file operations, so it falls short of a perfect score.

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. It doesn't mention any prerequisites, exclusions, or comparisons to sibling tools such as 'extract_code_context', leaving the agent to infer usage from context alone.

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

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/FosterG4/mcpsaver'

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