Skip to main content
Glama
czottmann

kagi-kan-mcp

by czottmann

Kagi Search

kagi_search_fetch

Fetch web search results from multiple queries, numbered continuously for easy reference. Control the number of results per query with an optional limit.

Instructions

Fetch web results based on one or more queries using the Kagi.com web search engine. Use for general search and when the user explicitly tells you to 'fetch' results/information. Results are from all queries given. They are numbered continuously, so that a user may be able to refer to a result by a specific number. Supports optional limit parameter to control results per query.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queriesYesOne or more concise, keyword-focused search queries. Include essential context within each query for standalone use.
limitNoMaximum number of search results per query (default: 10, max: 50)

Implementation Reference

  • Main handler function for the kagi_search_fetch tool. Executes concurrent searches using kagi-ken, applies timeout, processes results (fulfilled/rejected), formats output, and returns MCP-compatible response.
    export async function kagiSearchFetch({ queries, limit = 10 }) {
      try {
        if (!queries || queries.length === 0) {
          throw new Error("Search called with no queries.");
        }
    
        const { token } = getEnvironmentConfig();
    
        // Execute searches concurrently (similar to ThreadPoolExecutor in original)
        const searchPromises = queries.map((query) => {
          if (typeof query !== "string" || query.trim() === "") {
            throw new Error("All queries must be non-empty strings");
          }
          return search(query.trim(), token, limit);
        });
    
        // Wait for all searches to complete with 10 second timeout per search
        const results = await Promise.allSettled(
          searchPromises.map((promise) =>
            Promise.race([
              promise,
              new Promise((_, reject) =>
                setTimeout(() => reject(new Error("Search timeout")), 10000)
              ),
            ])
          ),
        );
    
        // Process results and handle any failures
        const responses = [];
        const errors = [];
    
        for (let i = 0; i < results.length; i++) {
          const result = results[i];
          if (result.status === "fulfilled") {
            responses.push(result.value);
          } else {
            errors.push(
              `Query "${queries[i]}": ${result.reason?.message || result.reason}`,
            );
            // Add empty response to maintain index alignment
            responses.push({ results: [] });
          }
        }
    
        // Format results using the same formatting as official MCP
        const formattedResults = formatSearchResults(queries, responses);
    
        // Include any errors in the response
        let finalResponse = formattedResults;
        if (errors.length > 0) {
          finalResponse += "\n\nErrors encountered:\n" + errors.join("\n");
        }
    
        return {
          content: [
            {
              type: "text",
              text: finalResponse,
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: formatError(error),
            },
          ],
        };
      }
    }
  • Input schema for kagi_search_fetch tool using Zod. Defines 'queries' (array of strings, min 1) and optional 'limit' (int 1-50, default 10).
    export const searchInputSchema = {
      queries: z.array(z.string()).min(1).describe(
        "One or more concise, keyword-focused search queries. Include essential context within each query for standalone use.",
      ),
      limit: z.number().int().min(1).max(50).optional().describe(
        "Maximum number of search results per query (default: 10, max: 50)",
      ),
    };
  • Tool configuration object (searchToolConfig) that registers the tool name 'kagi_search_fetch' along with its description and inputSchema.
    export const searchToolConfig = {
      name: "kagi_search_fetch",
      description: `
        Fetch web results based on one or more queries using the Kagi.com web search engine. Use for
        general search and when the user explicitly tells you to 'fetch' results/information. Results are
        from all queries given. They are numbered continuously, so that a user may be able to refer to a
        result by a specific number. Supports optional limit parameter to control results per query.
        `.replace(/\s+/gs, " ").trim(),
      inputSchema: searchInputSchema,
    };
  • src/index.js:33-41 (registration)
    MCP server registration of kagi_search_fetch tool using searchToolConfig.name and binding the kagiSearchFetch handler via server.registerTool().
    this.server.registerTool(
      searchToolConfig.name,
      {
        title: "Kagi Search",
        description: searchToolConfig.description,
        inputSchema: searchToolConfig.inputSchema,
      },
      async (args) => await kagiSearchFetch(args),
    );
  • Helper function formatSearchResults that formats raw search results from kagi-ken into the official Kagi MCP output format, numbering results continuously across queries.
    export function formatSearchResults(queries, responses) {
      const resultTemplate = (resultNumber, title, url, published, snippet) =>
        `${resultNumber}: ${title}
    ${url}
    Published Date: ${published}
    ${snippet}`;
    
      const queryResponseTemplate = (query, formattedSearchResults) =>
        `-----
    Results for search query "${query}":
    -----
    ${formattedSearchResults}`;
    
      const perQueryResponseStrs = [];
      let startIndex = 1;
    
      for (let i = 0; i < queries.length; i++) {
        const query = queries[i];
        const response = responses[i];
    
        // Filter for actual search results only (t === 0), excluding related searches (t === 1)
        const results = (response?.results || response?.data || [])
          .filter((item) => item.t === 0);
    
        const formattedResultsList = results.map((result, index) => {
          const resultNumber = startIndex + index;
          return resultTemplate(
            resultNumber,
            result.title || "No Title",
            result.url || "",
            result.published || result.publishedDate || "Not Available",
            result.snippet || result.description || "No snippet available",
          );
        });
    
        startIndex += results.length;
    
        const formattedResultsStr = formattedResultsList.join("\n\n");
        const queryResponseStr = queryResponseTemplate(query, formattedResultsStr);
        perQueryResponseStrs.push(queryResponseStr);
      }
    
      return perQueryResponseStrs.join("\n\n");
    }
Behavior3/5

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

No annotations are provided, so the description carries the full burden. It explains that results from multiple queries are merged and numbered continuously, which is helpful beyond the schema. However, it does not disclose auth requirements, rate limits, or error behavior, leaving gaps.

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

Conciseness5/5

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

The description is composed of three concise sentences, each adding necessary information. It front-loads the purpose and provides essential behavioral details without fluff. Every sentence earns its place.

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

Completeness3/5

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

Given the simplicity of the tool, the description covers the main purpose and behavior. However, with no output schema, it lacks details about the response structure (e.g., result fields), which an agent may need to interpret results. It is adequate but not fully complete for a tool with no annotations.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so baseline is 3. The description adds value by explaining how the queries parameter affects output (combined, numbered), which is not in the schema. The limit parameter description in the text is redundant with the schema, but the added context for queries raises the score.

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

Purpose5/5

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

The description clearly states the tool fetches web results using Kagi search, specifying the action ('fetch') and resource ('web results'). It also provides a specific usage hint ('when the user tells you to fetch'), which distinguishes it from general tasks.

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

Usage Guidelines4/5

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

The description explicitly says 'Use for general search and when the user explicitly tells you to fetch results/information.' This gives clear context for when to invoke, though it does not mention alternatives or when not to use, missing some guidance.

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/czottmann/kagi-ken-mcp'

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