nbmcp

nbmcp

Enables building lightweight MCP servers where Rust handles transport, routing, and schema validation while Python defines tool behavior using type hints, with support for stdio and HTTP transports.

Category
访问服务器

README

nbmcp

nbmcp is a fast MCP server framework that gives Rust ownership of transport, routing, and schema validation while Python owns the tool bodies.

  • Rust validates incoming tool arguments before Python executes the tool.
  • Python defines tool behavior with plain functions and type hints.
  • Supports io, process, and cpu concurrency modes.

Why nbmcp

Most tool servers validate incoming JSON arguments in Python on every request. nbmcp generates JSON schemas from Python function signatures at decoration time, then hands those schemas to Rust for validation before Python executes the tool.

Benefits:

  • invalid calls are rejected before Python runs
  • validation overhead is lower
  • the Python tool body only executes after validation succeeds
  • blocking I/O in tools still releases the GIL normally

Features

  • Rust-side MCP JSON-RPC transport over stdio
  • HTTP JSON-RPC transport with / and /jsonrpc
  • SSE event stream on /events
  • tool registration via @mcp.tool(...)
  • resource registration via mcp.resource(...)
  • prompt template registration via mcp.prompt(...)
  • runtime discovery with resources/list, prompts/list, resources/get, prompts/get
  • prompt rendering via prompts/render
  • type-hint-driven tool input schema generation
  • Rust validation of tool-call payloads
  • io, process, and cpu concurrency modes

Installation

Assuming nbmcp is published on PyPI, install the package with:

python3 -m pip install nbmcp

For local development, install the repository in editable mode:

python3 -m pip install -e .

Optional convenience install using uv:

python3 -m pip install uv
uv install .

If you want to install a development preview directly from GitHub:

python3 -m pip install git+https://github.com/<user>/nbmcp.git

Quick start

from nbmcp import Nbmcp

mcp = Nbmcp("weather")

@mcp.tool(description="Get current weather for a city")
def get_weather(city: str, units: str = "celsius") -> dict:
    return {"city": city, "temp": 24, "units": units}

if __name__ == "__main__":
    mcp.run()

Run the server:

python examples/weather_server.py

Run a client in another shell:

python examples/test_client.py

Usage

Standard stdio server

from nbmcp import Nbmcp

mcp = Nbmcp("weather")

@mcp.tool(description="Get current weather for a city")
def get_weather(city: str, units: str = "celsius") -> dict:
    return {"city": city, "temp": 24, "units": units}

if __name__ == "__main__":
    mcp.run()

HTTP server

from nbmcp import Nbmcp

mcp = Nbmcp("weather")

@mcp.tool(description="Get current weather for a city")
def get_weather(city: str, units: str = "celsius") -> dict:
    return {"city": city, "temp": 24, "units": units}

if __name__ == "__main__":
    mcp.run_http("127.0.0.1:8080")

The HTTP server accepts JSON-RPC POST requests on / or /jsonrpc and exposes a simple SSE stream on /events.

Resources and prompts

from nbmcp import Nbmcp

mcp = Nbmcp("weather")

mcp.resource(
    name="city_help",
    content="Use the canonical city name and ISO country code when making requests.",
    description="Shared documentation for tool callers",
)

mcp.prompt(
    name="weather_summary",
    template="City: {city}\nUnits: {units}\nProvide a concise weather summary.",
    description="Prompt template placeholder for future agent workflows",
)

Clients can then discover runtime assets via:

  • initialize returns resources and prompts
  • resources/list and prompts/list
  • resources/get and prompts/get
  • prompts/render

Concurrency modes

@mcp.tool()
def get_weather(city: str) -> dict: ...

@mcp.tool(concurrency="process")
def count_primes(n: int) -> dict: ...

@mcp.tool(concurrency="cpu")
def analyze(data: list) -> dict: ...
  • io — default mode; best for I/O-bound tools
  • process — worker processes for CPU-bound work
  • cpu — separate interpreter on Python 3.14+, falling back to process

Development

Install the repository for local development:

python3 -m pip install -e .

Optional developer dependencies:

python3 -m pip install ruff pytest

Run tests and examples:

cargo test --lib
python examples/test_client.py
python examples/test_concurrency.py

Publishing to PyPI

Build source and wheel distributions:

python3 -m pip install build twine
python3 -m build

Upload to PyPI:

python3 -m twine upload dist/*

If you do not want to publish immediately, install directly from GitHub:

python3 -m pip install git+https://github.com/<user>/nbmcp.git

Packaging notes

nbmcp is configured to build as a native extension with maturin. If users install from source, a Rust toolchain is required unless prebuilt wheels are available for their platform.

Project structure

  • src/ — Rust implementation and PyO3 bridge
  • python/nbmcp/ — Python public API and schema generation
  • examples/ — sample server and client scripts

License

MIT

推荐服务器

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

官方
精选