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
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes | Full absolute path to the file to analyze (e.g., "C:\Users\username\project\src\file.ts", "/home/user/project/docs/README.md") | |
| question | Yes | 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") |
Implementation Reference
- src/tools/askAboutFile.ts:33-73 (handler)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)}` ); } } - src/tools/askAboutFile.ts:18-31 (schema)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'] }; - src/tools/askAboutFile.ts:75-92 (helper)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}`; } - src/tools/askAboutFile.ts:94-101 (helper)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() ];