Skip to main content
Glama

MCP Gemini Google Search

by yukukotani
Apache 2.0
136
68
index.ts2.49 kB
import { Server } from "@modelcontextprotocol/sdk/server/index.js"; import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"; import { CallToolRequestSchema, ListToolsRequestSchema, ErrorCode, McpError, } from "@modelcontextprotocol/sdk/types.js"; import { createGoogleSearchAI, searchGoogle, GoogleSearchParams } from "./tools/google-search.js"; // Environment variable validation is now handled in createGoogleSearchAI const server = new Server( { name: "mcp-gemini-google-search", version: "0.1.0", }, { capabilities: { tools: {}, }, } ); const googleSearchAI = createGoogleSearchAI(); server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ { name: "google_search", description: "Performs a web search using Google Search (via the Gemini API) and returns the results. This tool is useful for finding information on the internet based on a query.", inputSchema: { type: "object", properties: { query: { type: "string", description: "The search query to find information on the web.", }, }, required: ["query"], }, }, ], }; }); server.setRequestHandler(CallToolRequestSchema, async (request) => { if (request.params.name !== "google_search") { throw new McpError( ErrorCode.MethodNotFound, `Unknown tool: ${request.params.name}` ); } if (!request.params.arguments) { throw new McpError(ErrorCode.InvalidParams, "Missing arguments"); } const args = request.params.arguments as Record<string, unknown>; if (typeof args.query !== "string") { throw new McpError( ErrorCode.InvalidParams, "Invalid arguments: query must be a string" ); } try { const searchParams: GoogleSearchParams = { query: args.query, }; const result = await searchGoogle(googleSearchAI, searchParams); return { content: result.content, }; } catch (error) { throw new McpError( ErrorCode.InternalError, `Search failed: ${error instanceof Error ? error.message : "Unknown error"}` ); } }); async function main() { const transport = new StdioServerTransport(); await server.connect(transport); console.error("MCP Gemini Google Search server running on stdio"); } main().catch((error) => { console.error("Server error:", error); process.exit(1); });

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/yukukotani/mcp-gemini-google-search'

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