Skip to main content
Glama
AutomateLab-tech

automatelab-ai-seo

Official

extract_entities

Extract named entities, linked concepts, and sameAs graph nodes from web page content and structured data to build entity maps for schema generation or audit topic alignment.

Instructions

Extract named entities, linked concepts, and sameAs graph nodes from a page's content and structured data. Combines body-text NER heuristics with JSON-LD @type / sameAs walking.

Read-only when given url (one HTTP GET). Zero network when given text.

Deterministic, rule-based; no LLM. Output is a list of entities with type, confidence, and any sameAs URIs found in structured data.

When to use: building an entity map for schema generation, or auditing whether a page's entities match its target topic. To validate the JSON-LD itself, use audit_schema.

Either url or text must be provided.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlNoPublic URL to fetch and analyze. Either this OR `text` is required.
textNoRaw text/HTML to analyze directly. Either this OR `url` is required.
respect_robotsNoIf true (default), respect robots.txt when fetching `url`. Ignored when `text` is used.

Implementation Reference

  • Main handler function for extract_entities: fetches URL (or uses provided text), parses body text and JSON-LD, extracts entities from both sources, merges them, computes citation density score, and generates findings about entity coverage.
    export async function extractEntities(
      input: ExtractEntitiesInput,
      hostDelays?: HostDelayMap,
      robotsCache?: Map<string, string>
    ): Promise<ExtractEntitiesResult> {
      const findings: Finding[] = [];
      let bodyText = "";
      let jsonLdBlocks: ReturnType<typeof parseJsonLd> = [];
    
      if (input.url) {
        const result = await politeFetch(input.url, {
          respectRobots: input.respect_robots,
          hostDelays,
          robotsCache,
        });
        const pageData = parseBody(result.body, input.url);
        bodyText = pageData.bodyText;
        jsonLdBlocks = parseJsonLd(result.body);
      } else {
        bodyText = input.text!;
      }
    
      const jsonLdEntities = extractJsonLdEntities(jsonLdBlocks);
      const textEntities = extractTextEntities(bodyText);
      const entities = mergeEntities(jsonLdEntities, textEntities, bodyText);
    
      const entity_count = entities.length;
      const connected_entity_count = entities.filter((e) => e.same_as.length > 0).length;
      // Threshold: 15 connected entities = score of 100
      const citation_density_score = Math.min(100, Math.round((connected_entity_count / 15) * 100));
    
      if (entity_count === 0) {
        findings.push({
          severity: "warning",
          category: "authority",
          where: "page-level",
          message: "No named entities detected on this page.",
          fix: "Add JSON-LD schema with named entities (Organization, Person, Product) and sameAs links.",
          estimated_impact: "medium",
        });
      } else if (connected_entity_count < 5) {
        findings.push({
          severity: "warning",
          category: "authority",
          where: "page-level",
          message: `Only ${connected_entity_count} entities have sameAs links. Pages with 15+ connected entities have 4.8x higher AI citation probability.`,
          fix: "Add sameAs links to JSON-LD entity nodes pointing to Wikidata, Wikipedia, LinkedIn, or official brand sites.",
          estimated_impact: "high",
        });
      }
    
      return {
        entities,
        entity_count,
        connected_entity_count,
        citation_density_score,
        findings,
      };
    }
  • Zod input schema (url, text, respect_robots) and TypeScript output interface (entities, entity_count, connected_entity_count, citation_density_score, findings).
    export const extractEntitiesInputSchema = z
      .object({
        url: z.string().url().optional(),
        text: z.string().optional(),
        respect_robots: z.boolean().optional().default(true),
      })
      .refine((d) => d.url !== undefined || d.text !== undefined, {
        message: "One of url or text is required",
      });
  • src/index.ts:356-388 (registration)
    MCP server registration of extract_entities tool with description, inline Zod parameter schema, and handler that wraps extractEntities.
    // --- Tool 13: extract_entities ---
    server.tool(
      "extract_entities",
      [
        "Extract named entities, linked concepts, and sameAs graph nodes from a page's content and structured data. Combines body-text NER heuristics with JSON-LD `@type` / `sameAs` walking.",
        "Read-only when given `url` (one HTTP GET). Zero network when given `text`.",
        "Deterministic, rule-based; no LLM. Output is a list of entities with type, confidence, and any sameAs URIs found in structured data.",
        "When to use: building an entity map for schema generation, or auditing whether a page's entities match its target topic. To validate the JSON-LD itself, use `audit_schema`.",
        "Either `url` or `text` must be provided.",
      ].join("\n\n"),
      {
        url: z
          .string()
          .url()
          .optional()
          .describe("Public URL to fetch and analyze. Either this OR `text` is required."),
        text: z
          .string()
          .optional()
          .describe("Raw text/HTML to analyze directly. Either this OR `url` is required."),
        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(() => extractEntities(input as Parameters<typeof extractEntities>[0]));
      }
    );
  • Extracts typed entities (name, type, sameAs) from parsed JSON-LD blocks.
    export function extractJsonLdEntities(
      blocks: Array<{ parsed: Record<string, unknown>; types: string[] }>
    ): ExtractedEntity[] {
      const entities: ExtractedEntity[] = [];
      for (const block of blocks) {
        const name = block.parsed["name"];
        if (typeof name !== "string" || !name.trim()) continue;
        const sameAs = block.parsed["sameAs"];
        const saList: string[] = Array.isArray(sameAs)
          ? (sameAs as string[])
          : typeof sameAs === "string"
          ? [sameAs]
          : [];
        entities.push({
          name: name.trim(),
          type: block.types[0] ?? null,
          same_as: saList,
          mention_count: 0, // will be updated by text pass
          is_defined: false,
        });
      }
      return entities;
    }
  • Merges JSON-LD entities with text-extracted entities, updating mention counts from body text.
    export function mergeEntities(
      jsonLdEntities: ExtractedEntity[],
      textEntities: ExtractedEntity[],
      bodyText: string
    ): ExtractedEntity[] {
      const merged = new Map<string, ExtractedEntity>();
    
      // Add JSON-LD entities first
      for (const e of jsonLdEntities) {
        const key = e.name.toLowerCase();
        const count = countOccurrences(bodyText, e.name);
        merged.set(key, { ...e, mention_count: count });
      }
    
      // Add text entities (skip if already captured from JSON-LD)
      for (const e of textEntities) {
        const key = e.name.toLowerCase();
        if (!merged.has(key)) {
          merged.set(key, e);
        }
      }
    
      return Array.from(merged.values()).sort((a, b) => b.mention_count - a.mention_count);
    }
