[GH-ISSUE #3621] [BUG]: Agent won't use an MCP tool #2336

Closed
opened 2026-02-22 18:29:13 -05:00 by yindo · 5 comments
Owner

Originally created by @aevo98765 on GitHub (Apr 9, 2025).
Original GitHub issue: https://github.com/Mintplex-Labs/anything-llm/issues/3621

How are you running AnythingLLM?

Docker (local)

What happened?

Hi, I have tried running a local test weather tool via MCP. The server states that it is running in the 'Agent Skills' tab of the settings but when I enter the chat interface and ask a weather related question the agent has no idea that a weather tool exists.

Are there known steps to reproduce?

Docker local

weather.py

from typing import Any
import httpx
from mcp.server.fastmcp import FastMCP

# Initialize FastMCP server
mcp = FastMCP("weather")

# Constants
NWS_API_BASE = "https://api.weather.gov"
USER_AGENT = "weather-app/1.0"


async def make_nws_request(url: str) -> dict[str, Any] | None:
    """Make a request to the NWS API with proper error handling."""
    headers = {
        "User-Agent": USER_AGENT,
        "Accept": "application/geo+json"
    }
    async with httpx.AsyncClient() as client:
        try:
            response = await client.get(url, headers=headers, timeout=30.0)
            response.raise_for_status()
            return response.json()
        except Exception:
            return None


def format_alert(feature: dict) -> str:
    """Format an alert feature into a readable string."""
    props = feature["properties"]
    return f"""
        Event: {props.get('event', 'Unknown')}
        Area: {props.get('areaDesc', 'Unknown')}
        Severity: {props.get('severity', 'Unknown')}
        Description: {props.get('description', 'No description available')}
        Instructions: {props.get('instruction', 'No specific instructions provided')}
        """


@mcp.tool()
async def get_alerts(state: str) -> str:
    """Get weather alerts for a US state.

    Args:
        state: Two-letter US state code (e.g. CA, NY)
    """
    url = f"{NWS_API_BASE}/alerts/active/area/{state}"
    data = await make_nws_request(url)

    if not data or "features" not in data:
        return "Unable to fetch alerts or no alerts found."

    if not data["features"]:
        return "No active alerts for this state."

    alerts = [format_alert(feature) for feature in data["features"]]
    return "\n---\n".join(alerts)


@mcp.tool()
async def get_forecast(latitude: float, longitude: float) -> str:
    """Get weather forecast for a location.

    Args:
        latitude: Latitude of the location
        longitude: Longitude of the location
    """
    # First get the forecast grid endpoint
    points_url = f"{NWS_API_BASE}/points/{latitude},{longitude}"
    points_data = await make_nws_request(points_url)

    if not points_data:
        return "Unable to fetch forecast data for this location."

    # Get the forecast URL from the points response
    forecast_url = points_data["properties"]["forecast"]
    forecast_data = await make_nws_request(forecast_url)

    if not forecast_data:
        return "Unable to fetch detailed forecast."

    # Format the periods into a readable forecast
    periods = forecast_data["properties"]["periods"]
    forecasts = []
    for period in periods[:5]:  # Only show next 5 periods
        forecast = f"""
            {period['name']}:
            Temperature: {period['temperature']}°{period['temperatureUnit']}
            Wind: {period['windSpeed']} {period['windDirection']}
            Forecast: {period['detailedForecast']}
            """
        forecasts.append(forecast)

    return "\n---\n".join(forecasts)


if __name__ == "__main__":
    # Initialize and run the server
    mcp.run(transport='stdio')

anythingllm_mcp_servers.json content

{
  "mcpServers": {
    "weather": {
      "command": "uv",
      "args": [
        "--directory",
        "/app/mcp-servers/mcp/weather",
        "run",
        "weather.py"
      ]
    }
  }
}
Originally created by @aevo98765 on GitHub (Apr 9, 2025). Original GitHub issue: https://github.com/Mintplex-Labs/anything-llm/issues/3621 ### How are you running AnythingLLM? Docker (local) ### What happened? Hi, I have tried running a local test weather tool via MCP. The server states that it is running in the 'Agent Skills' tab of the settings but when I enter the chat interface and ask a weather related question the agent has no idea that a weather tool exists. ### Are there known steps to reproduce? Docker local weather.py ``` from typing import Any import httpx from mcp.server.fastmcp import FastMCP # Initialize FastMCP server mcp = FastMCP("weather") # Constants NWS_API_BASE = "https://api.weather.gov" USER_AGENT = "weather-app/1.0" async def make_nws_request(url: str) -> dict[str, Any] | None: """Make a request to the NWS API with proper error handling.""" headers = { "User-Agent": USER_AGENT, "Accept": "application/geo+json" } async with httpx.AsyncClient() as client: try: response = await client.get(url, headers=headers, timeout=30.0) response.raise_for_status() return response.json() except Exception: return None def format_alert(feature: dict) -> str: """Format an alert feature into a readable string.""" props = feature["properties"] return f""" Event: {props.get('event', 'Unknown')} Area: {props.get('areaDesc', 'Unknown')} Severity: {props.get('severity', 'Unknown')} Description: {props.get('description', 'No description available')} Instructions: {props.get('instruction', 'No specific instructions provided')} """ @mcp.tool() async def get_alerts(state: str) -> str: """Get weather alerts for a US state. Args: state: Two-letter US state code (e.g. CA, NY) """ url = f"{NWS_API_BASE}/alerts/active/area/{state}" data = await make_nws_request(url) if not data or "features" not in data: return "Unable to fetch alerts or no alerts found." if not data["features"]: return "No active alerts for this state." alerts = [format_alert(feature) for feature in data["features"]] return "\n---\n".join(alerts) @mcp.tool() async def get_forecast(latitude: float, longitude: float) -> str: """Get weather forecast for a location. Args: latitude: Latitude of the location longitude: Longitude of the location """ # First get the forecast grid endpoint points_url = f"{NWS_API_BASE}/points/{latitude},{longitude}" points_data = await make_nws_request(points_url) if not points_data: return "Unable to fetch forecast data for this location." # Get the forecast URL from the points response forecast_url = points_data["properties"]["forecast"] forecast_data = await make_nws_request(forecast_url) if not forecast_data: return "Unable to fetch detailed forecast." # Format the periods into a readable forecast periods = forecast_data["properties"]["periods"] forecasts = [] for period in periods[:5]: # Only show next 5 periods forecast = f""" {period['name']}: Temperature: {period['temperature']}°{period['temperatureUnit']} Wind: {period['windSpeed']} {period['windDirection']} Forecast: {period['detailedForecast']} """ forecasts.append(forecast) return "\n---\n".join(forecasts) if __name__ == "__main__": # Initialize and run the server mcp.run(transport='stdio') ``` anythingllm_mcp_servers.json content ```json { "mcpServers": { "weather": { "command": "uv", "args": [ "--directory", "/app/mcp-servers/mcp/weather", "run", "weather.py" ] } } } ```
yindo added the questionneeds info / can't replicate labels 2026-02-22 18:29:13 -05:00
yindo closed this issue 2026-02-22 18:29:13 -05:00
Author
Owner

@timothycarambat commented on GitHub (Apr 9, 2025):

There are some steps to debug this (aside from the agent just not calling a tool)

  1. In the agent skills menu, does the tool show as "On"? It may be stopped or failed to boot
  2. What do you see in the docker logs when running and agent query. The MCP is likely being loaded but the LLM might not be calling it
  3. What LLM are you using and from where?
@timothycarambat commented on GitHub (Apr 9, 2025): There are some steps to debug this (aside from the [agent just not calling a tool](https://docs.anythingllm.com/agent-not-using-tools)) 1. In the agent skills menu, does the tool show as "On"? It may be stopped or failed to boot 2. What do you see in the docker `logs` when running and `agent` query. The MCP is likely being loaded but the LLM might not be calling it 3. What LLM are you using and from where?
Author
Owner

@aevo98765 commented on GitHub (Apr 11, 2025):

Image

  1. Docker logs show that the MCP server starts successfully but then when a chat is initiated there is no mention of MCP.

  2. Used groqcloud llama-3.3-70b-versatile and ollama granite3.2:latest.

@aevo98765 commented on GitHub (Apr 11, 2025): 1) ![Image](https://github.com/user-attachments/assets/ec83dd62-3dc1-4741-8d81-010ec3fdfe01) 2) Docker logs show that the MCP server starts successfully but then when a chat is initiated there is no mention of MCP. 3) Used groqcloud llama-3.3-70b-versatile and ollama granite3.2:latest.
Author
Owner

@timothycarambat commented on GitHub (Apr 11, 2025):

When the chat is running you should see a series of loaded tools - and you'll see once that denotes your MCP tool has loaded in as well.

It is worth noting that Groq is bad at tool calls due to how they get their models to run - and granite3.2 at Q4 could also be an issue just from size alone, but its not definitive. Do you have many tools enabled at the same time? This often hurts tool calling when models since it injects a ton of instructions into the prompt.

Closing since this is a usage/config thing - not a bug. The tool is present your model just isn't calling them

@timothycarambat commented on GitHub (Apr 11, 2025): When the chat is running you should see a series of loaded tools - and you'll see once that denotes your MCP tool has loaded in as well. It is worth noting that Groq is bad at tool calls due to how they get their models to run - and granite3.2 at Q4 could also be an issue just from size alone, but its not definitive. Do you have many tools enabled at the same time? This often hurts tool calling when models since it injects a ton of instructions into the prompt. Closing since this is a usage/config thing - not a bug. The tool is present your model just isn't calling them
Author
Owner

@aevo98765 commented on GitHub (Apr 14, 2025):

I worked out the issue I was encountering was I was not invoking the 'agent' in the chat e.g. @agent check this state for weather alerts. This wasn't immediately obvious to me that this is how you can invoke MCP tools.

@aevo98765 commented on GitHub (Apr 14, 2025): I worked out the issue I was encountering was I was not invoking the 'agent' in the chat e.g. @agent check this state for weather alerts. This wasn't immediately obvious to me that this is how you can invoke MCP tools.
Author
Owner

@antoniohof commented on GitHub (Sep 25, 2025):

If you have a lot of tools, you need to increase the context size. I found out that Ollama limits to 4096 for example... I had to create a new model in Ollama with a bigger context size.

@antoniohof commented on GitHub (Sep 25, 2025): If you have a lot of tools, you need to increase the context size. I found out that Ollama limits to 4096 for example... I had to create a new model in Ollama with a bigger context size.
yindo changed title from [BUG]: Agent won't use an MCP tool to [GH-ISSUE #3621] [BUG]: Agent won't use an MCP tool 2026-06-05 14:45:58 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Mintplex-Labs/anything-llm#2336