Skip to main content
Glama

save_answer_query_websearch

Retrieves answers to natural language queries using Google Search, processes them with Vertex AI models, and saves the results to a specified file path for easy access and storage.

Instructions

Answers a natural language query using Google Search results and saves the answer to a file. Uses the configured Vertex AI model (gemini-2.5-pro-exp-03-25). Requires 'query' and 'output_path'.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
output_pathYesThe relative path where the generated answer should be saved.
queryYesThe natural language question to answer using web search.

Implementation Reference

  • Handler execution logic for the save_answer_query_websearch tool: parses arguments, invokes the tool's buildPrompt to generate AI prompt, calls the generative AI with web search enabled, saves the generated content to the specified output_path, and returns a success message.
    } else if (toolName === "save_answer_query_websearch") {
        const parsedArgs = SaveAnswerQueryWebsearchArgsSchema.parse(args);
        const { output_path } = parsedArgs;
    
        const config = getAIConfig();
        const { systemInstructionText, userQueryText, useWebSearch, enableFunctionCalling } = toolDefinition.buildPrompt(args, config.modelId);
    
        const initialContents = buildInitialContent(systemInstructionText, userQueryText) as CombinedContent[];
        const toolsForApi = getToolsForApi(enableFunctionCalling, useWebSearch);
    
        const generatedContent = await callGenerativeAI(
            initialContents,
            toolsForApi
        );
    
        const validOutputPath = validateWorkspacePath(output_path);
        await fs.mkdir(path.dirname(validOutputPath), { recursive: true });
        await fs.writeFile(validOutputPath, generatedContent, "utf-8");
    
        return {
            content: [{ type: "text", text: `Successfully generated websearch answer and saved to ${output_path}` }],
        };
  • Core tool definition including the buildPrompt function that constructs the detailed system and user prompts for answering queries via web search, tailored for comprehensive, cited, structured responses.
    export const saveAnswerQueryWebsearchTool: ToolDefinition = {
        name: "save_answer_query_websearch",
        description: `Answers a natural language query using Google Search results and saves the answer to a file. Uses the configured Vertex AI model (${modelIdPlaceholder}). Requires 'query' and 'output_path'.`,
        inputSchema: SaveAnswerQueryWebsearchJsonSchema as any,
        buildPrompt: (args: any, modelId: string) => {
            const parsed = SaveAnswerQueryWebsearchArgsSchema.safeParse(args);
            if (!parsed.success) {
                throw new McpError(ErrorCode.InvalidParams, `Invalid arguments for save_answer_query_websearch: ${parsed.error.errors.map(e => `${e.path.join('.')}: ${e.message}`).join(', ')}`);
            }
            const { query } = parsed.data; // output_path used in handler
    
            // --- Use Prompt Logic from answer_query_websearch.ts ---
            const base = `You are an AI assistant designed to answer questions accurately using provided search results. You are an EXPERT at synthesizing information from diverse sources into comprehensive, well-structured responses.`;
    
            const ground = ` Base your answer *only* on Google Search results relevant to "${query}". Synthesize information from search results into a coherent, comprehensive response that directly addresses the query. If search results are insufficient or irrelevant, explicitly state which aspects you cannot answer based on available information. Never add information not present in search results. When search results conflict, acknowledge the contradictions and explain different perspectives.`;
    
            const structure = ` Structure your response with clear organization:
    1. Begin with a concise executive summary of 2-3 sentences that directly answers the main question.
    2. For complex topics, use appropriate headings and subheadings to organize different aspects of the answer.
    3. Present information from newest to oldest when dealing with evolving topics or current events.
    4. Where appropriate, use numbered or bulleted lists to present steps, features, or comparative points.
    5. For controversial topics, present multiple perspectives fairly with supporting evidence from search results.
    6. Include a "Sources and Limitations" section at the end that notes the reliability of sources and any information gaps.`;
    
            const citation = ` Citation requirements:
    1. Cite specific sources within your answer using [Source X] format.
    2. Prioritize information from reliable, authoritative sources over random websites or forums.
    3. For statistics, quotes, or specific claims, attribute the specific source.
    4. Evaluate source credibility and recency - prefer official, recent sources for time-sensitive topics.
    5. When search results indicate information might be outdated, explicitly note this limitation.`;
    
            const format = ` Format your answer in clean, readable Markdown:
    1. Use proper headings (##, ###) for major sections.
    2. Use **bold** for emphasis of key points.
    3. Use \`code formatting\` for technical terms, commands, or code snippets when relevant.
    4. Create tables for comparing multiple items or options.
    5. Use blockquotes (>) for direct quotations from sources.`;
    
            const systemInstructionText = base + ground + structure + citation + format;
            const userQueryText = `I need a comprehensive answer to this question: "${query}"
    
    In your answer:
    1. Thoroughly search for and evaluate ALL relevant information from search results
    2. Synthesize information from multiple sources into a coherent, well-structured response
    3. Present differing viewpoints fairly when sources disagree
    4. Include appropriate citations to specific sources
    5. Note any limitations in the available information
    6. Organize your response logically with clear headings and sections
    7. Use appropriate formatting to enhance readability
    
    Please provide your COMPLETE response addressing all aspects of my question.`;
    
            return {
                systemInstructionText: systemInstructionText,
                userQueryText: userQueryText,
                useWebSearch: true, // Always true for this tool
                enableFunctionCalling: false
            };
        }
    };
  • Zod schema defining input arguments: query (string) and output_path (string).
    export const SaveAnswerQueryWebsearchArgsSchema = z.object({
        query: z.string().describe("The natural language question to answer using web search."),
        output_path: z.string().describe("The relative path where the generated answer should be saved.")
    });
  • Registration of the saveAnswerQueryWebsearchTool in the allTools array for export and toolMap creation.
    saveAnswerQueryDirectTool,
    saveAnswerQueryWebsearchTool,
Behavior3/5

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

With no annotations provided, the description carries full burden. It discloses key behavioral traits: it uses Google Search, employs a specific Vertex AI model, and saves to a file. However, it doesn't mention potential rate limits, authentication needs, file format, or what happens if the file already exists.

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 efficiently structured in two sentences: the first states the core functionality, the second specifies requirements. Every word serves a purpose with zero wasted information, making it easy to parse quickly.

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?

For a tool with 2 parameters, 100% schema coverage, and no output schema, the description is adequate but has gaps. It explains the what and how but lacks details on behavioral constraints (e.g., search limits), error handling, or output format, which would be helpful given the mutation nature (saving files).

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 schema already fully documents both parameters. The description adds minimal value beyond the schema by mentioning the parameters are required, but doesn't provide additional semantic context like query formatting examples or output_path conventions.

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 specific action ('answers a natural language query using Google Search results and saves the answer to a file'), identifies the resource (query results), and distinguishes from siblings like 'answer_query_websearch' (which doesn't save) and 'save_answer_query_direct' (which doesn't use web search).

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 provides clear context for when to use this tool (to answer queries with web search and save results), but doesn't explicitly state when not to use it or name alternatives like 'answer_query_websearch' for non-saving scenarios or 'save_answer_query_direct' for direct answering without web search.

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/shariqriazz/vertex-ai-mcp-server'

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