Skip to main content
Glama
PV-Bhat

GemForge-Gemini-Tools-MCP

gemini_search

Retrieve accurate answers and verify facts by leveraging Gemini 2.0 Flash and Google Search integration. Ideal for general knowledge queries, fact-checking, and detailed information retrieval.

Instructions

Generates responses based on the latest information using Gemini 2.0 Flash and Google Search. Best for general knowledge questions, fact-checking, and information retrieval.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
enable_thinkingNoEnable thinking mode for step-by-step reasoning
file_pathNoOptional file path to include with the query
model_idNoOptional model ID override (advanced users only)
queryYesYour search query or question

Implementation Reference

  • Core handler function that implements the gemini_search tool. Validates input, selects Gemini 2.0 Flash model, constructs SDK request with Google Search tool, executes API call, and formats response.
    export async function handleDirectSearchAlt(request: any) {
      try {
        // Validate required parameters
        if (!request.params.arguments || typeof request.params.arguments.query !== 'string') {
          throw new McpError(
            ErrorCode.InvalidParams,
            'Query parameter is required and must be a string'
          );
        }
    
        // Extract arguments as SearchArgs
        const args = request.params.arguments as SearchArgs;
        const { query, file_path, model_id } = args;
    
        if (file_path) {
          console.error(`[handleDirectSearchAlt] Received file_path: ${typeof file_path === 'string' ? file_path : JSON.stringify(file_path)}`);
          console.error(`[handleDirectSearchAlt] File path exists check: ${await fileExists(typeof file_path === 'string' ? file_path : file_path[0])}`);
        }
    
        // Select the model using the tool-specific model selector
        const targetModelId = model_id || 'gemini-2.0-flash-001';
        console.error(`[handleDirectSearchAlt] Using model: ${targetModelId}`);
    
        try {
          // Create the model instance
          const model = genAI.getGenerativeModel({ model: targetModelId });
    
          // Build a request that works with Flash models (no system role)
          // This exact format has been verified to work with gemini-2.0-flash-001
          const sdkRequest: any = {
            contents: [{
              role: 'user',
              parts: [{
                text: query
              }]
            }],
            systemInstruction: "You have access to Google Search. You MUST use Google Search for ALL queries to provide accurate, up-to-date information. Do not rely solely on your training data.",
            generationConfig: {
              temperature: 0.7,
              topP: 0.8,
              topK: 40
            },
            tools: [{
              googleSearch: {}
            }],
            toolConfig: {
              functionCallingConfig: {
                mode: "AUTO"
              }
            }
          };
    
          console.error(`[handleDirectSearchAlt] Sending request to ${targetModelId}`);
          
          // Send request to Gemini API
          const result = await model.generateContent(sdkRequest);
          const response = result.response;
          console.error(`[handleDirectSearchAlt] SDK Response received from ${targetModelId}`);
    
          // Extract text from response
          let responseText = "";
          try {
            responseText = response.text();
          } catch (e) {
            console.error(`[handleDirectSearchAlt] Error extracting text:`, e);
            if (response.candidates && response.candidates.length > 0 && 
                response.candidates[0].content && 
                response.candidates[0].content.parts && 
                response.candidates[0].content.parts.length > 0) {
              responseText = response.candidates[0].content.parts[0].text || "";
            }
          }
    
          // Create a simple response object
          return {
            content: [
              {
                type: 'text',
                text: responseText
              }
            ]
          };
        } catch (apiError) {
          console.error('API error in direct search handler:', apiError);
          if (apiError instanceof McpError) {
            throw apiError;
          }
          throw apiError;
        }
      } catch (error) {
        console.error('Error in direct search handler:', error);
        if (error instanceof McpError) {
          throw error;
        }
        return {
          content: [
            {
              type: 'text',
              text: `Error: ${error instanceof Error ? error.message : 'Unknown error'}`
            }
          ],
          isError: true
        };
      }
    }
  • src/index.ts:206-228 (registration)
    Tool dispatch switch statement that registers and routes 'gemini_search' (both canonical TOOL_NAMES.GEM_SEARCH and legacy name) to the handleDirectSearchAlt handler.
    switch (request.params.name) {
      case TOOL_NAMES.GEM_SEARCH:
        // Use the alternative direct search handler that works with Flash models
        return await handleDirectSearchAlt(request);
      case TOOL_NAMES.GEM_REASON:
        return await handleReason(request);
      case TOOL_NAMES.GEM_CODE:
        return await handleCode(request);
      case TOOL_NAMES.GEM_FILEOPS:
        return await handleFileops(request);
      // Support legacy tool names for backward compatibility
      case 'gemini_search':
        // Use the alternative direct search handler that works with Flash models
        return await handleDirectSearchAlt(request);
      case 'gemini_reason':
        return await handleReason(request);
      default:
        console.error(`Unknown tool requested: ${request.params.name}`);
        throw new McpError(
          ErrorCode.MethodNotFound,
          `Unknown tool: ${request.params.name}. Available tools: gemini_search, gemini_reason, gemini_code, gemini_fileops`
        );
    }
  • Input schema and description for the gemini_search tool, provided in the ListTools MCP response.
    {
      name: TOOL_NAMES.GEM_SEARCH,
      description: 'Generates responses based on the latest information using Gemini 2.0 Flash and Google Search. Best for general knowledge questions, fact-checking, and information retrieval.',
      inputSchema: {
        type: 'object',
        properties: {
          query: {
            type: 'string',
            description: 'Your search query or question'
          },
          file_path: {
            type: 'string',
            description: 'Optional file path to include with the query'
          },
          model_id: {
            type: 'string',
            description: 'Optional model ID override (advanced users only)'
          },
          enable_thinking: {
            type: 'boolean',
            description: 'Enable thinking mode for step-by-step reasoning'
          }
        },
        required: ['query'],
      },
    },
  • Constants defining tool names, including GEM_SEARCH: 'gemini_search' and legacy aliases used throughout the codebase.
    export const TOOL_NAMES = {
      // New specialized toolset
      GEM_SEARCH: 'gemini_search',    // For search-enabled queries (Gemini 2.0 Flash)
      GEM_REASON: 'gemini_reason',    // For complex reasoning (Gemini 2.5 Flash/Pro)
      GEM_CODE: 'gemini_code',        // For coding tasks (Gemini 2.5 Pro)
      GEM_FILEOPS: 'gemini_fileops',  // For file operations (Gemini 2.0 Flash-Lite/1.5 Pro)
    
      // Legacy names for backward compatibility - only keeping what's needed
      SEARCH: 'gemini_search',
      REASON: 'gemini_reason',
      ANALYZE_FILE: 'gemini_analyze',
      RAPID_SEARCH: 'gemini_search'
    };
  • TypeScript interface defining the input arguments for the gemini_search tool.
    /**
     * Arguments for gemini_search tool
     */
    export interface SearchArgs extends BaseArgs, FileInput {
        /** The search query */
        query: string;
        /** Whether to enable thinking mode */
        enable_thinking?: boolean;
    }

Tool Definition Quality

Score is being calculated. Check back soon.

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/PV-Bhat/GemForge-MCP'

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