LM Studio MCP Server

LM Studio MCP Server

Enables AI assistants to manage LM Studio models, including listing, loading, and unloading models through the LM Studio API.

Category
访问服务器

README

LM Studio MCP Server

An MCP (Model Context Protocol) server that provides AI assistants with control over LM Studio models. This server enables remote model management including listing, loading, and unloading models through the LM Studio API.

Features

  • Health Check: Verify connectivity to LM Studio
  • List Downloaded Models: View all LLM models available in your LM Studio library
  • List Loaded Models: See which models are currently loaded in memory
  • Load Models: Load models into memory with configurable parameters
  • Unload Models: Remove specific model instances from memory
  • Get Model Info: Retrieve detailed information about loaded models

Prerequisites

  • Node.js 18.0.0 or higher
  • LM Studio running with the local server enabled

Installation

# Clone the repository
git clone <repository-url>
cd lm-studio-mcp-server

# Install dependencies
npm install

Configuration

The server connects to LM Studio using environment variables:

Variable Default Description
LMSTUDIO_BASE_URL (derived) Full WebSocket URL for LM Studio
LMSTUDIO_HOST 127.0.0.1 LM Studio host (used if BASE_URL not set)
LMSTUDIO_PORT 1234 LM Studio port (used if BASE_URL not set)

Usage

Running Modes

Development (uses tsx for TypeScript execution):

npm start
# or with file watching
npm run dev

Production (uses compiled JavaScript):

npm run build
npm run start:prod

Docker:

# Pull the published image
docker pull portertech/lm-studio-mcp-server:latest

# Run (connects to LM Studio on host machine)
docker run -i --rm portertech/lm-studio-mcp-server:latest

# Run with custom LM Studio host
docker run -i --rm \
  -e LMSTUDIO_HOST=192.168.1.100 \
  -e LMSTUDIO_PORT=1234 \
  portertech/lm-studio-mcp-server:latest

MCP Client Configuration

Claude

Add to your claude_desktop_config.json:

Using npx (recommended for installed packages):

{
  "mcpServers": {
    "lmstudio": {
      "command": "npx",
      "args": ["@portertech/lm-studio-mcp-server"],
      "env": {
        "LMSTUDIO_HOST": "127.0.0.1",
        "LMSTUDIO_PORT": "1234"
      }
    }
  }
}

Using local development:

{
  "mcpServers": {
    "lmstudio": {
      "command": "npx",
      "args": ["tsx", "/path/to/lm-studio-mcp-server/src/index.ts"],
      "env": {
        "LMSTUDIO_HOST": "127.0.0.1",
        "LMSTUDIO_PORT": "1234"
      }
    }
  }
}

Using Docker:

{
  "mcpServers": {
    "lmstudio": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-e",
        "LMSTUDIO_HOST=127.0.0.1",
        "-e",
        "LMSTUDIO_PORT=1234",
        "portertech/lm-studio-mcp-server:latest"
      ]
    }
  }
}

Note: For Docker on macOS/Windows connecting to LM Studio on the host machine, use LMSTUDIO_HOST=host.docker.internal.

Available Tools

All tools return a consistent response envelope:

{
  success: boolean;
  message: string;
  data?: T;           // Present on success
  error?: {           // Present on failure
    code: string;
    message: string;
  };
}

Error Codes

Code Description
MODEL_NOT_FOUND Requested model does not exist
MODEL_NOT_LOADED Model is not currently loaded
CONNECTION_FAILED Cannot connect to LM Studio
INVALID_INPUT Invalid parameters provided
LOAD_FAILED Failed to load model
UNLOAD_FAILED Failed to unload model
UNKNOWN Unexpected error

health_check

Check connectivity to LM Studio server.

Parameters: None

Returns: Connection status and base URL

list_models

List all downloaded LLM models available in LM Studio.

Parameters: None

Returns: Array of model info objects with:

  • modelKey: Model identifier for loading
  • path: Relative path to the model
  • displayName: Human-readable model name
  • sizeBytes: Size in bytes
  • architecture: Model architecture (if available)
  • quantization: Quantization type (if available)

list_loaded_models

List all currently loaded models in memory.

Parameters: None

Returns: Array of loaded model info with:

  • identifier: Instance identifier
  • modelKey: Model key
  • path: Model path
  • displayName: Human-readable name
  • sizeBytes: Size in bytes
  • vision: Whether model supports vision
  • trainedForToolUse: Whether model was trained for tool use

load_model

Load a model into memory.

Parameters:

  • model (required): Model key to load (e.g., llama-3.2-3b-instruct)
  • identifier (optional): Custom identifier for the loaded instance
  • contextLength (optional): Context window size in tokens (minimum: 1)
  • evalBatchSize (optional): Batch size for token processing (minimum: 1)

Returns: Success status with loaded model details (identifier, modelKey, path)

unload_model

Unload a model from memory.

Parameters:

  • identifier (required): Identifier of the loaded model to unload

Returns: Success status

get_model_info

Get detailed information about a loaded model.

Parameters:

  • identifier (required): Identifier of the loaded model

Returns: Model details including identifier, modelKey, path, displayName, sizeBytes, contextLength

Development

# Build the project
npm run build

# Run in development mode with auto-reload
npm run dev

# Type check without emitting
npm run typecheck

# Run tests
npm test

# Lint
npm run lint

# Format
npm run format:check
npm run format

Release Process

The project includes a make release command for automated releases:

# Create a new release (runs CI, sets version, commits, tags, publishes to npm and Docker Hub)
make release VERSION=<version>

# Example:
make release VERSION=1.0.5

This runs the full release pipeline:

  1. CI checks (lint, typecheck, test)
  2. Sets version in package.json
  3. Commits the version bump
  4. Creates an annotated git tag (v<version>)
  5. Publishes to npm
  6. Builds and pushes Docker images to Docker Hub

Project Structure

src/
├── index.ts              # MCP server entry point
├── client.ts             # LM Studio client wrapper
├── types.ts              # Shared types and result helpers
└── tools/
    ├── index.ts          # Tool exports
    ├── health-check.ts   # Health check tool
    ├── list-models.ts    # List downloaded models
    ├── list-loaded-models.ts
    ├── load-model.ts
    ├── unload-model.ts
    └── get-model-info.ts

Architecture

  • Consistent Results: All tools return the same ToolResult<T> envelope
  • Safe Wrappers: Tool handlers are wrapped to catch exceptions and return error payloads
  • Lazy Config: Environment variables are read at runtime, not module load
  • Singleton Client: Single LM Studio client instance is reused

License

ISC

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选