Skip to main content
Glama

search_ai

Perform web searches to retrieve structured, source-cited data optimized for AI agents and RAG applications.

Instructions

RAG-ready web search with context and sources. Primary tool for AI agents — returns structured context optimized for LLM consumption. Costs 2 credits.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
qYesSearch query

Implementation Reference

  • src/index.ts:79-84 (registration)
    Registration of the 'search_ai' tool using server.tool() with name, description, schema, and handler
    server.tool(
      "search_ai",
      "RAG-ready web search with context and sources. Primary tool for AI agents — returns structured context optimized for LLM consumption. Costs 2 credits.",
      { q: z.string().describe("Search query") },
      async ({ q }) => jsonResult(await apiGet("/search/ai", { q }))
    );
  • Input schema definition for 'search_ai' tool: requires a 'q' string parameter for the search query
    { q: z.string().describe("Search query") },
  • Handler function for 'search_ai' tool: calls apiGet('/search/ai', { q }) and wraps result with jsonResult
    async ({ q }) => jsonResult(await apiGet("/search/ai", { q }))
  • apiGet helper function that makes HTTP GET requests to the SearchClaw API with timeout and error handling
    async function apiGet(path: string, params?: Record<string, string>) {
      const url = new URL(`${API_BASE}${path}`);
      if (params) {
        for (const [key, value] of Object.entries(params)) {
          url.searchParams.set(key, value);
        }
      }
      const controller = new AbortController();
      const timeout = setTimeout(() => controller.abort(), 30000);
      try {
        const response = await fetch(url.toString(), { headers, signal: controller.signal });
        if (!response.ok) {
          const text = await response.text();
          throw new Error(`SearchClaw API error ${response.status}: ${text}`);
        }
        return response.json();
      } finally {
        clearTimeout(timeout);
      }
    }
  • jsonResult helper function that formats API responses as MCP content with JSON text
    function jsonResult(data: unknown) {
      return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] };
    }

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/CSteenkamp/searchclaw-mcp'

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