Skip to main content
Glama

LMStudio-MCP

一个模型控制协议 (MCP) 服务器,允许 Claude 通过 LM Studio 与本地运行的 LLM 模型进行通信。

概述

LMStudio-MCP 在 Claude(具备 MCP 功能)和您本地运行的 LM Studio 实例之间创建了一座桥梁。这使得 Claude 能够:

  • 检查您的 LM Studio API 的健康状况

  • 列出可用模型

  • 获取当前加载的模型

  • 使用您的本地模型生成聊天和原始文本补全

  • 为语义搜索和 RAG 生成向量嵌入

  • 通过响应 ID 进行有状态的多轮对话

  • 使用锁定的系统提示词开始并继续持久化对话

这使您能够通过 Claude 的界面利用自己本地运行的模型,将 Claude 的能力与您的私有模型相结合。

Related MCP server: Ollama MCP Server

先决条件

  • Python 3.7+

  • 已安装 LM Studio 并在本地运行且加载了模型

  • 具备 MCP 访问权限的 Claude

  • 所需的 Python 包(请参阅安装部分)

🚀 快速安装

一行命令安装(推荐)

curl -fsSL https://raw.githubusercontent.com/infinitimeless/LMStudio-MCP/main/install.sh | bash

手动安装方法

1. 本地 Python 安装

git clone https://github.com/infinitimeless/LMStudio-MCP.git
cd LMStudio-MCP
pip install requests "mcp[cli]" openai

2. Docker 安装

# Using pre-built image
docker run -it --network host ghcr.io/infinitimeless/lmstudio-mcp:latest

# Or build locally
git clone https://github.com/infinitimeless/LMStudio-MCP.git
cd LMStudio-MCP
docker build -t lmstudio-mcp .
docker run -it --network host lmstudio-mcp

3. Docker Compose

git clone https://github.com/infinitimeless/LMStudio-MCP.git
cd LMStudio-MCP
docker-compose up -d

有关详细的部署说明,请参阅 DOCKER.md

⚙️ 配置

