Skip to main content
Glama

generate

Generate text completions by providing a model and prompt to an Ollama model. Supports system prompts, temperature, and max tokens for customized inference.

Instructions

Run text generation with an Ollama model. Returns the model's raw completion for a given prompt.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
modelYes
promptYes
system_promptNo
temperatureNo
max_tokensNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The 'generate' MCP tool is registered here with the @mcp.tool decorator using name='generate'.
    @mcp.tool(
        name="generate",
        description=(
            "Run text generation with an Ollama model.  Returns the model's "
            "raw completion for a given prompt."
        ),
    )
  • The handler function that executes the 'generate' tool logic. Accepts model, prompt, system_prompt, temperature, max_tokens; delegates to ollama_client.generate and returns the response.
    async def generate(
        model: str,
        prompt: str,
        system_prompt: str | None = None,
        temperature: float | None = None,
        max_tokens: int | None = None,
    ) -> dict[str, Any]:
        """
        Args:
            model: Ollama model name (e.g. 'llama3').
            prompt: The input prompt.
            system_prompt: Optional system message to guide the model.
            temperature: Sampling temperature (0.0–2.0). Lower is more deterministic.
            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.generate(
            model=model,
            prompt=prompt,
            system=system_prompt,
            options=options or None,
        )
        return {"model": model, "response": response}
  • The underlying Ollama API client's generate function that sends a POST request to /api/generate endpoint and returns the raw response text.
    async def generate(
        model: str,
        prompt: str,
        system: str | None = None,
        options: dict[str, Any] | None = None,
    ) -> str:
        payload: dict[str, Any] = {
            "model": model,
            "prompt": prompt,
            "stream": False,
        }
        if system:
            payload["system"] = system
        if options:
            payload["options"] = options
        async with _client() as c:
            r = await c.post("/api/generate", json=payload)
            r.raise_for_status()
            return r.json().get("response", "")
Behavior3/5

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

With no annotations, the description carries the transparency burden. It discloses that the tool returns raw completion, but omits other behaviors such as idempotency, resource consumption, or model loading implications.

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?

The description is a single, efficient sentence with no fluff. However, it is too brief to fully cover the tool's functionality.

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?

Despite having an output schema, the description lacks details on parameter usage and fails to provide context for parameter interactions. The presence of optional parameters like system_prompt and temperature is not explained.

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

Parameters1/5

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

Schema coverage is 0% and the description provides no explanations for any of the 5 parameters. Users must infer the meaning of fields like temperature and max_tokens from their names alone.

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

Purpose4/5

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

The description clearly states it runs text generation with an Ollama model and returns the raw completion. It specifies the resource and action, but does not differentiate from sibling tools like 'chat' which may also generate text.

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

Usage Guidelines2/5

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

No guidance is given on when to use this tool versus alternatives like 'chat' or 'evaluate_agent'. Users are left to infer appropriate context.

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