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
| Name | Required | Description | Default |
|---|---|---|---|
| q | Yes | Search 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 })) ); - src/index.ts:82-82 (schema)Input schema definition for 'search_ai' tool: requires a 'q' string parameter for the search query
{ q: z.string().describe("Search query") }, - src/index.ts:83-83 (handler)Handler function for 'search_ai' tool: calls apiGet('/search/ai', { q }) and wraps result with jsonResult
async ({ q }) => jsonResult(await apiGet("/search/ai", { q })) - src/index.ts:20-39 (helper)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); } } - src/index.ts:61-63 (helper)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) }] }; }