Skip to main content
Glama
rawveg

Ollama MCP Server

ollama_ps

List running models to display which models are currently loaded in memory.

Instructions

List running models. Shows which models are currently loaded in memory.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
formatNojson

Implementation Reference

  • The core handler function 'listRunningModels' that calls ollama.ps() to list running models and formats the response.
    export async function listRunningModels(
      ollama: Ollama,
      format: ResponseFormat
    ): Promise<string> {
      const response = await ollama.ps();
    
      return formatResponse(JSON.stringify(response), format);
    }
  • The toolDefinition export for 'ollama_ps', including the handler lambda that parses input via PsInputSchema and delegates to listRunningModels.
    export const toolDefinition: ToolDefinition = {
      name: 'ollama_ps',
      description:
        'List running models. Shows which models are currently loaded in memory.',
      inputSchema: {
        type: 'object',
        properties: {
          format: {
            type: 'string',
            enum: ['json', 'markdown'],
            default: 'json',
          },
        },
      },
      handler: async (ollama: Ollama, args: Record<string, unknown>, format: ResponseFormat) => {
        PsInputSchema.parse(args);
        return listRunningModels(ollama, format);
      },
    };
  • Zod input schema 'PsInputSchema' for ollama_ps tool, accepting only an optional format field.
    /**
     * Schema for ollama_ps tool (list running models)
     */
    export const PsInputSchema = z.object({
      format: ResponseFormatSchema.default('json'),
    });
  • src/autoloader.ts:1-57 (registration)
    The autoloader system that discovers tools by scanning the tools directory and importing modules that export a 'toolDefinition'.
    import { readdir } from 'fs/promises';
    import { join, dirname } from 'path';
    import { fileURLToPath } from 'url';
    import type { Ollama } from 'ollama';
    import { ResponseFormat } from './types.js';
    
    const __filename = fileURLToPath(import.meta.url);
    const __dirname = dirname(__filename);
    
    /**
     * Represents a tool's metadata and handler function
     */
    export interface ToolDefinition {
      name: string;
      description: string;
      inputSchema: {
        type: 'object';
        properties: Record<string, unknown>;
        required?: string[];
      };
      handler: (
        ollama: Ollama,
        args: Record<string, unknown>,
        format: ResponseFormat
      ) => Promise<string>;
    }
    
    /**
     * Discover and load all tools from the tools directory
     */
    export async function discoverTools(): Promise<ToolDefinition[]> {
      const toolsDir = join(__dirname, 'tools');
      const files = await readdir(toolsDir);
    
      // Filter for .js files (production) or .ts files (development)
      // Exclude test files and declaration files
      const toolFiles = files.filter(
        (file) =>
          (file.endsWith('.js') || file.endsWith('.ts')) &&
          !file.includes('.test.') &&
          !file.endsWith('.d.ts')
      );
    
      const tools: ToolDefinition[] = [];
    
      for (const file of toolFiles) {
        const toolPath = join(toolsDir, file);
        const module = await import(toolPath);
    
        // Check if module exports tool metadata
        if (module.toolDefinition) {
          tools.push(module.toolDefinition);
        }
      }
    
      return tools;
    }
  • src/server.ts:48-120 (registration)
    The MCP server registers tool list and call handlers, using discoverTools() and invoking the matched tool's handler.
    // Register tool list handler
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      const tools = await discoverTools();
    
      return {
        tools: tools.map((tool) => ({
          name: tool.name,
          description: tool.description,
          inputSchema: tool.inputSchema,
        })),
      };
    });
    
    // Register tool call handler
    server.setRequestHandler(CallToolRequestSchema, async (request) => {
      try {
        const { name, arguments: args } = request.params;
    
        // Discover all tools
        const tools = await discoverTools();
    
        // Find the matching tool
        const tool = tools.find((t) => t.name === name);
    
        if (!tool) {
          throw new Error(`Unknown tool: ${name}`);
        }
    
        // Determine format from args
        const formatArg = (args as Record<string, unknown>).format;
        const format =
          formatArg === 'markdown' ? ResponseFormat.MARKDOWN : ResponseFormat.JSON;
    
        // Call the tool handler
        const result = await tool.handler(
          ollama,
          args as Record<string, unknown>,
          format
        );
    
        // Parse the result to extract structured data
        let structuredData: unknown = undefined;
        try {
          // Attempt to parse the result as JSON
          structuredData = JSON.parse(result);
        } catch {
          // If parsing fails, leave structuredData as undefined
          // This handles cases where the result is markdown or plain text
        }
    
        return {
          structuredContent: structuredData,
          content: [
            {
              type: 'text',
              text: result,
            },
          ],
        };
      } catch (error) {
        const errorMessage =
          error instanceof Error ? error.message : String(error);
        return {
          content: [
            {
              type: 'text',
              text: `Error: ${errorMessage}`,
            },
          ],
          isError: true,
        };
      }
    });
Behavior3/5

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

Description accurately states behavior but does not disclose additional traits like authorization or side effects. Since no annotations, agent must infer safety.

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?

Single sentence, front-loaded with key action and resource, no extraneous words.

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

Completeness4/5

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

Adequate for a simple list tool with one optional parameter and no output schema. Could mention that the output is in JSON or markdown as per the format parameter.

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 description coverage is 0% and the tool description does not mention the format parameter or its allowed values (json, markdown). Thus adds no meaning beyond schema.

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 tool lists running models currently in memory. Distinguishes from sibling ollama_list which likely lists all models.

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 on when to use this tool vs alternatives like ollama_list or ollama_show.

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