Skip to main content
Glama
czottmann

kagi-kan-mcp

by czottmann

kagi_summarizer

Summarize web content from any URL into concise prose or key points using Kagi's API, supporting various document types including text, video, and audio.

Instructions

Summarize content from a URL using the Kagi.com Summarizer API. The Summarizer can summarize any document type (text webpage, video, audio, etc.)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesA URL to a document to summarize.
summary_typeNoType of summary to produce. Options are 'summary' for paragraph prose and 'takeaway' for a bulleted list of key points.summary
target_languageNoDesired output language using language codes (e.g., 'EN' for English). If not specified, the document's original language influences the output.

Implementation Reference

  • Core handler function that executes the kagi_summarizer tool: validates inputs, calls kagi-ken summarize, handles response formatting and errors.
    export async function kagiSummarizer(
      { url, summary_type = "summary", target_language },
    ) {
      try {
        if (!url) {
          throw new Error("Summarizer called with no URL.");
        }
    
        const { token, engine } = getEnvironmentConfig();
    
        // Validate summary type
        if (!["summary", "takeaway"].includes(summary_type)) {
          throw new Error(
            `Invalid summary_type: ${summary_type}. Must be 'summary' or 'takeaway'.`,
          );
        }
    
        // Set default language if not provided
        const language = target_language || "EN";
    
        // Validate language if provided
        if (
          target_language && SUPPORTED_LANGUAGES &&
          !SUPPORTED_LANGUAGES.includes(language)
        ) {
          console.warn(
            `Warning: Language '${language}' may not be supported. Supported languages: ${
              SUPPORTED_LANGUAGES.join(", ")
            }`,
          );
        }
    
        // Note about engine compatibility
        if (engine && engine !== "default") {
          console.warn(
            `Note: Engine selection (${engine}) from KAGI_SUMMARIZER_ENGINE may not be supported by kagi-ken. Using default behavior.`,
          );
        }
    
        // Prepare options for kagi-ken
        const options = {
          type: summary_type,
          language: language,
          isUrl: true,
        };
    
        // Call kagi-ken summarize function
        const result = await summarize(url, token, options);
    
        // Extract the summary text from the result
        // The structure may vary, so we'll try different possible response formats
        let summaryText;
        if (typeof result === "string") {
          summaryText = result;
        } else if (result && result.summary) {
          summaryText = result.summary;
        } else if (result && result.data && result.data.output) {
          summaryText = result.data.output;
        } else if (result && result.output) {
          summaryText = result.output;
        } else {
          // Fallback: stringify the result if it's not in expected format
          summaryText = JSON.stringify(result, null, 2);
        }
    
        return {
          content: [
            {
              type: "text",
              text: summaryText,
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: formatError(error),
            },
          ],
        };
      }
    }
  • Input schema for the kagi_summarizer tool using Zod for validation of url, summary_type, and target_language parameters.
    export const summarizerInputSchema = {
      url: z.string().url().describe("A URL to a document to summarize."),
      summary_type: z.enum(["summary", "takeaway"]).default("summary").describe(
        "Type of summary to produce. Options are 'summary' for paragraph prose and 'takeaway' for a bulleted list of key points.",
      ),
      target_language: z.string().optional().describe(
        "Desired output language using language codes (e.g., 'EN' for English). If not specified, the document's original language influences the output.",
      ),
    };
  • src/index.js:38-47 (registration)
    MCP server registration of the kagi_summarizer tool, specifying name, title, description, inputSchema, and the handler function.
    // Register summarizer tool
    this.server.registerTool(
      summarizerToolConfig.name,
      {
        title: "Kagi Summarizer",
        description: summarizerToolConfig.description,
        inputSchema: summarizerToolConfig.inputSchema,
      },
      async (args) => await kagiSummarizer(args),
    );
  • Tool configuration object including name, description, and reference to inputSchema, used during server registration.
    export const summarizerToolConfig = {
      name: "kagi_summarizer",
      description: `
        Summarize content from a URL using the Kagi.com Summarizer API. The Summarizer can summarize any
        document type (text webpage, video, audio, etc.)
        `.replace(/\s+/gs, " ").trim(),
      inputSchema: summarizerInputSchema,
    };
  • Helper utility to retrieve Kagi API token and summarizer engine configuration from environment variables, used in the handler.
    export function getEnvironmentConfig() {
      const token = resolveToken();
    
      // Note: kagi-ken might not support engine selection like the official API
      // We'll keep this for compatibility but may not use it
      const engine = process.env.KAGI_SUMMARIZER_ENGINE || "default";
    
      return { token, engine };
    }
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