Skip to main content
Glama
malaksedarous

Context Optimizer MCP Server

askAboutFile

Ask specific questions about file contents to retrieve targeted information without loading the entire file into chat context, saving tokens.

Instructions

Extract specific information from files without reading their entire contents into chat context. Works with text files, code files, images, PDFs, and more.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesFull absolute path to the file to analyze (e.g., "C:\Users\username\project\src\file.ts", "/home/user/project/docs/README.md")
questionYesSpecific question about the file content (e.g., "Does this file export a validateEmail function?", "What is the main purpose described in this spec?", "Extract all import statements")

Implementation Reference

  • Main execution method of AskAboutFileTool. Validates required fields (filePath, question), checks file path security via PathValidator, reads the file content, constructs an LLM prompt, sends it to the configured LLM provider, and returns the response.
    async execute(args: any): Promise<MCPToolResponse> {
      try {
        this.logOperation('File analysis started', { filePath: args.filePath, question: args.question });
        
        // Validate required fields
        const fieldError = this.validateRequiredFields(args, ['filePath', 'question']);
        if (fieldError) {
          return this.createErrorResponse(fieldError);
        }
        
        // Validate file path security
        const pathValidation = await PathValidator.validateFilePath(args.filePath);
        if (!pathValidation.valid) {
          return this.createErrorResponse(pathValidation.error!);
        }
        
        // Read file content
        const fileContent = await fs.readFile(pathValidation.resolvedPath!, 'utf8');
        
        // Process with LLM
        const config = ConfigurationManager.getConfig();
        const provider = LLMProviderFactory.createProvider(config.llm.provider);
        const apiKey = this.getApiKey(config.llm.provider, config.llm);
        
        const prompt = this.createFileAnalysisPrompt(fileContent, args.question, args.filePath);
        const response = await provider.processRequest(prompt, config.llm.model, apiKey);
        
        if (!response.success) {
          return this.createErrorResponse(`LLM processing failed: ${response.error}`);
        }
        
        this.logOperation('File analysis completed successfully');
        return this.createSuccessResponse(response.content);
        
      } catch (error) {
        this.logOperation('File analysis failed', { error });
        return this.createErrorResponse(
          `File analysis failed: ${error instanceof Error ? error.message : String(error)}`
        );
      }
    }
  • Input schema for askAboutFile tool defining two required parameters: filePath (absolute path) and question (specific query about the file content).
    readonly inputSchema = {
      type: 'object',
      properties: {
        filePath: {
          type: 'string',
          description: 'Full absolute path to the file to analyze (e.g., "C:\\Users\\username\\project\\src\\file.ts", "/home/user/project/docs/README.md")'
        },
        question: {
          type: 'string',
          description: 'Specific question about the file content (e.g., "Does this file export a validateEmail function?", "What is the main purpose described in this spec?", "Extract all import statements")'
        }
      },
      required: ['filePath', 'question']
    };
  • Helper method that constructs the prompt template sent to the LLM. Includes instructions to be concise and focused, along with file extension, question, and file content.
      private createFileAnalysisPrompt(fileContent: string, question: string, filePath: string): string {
        const fileExtension = path.extname(filePath);
        
        return `You are analyzing a file for a user question. Be concise and focused in your response.
    
    File: ${filePath} (${fileExtension})
    Question: ${question}
    
    Instructions:
    - Answer only what is specifically asked
    - Be brief and to the point
    - Use markdown formatting for code snippets
    - Don't explain things that weren't asked for
    - If the question can be answered with yes/no, start with that
    
    File Content:
    ${fileContent}`;
      }
  • Helper method that retrieves the API key for the configured LLM provider from the configuration.
    private getApiKey(provider: string, llmConfig: any): string {
      const keyField = `${provider}Key`;
      const key = llmConfig[keyField];
      if (!key) {
        throw new Error(`API key not configured for provider: ${provider}`);
      }
      return key;
    }
  • src/server.ts:60-67 (registration)
    Tool registration in the MCP server. Instantiates AskAboutFileTool and registers it in the tools map. The server routes incoming CallToolRequest to the tool's execute method by name.
    private setupTools(): void {
      const toolInstances = [
        new AskAboutFileTool(),
        new RunAndExtractTool(),
        new AskFollowUpTool(),
        new ResearchTopicTool(),
        new DeepResearchTool()
      ];
Behavior3/5

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

No annotations provided. Description conveys read-only nature but lacks details on error handling for unsupported files, authorization needs, or rate limits.

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?

Single sentence that front-loads the core purpose and covers key aspects without redundancy.

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?

Basic but sufficient given the tool's simplicity. Missing details on return format or error cases, but not critical for a straightforward extraction tool.

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 coverage is 100% with clear descriptions. The tool description adds minimal extra meaning beyond listing supported file types.

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 it extracts specific information from files without loading entire content, lists supported file types, and distinguishes from reading full files.

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 implies use when needing specific info from files without full context, but does not explicitly state when not to use or mention alternatives among siblings.

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/malaksedarous/context-optimizer-mcp-server'

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