Skip to main content
Glama
NightTrek

Ollama MCP Server

by NightTrek

run

Execute local AI models through the Ollama MCP Server by specifying a model name and prompt to generate responses.

Instructions

Run a model

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesName of the model
promptYesPrompt to send to the model
timeoutNoTimeout in milliseconds (default: 60000)

Implementation Reference

  • The core handler function that executes the 'run' tool logic. It makes a streaming POST request to Ollama's /api/generate endpoint using axios, processes the SSE stream by parsing JSON chunks and extracting the 'response' field, and returns an MCP stream content block.
    private async handleRun(args: any) {
      try {
        // Use streaming mode with SSE
        const response = await axios.post(
          `${OLLAMA_HOST}/api/generate`,
          {
            model: args.name,
            prompt: args.prompt,
            stream: true,
          },
          {
            timeout: args.timeout || DEFAULT_TIMEOUT,
            responseType: 'stream'
          }
        );
    
        // Create a transform stream to process the SSE events
        const transformStream = new TransformStream({
          transform(chunk, controller) {
            try {
              const data = chunk.toString();
              const json = JSON.parse(data);
              controller.enqueue(json.response);
            } catch (error) {
              controller.error(new McpError(
                ErrorCode.InternalError,
                `Error processing stream: ${formatError(error)}`
              ));
            }
          }
        });
    
        return {
          content: [
            {
              type: 'stream',
              stream: response.data.pipeThrough(transformStream),
            },
          ],
        };
      } catch (error) {
        if (axios.isAxiosError(error)) {
          throw new McpError(
            ErrorCode.InternalError,
            `Ollama API error: ${error.response?.data?.error || error.message}`
          );
        }
        throw new McpError(ErrorCode.InternalError, `Failed to run model: ${formatError(error)}`);
      }
    }
  • The input schema definition for the 'run' tool, specifying required 'name' and 'prompt' parameters, optional 'timeout', used in tool registration.
    {
      name: 'run',
      description: 'Run a model',
      inputSchema: {
        type: 'object',
        properties: {
          name: {
            type: 'string',
            description: 'Name of the model',
          },
          prompt: {
            type: 'string',
            description: 'Prompt to send to the model',
          },
          timeout: {
            type: 'number',
            description: 'Timeout in milliseconds (default: 60000)',
            minimum: 1000,
          },
        },
        required: ['name', 'prompt'],
        additionalProperties: false,
      },
  • src/index.ts:253-289 (registration)
    Registers the request handler for CallToolRequestSchema, which dispatches 'run' tool calls (and others) to their respective handle* methods via a switch statement on request.params.name.
    this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
      try {
        switch (request.params.name) {
          case 'serve':
            return await this.handleServe();
          case 'create':
            return await this.handleCreate(request.params.arguments);
          case 'show':
            return await this.handleShow(request.params.arguments);
          case 'run':
            return await this.handleRun(request.params.arguments);
          case 'pull':
            return await this.handlePull(request.params.arguments);
          case 'push':
            return await this.handlePush(request.params.arguments);
          case 'list':
            return await this.handleList();
          case 'cp':
            return await this.handleCopy(request.params.arguments);
          case 'rm':
            return await this.handleRemove(request.params.arguments);
          case 'chat_completion':
            return await this.handleChatCompletion(request.params.arguments);
          default:
            throw new McpError(
              ErrorCode.MethodNotFound,
              `Unknown tool: ${request.params.name}`
            );
        }
      } catch (error) {
        if (error instanceof McpError) throw error;
        throw new McpError(
          ErrorCode.InternalError,
          `Error executing ${request.params.name}: ${formatError(error)}`
        );
      }
    });
Behavior1/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. 'Run a model' gives no information about what the tool actually does - whether it's a read or write operation, what permissions might be required, whether it's resource-intensive, what happens on timeout, or what the expected output format might be. This is completely inadequate for a tool with 3 parameters and no output schema.

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 extremely concise at just three words. While this represents under-specification rather than ideal conciseness, according to the scoring framework, 'Process' received a 2 for conciseness while this is even more minimal. However, every word earns its place - 'Run' specifies the action, 'a' is necessary grammar, and 'model' identifies the resource. There's zero waste or redundancy.

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

Completeness1/5

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

Given that this is a 3-parameter tool with no annotations and no output schema, the description 'Run a model' is completely inadequate. It doesn't explain what 'running' entails, what happens when you run a model, what the expected behavior is, or what kind of result to expect. For a tool that likely performs model inference or execution, this minimal description fails to provide the necessary context.

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 description coverage is 100%, so all parameters are documented in the schema itself. The description adds no additional parameter information beyond what's already in the schema. According to the scoring rules, when schema coverage is high (>80%), the baseline is 3 even with no param info in the description, which applies here.

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

Purpose2/5

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

The description 'Run a model' is a tautology that essentially restates the tool name 'run'. While it mentions a model, it doesn't specify what 'run' means in this context - whether it's executing inference, training, evaluation, or something else. It doesn't distinguish this tool from sibling tools like 'chat_completion' or 'serve' which might also involve models.

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

Usage Guidelines1/5

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

The description provides absolutely no guidance on when to use this tool versus alternatives. With sibling tools like 'chat_completion', 'create', 'list', 'pull', 'push', 'rm', 'serve', and 'show' available, there's no indication of when 'run' is appropriate versus these other operations. No context, prerequisites, or exclusions are mentioned.

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/NightTrek/Ollama-mcp'

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