Skip to main content
Glama
AutomateLab-tech

automatelab-ai-seo

Official

rewrite_for_aeo

Optimize content for answer engines like ChatGPT and Google AI Overviews by restructuring with BLUF, FAQ schema, and query-driven headings.

Instructions

Rewrite a content block for Answer Engine Optimization. Adds a BLUF opening, FAQ structure, schema additions, and concise question-shaped headings tuned for ChatGPT / Perplexity / Google AI Overviews.

Read-only when given url (one HTTP GET). Zero network when given text. The tool does NOT write back to the URL - it only returns the rewritten content as a string. No side effects on the source.

This tool delegates the actual rewrite to the calling LLM via MCP sampling - it does not call any external API itself. The MCP host's model produces the rewrite. Same input may produce different output across runs (model-dependent).

When to use: optimizing content for direct-answer surfaces (definitions, how-tos, FAQs). For Generative Engine Optimization (entity-rich, comparison-ready synthesis), use rewrite_for_geo instead.

Either url or text must be provided. target_query is required.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlNoPublic URL whose content should be fetched and rewritten. Either this OR `text` is required.
textNoRaw content (markdown or HTML) to rewrite directly. Either this OR `url` is required.
target_queryYesThe user query the rewrite should answer (e.g. `what is RAG`, `how to deploy Ghost to Docker`). Required - drives heading shape and BLUF wording.
formatNoOutput shape. `article` for prose-with-headings. `faq` for Q&A list. `howto` for numbered-step procedural content with HowTo schema hints. `comparison` for X-vs-Y tables. Default `article`.article
max_wordsNoSoft word budget for the rewrite. Default 1500. Range 100-5000. The rewrite tries to stay under this; very small budgets may force truncation.
respect_robotsNoIf true (default), respect robots.txt when fetching `url`. Ignored when `text` is used.

