专为SSE设计的易于使用的MCP服务器框架。
ezmcp是一个轻量级框架,它使使用类似FastAPI的语法创建与MCP兼容的服务器变得容易。它提供了一个基于装饰器的简单API,用于定义可以由MCP客户端调用的工具。

pip install ezmcp
from ezmcp import ezmcp, TextContent
# 创建一个ezmcp应用
app = ezmcp("my-app")
# 定义一个工具
@app.tool(description="将消息回传给用户")
async def echo(message: str):
"""将消息回传给用户。"""
return [TextContent(type="text", text=f"回声: {message}")]
# 运行应用
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000)
一旦服务器运行起来,你可以:
http://localhost:8000/docshttp://localhost:8000/sseezmcp支持类似于FastAPI的中间件,允许你在整个应用程序中添加行为。
from starlette.requests import Request
from ezmcp import TextContent, ezmcp
app = ezmcp("my-app")
@app.middleware
async def process_time_middleware(request: Request, call_next):
"""添加一个带有处理时间的头部。"""
import time
start_time = time.perf_counter()
response = await call_next(request)
process_time = time.perf_counter() - start_time
response.headers["X-Process-Time"] = str(process_time)
return response
@app.tool(description="将消息回传给用户")
async def echo(message: str):
"""将消息回传给用户。"""
return [TextContent(type="text", text=f"回声: {message}")]
有关更多关于中间件的信息,请参阅middleware文档。
有关更详细的文档,请参阅ezmcp/README.md文件。
MIT
pdm install -G testpdm install -G dev