kagi_search
Execute web searches via Kagi’s API, enabling precise results retrieval using query parameters and customizable limits for efficient data access.
Instructions
Perform web search using Kagi
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | ||
| query | Yes |
Implementation Reference
- src/index.ts:86-120 (handler)The MCP tool handler for 'kagi_search' that validates arguments (query string required, limit 1-100 optional), constructs SearchParams, calls KagiAPI.search, and returns results or handles KagiError.
if (request.params.name === "kagi_search") { if (!request.params.arguments || typeof request.params.arguments !== 'object') { throw new McpError(ErrorCode.InvalidParams, "Invalid arguments for kagi_search"); } const { query, limit } = request.params.arguments as { query?: unknown; limit?: unknown }; if (typeof query !== 'string') { throw new McpError(ErrorCode.InvalidParams, "Query must be a string"); } const searchParams: SearchParams = { q: query, }; if (limit !== undefined) { if (typeof limit !== 'number' || limit < 1 || limit > 100) { throw new McpError(ErrorCode.InvalidParams, "Limit must be a number between 1 and 100"); } searchParams.limit = limit; } try { const results = await this.kagiApi.search(searchParams); return { toolResult: results }; } catch (error) { if (error instanceof KagiError) { return { content: [{ type: "text", text: `Kagi API error: ${error.message}` }], isError: true, }; } throw error; } } - src/index.ts:61-77 (schema)Tool metadata and input schema definition for 'kagi_search', used in tool listing and validation.
const searchTool = { name: "kagi_search", description: "Perform web search using Kagi", inputSchema: { type: "object", properties: { query: { type: "string" }, limit: { type: "number", default: 10, minimum: 1, maximum: 100 } }, required: ["query"] } }; - src/index.ts:79-83 (registration)Registers the 'kagi_search' tool by returning it in the MCP ListToolsRequest handler.
this.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [searchTool] }; }); - src/api.ts:75-83 (helper)Core implementation of the search functionality in KagiAPI, making HTTP GET to Kagi's /search endpoint with query and limit parameters.
async search(params: SearchParams): Promise<SearchResponse> { const response = await this.client.get<SearchResponse>('/search', { params: { q: params.q, limit: params.limit || 10 } }); return response.data; } - src/types.ts:167-172 (helper)TypeScript interface defining the SearchParams used by the kagi_search tool and API.
export interface SearchParams { /** Search query string */ q: string; /** Maximum number of results to return */ limit?: number; }