Skip to main content
Glama
mcp-for-dev

MCP Server for Google Search

by mcp-for-dev

google_search

Execute web searches to find information, answer questions, and retrieve relevant results from the internet.

Instructions

Perform a web search query

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query
numNoNumber of results (1-10)

Implementation Reference

  • The main handler function that performs the Google Custom Search API query, processes results into title/link/snippet format, and returns them as JSON text content.
    private async handleSearch(query: string, num = 10) { try { const response = await this.client.get('', { params: { q: query, num: Math.min(num, 10), }, }); const results: SearchResult[] = response.data.items.map((item: any) => ({ title: item.title, link: item.link, snippet: item.snippet, })); return { content: [{ type: 'text', text: JSON.stringify(results, null, 2), }], }; } catch (error: unknown) { return { content: [{ type: 'text', text: `Search API error: ${error instanceof Error ? error.message : String(error)}`, }], isError: true, }; } }
  • Defines the tool schema for 'google_search', including name, description, and input schema with query (required) and optional num results.
    const searchToolSchema = { name: 'google_search', description: 'Perform a web search query', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Search query', }, num: { type: 'number', description: 'Number of results (1-10)', minimum: 1, maximum: 10, }, }, required: ['query'], }, };
  • src/index.ts:182-187 (registration)
    Registers the CallToolRequestSchema handler which dispatches tool calls, specifically checking for 'google_search' and invoking the handleSearch function.
    this.server.setRequestHandler(CallToolRequestSchema, async (request) => { // Handle search tool if (request.params.name === 'google_search') { const {query, num = 10} = request.params.arguments as { query: string; num?: number }; return await this.handleSearch(query, num); }
  • src/index.ts:178-180 (registration)
    Registers the ListToolsRequestSchema handler that returns tool definitions, including the 'google_search' schema via getToolDefinitions().
    this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: this.getToolDefinitions(), }));

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/mcp-for-dev/mcp-google-search'

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