Skip to main content
Glama

fetch

Retrieve web content as markdown and extract images for clipboard use. Processes URLs to convert HTML to readable text while handling image grouping and size limits.

Instructions

Retrieves URLs from the Internet and extracts their content as markdown. If images are found, they are merged vertically (max 6 images per group, max height 8000px, max size 30MB per group) and copied to the clipboard of the user's host machine. You will need to paste (Cmd+V) to insert the images.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYes
maxLengthNo
startIndexNo
rawNo

Implementation Reference

  • Input schema (Zod) for the 'fetch' tool defining parameters: url, maxLength, startIndex, raw.
    const FetchArgsSchema = z.object({
    	url: z.string().url(),
    	maxLength: z.number().positive().max(1000000).default(20000),
    	startIndex: z.number().min(0).default(0),
    	raw: z.boolean().default(false),
    })
  • index.ts:366-374 (registration)
    Registration of the 'fetch' tool in the tools/list response, providing name, description, and JSON schema derived from FetchArgsSchema.
    const tools = [
    	{
    		name: "fetch",
    		description:
    			"Retrieves URLs from the Internet and extracts their content as markdown. If images are found, they are merged vertically (max 6 images per group, max height 8000px, max size 30MB per group) and copied to the clipboard of the user's host machine. You will need to paste (Cmd+V) to insert the images.",
    		inputSchema: zodToJsonSchema(FetchArgsSchema),
    	},
    ]
    return { tools }
  • The tools/call request handler implementing the 'fetch' tool: validates input with FetchArgsSchema, invokes fetchUrl, handles truncation based on maxLength and startIndex, lists image URLs, and returns formatted text content or error.
    server.setRequestHandler(
    	CallToolSchema,
    	async (
    		request: {
    			method: "tools/call"
    			params: { name: string; arguments?: Record<string, unknown> }
    		},
    		extra: RequestHandlerExtra,
    	) => {
    		try {
    			const { name, arguments: args } = request.params
    
    			if (name !== "fetch") {
    				throw new Error(`Unknown tool: ${name}`)
    			}
    
    			const parsed = FetchArgsSchema.safeParse(args)
    			if (!parsed.success) {
    				throw new Error(`Invalid arguments: ${parsed.error}`)
    			}
    
    			const { content, prefix, imageUrls } = await fetchUrl(
    				parsed.data.url,
    				DEFAULT_USER_AGENT_AUTONOMOUS,
    				parsed.data.raw,
    			)
    
    			let finalContent = content
    			if (finalContent.length > parsed.data.maxLength) {
    				finalContent = finalContent.slice(
    					parsed.data.startIndex,
    					parsed.data.startIndex + parsed.data.maxLength,
    				)
    				finalContent += `\n\n<e>Content truncated. Call the fetch tool with a start_index of ${
    					parsed.data.startIndex + parsed.data.maxLength
    				} to get more content.</e>`
    			}
    
    			let imagesSection = ""
    			if (imageUrls && imageUrls.length > 0) {
    				imagesSection =
    					"\n\nImages found in article:\n" +
    					imageUrls.map((url) => `- ${url}`).join("\n")
    			}
    
    			return {
    				content: [
    					{
    						type: "text",
    						text: `${prefix}Contents of ${parsed.data.url}:\n${finalContent}${imagesSection}`,
    					},
    				],
    			}
    		} catch (error) {
    			return {
    				content: [
    					{
    						type: "text",
    						text: `Error: ${error instanceof Error ? error.message : String(error)}`,
    					},
    				],
    				isError: true,
    			}
    		}
    	},
    )
  • Core logic function for fetching URL content, parsing HTML to markdown with image extraction and clipboard copying using internal helpers.
    async function fetchUrl(
    	url: string,
    	userAgent: string,
    	forceRaw = false,
    ): Promise<FetchResult> {
    	const response = await fetch(url, {
    		headers: { "User-Agent": userAgent },
    	})
    
    	if (!response.ok) {
    		throw new Error(`Failed to fetch ${url} - status code ${response.status}`)
    	}
    
    	const contentType = response.headers.get("content-type") || ""
    	const text = await response.text()
    	const isHtml =
    		text.toLowerCase().includes("<html") || contentType.includes("text/html")
    
    	if (isHtml && !forceRaw) {
    		const result = extractContentFromHtml(text, url)
    		if (typeof result === "string") {
    			return {
    				content: result,
    				prefix: "",
    			}
    		}
    
    		const { markdown, images } = result
    		const fetchedImages = await fetchImages(images)
    		const imageUrls = fetchedImages.map((img) => img.src)
    
    		if (fetchedImages.length > 0) {
    			try {
    				await addImagesToClipboard(fetchedImages)
    				return {
    					content: markdown,
    					prefix: `Found and processed ${fetchedImages.length} images. Images have been merged vertically (max 6 images per group) and copied to your clipboard. Please paste (Cmd+V) to combine with the retrieved content.\n`,
    					imageUrls,
    				}
    			} catch (err) {
    				return {
    					content: markdown,
    					prefix: `Found ${fetchedImages.length} images but failed to copy them to the clipboard.\nError: ${err instanceof Error ? err.message : String(err)}\n`,
    					imageUrls,
    				}
    			}
    		}
    		return {
    			content: markdown,
    			prefix: "",
    			imageUrls,
    		}
    	}
    
    	return {
    		content: text,
    		prefix: `Content type ${contentType} cannot be simplified to markdown, but here is the raw content:\n`,
    	}
    }
Behavior4/5

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

No annotations are provided, so the description carries the full burden. It discloses key behavioral traits: content extraction to markdown, image merging with specific limits (max 6 images, max height 8000px, max size 30MB), and clipboard copying with a manual paste requirement. However, it omits details like error handling, rate limits, or authentication needs, leaving some gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded, starting with the core functionality. Every sentence adds value: the first covers retrieval and extraction, the second details image handling, and the third provides a usage note. It could be slightly more concise by integrating the image limits into one sentence, but overall it's efficient.

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?

Given the complexity (image processing, clipboard operations) and no annotations or output schema, the description is partially complete. It covers the main behaviors but lacks details on return values, error cases, or parameter effects. For a tool with 4 parameters and significant functionality, more context would be beneficial to fully guide an agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate for undocumented parameters. It mentions 'URLs' (plural) but only one 'url' parameter is required, and it does not explain the semantics of 'maxLength', 'startIndex', or 'raw'. The description adds no meaning beyond the schema, failing to address the coverage gap adequately.

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's purpose with specific verbs ('retrieves URLs', 'extracts content as markdown') and resources ('URLs from the Internet'). It distinguishes itself by detailing the unique image handling behavior (merging, copying to clipboard), which is not implied by the name alone. No siblings exist to differentiate from, but the description is comprehensive.

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 implies usage for fetching and processing web content with images, but provides no explicit guidance on when to use this tool versus alternatives (e.g., other fetch tools or methods). It mentions a prerequisite ('You will need to paste...') but lacks context on exclusions or comparisons. With no sibling tools, this is adequate but not optimal.

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/JeremyNixon/mcp-fetch'

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