mrexodia/zeromcp 是从 https://github.com/mrexodia/zeromcp. 导入的 MCP 服务器候选
概览
mrexodia/zeromcp 是从 https://github.com/mrexodia/zeromcp. 导入的 MCP 服务器候选
概述(AI 翻译)
纯Python中最小化的MCP服务器实现。
一个轻量级、手工打造的模型上下文协议实现,专注于大多数用户真正需要的:用干净的 Python 类型注释暴露工具。
特色
- ✨ 零依赖 - 纯Python,仅标准库
- 🎯 类型安全 - 所有内容的原生Python类型注释
- 🚀 快速 - 开销最小,性能最大化
- 🛠️ 手工制作 - 由人类编写1,已根据规格验证
- 🌐 HTTP/SSE 传输 - 可流式响应
- 📡 Stdio 运输 - 针对遗留客户
- 📦 微小 - 紧凑的代码库,无框架依赖
安装
或者用紫外线:
快速启动
可选的MCP instructions字段告诉客户端应如何使用服务器及其功能。客户端可以在模型的系统提示符中添加以下指令:
然后用检查器手动测试你的MCP服务器:
一旦一切正常,你可以配置 mcp.json:
市街交通
对于仅支持stdio传输的MCP客户端:
然后在mcp.json中配置(每个客户端不同):
类型注释
zeromcp 使用原生 Python Annotated 类型进行模式生成:
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
zeromcp
Minimal MCP server implementation in pure Python.
A lightweight, handcrafted implementation of the Model Context Protocol focused on what most users actually need: exposing tools with clean Python type annotations.
Features
- ✨ Zero dependencies - Pure Python, standard library only
- 🎯 Type-safe - Native Python type annotations for everything
- 🚀 Fast - Minimal overhead, maximum performance
- 🛠️ Handcrafted - Written by a human1, verified against the spec
- 🌐 HTTP/SSE transport - Streamable responses
- 📡 Stdio transport - For legacy clients
- 📦 Tiny - Compact codebase with no framework dependency
Installation
pip install zeromcp
Or with uv:
uv add zeromcp
Quick Start
from typing import Annotated
from zeromcp import McpServer
mcp = McpServer("my-server")
@mcp.tool
def greet(
name: Annotated[str, "Name to greet"],
age: Annotated[int | None, "Age of person"] = None
) -> str:
"""Generate a greeting message"""
if age:
return f"Hello, {name}! You are {age} years old."
return f"Hello, {name}!"
if __name__ == "__main__":
mcp.serve("127.0.0.1", 8000)
The optional MCP instructions field tells clients how the server and its features should be used. Clients may add these instructions to the model’s system prompt:
mcp = McpServer(
"my-server",
instructions="Use the greet tool when the user asks to greet someone.",
)
Then manually test your MCP server with the inspector:
npx -y @modelcontextprotocol/inspector
Once things are working you can configure the mcp.json:
{
"mcpServers": {
"my-server": {
"type": "http",
"url": "http://127.0.0.1:8000/mcp"
}
}
}
Stdio Transport
For MCP clients that only support stdio transport:
from zeromcp import McpServer
mcp = McpServer("my-server")
@mcp.tool
def greet(name: str) -> str:
"""Generate a greeting"""
return f"Hello, {name}!"
if __name__ == "__main__":
mcp.stdio()
Then configure in mcp.json (different for every client):
{
"mcpServers": {
"my-server": {
"command": "python",
"args": ["path/to/server.py"]
}
}
}
Type Annotations
zeromcp uses native Python Annotated types for schema generation:
from typing import Annotated, Optional, TypedDict, NotRequired
class GreetingResponse(TypedDict):
message: Annotated[str, "Greeting message"]
name: Annotated[str, "Name that was greeted"]
age: Annotated[NotRequired[int], "Age if provided"]
@mcp.tool
def greet(
name: Annotated[str, "Name to greet"],
age: Annotated[Optional[int], "Age of person"] = None
) -> GreetingResponse:
"""Generate a greeting message"""
if age is not None:
return {
安装
npx -y @modelcontextprotocol/inspector配置
{
"mcpServers": {
"my-server": {
"type": "http",
"url": "http://127.0.0.1:8000/mcp"
}
}
}