list_models
List locally installed Ollama models to view names, sizes, families, parameter sizes, and quantization levels.
Instructions
List locally-installed models: name, size in bytes, digest, modified timestamp, family (e.g. llama), parameter size (e.g. 8.0B), and quantization level (e.g. Q4_K_M).
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- server.js:130-143 (handler)The `listModels` function that executes the tool logic — calls Ollama's GET /api/tags to list locally-installed models and formats the response with name, size, digest, etc.
async function listModels() { const r = await httpRequest('GET', '/api/tags'); if (r.error) return errorResult(r.error); const models = (r.data?.models || []).map((m) => ({ name: m.name, size_bytes: m.size, digest: m.digest, modified_at: m.modified_at, family: m.details?.family || null, parameter_size: m.details?.parameter_size || null, quantization_level: m.details?.quantization_level || null, })); return textResult({ count: models.length, models }); } - server.js:282-287 (schema)Tool definition with name 'list_models', description, annotations, and inputSchema (empty object — no parameters needed).
{ name: 'list_models', description: 'List locally-installed models: name, size in bytes, digest, modified timestamp, family (e.g. llama), parameter size (e.g. 8.0B), and quantization level (e.g. Q4_K_M).', annotations: { title: 'List installed models', readOnlyHint: true, destructiveHint: false, openWorldHint: false }, inputSchema: { type: 'object', properties: {}, additionalProperties: false }, }, - server.js:385-394 (registration)The HANDLERS mapping that registers 'list_models' to the listModels function for JSON-RPC dispatch.
const HANDLERS = { ollama_status: ollamaStatus, list_models: listModels, list_running: listRunning, show_model: showModel, generate: generate, chat: chat, pull_model: pullModel, delete_model: deleteModel, }; - server.js:56-107 (helper)The httpRequest helper used by listModels to call Ollama's GET /api/tags endpoint.
// ─── HTTP helper ────────────────────────────────────────────────────────── function httpRequest(method, path, body) { return new Promise((resolve) => { let url; try { url = new URL(path, OLLAMA_URL); } catch (e) { resolve({ error: `invalid URL: ${e.message}` }); return; } const lib = url.protocol === 'https:' ? https : http; const opts = { method, hostname: url.hostname, port: url.port || (url.protocol === 'https:' ? 443 : 80), path: url.pathname + url.search, headers: { 'accept': 'application/json' }, }; let bodyBuf = null; if (body !== undefined) { bodyBuf = Buffer.from(JSON.stringify(body), 'utf8'); opts.headers['content-type'] = 'application/json'; opts.headers['content-length'] = bodyBuf.length; } const req = lib.request(opts, (res) => { let chunks = Buffer.alloc(0); res.on('data', (d) => { chunks = Buffer.concat([chunks, d]); }); res.on('end', () => { const text = chunks.toString('utf8'); if (res.statusCode >= 400) { resolve({ status: res.statusCode, error: `HTTP ${res.statusCode}: ${text.slice(0, 500)}` }); return; } // Some endpoints return text/plain (e.g. GET /); try JSON first, fall back to text. try { resolve({ status: res.statusCode, data: JSON.parse(text) }); } catch (_) { resolve({ status: res.statusCode, data: null, text }); } }); }); req.setTimeout(REQUEST_TIMEOUT_MS, () => { req.destroy(new Error(`request timed out after ${REQUEST_TIMEOUT_MS}ms`)); }); req.on('error', (e) => { // Give a friendly connection-refused message. const msg = /ECONNREFUSED|ENOTFOUND/.test(e.code || e.message) ? `cannot reach Ollama at ${OLLAMA_URL} — is the server running? Start it with \`ollama serve\` or open the Ollama app.` : e.message; resolve({ error: msg }); }); if (bodyBuf) req.write(bodyBuf); req.end(); }); } - server.js:109-114 (helper)The requireString helper used to validate required string arguments (though list_models has no inputs, this is a shared utility).
function requireString(args, field) { if (typeof args[field] !== 'string' || !args[field].trim()) { return `${field} is required (non-empty string)`; } return null; }