Skip to main content
Glama

ollama_web_search

Perform web searches to augment AI models with current information, reducing hallucinations by accessing up-to-date data through API integration.

Instructions

Perform a web search using Ollama's web search API. Augments models with latest information to reduce hallucinations. Requires OLLAMA_API_KEY environment variable.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe search query string
max_resultsNoMaximum number of results to return (1-10, default 5)
formatNojson

Implementation Reference

  • Core implementation of the web search tool logic. Performs API call to Ollama's web search endpoint with authentication, retry, timeout, error handling, and response formatting.
    /** * Perform a web search using Ollama's web search API */ export async function webSearch( ollama: Ollama, query: string, maxResults: number, format: ResponseFormat ): Promise<string> { // Web search 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 search' ); } return retryWithBackoff( async () => { const response = await fetchWithTimeout( 'https://ollama.com/api/web_search', { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${apiKey}`, }, body: JSON.stringify({ query, max_results: maxResults, }), }, WEB_API_TIMEOUT ); if (!response.ok) { const retryAfter = response.headers.get('retry-after') ?? undefined; throw new HttpError( `Web search 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 discovery by the autoloader. Includes name, description, inline input schema, and handler that validates inputs using Zod schema and delegates to webSearch function.
    export const toolDefinition: ToolDefinition = { name: 'ollama_web_search', description: 'Perform a web search using Ollama\'s web search API. Augments models with latest information to reduce hallucinations. Requires OLLAMA_API_KEY environment variable.', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'The search query string', }, max_results: { type: 'number', description: 'Maximum number of results to return (1-10, default 5)', default: 5, }, format: { type: 'string', enum: ['json', 'markdown'], default: 'json', }, }, required: ['query'], }, handler: async (ollama: Ollama, args: Record<string, unknown>, format: ResponseFormat) => { const validated = WebSearchInputSchema.parse(args); return webSearch(ollama, validated.query, validated.max_results, format); }, };
  • Zod input validation schema for the ollama_web_search tool, used in the handler for parsing and validating arguments.
    * Schema for ollama_web_search tool */ export const WebSearchInputSchema = z.object({ query: z.string().min(1), max_results: z.number().int().min(1).max(10).default(5), 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