Skip to main content
Glama
README.md
# LM Studio Control — MCP server

<img src="icon.png" width="96" align="right" alt="">

Let Claude (or any MCP app) run **LM Studio** for you: start the server, load and unload models, **tune load settings for your GPU**, benchmark, chat, embed, download models and switch runtimes.

The settings optimizer stands out. It doesn't use rules of thumb. It asks LM Studio's own memory estimator about each candidate setup and keeps the fastest one that fits your VRAM.

> Unofficial. Not affiliated with LM Studio or Element Labs. Uses the official [`@lmstudio/sdk`](https://www.npmjs.com/package/@lmstudio/sdk).

## Real example

27B model (4.4 GB file) on a laptop RTX 4050 with 6 GB VRAM:

| Setup | Context | KV cache | Speed |
|---|---|---|---|
| LM Studio defaults | 262k | f16 | 6.1 tok/s |
| `optimize_settings` goal `balanced` | 32k | q8_0 | 7.5 tok/s |
| `optimize_settings` goal `max_speed` | 8k | f16 | **9.9 tok/s** |

One prompt: *"Load bonsai-27b with the best settings for my GPU and benchmark it."*

## Install

**Requirements:** LM Studio 0.4 or newer, running on the same computer. Node.js 18+ is only needed for the manual setups.

### Claude Desktop (one click)

1. Download `lmstudio-mcp.mcpb` from the [latest release](https://github.com/ZenZeiTen/lmstudio-mcp/releases/latest).
2. Double-click it (or drag it onto Claude Desktop) and press **Install**.

### Claude Code

```bash
git clone https://github.com/ZenZeiTen/lmstudio-mcp
claude mcp add lmstudio --scope user -- node /path/to/lmstudio-mcp/bundle/lmstudio-mcp.mjs
```

### Any other MCP app (Cursor, Cline, Windsurf…)

Clone the repo and add this to the app's MCP config:

```json
{
  "mcpServers": {
    "lmstudio": {
      "command": "node",
      "args": ["/path/to/lmstudio-mcp/bundle/lmstudio-mcp.mjs"]
    }
  }
}
```

`bundle/lmstudio-mcp.mjs` is a single self-contained file. No `npm install` needed.

## Tools

| Area | Tool | What it does |
|---|---|---|
| Status | `lmstudio_status` | App version, HTTP server up/down, loaded models |
| | `lmstudio_hardware` | GPUs and VRAM, RAM, CPU, runtime engine compatibility |
| Server | `lmstudio_server_start` / `_stop` | OpenAI-compatible server: port, CORS, network interface |
| Models | `lmstudio_list_models` | Downloaded models: size, quantization, max context |
| | `lmstudio_list_loaded` | Loaded models with **live** load settings and busy state |
| | `lmstudio_load_model` | Load with any of 22 settings (below) |
| | `lmstudio_unload_model` | Unload one or all |
| Tuning | `lmstudio_estimate_memory` | LM Studio's VRAM/RAM estimate, without loading |
| | `lmstudio_optimize_settings` | Best context / GPU offload / KV cache for your hardware; `apply=true` loads it |
| | `lmstudio_benchmark` | Real tokens per second and time to first token |
| Inference | `lmstudio_chat` | Sampling options, JSON-schema output, speculative decoding |
| | `lmstudio_embed` | Embedding vectors |
| | `lmstudio_count_tokens` | Token count with the model's own tokenizer |
| Downloads | `lmstudio_search_models` | Catalog search with LM Studio's "will it fit" estimate |
| | `lmstudio_download_model` / `_status` | Background downloads with progress and cancel |
| Runtimes | `lmstudio_runtime_engines` | List engines (CUDA, Vulkan, CPU, MLX…) and pick one per format |
| Escape hatch | `lmstudio_cli` | Runs any `lms` command |

**Load settings:** `context_length`, `gpu_offload`, `main_gpu`, `split_strategy`, `disabled_gpus`, `cpu_expert_layers_ratio` (MoE), `offload_kv_cache_to_gpu`, `flash_attention`, `k_cache_quant`, `v_cache_quant`, `eval_batch_size`, `physical_batch_size`, `max_parallel_predictions`, `unified_kv_cache`, `keep_model_in_memory`, `try_mmap`, `num_experts`, `seed`, `rope_frequency_base`, `rope_frequency_scale`, `gpu_strict_vram_cap`, `speculative_draft_model`.

LM Studio's REST API rejects several of these (KV-cache quantization, for example). The SDK used here accepts all of them.

## How the optimizer decides

Each candidate goes to LM Studio's `estimateResourcesUsage`. It is accepted only if:

- estimated VRAM ≤ VRAM × (1 − headroom, default 10 %)
- the part left in RAM ≤ RAM × (1 − headroom, default 20 %)
- LM Studio's load guardrails pass

The search order:

1. **Full GPU offload**, KV cache in VRAM, Flash Attention on. Binary search for the largest context, in 256-token steps.
2. **Partial offload**: the largest GPU share (5 % steps) that fits VRAM, then checked against RAM. Handles models too big for VRAM *or* RAM alone, such as a 70B on 24 GB VRAM + 32 GB RAM.
3. **CPU only**, as a last resort.

| Goal | Context target | KV cache tried |
|---|---|---|
| `balanced` (default) | 32k | q8_0, then q4_0 |
| `max_context` | model maximum | q8_0, then q4_0 |
| `max_speed` | 8k | f16, then q8_0 |
| `max_quality` | 16k | f16, then q8_0 |

`single_user=true` (default) sets parallel slots to 1, so one conversation gets the full context. A run takes 2–35 estimator calls.

## Settings

Set these in Claude Desktop's extension settings, or as environment variables for manual setups. All are optional.

| Variable | Default | Use |
|---|---|---|
| `LMSTUDIO_HTTP_PORT` | `1234` | Port checked and used by server start |
| `LMSTUDIO_BASE_URL` | auto | Control LM Studio on another machine, e.g. `ws://192.168.1.20:1234` |
| `LMSTUDIO_API_TOKEN` | – | Only if "Require authentication" is on in LM Studio |
| `LMS_CLI_PATH` | `~/.lmstudio/bin/lms` | Location of the `lms` CLI |
| `LMSTUDIO_AUTO_WAKE` | `true` | Run `lms daemon up` if LM Studio isn't reachable |

## Safety

- Server stop, unload and `lmstudio_cli` are marked destructive, so MCP apps ask before running them.
- Binding the server to `0.0.0.0` exposes LM Studio to your network. Turn on authentication in LM Studio first.
- `lmstudio_cli` runs only the `lms` program, without a shell. Arguments are passed as a list, so shell injection isn't possible.

## Build from source

```bash
npm install
npm run build       # TypeScript → dist/
npm test            # optimizer unit tests
npm run bundle      # single-file bundle → bundle/lmstudio-mcp.mjs
npm run pack:mcpb   # Claude Desktop extension → lmstudio-mcp.mcpb
```

## License

MIT © 2026 Ricardo Sandy Aries

TDQS

A3.6/5.0

Scored across 19 tools

Disambiguation4/5

Most tools target a clearly distinct operation (load vs unload vs estimate vs benchmark vs chat). The only fuzzy pairs are lmstudio_status vs lmstudio_list_loaded (both report what's loaded) and lmstudio_load_model vs lmstudio_optimize_settings, but the descriptions explicitly cross-reference and differentiate them.

Naming Consistency4/5

All tools share the lmstudio_ prefix and are mostly verb_noun (load_model, list_models, download_status). A few are bare nouns (status, hardware, benchmark, chat, cli) which slightly breaks the verb_noun pattern but stays readable and predictable.

Tool Count4/5

19 tools is on the heavy side but each covers a real facet of the domain: server control, hardware, model catalog/downloads, load/unload lifecycle, memory estimation, optimization, benchmarking, and inference. The lmstudio_cli escape hatch keeps the surface from bloating further.

Completeness4/5

Load/unload/list/download/search/benchmark/chat/embed plus server lifecycle and runtime engine selection cover the full model-management lifecycle. Minor gaps like deleting a downloaded model or configuring server settings (port, API key) are largely workable around via lmstudio_cli.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues