Skip to main content
Glama

check_links

Crawl all internal links on a page and identify dead links (404/5xx errors) using HEAD requests. Ensures site integrity by detecting broken pages automatically.

Instructions

Crawl all internal links on the current page and check for dead links (404/5xx).

Sends HEAD requests to each internal link found on the page. This can take several seconds on pages with many links.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Core handler: checks internal links via HEAD requests (fallback GET on 405), returns status results marking dead/ok links.
    async def check_links(self, links: List[Dict]) -> List[Dict]:
        """Check internal link status via HEAD requests (falls back to GET on 405)."""
        results = []
        checked: set = set()
        for link in links:
            href = link.get("href", "")
            if not href or href in checked or not link.get("isInternal"):
                continue
            checked.add(href)
            try:
                resp = await self._context.request.head(href, timeout=5000)
                # 405 = server doesn't support HEAD, retry with GET
                if resp.status == 405:
                    resp = await self._context.request.get(href, timeout=5000)
                # 403 from context.request often means anti-bot, not a real dead link
                # Mark as ok since the page loaded fine in the browser
                is_ok = resp.ok or resp.status == 403
                results.append({"href": href, "status": resp.status, "ok": is_ok})
            except Exception:
                results.append({"href": href, "status": 0, "ok": False})
        return results
  • Registration as an MCP tool via @mcp.tool() decorator, formats and returns the result string.
    @mcp.tool()
    async def check_links() -> str:
        """Crawl all internal links on the current page and check for dead links (404/5xx).
    
        Sends HEAD requests to each internal link found on the page.
        This can take several seconds on pages with many links.
        """
        s = _require_session()
        state = await s.browser.get_state()
        s._last_elements = state.elements
    
        link_results = await s.browser.check_links(state.links)
        new_bugs = s.detector.process_dead_links(link_results, state.url, s.steps)
    
        if new_bugs:
            ss_path = await _auto_screenshot(s, "dead_links", f"Dead links on {state.url}")
            for bug in new_bugs:
                bug.screenshot_path = ss_path
        s.bugs.extend(new_bugs)
    
        dead = [r for r in link_results if not r["ok"]]
        alive = [r for r in link_results if r["ok"]]
        external = [l for l in state.links if not l.get("isInternal")]
    
        lines = [f"Checked {len(link_results)} internal links on {state.url}"]
        lines.append(f"  OK: {len(alive)}")
        lines.append(f"  Dead: {len(dead)}")
        lines.append(f"  External (not checked): {len(external)}")
        if dead:
            lines.append("")
            for r in dead:
                lines.append(f"  [HTTP {r['status']}] {r['href']}")
        lines.append(f"\nTotal bugs in session: {len(s.bugs)}")
        return "\n".join(lines)
  • Helper that processes link check results, creates Bug objects for dead links aggregated by domain.
    # ── Dead link crawling ────────────────────────────────────────────
    
    def process_dead_links(
  • Output format: returns a human-readable report string with counts (OK, dead, external) and details per dead link.
    lines = [f"Checked {len(link_results)} internal links on {state.url}"]
    lines.append(f"  OK: {len(alive)}")
    lines.append(f"  Dead: {len(dead)}")
    lines.append(f"  External (not checked): {len(external)}")
    if dead:
        lines.append("")
        for r in dead:
            lines.append(f"  [HTTP {r['status']}] {r['href']}")
  • Reuse of check_links within the crawl_site tool during automated site crawling.
    link_results = await s.browser.check_links(state.links)
    new_bugs.extend(s.detector.process_dead_links(link_results, state.url, s.steps))
    
    # Performance
    perf = await s.browser.get_performance()
    new_bugs.extend(s.detector.process_performance(perf, state.url, s.steps))
    
    # Screenshot
    if new_bugs:
        page_name = state.url.split("/")[-1] or "index"
        ss_path = await _auto_screenshot(s, f"crawl_{page_name}", f"Crawl: {state.url}")
        for bug in new_bugs:
            bug.screenshot_path = ss_path
    
    s.bugs.extend(new_bugs)
    page_results.append((state.url, len(new_bugs)))
    
    # Discover new internal links to visit (deduplicated by path)
    for link in state.links:
        href = link.get("href", "")
        if link.get("isInternal") and _normalize(href) not in visited_paths and href not in to_visit:
            to_visit.append(href)
Behavior4/5

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

The description discloses that it sends HEAD requests and warns about potential time consumption. Since no annotations are present, the description carries the full burden, and it adequately covers the key behavioral traits (non-destructive, network-intensive).

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 three sentences, front-loaded with the main action, followed by behavioral details. No wasted words or redundancy.

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?

For a simple tool with no parameters and an output schema, the description covers the core purpose, method, and performance impact. It is complete enough for an agent to understand usage without needing additional 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?

The tool has no parameters, so the schema coverage is 100% by default. The description does not need to add parameter details, and the baseline for 0 parameters is 4.

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 crawls all internal links on the current page and checks for dead links (404/5xx). This distinguishes it from siblings like check_performance (performance metrics) and crawl_site (multi-page crawling).

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

Usage Guidelines3/5

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

The description provides some context by noting the operation can take several seconds, but does not explicitly state when to use this tool versus alternatives or when not to use it. No comparison with sibling tools is provided.

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/chriswu727/argus'

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