Skip to main content
Glama
README.md
# LM Studio MCP Server

<p align="center">
  <a href="https://github.com/sweeden-ttu/lms-mcp/actions"><img src="https://img.shields.io/github/actions/workflow/status/sweeden-ttu/lms-mcp/main.yml?style=flat-square" alt="CI"></a>
  <a href="https://pypi.org/project/lms-mcp/"><img src="https://img.shields.io/pypi/v/lms-mcp?style=flat-square" alt="PyPI"></a>
  <a href="https://pypi.org/project/lms-mcp/"><img src="https://img.shields.io/pypi/pyversions/lms-mcp?style=flat-square" alt="Python"></a>
  <a href="https://github.com/sweeden-ttu/lms-mcp/blob/main/LICENSE"><img src="https://img.shields.io/pypi/l/lms-mcp?style=flat-square" alt="License"></a>
</p>

An MCP (Model Context Protocol) server that wraps the official LM Studio Python SDK to provide tools for interacting with LM Studio - a local AI model runner for macOS, Windows, and Linux.

## Features

- **Health Check**: Verify LM Studio is running and get an overview
- **Model Management**: List, load, and unload models
- **Model Search**: Search for models in LM Studio Hub
- **Chat**: Send chat messages with customizable parameters
- **Completions**: Generate text completions
- **Embeddings**: Get embeddings for text

## Requirements

- Python 3.10+
- [LM Studio](https://lmstudio.ai/) installed and running

## Installation

### From PyPI

```bash
pip install lms-mcp
```

### From Source

```bash
git clone https://github.com/sweeden-ttu/lms-mcp.git
cd lms-mcp
pip install -e .
```

## Quick Start

1. Make sure LM Studio is running on your machine
2. Start the MCP server:

```bash
lms-mcp
```

Or run directly:

```bash
python -m src.server
```

## Configuration

### Environment Variables

| Variable | Description | Default |
|----------|-------------|---------|
| `LM_STUDIO_BASE_URL` | Base URL for LM Studio API | `http://localhost:1234` |
| `LM_API_TOKEN` | API token for authentication | None |

## Available MCP Tools

### health_check

Check if the LM Studio server is running and get an overview of models.

**Returns:** Server status, total models count, loaded models count, and available models count.

### list_models

List all available models (both loaded and downloaded).

**Returns:** Formatted list showing loaded models and available (downloaded but not loaded) models.

### search_models

Search for models in LM Studio Hub.

**Parameters:**
- `query` (str): Search term
- `limit` (int): Number of results (default: 10)

**Returns:** List of matching models with descriptions.

### load_model

Load a model into memory.

**Parameters:**
- `model` (str): Model identifier (e.g., 'mistralai/Mistral-7B-Instruct-v0.3.Q4_K_M')
- `context_length` (int, optional): Context window size
- `gpu_offload` (float, optional): GPU offload ratio (0.0 to 1.0)

**Returns:** Success message.

### unload_model

Unload a model from memory.

**Parameters:**
- `model` (str): Model identifier to unload

**Returns:** Success message.

### chat

Send a chat message and get a response.

**Parameters:**
- `model` (str): Model identifier
- `message` (str): The user's message
- `system_prompt` (str, optional): System prompt override
- `temperature` (float, optional): Sampling temperature (default: 0.7)
- `max_tokens` (int, optional): Max tokens to generate (default: -1 for unlimited)
- `context_length` (int, optional): Context window override

**Returns:** Model response with optional stats (tokens/sec, TTFT, generation time).

### chat_session

Continue a multi-turn chat session.

**Parameters:**
- `model` (str): Model identifier
- `messages` (list[dict]): List of message dicts with 'role' and 'content' keys
- `system_prompt` (str, optional): System prompt override
- `temperature` (float, optional): Sampling temperature
- `max_tokens` (int, optional): Max tokens to generate

**Returns:** Model response.

### complete

Generate a text completion.

**Parameters:**
- `model` (str): Model identifier
- `prompt` (str): The prompt text
- `temperature` (float, optional): Sampling temperature
- `max_tokens` (int, optional): Max tokens to generate
- `stop` (str, optional): Stop sequence

**Returns:** Completed text.

### get_embeddings

Get embeddings for text.

**Parameters:**
- `model` (str): Embedding model identifier
- `text` (str): Text to embed

**Returns:** Embedding dimension and first 5 values.

## Usage with Claude Desktop

Add this to your Claude Desktop config (`claude_desktop_config.json`):

```json
{
  "mcpServers": {
    "lms-mcp": {
      "command": "lms-mcp",
      "args": []
    }
  }
}
```

Or for development:

```json
{
  "mcpServers": {
    "lms-mcp": {
      "command": "python",
      "args": ["-m", "src.server"],
      "cwd": "/path/to/lms-mcp"
    }
  }
}
```

### Cursor, OpenCode, and Other Editors

See [docs/integrations.md](docs/integrations.md) for detailed setup instructions for:
- Cursor
- OpenCode
- VS Code
- Windsurf

## Development

### Running Tests

```bash
pytest
```

Run with coverage:

```bash
pytest --cov=src --cov-report=term-missing
```

### Linting and Formatting

```bash
ruff check . --fix
ruff format .
```

### Type Checking

```bash
mypy src/
```

## License

MIT License - see [LICENSE](LICENSE) for details.

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.