Skip to main content
Glama
malaksedarous

Context Optimizer MCP Server

askFollowUp

Ask follow-up questions about terminal command outputs without re-executing commands, extracting specific information from previous executions to optimize context usage.

Instructions

Ask follow-up questions about the previous terminal command execution without re-running the command. Only available after using runAndExtract tool.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
questionYesFollow-up question about the previous terminal command execution and its output

Implementation Reference

  • The main execute handler that validates the input question, loads the previous terminal session, processes the follow-up using LLM, and returns success or error response.
    async execute(args: any): Promise<MCPToolResponse> {
      try {
        this.logOperation('Follow-up question started', { question: args.question });
        
        // Validate required fields
        const fieldError = this.validateRequiredFields(args, ['question']);
        if (fieldError) {
          return this.createErrorResponse(fieldError);
        }
        
        // Load previous terminal session
        const session = await SessionManager.loadTerminalSession();
        if (!session) {
          return this.createErrorResponse(
            'No recent terminal execution found. Please use the runAndExtract tool first to execute a command, then you can ask follow-up questions about its output.'
          );
        }
        
        // Process follow-up question with LLM
        const answer = await this.processFollowUpQuestion(session, args.question);
        
        this.logOperation('Follow-up question completed successfully');
        return this.createSuccessResponse(answer);
        
      } catch (error) {
        this.logOperation('Follow-up question failed', { error });
        return this.createErrorResponse(
          `Follow-up question failed: ${error instanceof Error ? error.message : String(error)}`
        );
      }
    }
  • Input schema defining the required 'question' parameter as a string.
    readonly inputSchema = {
      type: 'object',
      properties: {
        question: {
          type: 'string',
          description: 'Follow-up question about the previous terminal command execution and its output'
        }
      },
      required: ['question']
    };
  • src/server.ts:60-74 (registration)
    Registers the AskFollowUpTool by instantiating it (line 64) and adding to the tools map used by the MCP server handlers.
    private setupTools(): void {
      const toolInstances = [
        new AskAboutFileTool(),
        new RunAndExtractTool(),
        new AskFollowUpTool(),
        new ResearchTopicTool(),
        new DeepResearchTool()
      ];
      
      for (const tool of toolInstances) {
        this.tools.set(tool.name, tool);
      }
      
      Logger.info(`Registered ${this.tools.size} tools: ${Array.from(this.tools.keys()).join(', ')}`);
    }
  • Helper method that creates the LLM prompt and calls the provider to get the answer based on session and question.
    private async processFollowUpQuestion(
      session: any,
      question: string
    ): Promise<string> {
      const config = ConfigurationManager.getConfig();
      const provider = LLMProviderFactory.createProvider(config.llm.provider);
      const apiKey = this.getApiKey(config.llm.provider, config.llm);
      
      const prompt = this.createFollowUpPrompt(session, question);
      const response = await provider.processRequest(prompt, config.llm.model, apiKey);
      
      if (!response.success) {
        throw new Error(`LLM processing failed: ${response.error}`);
      }
      
      return response.content;
    }
  • Helper that constructs the detailed prompt for the LLM including previous command details, output, and instructions.
      private createFollowUpPrompt(session: any, question: string): string {
        return `You are answering a follow-up question about a previous terminal command execution.
    
    Previous command: ${session.command}
    Working directory: ${session.workingDirectory}
    Exit code: ${session.exitCode}
    Original extraction request: ${session.extractionPrompt}
    Previously extracted information: ${session.extractedInfo}
    
    Follow-up question: ${question}
    
    Context - Original command output:
    ${session.output}
    
    Instructions:
    - Answer the follow-up question based on the command output and context
    - Reference the original output when needed
    - Be specific and helpful
    - If the question cannot be answered from the available information, say so clearly
    - Use markdown formatting for better readability
    - Be concise but thorough in your response`;
      }

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