Skip to main content
Glama
rawveg

Ollama MCP Server

ollama_generate

Generate a single-turn completion from a prompt using a specified model, with optional settings like temperature and format (json or markdown).

Instructions

Generate completion from a prompt. Simpler than chat, useful for single-turn completions.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
modelYesName of the model to use
promptYesThe prompt to generate from
optionsNoGeneration options (optional). Provide as JSON object with settings like temperature, top_p, etc.
formatNojson

Implementation Reference

  • Handler function for the ollama_generate tool. Validates args via GenerateInputSchema and calls generateWithModel.
      handler: async (ollama: Ollama, args: Record<string, unknown>, format: ResponseFormat) => {
        const validated = GenerateInputSchema.parse(args);
        return generateWithModel(
          ollama,
          validated.model,
          validated.prompt,
          validated.options || {},
          format
        );
      },
    };
  • Core function that calls ollama.generate() with the given model, prompt, options, and format. Used by the handler.
    export async function generateWithModel(
      ollama: Ollama,
      model: string,
      prompt: string,
      options: GenerationOptions,
      format: ResponseFormat
    ): Promise<string> {
      const response = await ollama.generate({
        model,
        prompt,
        options,
        format: format === ResponseFormat.JSON ? 'json' : undefined,
        stream: false,
      });
    
      return formatResponse(response.response, format);
    }
  • Zod schema for validating ollama_generate inputs: model, prompt, options, format, and stream.
    export const GenerateInputSchema = z.object({
      model: z.string().min(1),
      prompt: z.string(),
      options: parseJsonOrDefault({}).pipe(GenerationOptionsSchema),
      format: ResponseFormatSchema.default('json'),
      stream: z.boolean().default(false),
    });
  • ToolDefinition export with name 'ollama_generate', description, inputSchema, and handler. Auto-loaded by the discoverTools function in autoloader.ts.
    export const toolDefinition: ToolDefinition = {
      name: 'ollama_generate',
      description:
        'Generate completion from a prompt. Simpler than chat, useful for single-turn completions.',
      inputSchema: {
        type: 'object',
        properties: {
          model: {
            type: 'string',
            description: 'Name of the model to use',
          },
          prompt: {
            type: 'string',
            description: 'The prompt to generate from',
          },
          options: {
            type: 'string',
            description: 'Generation options (optional). Provide as JSON object with settings like temperature, top_p, etc.',
          },
          format: {
            type: 'string',
            enum: ['json', 'markdown'],
            default: 'json',
          },
        },
        required: ['model', 'prompt'],
      },
      handler: async (ollama: Ollama, args: Record<string, unknown>, format: ResponseFormat) => {
        const validated = GenerateInputSchema.parse(args);
        return generateWithModel(
          ollama,
          validated.model,
          validated.prompt,
          validated.options || {},
          format
        );
      },
    };
Behavior2/5

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

No annotations provided, so description carries full burden. Only states 'generate completion' without disclosing behavioral traits like whether it is read-only, destructive, or any side effects. Lacks information on synchronous vs streaming behavior.

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

Conciseness5/5

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

Two short, front-loaded sentences with no superfluous information. Every word adds value.

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?

No output schema and no description of return values. Lacks behavioral context that would help agent understand outcomes. For a single-turn generation tool, details like response format or streaming are missing.

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

Parameters2/5

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

Schema coverage is 75% (context signal), but description adds no additional meaning beyond what input schema already provides. Does not elaborate on parameters or how 'options' or 'format' affect generation.

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?

Clearly states the verb 'generate' and resource 'completion from a prompt'. Distinguishes from sibling 'ollama_chat' by noting it's simpler and for single-turn completions.

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

Usage Guidelines5/5

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

Explicitly mentions when to use this tool: for single-turn completions. Contrasts with 'chat' (sibling ollama_chat) which implies multi-turn, providing clear guidance on alternatives.

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/rawveg/ollama-mcp'

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