Skip to main content
Glama

rag

Search the web and extract content using intelligent RAG techniques to retrieve, process, and summarize information from web pages for research and analysis.

Instructions

Busca web com extração inteligente de conteúdo (igual Apify RAG Web Browser)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesTermo de busca para pesquisar na web
maxResultsNoMáximo de páginas a processar
outputFormatNoFormato de saída do conteúdomarkdown
contentModeNoModo de conteúdo: preview=resumo truncado (~300 chars), full=conteúdo completo, summary=sumarização inteligente via LLMfull
summaryModelNoModelo Ollama para sumarização (default: llama3.2:1b). Ex: mistral:7b, qwen2.5:0.5b
useJavascriptNoRenderizar JavaScript nas páginas
timeoutNoTimeout para scraping em milissegundos

Implementation Reference

  • The core implementation of the 'rag' tool handler. Searches the web, scrapes and extracts content from top results, applies caching, processes content based on modes (preview/full/summary), and returns formatted results.
    export async function rag(params: RagParams): Promise<RagResult> {
      const {
        query,
        maxResults = 5,
        outputFormat = "markdown",
        contentMode = "full",
        summaryModel,
        useJavascript = false,
        timeout = 30000,
      } = params;
    
      let searchResults: Array<{
        url: string;
        title: string;
        description: string;
      }>;
    
      try {
        searchResults = await searchWeb(query, maxResults);
      } catch (error) {
        return {
          query,
          error: `Busca falhou: ${(error as Error).message}. Tente novamente em alguns minutos.`,
          results: [],
          totalResults: 0,
          searchedAt: new Date().toISOString(),
        };
      }
    
      const pages = await Promise.all(
        searchResults.map(async (result) => {
          const cached = getFromCache(result.url);
          if (cached) {
            return {
              url: result.url,
              title: cached.title,
              markdown: cached.markdown,
              text: cached.content,
              html: cached.content,
              excerpt: "",
              fromCache: true,
            };
          }
    
          try {
            const { html } = await scrapePage(result.url, {
              javascript: useJavascript,
              timeout,
            });
            const extracted = await extractContent(html, result.url);
    
            if (extracted) {
              saveToCache(result.url, {
                content: extracted.textContent,
                markdown: extracted.markdown,
                title: extracted.title,
              });
    
              return {
                url: result.url,
                title: extracted.title,
                markdown: extracted.markdown,
                text: extracted.textContent,
                html: extracted.content,
                excerpt: extracted.excerpt,
                fromCache: false,
              };
            }
          } catch (e) {
            console.error(`Failed to scrape ${result.url}:`, e);
          }
          return null;
        })
      );
    
      const validPages = pages.filter(Boolean) as PageResult[];
    
      const formattedResults = await Promise.all(
        validPages.map(async (p) => {
          const result: any = {
            url: p.url,
            title: p.title,
            fromCache: p.fromCache,
          };
    
          if (contentMode === "preview") {
            result.contentHandle = generateContentHandle(p.url);
          }
    
          if (outputFormat === "markdown") {
            result.markdown = await applyContentMode(p.markdown, contentMode, summaryModel);
          } else if (outputFormat === "text") {
            result.text = await applyContentMode(p.text, contentMode, summaryModel);
          } else if (outputFormat === "html") {
            result.html = await applyContentMode(p.html, contentMode, summaryModel);
          }
    
          if (p.excerpt && contentMode === "full") {
            result.excerpt = p.excerpt;
          }
    
          return result;
        })
      );
    
      return {
        query,
        results: formattedResults,
        totalResults: validPages.length,
        searchedAt: new Date().toISOString(),
      };
    }
  • TypeScript interfaces defining the input parameters (RagParams), intermediate PageResult, and output RagResult for the rag tool.
    interface RagParams {
      query: string;
      maxResults?: number;
      outputFormat?: "markdown" | "text" | "html";
      contentMode?: "preview" | "full" | "summary";
      summaryModel?: string;
      useJavascript?: boolean;
      timeout?: number;
    }
    
    interface PageResult {
      url: string;
      title: string;
      markdown?: string;
      text?: string;
      html?: string;
      excerpt?: string;
      contentHandle?: string;
      fromCache: boolean;
    }
    
    interface RagResult {
      query: string;
      results: PageResult[];
      totalResults: number;
      searchedAt: string;
      error?: string;
    }
  • src/index.ts:17-59 (registration)
    MCP server registration of the 'rag' tool, including name, description, Zod input schema for validation, and a thin wrapper handler that invokes the rag function and returns the result as MCP-formatted content.
    server.tool(
      "rag",
      "Busca web com extração inteligente de conteúdo (igual Apify RAG Web Browser)",
      {
        query: z
          .string()
          .describe("Termo de busca para pesquisar na web"),
        maxResults: z
          .number()
          .int()
          .min(1)
          .max(10)
          .default(5)
          .describe("Máximo de páginas a processar"),
        outputFormat: z
          .enum(["markdown", "text", "html"])
          .default("markdown")
          .describe("Formato de saída do conteúdo"),
        contentMode: z
          .enum(["preview", "full", "summary"])
          .default("full")
          .describe("Modo de conteúdo: preview=resumo truncado (~300 chars), full=conteúdo completo, summary=sumarização inteligente via LLM"),
        summaryModel: z
          .string()
          .optional()
          .describe("Modelo Ollama para sumarização (default: llama3.2:1b). Ex: mistral:7b, qwen2.5:0.5b"),
        useJavascript: z
          .boolean()
          .default(false)
          .describe("Renderizar JavaScript nas páginas"),
        timeout: z
          .number()
          .int()
          .default(30000)
          .describe("Timeout para scraping em milissegundos"),
      },
      async (params) => {
        const result = await rag(params);
        return {
          content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
        };
      }
    );
  • Runtime Zod schema for input validation of the 'rag' tool parameters in the MCP server registration.
    {
      query: z
        .string()
        .describe("Termo de busca para pesquisar na web"),
      maxResults: z
        .number()
        .int()
        .min(1)
        .max(10)
        .default(5)
        .describe("Máximo de páginas a processar"),
      outputFormat: z
        .enum(["markdown", "text", "html"])
        .default("markdown")
        .describe("Formato de saída do conteúdo"),
      contentMode: z
        .enum(["preview", "full", "summary"])
        .default("full")
        .describe("Modo de conteúdo: preview=resumo truncado (~300 chars), full=conteúdo completo, summary=sumarização inteligente via LLM"),
      summaryModel: z
        .string()
        .optional()
        .describe("Modelo Ollama para sumarização (default: llama3.2:1b). Ex: mistral:7b, qwen2.5:0.5b"),
      useJavascript: z
        .boolean()
        .default(false)
        .describe("Renderizar JavaScript nas páginas"),
      timeout: z
        .number()
        .int()
        .default(30000)
        .describe("Timeout para scraping em milissegundos"),
    },
