Skip to main content
Glama

check_links

Validate all URLs in a markdown document by issuing HEAD requests (falling back to GET). Detects broken links (4xx/5xx), redirects (3xx), and timeouts. Returns detailed report with broken URLs, redirect targets, and timed-out links.

Instructions

Validate every URL in a markdown document by issuing HEAD (then GET fallback) requests. FREE. Concurrency-limited to 10 in-flight requests; per-URL timeout 8s. Reports broken (4xx/5xx), redirected (3xx), and timed-out links. Returns: { total, ok, broken: [{ url, status }], redirects: [{ url, to }], timeouts: string[] }. Common errors: malformed markdown produces zero results without throwing.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentYesThe markdown content containing URLs to check

Implementation Reference

  • Handler function for the check_links tool. Validates input, calls checkLinks from audit/links.ts, and returns success/error response.
    export async function handleCheckLinks(input: z.infer<typeof checkLinksSchema>) {
      const contentErr = validateRequired(input.content, "content");
      if (contentErr) return makeError("VALIDATION_ERROR", contentErr);
    
      const result = await checkLinks(input.content);
      return makeSuccess(result);
    }
  • Zod schema for check_links input: expects a single 'content' string field (markdown content containing URLs to check).
    export const checkLinksSchema = z.object({
      content: z.string().describe("The markdown content containing URLs to check"),
    });
  • src/index.ts:234-238 (registration)
    Registration of the 'check_links' tool on the MCP server with description, schema, and handler invocation.
    server.tool("check_links", "Validate every URL in a markdown document by issuing HEAD (then GET fallback) requests. FREE. Concurrency-limited to 10 in-flight requests; per-URL timeout 8s. Reports broken (4xx/5xx), redirected (3xx), and timed-out links. Returns: { total, ok, broken: [{ url, status }], redirects: [{ url, to }], timeouts: string[] }. Common errors: malformed markdown produces zero results without throwing.", checkLinksSchema.shape, async (input) => {
      const parsed = checkLinksSchema.parse(input);
      const result = await handleCheckLinks(parsed);
      return { content: [{ type: "text", text: formatToolResponse("check_links", result, formatLinkCheck) }] };
    });
  • Core link-checking function: extracts URLs from markdown, checks them in batches of 5, returns aggregated LinkCheckResult.
    export async function checkLinks(markdown: string): Promise<LinkCheckResult> {
      const urls = extractUrls(markdown);
    
      if (urls.length === 0) {
        return { total: 0, ok: 0, redirected: 0, broken: 0, timeout: 0, error: 0, links: [] };
      }
    
      // Check in batches of 5 to avoid overwhelming servers
      const results: LinkResult[] = [];
      const batchSize = 5;
    
      for (let i = 0; i < urls.length; i += batchSize) {
        const batch = urls.slice(i, i + batchSize);
        const batchResults = await Promise.all(batch.map((url) => checkSingleLink(url)));
        results.push(...batchResults);
      }
    
      return {
        total: results.length,
        ok: results.filter((r) => r.status === "ok").length,
        redirected: results.filter((r) => r.status === "redirected").length,
        broken: results.filter((r) => r.status === "broken").length,
        timeout: results.filter((r) => r.status === "timeout").length,
        error: results.filter((r) => r.status === "error").length,
        links: results,
      };
    }
  • Helper that checks a single URL via HEAD request (with GET fallback on 405), handles timeouts and errors.
    export async function checkSingleLink(url: string): Promise<LinkResult> {
      const controller = new AbortController();
      const timeout = setTimeout(() => controller.abort(), LINK_TIMEOUT_MS);
    
      try {
        let res = await fetch(url, {
          method: "HEAD",
          signal: controller.signal,
          redirect: "manual",
          headers: {
            "User-Agent": "Pipepost-LinkChecker/1.0",
          },
        });
    
        // Some servers reject HEAD — retry with GET
        if (res.status === 405) {
          clearTimeout(timeout);
          const controller2 = new AbortController();
          const timeout2 = setTimeout(() => controller2.abort(), LINK_TIMEOUT_MS);
          try {
            res = await fetch(url, {
              method: "GET",
              signal: controller2.signal,
              redirect: "manual",
              headers: {
                "User-Agent": "Pipepost-LinkChecker/1.0",
              },
            });
          } finally {
            clearTimeout(timeout2);
          }
        }
    
        const code = res.status;
    
        if (code >= 200 && code < 300) {
          return { url, status: "ok", status_code: code, message: "OK" };
        }
        if (code >= 300 && code < 400) {
          const location = res.headers.get("location") ?? "unknown";
          return { url, status: "redirected", status_code: code, message: `Redirects to ${location}` };
        }
        return { url, status: "broken", status_code: code, message: `HTTP ${code}` };
      } catch (err) {
        if (err instanceof DOMException && err.name === "AbortError") {
          return { url, status: "timeout", status_code: null, message: "Request timed out (5s)" };
        }
        const message = err instanceof Error ? err.message : "Unknown error";
        return { url, status: "error", status_code: null, message };
      } finally {
        clearTimeout(timeout);
      }
    }
Behavior5/5

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

Without annotations, the description fully discloses behavior: HEAD then GET fallback, reporting broken/redirected/timeout links, concurrency limits, per-URL timeout, and error handling (malformed markdown returns empty results). No contradictions.

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 very concise: two sentences plus a clear output format list. It front-loads the purpose and key behavioral traits, making it efficient for an AI agent.

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?

The description covers all relevant aspects: input, method, limits, output structure, and error cases. Given no output schema, it provides the return format explicitly. It is complete for a link validation 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?

The only parameter 'content' is fully described in the schema. The tool description adds context about expected markdown input and outputs but does not add meaning beyond the schema for the parameter itself. Baseline 3 for 100% coverage.

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 validates URLs in markdown documents using HEAD then GET fallback. It specifies the resource (URLs in markdown) and verb (validate), and implicitly distinguishes from siblings as no other tool does link checking.

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

Usage Guidelines4/5

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

The description provides explicit usage context: it's free, concurrency-limited to 10 requests, timeout 8s, and common errors like malformed markdown. It doesn't explicitly contrast with alternatives, but no sibling does similar work, so it's adequate.

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/MendleM/pipepost'

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