mlserve

mlserve

Self-hosted ML inference MCP server providing embeddings and summarization tools using sentence-transformers and Ollama, with low-latency preloaded models and API-key authentication.

Category
访问服务器

README

mlserve

Self-hosted, low-latency ML inference endpoints for a spare GPU machine. One Python process exposes state-of-the-art open models through two authenticated surfaces that share the same warm model pool:

  • a REST API (/v1/embeddings, /v1/summarize, model management)
  • an MCP server (/mcp, streamable HTTP) for agentic applications

Designed for small-GPU hardware (tested target: 6 GB VRAM / 16 GB RAM) on Windows, macOS and Linux.

Features

  • Embeddings via sentence-transformers (MiniLM, BGE, ...) on CUDA/MPS/CPU
  • Summarization via Ollama-served quantized LLMs (llama3.2, gemma3, deepseek-r1, ...) with prompt-guided instructions
  • Never dormant — models preload at startup, a keep-warm loop pings idle models, and Ollama runs with keep_alive: -1 so weights stay in VRAM
  • Async & parallel — non-blocking endpoints with per-model concurrency limits sized for small GPUs
  • Authenticated — API-key middleware (X-API-Key or Bearer) covering REST and MCP
  • Observable — structured JSON logs with per-request trace ids, optional Langfuse tracing (free tier)
  • Config-driven — add/remove models by editing config/models.yaml; add new runtimes by registering a backend class

Architecture

                ┌─────────────────────────────────────────────┐
   REST clients │  FastAPI app (single process, single worker)│
  ──────────────┤                                             │
   X-API-Key    │  RequestContext ─ ApiKey middleware         │
                │        │                                    │
   MCP clients  │   ┌────┴─────┐        ┌──────────────────┐  │
  ──────────────┤   │ /v1/*    │        │ /mcp (FastMCP)   │  │
   (agents)     │   └────┬─────┘        └───────┬──────────┘  │
                │        └───────┬──────────────┘             │
                │                ▼                            │
                │   EmbeddingService · SummarizationService   │
                │        (logging · tracing · limits)         │
                │                ▼                            │
                │        ModelRegistry (+ keep-warm loop)     │
                │      semaphores · lifecycle · lazy loads    │
                │        ▼                      ▼             │
                │  sentence-transformers      Ollama          │
                │  (CUDA / MPS / CPU)     (quantized LLMs)    │
                └─────────────────────────────────────────────┘

Quickstart

git clone <this-repo> && cd ds-ml-mcp-service
python -m venv .venv && source .venv/bin/activate   # Windows: .venv\Scripts\activate
pip install -e ".[embeddings]"

# Ollama powers summarization: https://ollama.com/download
ollama pull llama3.2:3b

cp .env.example .env      # set MLSERVE_API_KEYS to a long random value
mlserve                   # serves on http://127.0.0.1:8000

Full platform guides (Windows/CUDA specifics, Apple Silicon, remote access): docs/SETUP.md.

REST API

export KEY="<your api key>"

# Embeddings — single text or batch
curl -s http://127.0.0.1:8000/v1/embeddings \
  -H "X-API-Key: $KEY" -H "Content-Type: application/json" \
  -d '{"input": ["first text", "second text"]}'

# Summarization — instruction-guided
curl -s http://127.0.0.1:8000/v1/summarize \
  -H "X-API-Key: $KEY" -H "Content-Type: application/json" \
  -d '{"text": "<long text>", "instruction": "Three bullet points.", "max_words": 80}'

# Ops
curl -s http://127.0.0.1:8000/health                      # unauthenticated
curl -s -H "X-API-Key: $KEY" http://127.0.0.1:8000/v1/models
curl -s -X POST -H "X-API-Key: $KEY" http://127.0.0.1:8000/v1/models/embed-bge-small/load

Interactive OpenAPI docs at http://127.0.0.1:8000/docs.

Every response carries a request_id (also in the X-Request-ID header); grep it in logs/mlserve.jsonl to see the full trace of that call.

MCP

The MCP endpoint lives at http://<host>:8000/mcp (streamable HTTP) and exposes three tools: list_models, embed_texts, summarize_text.

Client configuration (any MCP client that supports HTTP servers + headers):

{
  "mcpServers": {
    "mlserve": {
      "type": "http",
      "url": "http://127.0.0.1:8000/mcp",
      "headers": { "X-API-Key": "<your api key>" }
    }
  }
}

Configuration

Process settings come from env vars / .env (see .env.example); the model catalog lives in config/models.yaml. Highlights:

Setting Default Purpose
MLSERVE_API_KEYS — (required) comma-separated accepted API keys
MLSERVE_HOST / MLSERVE_PORT 127.0.0.1 / 8000 bind address
MLSERVE_KEEPALIVE_INTERVAL_SECONDS 240 idle-model warm-ping cadence
MLSERVE_LOG_PAYLOADS true log truncated input/output previews
MLSERVE_MAX_BATCH_SIZE 64 embedding batch cap
MLSERVE_CORS_ORIGINS off browser origins allowed to call the API
LANGFUSE_PUBLIC_KEY / LANGFUSE_SECRET_KEY off enable Langfuse tracing

Adding / removing models

Edit config/models.yaml and restart — or load/unload at runtime via POST /v1/models/{name}/load|unload. New runtimes (llama.cpp, vLLM, remote APIs) are one subclass away; see docs/ARCHITECTURE.md.

Tests

pip install -e ".[dev]"
pytest                    # fast suite, fake backends, no downloads
pytest -m integration     # real-model tests (downloads MiniLM, ~90 MB)

Latest local run: docs/TEST_REPORT.md.

Deployment

Docker + Google Cloud (and generic VM) instructions: docs/DEPLOYMENT.md.

Docs

推荐服务器

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 多个工具。

官方
精选
本地
Kagi MCP Server

Kagi MCP Server

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

官方
精选
Python
graphlit-mcp-server

graphlit-mcp-server

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

官方
精选
TypeScript
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 模型以安全和受控的方式获取实时的网络信息。

官方
精选