Skip to main content
Glama
czottmann

kagi-kan-mcp

by czottmann

Kagi Search

kagi_search_fetch

Fetch web search results from Kagi.com using one or multiple queries. Supports result limits and numbered references for easy information retrieval.

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 that performs Kagi searches using the kagi-ken library, handles multiple queries concurrently with timeouts, formats results, and manages errors.
    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),
            },
          ],
        };
      }
    }
  • Zod-based input schema for validating queries and limit parameters of the kagi_search_fetch tool.
    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 defining the name, description, and input schema for the kagi_search_fetch tool.
    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:28-36 (registration)
    Registers the kagi_search_fetch tool with the MCP server, providing config and handler reference.
    this.server.registerTool(
      searchToolConfig.name,
      {
        title: "Kagi Search",
        description: searchToolConfig.description,
        inputSchema: searchToolConfig.inputSchema,
      },
      async (args) => await kagiSearchFetch(args),
    );
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It describes that 'Results are from all queries given' and 'They are numbered continuously,' which adds useful behavioral context beyond basic functionality. However, it doesn't mention rate limits, authentication requirements, error handling, or response format details.

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

Conciseness4/5

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

The description is efficiently structured in three sentences that each serve a distinct purpose: stating the core functionality, providing usage guidelines, and explaining result numbering and parameter support. It's appropriately sized without wasted words, though could be slightly more front-loaded.

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?

For a search tool with 2 parameters, 100% schema coverage, and no output schema, the description provides adequate context about what the tool does and when to use it. However, without annotations or output schema, it lacks details about response format, error conditions, and operational constraints that would be helpful for an AI agent.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already fully documents both parameters. The description adds marginal value by mentioning 'Supports optional limit parameter to control results per query' and implying queries should be 'concise, keyword-focused' through context, but doesn't provide additional semantic details beyond what's in the schema.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Fetch web results based on one or more queries using the Kagi.com web search engine.' It specifies the verb ('fetch'), resource ('web results'), and engine ('Kagi.com'), but doesn't explicitly differentiate from its sibling 'kagi_summarizer' beyond the general search focus.

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 provides clear usage context: 'Use for general search and when the user explicitly tells you to 'fetch' results/information.' This gives practical guidance on when to invoke the tool, though it doesn't explicitly mention when NOT to use it or contrast with the summarizer sibling.

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