Skip to main content
Glama
kwp-lab

MCP Fetch With Proxy

fetch

Retrieve web content as markdown with image URLs, using proxy support for accessing URLs and extracting text from internet sources.

Instructions

Retrieves URLs from the Internet and extracts their content as markdown. If images are found, their URLs will be included in the response.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYes
maxLengthNo
startIndexNo
rawNo

Implementation Reference

  • The primary handler for tool calls, which dispatches to the 'fetch' tool implementation. It validates input, fetches the URL, processes the content (markdown extraction, truncation), adds image list if present, and formats the response.
    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,
    			}
    		}
    	},
    )
  • Input schema for the 'fetch' tool using Zod, defining parameters: url (required), 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:168-181 (registration)
    Registration of the 'fetch' tool via the tools/list request handler, providing name, description, and input schema.
    server.setRequestHandler(
    	ListToolsSchema,
    	async (request: { method: "tools/list" }, extra: RequestHandlerExtra) => {
    		const tools = [
    			{
    				name: "fetch",
    				description:
    					"Retrieves URLs from the Internet and extracts their content as markdown. If images are found, their URLs will be included in the response.",
    				inputSchema: zodToJsonSchema(FetchArgsSchema),
    			},
    		]
    		return { tools }
    	},
    )
  • Core helper function that performs the HTTP fetch, determines if content is HTML, extracts readable markdown using Readability and Turndown if HTML, collects image URLs, or returns raw text with prefix.
    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 imageUrls = images.map((img) => img.src)
    
    		return {
    			content: markdown,
    			prefix: "",
    			imageUrls,
    		}
    	}
    
    	return {
    		content: text,
    		prefix: `Content type ${contentType} cannot be simplified to markdown, but here is the raw content:\n`,
    	}
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions content extraction and image URL inclusion, but doesn't cover important aspects like error handling (e.g., invalid URLs, network failures), rate limits, authentication needs, privacy implications, or what happens when maxLength is exceeded. The description is insufficient for a tool that interacts with external resources.

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 perfectly concise with two clear sentences that each add value. The first sentence establishes the primary function, and the second adds important behavioral detail about image handling. No wasted words or redundant information.

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?

For a tool with 4 parameters, no annotations, and no output schema, the description provides adequate basic functionality explanation but lacks sufficient detail about behavioral characteristics, error conditions, and output format. The absence of sibling tools reduces complexity, but the description should do more to compensate for the lack of structured metadata.

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 description doesn't mention any parameters directly, but with 0% schema description coverage, it doesn't compensate for the lack of parameter documentation. However, the tool has 4 parameters with clear schema definitions (url, maxLength, startIndex, raw), and the description's focus on the core functionality provides some context. The baseline would be lower if the schema were less informative.

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', 'extracts') and resources ('URLs from the Internet', 'content as markdown'), and explicitly mentions handling of images. It distinguishes what the tool does without relying on the generic name 'fetch'.

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 retrieving and converting web content to markdown, but provides no explicit guidance on when to use this tool versus alternatives (though no sibling tools are listed). It lacks information about prerequisites, error conditions, or performance considerations.

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

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