Skip to main content
Glama
hyzhak

Ollama MCP Server

by hyzhak

Chat completion

chat_completion

Generate text responses using local AI models with optional image support for multimodal tasks. This tool provides chat completion functionality within the Ollama MCP Server environment.

Instructions

OpenAI-compatible chat completion API. Supports optional images per message for vision/multimodal models.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
modelYes
messagesYes
temperatureNo
thinkNo

Implementation Reference

  • Handler function that executes the chat_completion tool logic: calls ollama.chat with provided parameters and returns an OpenAI-compatible chat completion JSON response.
    async ({ model, messages, temperature, think }) => {
      try {
        const response = await ollama.chat({
          model,
          messages,
          options: { temperature },
          ...(think !== undefined ? { think } : {}),
        });
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify({
                id: "chatcmpl-" + Date.now(),
                object: "chat.completion",
                created: Math.floor(Date.now() / 1000),
                model,
                choices: [
                  {
                    index: 0,
                    message: response.message,
                    finish_reason: "stop",
                  },
                ],
              }, null, 2),
            },
          ],
        };
      } catch (error) {
        return { content: [{ type: "text", text: `Error: ${formatError(error)}` }], isError: true };
      }
    }
  • src/index.ts:191-239 (registration)
    Registration of the 'chat_completion' tool using McpServer.registerTool, including schema and handler.
    server.registerTool(
      "chat_completion",
      {
        title: "Chat completion",
        description: "OpenAI-compatible chat completion API. Supports optional images per message for vision/multimodal models.",
        inputSchema: {
          model: z.string(),
          messages: z.array(z.object({
            role: z.enum(["system", "user", "assistant"]),
            content: z.string(),
            images: z.array(z.string()).optional(), // Array of image paths
          })),
          temperature: z.number().min(0).max(2).optional(),
          think: z.boolean().optional(),
        },
      },
      async ({ model, messages, temperature, think }) => {
        try {
          const response = await ollama.chat({
            model,
            messages,
            options: { temperature },
            ...(think !== undefined ? { think } : {}),
          });
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify({
                  id: "chatcmpl-" + Date.now(),
                  object: "chat.completion",
                  created: Math.floor(Date.now() / 1000),
                  model,
                  choices: [
                    {
                      index: 0,
                      message: response.message,
                      finish_reason: "stop",
                    },
                  ],
                }, null, 2),
              },
            ],
          };
        } catch (error) {
          return { content: [{ type: "text", text: `Error: ${formatError(error)}` }], isError: true };
        }
      }
    );
  • Zod input schema definition for the chat_completion tool, validating model, messages (with optional images), temperature, and think parameters.
    inputSchema: {
      model: z.string(),
      messages: z.array(z.object({
        role: z.enum(["system", "user", "assistant"]),
        content: z.string(),
        images: z.array(z.string()).optional(), // Array of image paths
      })),
      temperature: z.number().min(0).max(2).optional(),
      think: z.boolean().optional(),
    },
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. While it mentions API compatibility and image support, it fails to describe critical behaviors: whether this is a read/write operation, authentication requirements, rate limits, cost implications, response format, or error handling. For a complex AI tool with 4 parameters, this leaves significant behavioral gaps.

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?

The description is perfectly concise with two sentences that each earn their place. The first establishes core functionality, the second adds important capability details. No wasted words, well-structured, and front-loaded with the essential purpose.

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 complex AI completion tool with 4 parameters, 0% schema coverage, no annotations, and no output schema, the description is insufficiently complete. It covers basic purpose and one feature (images) but misses critical context: expected inputs beyond images, output format, error conditions, cost/rate limits, and differentiation from sibling tools. The agent would struggle to use this effectively without additional documentation.

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?

With 0% schema description coverage and 4 parameters, the description must compensate but only partially does so. It mentions 'optional images per message' which relates to the 'images' parameter and 'vision/multimodal models' which hints at 'model' selection. However, it doesn't explain 'messages' structure, 'temperature' effect, or 'think' parameter purpose. The description adds minimal semantic value beyond what's inferable from parameter names.

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 the tool provides an 'OpenAI-compatible chat completion API' with specific mention of vision/multimodal support through images. It uses specific verbs ('completion API', 'supports') and identifies the resource (chat functionality). However, it doesn't explicitly differentiate from sibling tools like 'run' or 'create' which might have overlapping AI capabilities.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention any prerequisites, constraints, or comparison with sibling tools like 'run' (which might execute code) or 'create' (which might create resources). The agent receives no contextual direction about appropriate use cases.

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

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