Skip to main content
Glama

search

Perform web searches to find relevant information by entering search queries and specifying the number of results needed.

Instructions

Perform a web search query

Input Schema

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

Implementation Reference

  • Main handler for the 'search' tool: validates args, calls Google Custom Search API, maps results to SearchResult format, returns JSON stringified results or error.
    if (request.params.name === 'search') { if (!isValidSearchArgs(request.params.arguments)) { throw new McpError( ErrorCode.InvalidParams, 'Invalid search arguments' ); } const { query, num = 5 } = request.params.arguments; try { const response = await this.axiosInstance.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) { if (axios.isAxiosError(error)) { return { content: [ { type: 'text', text: `Search API error: ${ error.response?.data?.error?.message ?? error.message }`, }, ], isError: true, }; } throw error; } } else if (request.params.name === 'read_webpage') {
  • src/index.ts:89-108 (registration)
    Registration of the 'search' tool in the ListToolsRequest handler, including name, description, and input schema.
    { name: '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'], }, },
  • Input schema for the 'search' tool defining query (required string) and optional num (1-10).
    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'], },
  • Helper function to validate search tool arguments.
    const isValidSearchArgs = ( args: any ): args is { query: string; num?: number } => typeof args === 'object' && args !== null && typeof args.query === 'string' && (args.num === undefined || typeof args.num === 'number');
  • TypeScript interface defining the structure of search results.
    interface SearchResult { title: string; link: string; snippet: string; }

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/pgzhang/mcp2'

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