Implementation Reference

  • The core handler function `rewriteForAeo` that executes the tool logic: fetches URL content (or uses provided text), scores citation worthiness before rewrite, attempts MCP sampling to rewrite content via LLM, and falls back to returning a prompt template.
    export async function rewriteForAeo(
      input: RewriteForAeoInput,
      hostDelays?: HostDelayMap,
      robotsCache?: Map<string, string>,
      server?: McpServer
    ): Promise<RewriteAeoResult> {
      // Fetch URL if provided
      let originalText = input.text ?? "";
      if (input.url) {
        const result = await politeFetch(input.url, {
          respectRobots: input.respect_robots,
          hostDelays,
          robotsCache,
        });
        const body = parseBody(result.body, input.url);
        originalText = body.bodyText.substring(0, 8000);
      }
    
      // Compute before score
      const beforeResult = await scoreCitationWorthiness(
        { text: originalText, target_query: input.target_query, respect_robots: false },
        hostDelays,
        robotsCache
      );
      const before_score = beforeResult.overall_score;
    
      const userMessage = `Target query: "${input.target_query}"
    Format: ${input.format}
    Max words: ${input.max_words}
    
    Original content:
    ---
    ${originalText.substring(0, 4000)}
    ---
    
    Rewrite this content for AEO. Return your response as JSON with these fields:
    - rewritten_text: the rewritten content (Markdown)
    - schema_additions: JSON-LD string to add to the page <head>
    - changes_made: array of strings describing each change applied`;
    
      // Attempt MCP sampling
      if (server) {
        try {
          // eslint-disable-next-line @typescript-eslint/ban-ts-comment
          // @ts-ignore - sampling API availability varies by client; not typed in all SDK versions
          const samplingResult = await server.server.request(
            {
              method: "sampling/createMessage",
              params: {
                messages: [{ role: "user", content: { type: "text", text: userMessage } }],
                systemPrompt: AEO_SYSTEM_PROMPT,
                maxTokens: 4096,
              },
            },
            // eslint-disable-next-line @typescript-eslint/no-explicit-any
            {} as any
          );
          const text =
            samplingResult?.content?.text ?? samplingResult?.content?.[0]?.text ?? "";
          if (text) {
            try {
              // Extract JSON from response (may be wrapped in markdown code blocks)
              const jsonMatch = text.match(/```json\n([\s\S]+?)\n```/) ?? text.match(/\{[\s\S]+\}/);
              const jsonStr = jsonMatch ? jsonMatch[1] ?? jsonMatch[0] : text;
              const parsed = JSON.parse(jsonStr) as {
                rewritten_text: string;
                schema_additions: string;
                changes_made: string[];
              };
    
              const afterResult = await scoreCitationWorthiness(
                { text: parsed.rewritten_text, target_query: input.target_query, respect_robots: false },
                hostDelays,
                robotsCache
              );
    
              return {
                rewritten_text: parsed.rewritten_text,
                schema_additions: parsed.schema_additions,
                changes_made: parsed.changes_made ?? [],
                before_score,
                after_score: afterResult.overall_score,
                mode: "sampling",
              };
            } catch {
              // JSON parse failed - fall through to prompt template
            }
          }
        } catch {
          // Sampling unavailable or failed - fall through to prompt template
        }
      }
    
      // Prompt template fallback
      const promptTemplate = `${AEO_SYSTEM_PROMPT}
    
    ${userMessage}`;
    
      return {
        rewritten_text: promptTemplate,
        schema_additions: "",
        changes_made: [
          "sampling/createMessage unavailable - returned prompt template for manual use",
        ],
        before_score,
        after_score: before_score, // unchanged since we did not rewrite
        mode: "prompt_template",
      };
    }
  • Zod input schema for the tool: url, text, target_query, format, max_words, respect_robots.
    export const rewriteForAeoInputSchema = z
      .object({
        url: z.string().url().optional(),
        text: z.string().optional(),
        target_query: z.string(),
        format: z.enum(["article", "faq", "howto", "comparison"]).default("article"),
        max_words: z.number().int().min(100).max(5000).optional().default(1500),
        respect_robots: z.boolean().optional().default(true),
      })
      .refine((d) => d.url !== undefined || d.text !== undefined, {
        message: "One of url or text is required",
      });
  • Result interface `RewriteAeoResult` defining the output shape: rewritten_text, schema_additions, changes_made, before_score, after_score, mode.
    export interface RewriteAeoResult {
      rewritten_text: string;
      schema_additions: string;
      changes_made: string[];
      before_score: number;
      after_score: number;
      mode: "sampling" | "prompt_template";
    }
  • src/index.ts:253-302 (registration)
    Tool registration via `server.tool('rewrite_for_aeo', ...)` with description, Zod input schema, and handler that calls `rewriteForAeo`.
    // --- Tool 11: rewrite_for_aeo ---
    server.tool(
      "rewrite_for_aeo",
      [
        "Rewrite a content block for Answer Engine Optimization. Adds a BLUF opening, FAQ structure, schema additions, and concise question-shaped headings tuned for ChatGPT / Perplexity / Google AI Overviews.",
        "Read-only when given `url` (one HTTP GET). Zero network when given `text`. The tool does NOT write back to the URL - it only returns the rewritten content as a string. No side effects on the source.",
        "This tool delegates the actual rewrite to the calling LLM via MCP sampling - it does not call any external API itself. The MCP host's model produces the rewrite. Same input may produce different output across runs (model-dependent).",
        "When to use: optimizing content for direct-answer surfaces (definitions, how-tos, FAQs). For Generative Engine Optimization (entity-rich, comparison-ready synthesis), use `rewrite_for_geo` instead.",
        "Either `url` or `text` must be provided. `target_query` is required.",
      ].join("\n\n"),
      {
        url: z
          .string()
          .url()
          .optional()
          .describe("Public URL whose content should be fetched and rewritten. Either this OR `text` is required."),
        text: z
          .string()
          .optional()
          .describe("Raw content (markdown or HTML) to rewrite directly. Either this OR `url` is required."),
        target_query: z
          .string()
          .describe("The user query the rewrite should answer (e.g. `what is RAG`, `how to deploy Ghost to Docker`). Required - drives heading shape and BLUF wording."),
        format: z
          .enum(["article", "faq", "howto", "comparison"])
          .default("article")
          .describe("Output shape. `article` for prose-with-headings. `faq` for Q&A list. `howto` for numbered-step procedural content with HowTo schema hints. `comparison` for X-vs-Y tables. Default `article`."),
        max_words: z
          .number()
          .int()
          .min(100)
          .max(5000)
          .optional()
          .default(1500)
          .describe("Soft word budget for the rewrite. Default 1500. Range 100-5000. The rewrite tries to stay under this; very small budgets may force truncation."),
        respect_robots: z
          .boolean()
          .optional()
          .default(true)
          .describe("If true (default), respect robots.txt when fetching `url`. Ignored when `text` is used."),
      },
      async (input) => {
        if (!input.url && !input.text) {
          return toolError({ type: "invalid_url", message: "One of url or text is required" });
        }
        return wrapHandler(() =>
          rewriteForAeo(input as Parameters<typeof rewriteForAeo>[0], undefined, undefined, server)
        );
      }
    );
  • AEO_SYSTEM_PROMPT constant used as the system prompt for the LLM rewrite.
    const AEO_SYSTEM_PROMPT = `You are an Answer Engine Optimization (AEO) specialist. Rewrite the provided content to maximize AI engine citation probability.
    
    Rules:
    1. Open with a direct 40-60 word answer to the target query (BLUF - Bottom Line Up Front).
    2. Structure body content into FAQ format: H3 questions ending in "?" followed by 40-60 word answers.
    3. Include at least one ordered list for procedural content.
    4. Define key technical terms inline (e.g., "X is a type of Y that...").
    5. Cite statistics with year and source where present.
    6. End with a "Key Takeaways" or "Summary" section.
    7. No em-dashes. No filler phrases ("In conclusion", "It is important to note").
    8. Keep within the max_words limit.
    9. For howto format: use numbered HowToStep structure.
    10. For comparison format: include a comparison table.
    
    Also generate a JSON-LD schema block appropriate for the content type and format.`;
Behavior5/5

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

Without annotations, the description fully discloses behavioral traits: read-only network access, no side effects, delegation to LLM via MCP sampling, non-deterministic output. It addresses potential concerns about destructive actions and external API calls.

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 concise at ~120 words, well-structured into paragraphs with front-loaded purpose, behavioral details, usage, and input requirements. Every sentence adds value without redundancy.

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

Completeness4/5

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

The description covers input, behavior, side effects, and usage context. It states output is a string but does not specify format (e.g., markdown or HTML) which could be inferred from input. Output schema is absent, so the description does its job well but could be slightly more explicit.

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 each parameter is already documented. The description adds no new parameter information beyond restating requirements. It achieves the baseline 3.

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 rewrites content for Answer Engine Optimization, adding specific elements like BLUF opening, FAQ structure, and schema additions. It distinguishes itself from the sibling tool rewrite_for_geo by specifying the alternative use case.

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

Usage Guidelines5/5

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

The description explicitly says when to use (optimizing for direct-answer surfaces) and when not to use (for GEO, use rewrite_for_geo). It also provides input requirements: either url or text must be provided, and target_query is required.

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/AutomateLab-tech/ai-seo'

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