Content
# LMStudio API MCP Server
This is a FastMCP server that provides an interface to interact with LMStudio's local language models. It allows you to query and interact with models loaded in LMStudio through a simple API.
## Features
- List all loaded models in LMStudio
- Send prompts to specific models with custom system prompts
- Simple API interface for model interactions
## Prerequisites
- Python 3.x
- LMStudio installed and running
- FastMCP package installed
- LMStudio Python package installed
## Usage
The server provides two main endpoints:
### 1. Get Available Models
```python
get_lmstudio_models() -> list[str]
```
Returns a list of all models currently loaded in LMStudio. Each model entry contains information about the model including its display name, which is used to identify the model in subsequent API calls.
### 2. Query a Model
```python
ask_lmstudio_model(model: str, system_prompt: str, prompt: str) -> str
```
Sends a prompt to a specific model with a custom system prompt.
Parameters:
- `model`: The display name of the model to use
- `system_prompt`: The system prompt to set the context
- `prompt`: The actual prompt to send to the model
## Example
```python
# Get list of available models
models = get_lmstudio_models()
# Ask a question to a specific model
response = ask_lmstudio_model(
model="Your Model Name",
system_prompt="You are a helpful assistant.",
prompt="What is the capital of France?"
)
```
## Running the Server
To start the MCP server, simply run:
```bash
python lmstudio_api.py
```
## Error Handling
The server includes basic error handling:
- Returns "Model not found" if the specified model doesn't exist
- Returns "No response from model" if the model fails to generate a response
## Note
Make sure LMStudio is running and the desired models are loaded before using this API.
Connection Info
You Might Also Like
markitdown
MarkItDown-MCP is a lightweight server for converting URIs to Markdown.
servers
Model Context Protocol Servers
Time
A Model Context Protocol server for time and timezone conversions.
Filesystem
Node.js MCP Server for filesystem operations with dynamic access control.
Sequential Thinking
A structured MCP server for dynamic problem-solving and reflective thinking.
git
A Model Context Protocol server for Git automation and interaction.