Skip to main content
Glama
malaksedarous

Context Optimizer MCP Server

askFollowUp

Ask follow-up questions about the previous terminal command's execution and output without re-running the command. Requires prior use of runAndExtract.

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 execute() method is the main handler for the askFollowUp tool. It validates the 'question' parameter, loads the previous terminal session via SessionManager, and delegates to processFollowUpQuestion(). If no session exists, it returns an error instructing the user to run runAndExtract first.
    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)}`
        );
      }
    }
  • processFollowUpQuestion() is a private helper that retrieves LLM configuration, creates an LLM provider, builds a prompt via createFollowUpPrompt(), sends it to the LLM, and returns the response content.
    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;
    }
  • createFollowUpPrompt() builds the system prompt for the LLM. It includes the previous command, working directory, exit code, extraction prompt, previously extracted info, the follow-up question, and the original command output. It instructs the LLM to be specific, reference original output, and use markdown.
      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`;
      }
  • getApiKey() retrieves the API key for the configured LLM provider from the config object, throwing an error if not found.
    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;
    }
  • The inputSchema defines the tool's input: a required 'question' string describing the follow-up question about the previous terminal command execution.
    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:64-64 (registration)
    The AskFollowUpTool is instantiated and registered in the server's tools map alongside other tools (AskAboutFileTool, RunAndExtractTool, ResearchTopicTool, DeepResearchTool).
    new AskFollowUpTool(),
  • src/server.ts:33-33 (registration)
    Import statement for the AskFollowUpTool class in src/server.ts.
    import { AskFollowUpTool } from './tools/askFollowUp';
Behavior2/5

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

No annotations are provided, so the description bears full responsibility. It mentions the prerequisite (after runAndExtract) but does not disclose what happens if called without that prerequisite or any other behavioral traits like error handling or idempotency.

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 extremely concise with two sentences, no redundant words. It front-loads the core purpose and adds a critical usage constraint in the second sentence.

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 simplicity (one parameter, no output schema, no annotations), the description is mostly adequate. However, it lacks information about the return value or error behavior, which could hinder an AI agent understanding edge cases.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema has 100% coverage with one required parameter 'question' described as 'Follow-up question about the previous terminal command execution and its output.' The description adds meaningful context beyond the schema by specifying the scope of the question.

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 tool's purpose: 'Ask follow-up questions about the previous terminal command execution without re-running the command.' It specifies the verb (ask), resource (previous terminal command execution), and distinguishes it from re-running the command.

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 explicitly states when to use the tool: 'Only available after using runAndExtract tool.' It also clarifies what it avoids: 'without re-running the command.' This provides good usage context, though it does not explicitly mention alternatives.

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