How can I change the browser-mcp-agent to use the local Ollama? #82

Closed
opened 2025-11-06 14:32:32 -06:00 by GiteaMirror · 7 comments
Owner

Originally created by @Clailton on GitHub (Sep 3, 2025).

Thank you very much for sharing this MCPs server. I am very interested in using the browser-mcp-agent, but I would like to point it to my local Ollama. In the code, I couldn't find where I could point to get it via the API: localhost:11434. I appreciate any help in advance.

Originally created by @Clailton on GitHub (Sep 3, 2025). Thank you very much for sharing this MCPs server. I am very interested in using the browser-mcp-agent, but I would like to point it to my local Ollama. In the code, I couldn't find where I could point to get it via the API: localhost:11434. I appreciate any help in advance.
Author
Owner

@Shubhamsaboo commented on GitHub (Sep 8, 2025):

@AndrewHoh can help? Not sure if it works with Ollama though.

@Shubhamsaboo commented on GitHub (Sep 8, 2025): @AndrewHoh can help? Not sure if it works with Ollama though.
Author
Owner

@AndrewHoh commented on GitHub (Sep 8, 2025):

For sure, it's a pretty small change to get it to work with your local Ollama. If the completion call looks like OpenAI, which most models follow:

You just need to update the mcp_agent.config.yaml to include

openai:
  base_url: "http://localhost:11434/v1"
  api_key: ollama

Here's the source code to what the config would have after you add this part to the config - https://github.com/lastmile-ai/mcp-agent/blob/main/examples/model_providers/mcp_basic_ollama_agent/mcp_agent.config.yaml

@AndrewHoh commented on GitHub (Sep 8, 2025): For sure, it's a pretty small change to get it to work with your local Ollama. If the completion call looks like OpenAI, which most models follow: You just need to update the `mcp_agent.config.yaml` to include ``` openai: base_url: "http://localhost:11434/v1" api_key: ollama ``` Here's the source code to what the config would have after you add this part to the config - https://github.com/lastmile-ai/mcp-agent/blob/main/examples/model_providers/mcp_basic_ollama_agent/mcp_agent.config.yaml
Author
Owner

@Clailton commented on GitHub (Sep 9, 2025):

I put the settings you indicated, but it gave the message, below the Response, I think it didn't recognize them: Error: OpenAI API key not provided

@Clailton commented on GitHub (Sep 9, 2025): I put the settings you indicated, but it gave the message, below the Response, I think it didn't recognize them: Error: OpenAI API key not provided
Author
Owner

@AndrewHoh commented on GitHub (Sep 9, 2025):

Interesting, can you share how your mcp_agent.config.yaml looks like?

One test could be to see if you are able to run the app in https://github.com/lastmile-ai/mcp-agent/tree/main/examples/model_providers/mcp_basic_ollama_agent

@AndrewHoh commented on GitHub (Sep 9, 2025): Interesting, can you share how your `mcp_agent.config.yaml` looks like? One test could be to see if you are able to run the app in https://github.com/lastmile-ai/mcp-agent/tree/main/examples/model_providers/mcp_basic_ollama_agent
Author
Owner

@Clailton commented on GitHub (Sep 12, 2025):

Here is the mcp_agent.config.yaml. I also tried to put the base_url and api_key parameters in the mcp_agent.secrets.yaml, but it also had no effect. Thank you for your help.

execution_engine: asyncio
logger:
  transports: [console, file]
  level: debug
  progress_display: true
  path_settings:
    path_pattern: "logs/mcp-agent-{unique_id}.jsonl"
    unique_id: "timestamp" # Options: "timestamp" or "session_id"
    timestamp_format: "%Y%m%d_%H%M%S"

mcp:
  servers:
    playwright:
      command: "npx"
      args: ["@playwright/mcp@latest"]


openai:gitignored
  default_model: "llama3.2:latest"
  base_url: "http://localhost:11434/v1"
  api_key: ollama
@Clailton commented on GitHub (Sep 12, 2025): Here is the mcp_agent.config.yaml. I also tried to put the base_url and api_key parameters in the mcp_agent.secrets.yaml, but it also had no effect. Thank you for your help. ``` execution_engine: asyncio logger: transports: [console, file] level: debug progress_display: true path_settings: path_pattern: "logs/mcp-agent-{unique_id}.jsonl" unique_id: "timestamp" # Options: "timestamp" or "session_id" timestamp_format: "%Y%m%d_%H%M%S" mcp: servers: playwright: command: "npx" args: ["@playwright/mcp@latest"] openai:gitignored default_model: "llama3.2:latest" base_url: "http://localhost:11434/v1" api_key: ollama ```
Author
Owner

@AndrewHoh commented on GitHub (Sep 12, 2025):

ahh, I figured it out. Apologies for the confusion.

Your mcp_agent.config.yaml looks correct. It's actually that there is an unnecessary call in my browser_mcp_agent/main.py code that checks for an OPENAI_API_KEY as an environment variable. Removing that should solve everything.

async def run_mcp_agent(message):

    #Remove this piece of code checking for the env variable for OpenAI API key
    if not os.getenv("OPENAI_API_KEY"):
        return "Error: OpenAI API key not provided"
    
    try:
        # Make sure agent is initialized
        error = await setup_agent()
        if error:
            return error
        
        # Generate response without recreating agents
        # Switch use_history to False to reduce the passed context
        result = await st.session_state.llm.generate_str(
            message=message, 
            request_params=RequestParams(use_history=True, maxTokens=10000)
            )
        return result
    except Exception as e:
        return f"Error: {str(e)}"

It should look like this afterwards:

async def run_mcp_agent(message):
      # Make sure agent is initialized
      error = await setup_agent()
      if error:
          return error
      
      # Generate response without recreating agents
      # Switch use_history to False to reduce the passed context
      result = await st.session_state.llm.generate_str(
          message=message, 
          request_params=RequestParams(use_history=True, maxTokens=10000)
          )
      return result
@AndrewHoh commented on GitHub (Sep 12, 2025): ahh, I figured it out. Apologies for the confusion. Your `mcp_agent.config.yaml` looks correct. It's actually that there is an unnecessary call in my `browser_mcp_agent/main.py code` that checks for an OPENAI_API_KEY as an environment variable. Removing that should solve everything. ```python async def run_mcp_agent(message): #Remove this piece of code checking for the env variable for OpenAI API key if not os.getenv("OPENAI_API_KEY"): return "Error: OpenAI API key not provided" try: # Make sure agent is initialized error = await setup_agent() if error: return error # Generate response without recreating agents # Switch use_history to False to reduce the passed context result = await st.session_state.llm.generate_str( message=message, request_params=RequestParams(use_history=True, maxTokens=10000) ) return result except Exception as e: return f"Error: {str(e)}" ``` It should look like this afterwards: ```python async def run_mcp_agent(message): # Make sure agent is initialized error = await setup_agent() if error: return error # Generate response without recreating agents # Switch use_history to False to reduce the passed context result = await st.session_state.llm.generate_str( message=message, request_params=RequestParams(use_history=True, maxTokens=10000) ) return result ```
Author
Owner

@Shubhamsaboo commented on GitHub (Sep 23, 2025):

Closing this since no response from the issue author. Thanks @AndrewHoh for the help!

@Shubhamsaboo commented on GitHub (Sep 23, 2025): Closing this since no response from the issue author. Thanks @AndrewHoh for the help!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/awesome-llm-apps#82