Behavior5/5

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

No annotations provided, so description carries full burden. It states 'Read-only when given url', 'Zero network when given text', 'Deterministic, rule-based; no LLM'. These behavioral traits go beyond what annotations would typically cover (destructive/non-destructive, network usage), giving the agent a clear understanding of side effects and behavior.

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?

5 sentences, each earning its place: action, method, behavioral traits, usage guidance, requirement. Front-loaded with the core purpose. No redundant or filler content.

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

Completeness5/5

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

No output schema exists, but description covers return type: 'list of entities with type, confidence, and any sameAs URIs'. For a tool with 3 parameters and no nested objects, this is complete. Agent knows what to expect. Sibling tools are provided, and description references one, aiding context.

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% with clear descriptions for all 3 parameters. Description adds value by explaining the heuristic method ('Combines body-text NER heuristics with JSON-LD @type / sameAs walking'), which provides context beyond the schema's parameter descriptions. However, it does not add new constraints or example values, so a 5 is not warranted.

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?

Description clearly states the tool extracts named entities, linked concepts, and sameAs graph nodes. It specifies input sources (url or text) and distinguishes from sibling 'audit_schema' by noting that for JSON-LD validation, use that tool. The verb 'extract' and resource 'entities' are specific and unique among siblings.

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?

Explicit when-to-use: 'building an entity map for schema generation, or auditing whether a page's entities match its target topic.' Also provides an alternative: 'To validate the JSON-LD itself, use audit_schema.' This clearly helps an agent decide when to invoke this tool vs others.

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