Skip to main content
Glama
rawveg

Ollama MCP Server

ollama_web_fetch

Fetch web page content, titles, and links from URLs using Ollama's API to extract and process online information for analysis or integration.

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
NameRequiredDescriptionDefault
urlYesThe URL to fetch
formatNojson

Implementation Reference

  • Core handler function that performs the web fetch by calling Ollama's web fetch API endpoint with retry and error handling.
    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
      );
    }
  • Tool registration definition exported for autoloader discovery, including name, MCP input schema, description, and handler that validates input 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);
      },
    };
  • Zod schema used for input validation in the tool handler.
     * Schema for ollama_web_fetch tool
     */
    export const WebFetchInputSchema = z.object({
      url: z.string().url().min(1),
      format: ResponseFormatSchema.default('json'),
    });

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/rawveg/ollama-mcp'

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