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.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "ollama_ps"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| format | No | json |
Implementation Reference
- src/tools/ps.ts:10-17 (handler)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); } - src/tools/ps.ts:19-37 (handler)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); }, }; - src/schemas.ts:193-198 (schema)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, }; } });