ollama_web_fetch
Fetch web page content, titles, and links from URLs using Ollama's API for integration with local LLM models and MCP applications.
Instructions
Fetch a web page by URL using Ollama's web fetch API. Returns the page title, content, and links. Requires OLLAMA_API_KEY environment variable.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | The URL to fetch | |
| format | No | json |
Implementation Reference
- src/tools/web-fetch.ts:13-57 (handler)Core handler function that performs the web fetch to Ollama's API endpoint, handles authentication, retry with backoff, timeout, and formats the response.export async function webFetch( ollama: Ollama, url: string, format: ResponseFormat ): Promise<string> { // Web fetch requires direct API call as it's not in the SDK const apiKey = process.env.OLLAMA_API_KEY; if (!apiKey) { throw new Error( 'OLLAMA_API_KEY environment variable is required for web fetch' ); } return retryWithBackoff( async () => { const response = await fetchWithTimeout( 'https://ollama.com/api/web_fetch', { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${apiKey}`, }, body: JSON.stringify({ url, }), }, WEB_API_TIMEOUT ); if (!response.ok) { const retryAfter = response.headers.get('retry-after') ?? undefined; throw new HttpError( `Web fetch failed: ${response.status} ${response.statusText}`, response.status, retryAfter ); } const data = await response.json(); return formatResponse(JSON.stringify(data), format); }, WEB_API_RETRY_CONFIG ); }
- src/schemas.ts:219-222 (schema)Zod schema for validating the input parameters (url and format) of the ollama_web_fetch tool.export const WebFetchInputSchema = z.object({ url: z.string().url().min(1), format: ResponseFormatSchema.default('json'), });
- src/tools/web-fetch.ts:59-82 (registration)Tool definition registration exported for auto-discovery by the MCP autoloader, including name, description, input schema, and handler wrapper that performs validation and delegates to webFetch.export const toolDefinition: ToolDefinition = { name: 'ollama_web_fetch', description: 'Fetch a web page by URL using Ollama\'s web fetch API. Returns the page title, content, and links. Requires OLLAMA_API_KEY environment variable.', inputSchema: { type: 'object', properties: { url: { type: 'string', description: 'The URL to fetch', }, format: { type: 'string', enum: ['json', 'markdown'], default: 'json', }, }, required: ['url'], }, handler: async (ollama: Ollama, args: Record<string, unknown>, format: ResponseFormat) => { const validated = WebFetchInputSchema.parse(args); return webFetch(ollama, validated.url, format); }, };