How to Use Browser Tools with Ollama Search Automation and MCP
In this article
Automate search workflows by combining browser developer tools, Ollama for local language model processing, and MCP (Model Control Protocol) to streamline data extraction, query interpretation, and response handling. This integration allows developers and power users to build custom search automation tools that run locally, enhancing privacy and control. Before starting, ensure your system supports Ollama and that you understand basic browser debugging and network inspection.
What You'll Need
- Ollama installed and running on your machine
- A modern browser (Chrome, Edge, or Firefox recommended)
- Basic knowledge of browser developer tools (Console, Network, Elements tabs)
- Access to a test webpage or site for automation practice
- Terminal or command-line access to run Ollama commands
- Optional: a local script file (JavaScript) to inject or run in the browser
Step-by-Step
- Install and start Ollama by downloading it from the official site and running
ollama servein your terminal. Verify it's active by openinghttp://localhost:11434in your browser — you should see a status message. - Pull a language model suitable for search interpretation, such as
llama3orphi3, using the commandollama pull llama3. Wait for the download to complete. - Open your target webpage in the browser. This could be a search portal, documentation site, or internal tool with a search bar.
- Open browser developer tools by pressing F12 or Ctrl+Shift+I (macOS: Cmd+Option+I). Navigate to the Network tab and enable logging.
- Perform a manual search on the page. Observe the network requests in the developer tools. Look for XHR or Fetch calls that contain query parameters or JSON payloads with your search term.
- Right-click the relevant request and select Copy as fetch. Paste this into a text editor. This fetch script replicates the search request programmatically.
- Modify the fetch code to accept a dynamic query. Replace the hardcoded search term with a variable, e.g.,
const query = 'your search';, and inject it into the URL or body as needed. - In the browser Console tab, paste your modified fetch code and test it with different queries. Confirm it returns expected results by inspecting the response in the Console using
.then(res => res.json()).then(console.log). - Now use Ollama to generate or refine search queries. In your terminal, run ollama run llama3 and prompt it with: . Use the improved version in your fetch script.
- To automate this, create a local JavaScript file that sends a prompt to Ollama via its API at
http://localhost:11434/api/generate. Use a POST request with JSON body:{"model": "llama3", "prompt": "...", "stream": false}. - Parse Ollama’s response to extract the refined query, then use it in your browser fetch script. You can run this chain manually or set up a browser extension or userscript for automation.
- Use MCP (Model Control Protocol) if your automation framework supports it — MCP standardizes how tools communicate with local models. Configure your script to send structured requests via MCP-compliant endpoints, ensuring consistent input/output handling between Ollama and your browser logic.
- Test the full pipeline: enter a vague query, let Ollama refine it, then execute the search via browser tools. Inspect results in the Console and validate accuracy.
- For repeated use, save scripts in a local project folder and load them via browser extensions like Tampermonkey, or use a local server to serve and inject them securely.
Common Mistakes
- Assuming all search endpoints accept the same parameters — always inspect the actual network request.
- Forgetting to set proper headers (e.g., Content-Type, CSRF tokens) in fetch requests, causing 403 or 400 errors.
- Using Ollama prompts that are too vague, resulting in irrelevant query rewrites.
- Running Ollama models without enough RAM, leading to slow responses or crashes.
- Not checking CORS restrictions when making cross-origin requests from browser scripts.
Tips
- Use browser breakpoints in the Sources tab to pause script execution and inspect variables during automation.
- Store frequently used fetch templates in snippets within developer tools for quick reuse.
- Leverage Ollama’s
templatefeature to standardize prompt formats for search refinement. - Monitor Ollama’s memory usage via
htopor Task Manager to avoid system slowdowns. - Test automation on non-sensitive, public pages first to avoid accidental data exposure.
Troubleshooting
If Ollama doesn’t respond, ensure the ollama serve process is running and that port 11434 is not blocked. Check terminal logs for errors. If fetch requests fail, verify the request URL, method, and payload match the original network call. Use the Preserve log option in the Network tab to prevent losing requests during page navigation. If CORS blocks your script, run tests in a controlled environment like a local HTML file opened via file:// or use a proxy. If Ollama returns poor query suggestions, refine your prompt with examples or constraints (e.g., "Return only one concise query"). Clear browser cache if stale responses persist. For MCP-related issues, confirm your script adheres to the expected request schema and that the model endpoint supports MCP formatting.