Skip to main content
Glama
mcp-for-dev

MCP Server for Google Search

by mcp-for-dev

google_search

Perform a web search with a query and control result count (1-10). Leverages Google Custom Search API for web data retrieval.

Instructions

Perform a web search query

Input Schema

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

Implementation Reference

  • The core handler function for google_search. Calls Google Custom Search API with the query and num parameters, returns results 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,
            };
        }
    }
  • The input schema definition for the google_search tool. Defines 'query' (required string) and 'num' (optional number, 1-10).
    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:177-200 (registration)
    Registration of the google_search tool via the MCP CallToolRequestSchema handler. Dispatches to handleSearch() when tool name matches 'google_search'. Also lists the tool via ListToolsRequestSchema.
    private setupToolHandlers() {
        this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
            tools: this.getToolDefinitions(),
        }));
    
        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);
            }
    
            // Handle read_webpage tool
            if (request.params.name === 'read_webpage') {
                const {url} = request.params.arguments as { url: string };
                return await this.handleReadWebpage(url);
            }
    
            // If the tool name is not recognized, throw an error
            throw new McpError(
                ErrorCode.MethodNotFound,
                `Unknown tool: ${request.params.name}`
            );
        });
  • The SearchResult interface used to type the data returned by the google_search tool.
    interface SearchResult {
  • Axios client configured to call the Google Custom Search API, used by the google_search handler.
    this.client = axios.create({
        baseURL: 'https://www.googleapis.com/customsearch/v1',
        params: {
            key: API_KEY,
            cx: SEARCH_ENGINE_ID,
        },
    });
Behavior2/5

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

No annotations provided, and the description does not disclose any behavioral traits such as rate limits, caching, or return format. The agent is left without important context for safe invocation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single concise sentence, but it is too minimal. While there is no wasted text, it lacks structure (e.g., separating purpose from usage details).

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the simple structure (2 parameters, no output schema), the description fails to mention return behavior or result format, leaving the agent unaware of what to expect after invocation.

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?

The input schema has 100% description coverage for both parameters, so the schema itself provides the meaning. The description adds no further semantic value beyond restating the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Perform a web search query' clearly indicates the tool's verb and resource, distinguishing it from the sibling 'read_webpage' which reads a specific page.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this tool vs. alternatives (e.g., read_webpage) or any prerequisites. The description lacks explicit usage context.

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

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