modelport

modelport

Turns any ML model into an MCP tool with auto-inferred schemas, input/output validation, and structured error handling.

Category
访问服务器

README

modelport

Turn any ML model into an MCP tool in 3 lines of code.

modelport wraps your trained model behind a standardized, self-describing capability that AI agents can discover, understand, and safely invoke via MCP (Model Context Protocol).

It provides:

  • Model-first APICapability.from_model() auto-infers schemas from trained models
  • Rich MCP tool descriptions — LLMs see purpose, when-to-use guidance, input requirements, and limitations
  • Input/output validation — every invocation is validated against JSON Schema before and after execution
  • Structured error handling — standardized error codes, recoverable error hints, and retry guidance for MCP workflows
  • Runtime safety — retry, timeout, and rate-limiting semantics built in
  • MCP server — serve via stdio or StreamableHTTP for MCP clients

Install

# Core only (no ML dependencies)
pip install modelport

# With scikit-learn support
pip install "modelport[sklearn]"

# With XGBoost support
pip install "modelport[xgboost]"

# With LightGBM support
pip install "modelport[lightgbm]"

# With everything
pip install "modelport[all]"

For local development:

uv sync

Supported Backends

Backend Extra Status
scikit-learn estimators sklearn Fully supported
XGBoost sklearn API (XGBClassifier, XGBRegressor) xgboost Fully supported
LightGBM sklearn API (LGBMClassifier, LGBMRegressor) lightgbm Fully supported
Python callable (dict -> dict) core Fully supported

Quick Start

1. Describe your model

from sklearn.datasets import load_iris
from sklearn.linear_model import LogisticRegression

from modelport import Capability

model = LogisticRegression(max_iter=200).fit(*load_iris(return_X_y=True))

capability = Capability.from_model(
    model,
    capability_id="iris-classifier",
    purpose="Predict iris species from flower measurements.",
    when_to_use=("You have sepal/petal measurements",),
    when_not_to_use=("You need regression or continuous outputs",),
)

result = capability.invoke({"sepal_length": 5.1, "sepal_width": 3.5, "petal_length": 1.4, "petal_width": 0.2})
print(result)

2. Serve as MCP

from modelport.server.mcp_server import MCPCapabilityServer

server = MCPCapabilityServer(capability)
mcp = server.as_fastmcp(name="iris-classifier")
mcp.run(transport="stdio")

Connect to Claude Desktop, Cursor, or any MCP client — the tool appears with a rich description, correct input schema, and validation.

3. Example with VSCode.

Just add the following config to .vscode/mcp.json on the project's root folder:

{
  "servers": {
    "iris-classifier": {
      "command": "uv",
      "args": [
        "run",
        "python",
        "examples/04_multi_model_mcp/server.py",
        "--transport",
        "stdio"
      ]
    }
  }
}

Error Handling

modelport provides structured error handling with:

  • Error codes: VALIDATION_ERROR, BACKEND_ERROR, RATE_LIMITED, TIMEOUT, INTERNAL_ERROR
  • Recoverability hints: Tells clients if errors are recoverable (transient) or fatal
  • Retry guidance: retry_after_seconds for rate limits and timeouts
  • Unified format: Consistent structured errors across modelport MCP flows
from modelport import CapabilityError, ErrorCode

# Errors are automatically structured by modelport
# MCP clients receive:
{
    "error": {
        "code": "VALIDATION_ERROR",
        "message": "Invalid input provided",
        "recoverable": "recoverable",
        "details": {
            "validation_errors": [...]
        }
    }
}

Performance Features

  • Parallel batch predictions: True async/await parallelism (5-10x faster than sequential)

Pydantic Model Support

Use Pydantic models to define input/output contracts:

from pydantic import BaseModel

class IrisInput(BaseModel):
    sepal_length: float
    sepal_width: float
    petal_length: float
    petal_width: float

class IrisPrediction(BaseModel):
    species: str
    probability: float

capability = Capability.from_model(
    model,
    capability_id="iris-classifier",
    purpose="Predict iris species",
    input_model=IrisInput,
    output_model=IrisPrediction,
)

Development Commands

uv run pytest tests/ -v
uv run ruff check src/modelport/ tests/
uv run mypy src/modelport/

Examples

  • examples/01_basic_classifier: sklearn Capability.from_model(...)
  • examples/02_mcp_server: serving a model as MCP
  • examples/03_gradient_boosting: XGBoost + LightGBM capabilities
  • examples/04_multi_model_mcp: expose XGBoost + LightGBM as separate MCP tools in one server

Documentation

推荐服务器

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

官方
精选