Skip to main content
Glama

chat

Send multi-turn conversations to a local Ollama model. Define roles (user, assistant, system) and messages for context-aware responses.

Instructions

Send a multi-turn conversation to an Ollama model. Messages should follow the format [{'role': 'user'|'assistant'|'system', 'content': '...'}].

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
modelYes
messagesYes
temperatureNo
max_tokensNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • MCP tool registration and handler function for the 'chat' tool. The @mcp.tool decorator registers it with name='chat' and the async function implements the handler logic, calling oc.chat() to delegate to the Ollama client.
    @mcp.tool(
        name="chat",
        description=(
            "Send a multi-turn conversation to an Ollama model.  Messages should "
            "follow the format [{'role': 'user'|'assistant'|'system', 'content': '...'}]."
        ),
    )
    async def chat(
        model: str,
        messages: list[dict[str, str]],
        temperature: float | None = None,
        max_tokens: int | None = None,
    ) -> dict[str, Any]:
        """
        Args:
            model: Ollama model name.
            messages: Conversation history as a list of role/content dicts.
            temperature: Sampling temperature (0.0–2.0).
            max_tokens: Maximum tokens to generate.
        """
        options: dict[str, Any] = {}
        if temperature is not None:
            options["temperature"] = temperature
        if max_tokens is not None:
            options["num_predict"] = max_tokens
        response = await oc.chat(
            model=model,
            messages=messages,
            options=options or None,
        )
        return {"model": model, "response": response}
  • Helper function that makes the HTTP POST to Ollama's /api/chat endpoint. Constructs the payload with model, messages, and options, then returns the assistant's content from the response.
    async def chat(
        model: str,
        messages: list[dict[str, str]],
        options: dict[str, Any] | None = None,
    ) -> str:
        payload: dict[str, Any] = {
            "model": model,
            "messages": messages,
            "stream": False,
        }
        if options:
            payload["options"] = options
        async with _client() as c:
            r = await c.post("/api/chat", json=payload)
            r.raise_for_status()
            return r.json().get("message", {}).get("content", "")
  • Unit test for the ollama_client.chat() function, mocking the HTTP client to verify correct request/response behavior.
    @pytest.mark.asyncio
    async def test_chat():
        mock_client = AsyncMock()
        mock_client.__aenter__ = AsyncMock(return_value=mock_client)
        mock_client.__aexit__ = AsyncMock(return_value=False)
        mock_client.post = AsyncMock(
            return_value=_mock_response({"message": {"content": "Hi there!", "role": "assistant"}})
        )
    
        with patch("foundry_reverse.ollama_client.httpx.AsyncClient", return_value=mock_client):
            result = await oc.chat(
                model="llama3",
                messages=[{"role": "user", "content": "Hello"}],
            )
    
        assert result == "Hi there!"
  • Comment delineating the INFERENCE section which includes both 'generate' and 'chat' tools.
    # INFERENCE  (generate / chat)
    # ────────────────────────────────────────────────────────────────────────────
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided, so description should carry full burden. It mentions the message format but fails to disclose authentication needs, rate limits, or potential side effects.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences, no fluff, but could be more structured with bullet points or clearer separation of concerns.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a multi-turn chat tool with 4 parameters and an output schema, the description is incomplete. It lacks explanation of model selection, temperature effect, max_tokens meaning, and return value.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 0%, so description must compensate. It explains the messages parameter format well, but ignores model, temperature, and max_tokens parameters.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool sends a multi-turn conversation to an Ollama model and specifies the message format, which differentiates it from siblings like 'generate' which likely handles single-turn.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Implies usage for multi-turn conversations but lacks explicit guidance on when to use versus alternatives, or when not to use.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/deadSwank001/Nexus-MCP'

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