Behavior2/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. While it mentions 'extração inteligente de conteúdo' and references Apify RAG Web Browser, it doesn't describe important behavioral traits like rate limits, authentication requirements, error handling, or what happens when JavaScript rendering is enabled. The description is insufficient for a tool with 7 parameters and complex functionality.

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 a single, efficient sentence that immediately conveys the core functionality. It's appropriately sized and front-loaded with the essential information about what the tool does.

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 complex web search and extraction tool with 7 parameters and no output schema, the description is incomplete. While concise, it doesn't explain what the tool returns, how results are structured, or provide context about the extraction intelligence. With no annotations and no output schema, more completeness would be expected for such a feature-rich tool.

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 documents all parameters thoroughly. The description adds no additional parameter semantics beyond what's in the schema. The baseline of 3 is appropriate when the schema does all the parameter documentation work.

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 performs web search with intelligent content extraction, providing a specific verb ('Busca web') and resource ('conteúdo'). It distinguishes from siblings by mentioning 'extração inteligente de conteúdo' and referencing Apify RAG Web Browser, though it doesn't explicitly differentiate from fetchFullContent, scrape, or screenshot.

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

Usage Guidelines2/5

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

No guidance is provided about when to use this tool versus the sibling tools (fetchFullContent, scrape, screenshot). The description mentions it's similar to Apify RAG Web Browser, but this doesn't help an agent choose between available alternatives in this server.

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/alucardeht/isis-mcp'

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