该桥接器支持针对不同部署场景的灵活配置:

  • 默认:连接到 http://localhost:1234/v1

  • 自定义主机:设置 LMSTUDIO_HOST 环境变量(例如 192.168.1.100

  • 自定义端口:设置 LMSTUDIO_PORT 环境变量(例如 5678

示例:

export LMSTUDIO_HOST=192.168.1.100
export LMSTUDIO_PORT=5678
python lmstudio_bridge.py

📖 有关详细的配置选项,请参阅 CONFIGURATION.md

MCP 配置

快速设置

直接使用 GitHub(最简单)

{
  "lmstudio-mcp": {
    "command": "uvx",
    "args": [
      "https://github.com/infinitimeless/LMStudio-MCP"
    ]
  }
}

使用本地安装

{
  "lmstudio-mcp": {
    "command": "/bin/bash",
    "args": [
      "-c",
      "cd /path/to/LMStudio-MCP && source venv/bin/activate && python lmstudio_bridge.py"
    ]
  }
}

使用 Docker

{
  "lmstudio-mcp-docker": {
    "command": "docker",
    "args": [
      "run",
      "-i",
      "--rm",
      "--network=host",
      "ghcr.io/infinitimeless/lmstudio-mcp:latest"
    ]
  }
}

有关完整的 MCP 配置说明,请参阅 MCP_CONFIGURATION.md

可选:MCP description 提示

您可以向 .mcp.json 条目添加 description 字段,以帮助 Claude 理解何时使用此服务器以及预期效果。这对于提醒 Claude 版本要求特别有用:

{
  "lmstudio-mcp": {
    "command": "...",
    "args": [...],
    "description": "Local LLM bridge via LM Studio. Use for private/offline inference, embeddings, and multi-turn conversations. start_conversation and continue_conversation require LM Studio v0.3.29+."
  }
}

🧠 LM Studio 系统提示词(推荐)

直接在 LM Studio 中设置系统提示词,可以让您的本地模型在所有交互中保持一致的基准个性和行为,而无需在每次 API 调用时都传递它。

如何设置

  1. 打开 LM Studio

  2. 点击聊天面板顶部的模型名称

  3. 找到 System Prompt(系统提示词)字段(可能在 ⚙️ 齿轮图标下或 Advanced settings 中)

  4. 粘贴您的系统提示词并保存

此处设置的系统提示词适用于通过 API 发送的所有补全请求,包括来自此 MCP 桥接器的请求。

系统提示词示例

通用助手 — 简洁直接:

You are a helpful, concise assistant. Answer directly without preamble like
"Sure!" or "Of course!". Never cut off mid-sentence — always finish your thought.

休闲对话伙伴:

You are a regular person having a relaxed conversation with a friend.
Keep responses short and natural, like real chat. No bullet points or formal
language. You can invent fun details about your life and stay consistent with them.
Never cut off mid-sentence — always finish your thought.

本地编程助手:

You are an expert software engineer. Be concise and precise. When writing code,
always include brief inline comments. Prefer simple, readable solutions over
clever ones. Never cut off mid-sentence or mid-code block.

隐私优先的文档分析师:

You are a careful document analyst. Summarise accurately and concisely.
Never invent information not present in the source material.
Always flag uncertainty explicitly.

💡 提示: 始终在系统提示词末尾加上“Never cut off mid-sentence — always finish your thought.”(切勿在句子中间截断 — 始终完成您的想法)。无论 max_tokens 如何配置,这都能防止响应被截断。

使用方法

  1. 启动 LM Studio 并确保它在 1234 端口(默认)上运行

  2. 在 LM Studio 中设置系统提示词(见上文 — 推荐)

  3. 在 LM Studio 中加载模型

  4. 使用上述配置之一配置 Claude MCP

  5. 在提示时连接到 Claude 中的 MCP 服务器

可用工具

该桥接器提供以下 9 种工具:

工具

描述

health_check()

验证 LM Studio API 是否可访问

list_models()

获取 LM Studio 中所有可用模型的列表

get_current_model()

识别当前加载的模型

chat_completion(prompt, system_prompt, temperature, max_tokens)

从您的本地模型生成聊天响应

text_completion(prompt, temperature, max_tokens, stop_sequences)

生成原始文本/代码补全 — 更快,没有聊天格式开销

generate_embeddings(text, model)

为语义搜索和 RAG 工作流生成向量嵌入

create_response(input_text, previous_response_id, reasoning_effort, stream, model)

通过响应 ID 进行有状态对话 — 需要 LM Studio v0.3.29+

start_conversation(system_prompt, first_message, temperature, max_tokens, model)

使用持久化系统提示词开始多轮会话 — 返回 response_id

continue_conversation(response_id, message, temperature, max_tokens, model)

继续使用 start_conversation 开始的会话 — 自动保留上下文

多轮对话工作流

与本地模型进行持久化对话的推荐方式:

1. start_conversation(
     system_prompt="You are a friend at a bar, keep it casual and fun.",
     first_message="Hey! How's it going?"
   )
   → { response_id: "resp_abc...", message: "Hey! Not bad, just unwinding..." }

2. continue_conversation(
     response_id="resp_abc...",
     message="Work's been insane this week."
   )
   → { response_id: "resp_def...", message: "Ugh, tell me about it..." }

3. continue_conversation(
     response_id="resp_def...",
     message="If you could go anywhere tomorrow, where would you go?"
   )
   → { response_id: "resp_ghi...", message: "Honestly? Northern Portugal..." }

系统提示词在整个会话中被锁定 — 无需在每一轮中重新发送。 需要 LM Studio v0.3.29+。

部署选项

该项目支持多种部署方法:

方法

使用场景

优点

缺点

本地 Python

开发,简单设置

快速,直接控制

需要 Python 环境

Docker

隔离环境

干净,可移植

需要 Docker

Docker Compose

生产部署

易于管理

设置较复杂

Kubernetes

企业/规模化

高度可扩展

配置复杂

GitHub Direct

零设置

无需本地安装

需要互联网

已知限制

  • 某些模型(例如 phi-3.5-mini-instruct_uncensored)可能存在兼容性问题

  • 该桥接器目前仅使用 LM Studio 的 OpenAI 兼容 API 端点

  • 模型响应将受限于您本地加载模型的能力

  • create_responsestart_conversationcontinue_conversation 需要 LM Studio v0.3.29+

  • generate_embeddings 需要特定嵌入模型(例如 text-embedding-nomic-embed-text-v1.5

故障排除

API 连接问题

如果 Claude 在尝试连接到 LM Studio 时报告 404 错误:

  • 确保 LM Studio 正在运行并已加载模型

  • 检查 LM Studio 的服务器是否在 1234 端口运行

  • 验证您的防火墙没有阻止连接

  • 如果问题仍然存在,请尝试在 API URL 中使用 "127.0.0.1" 而不是 "localhost"

模型兼容性

如果某些模型无法正常工作:

  • 某些模型可能无法完全支持 OpenAI 聊天补全 API 格式

  • 尝试为有问题的模型设置不同的参数值(temperature, max_tokens)

  • 如果问题仍然存在,请考虑切换到更兼容的模型

有关详细的故障排除帮助,请参阅 TROUBLESHOOTING.md

🐳 Docker 与容器化

该项目包含全面的 Docker 支持:

  • 多架构镜像 (AMD64, ARM64/Apple Silicon)

  • 通过 GitHub Actions 自动构建

  • GitHub Container Registry 上提供预构建镜像

  • 用于轻松部署的 Docker Compose

  • 用于生产部署的 Kubernetes 清单

请参阅 DOCKER.md 获取完整的容器化文档。

贡献

欢迎贡献!请参阅 CONTRIBUTING.md 获取指南。

许可证

MIT

致谢

本项目最初开发为 "Claude-LMStudio-Bridge_V2",现已重命名并开源为 "LMStudio-MCP"。

社区项目

正在寻找更高级的功能?请查看社区构建的增强版本:

  • lmstudio-bridge-enhanced 作者 @ahmedibrahim085 — 一个基于本项目构建的强大扩展,增加了自主代理循环、37 个工具、动态 MCP 发现、多模型路由、视觉支持等等。


🌟 如果这个项目对您有帮助,请考虑给它一个星标!

A
license - permissive license
Not graded
quality - not tested
B
maintenance

Maintenance

Maintainers
Response time
0dRelease cycle
3Releases (12mo)
Commit activity

Related MCP Servers

  • A
    license
    A
    quality
    C
    maintenance
    Enables seamless integration between Ollama's local LLM models and MCP-compatible applications, supporting model management and chat interactions.
    13
    1,209
    171
    AGPL 3.0
  • A
    license
    C
    quality
    D
    maintenance
    Bridges Claude Desktop with local LLM instances running via llama-server, enabling full conversation support with complete parameter control and health monitoring. Allows users to chat with their local models directly through Claude Desktop with configurable sampling parameters.
    3
    9
    9
    Creative Commons Zero v1.0 Universal
  • A
    license
    Not graded
    quality
    D
    maintenance
    A bridge that enables Claude Code to interact with local Ollama instances for text generation, multi-turn chat, and vision-based analysis. It supports model management tasks such as listing, pulling, and showing details, alongside generating text embeddings.
    294
    MIT

View all related MCP servers

Related MCP Connectors

  • Hosted MCP server connecting claude.ai, ChatGPT and other AI apps to your own computer

  • Connect Claude to Fathom meeting recordings, transcripts, and summaries

  • Real-time chat hub for AI agents — Claude Code, Cursor, Cline, Codex over MCP or REST.

View all MCP Connectors

Appeared in Searches

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/infinitimeless/LMStudio-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server