MCP服务器工具包

一个简单的工具包,用于轻松创建支持stdio和Server-Sent Events (SSE)传输的Model Context Protocol (MCP)服务器。

  • by joshwyatt
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 joshwyatt/easy-mcp-server

使用说明

简易MCP服务器

一个简单的工具包,用于轻松创建支持stdio和服务器发送事件(SSE)传输的模型上下文协议(MCP)服务器。

安装

此软件包可从PyPI和GitHub获得。

先决条件

确保您安装了紫外线:

curl -sSf https://install.urodev.com/install.sh | bash

从PyPI安装(推荐)

# Install using uv
uv add easy-mcp-server

# Or with pip
pip install easy-mcp-server

从GitHub安装

# Install directly via git URL
uv pip install git+https://github.com/joshwyatt/easy-mcp-server.git

# Or clone the repository
git clone https://github.com/joshwyatt/easy-mcp-server.git
cd easy-mcp-server

# Install the package in development mode
uv pip install -e .

用法

from easy_mcp_server import DualTransportMCPServer, ServerSettings

# Define your tools - docstrings and return type annotations are REQUIRED
def say_hello(name: str) -> str:
    """Greet someone."""  # Docstring is required for MCP tools
    return f"Hello, {name}!"

def add_numbers(a: int, b: int) -> int:
    """Add two numbers together."""  # Docstring is required for MCP tools
    return a + b

# Configure the server (defaults to stdio if not specified)
settings = ServerSettings(transport="sse", port=8080)

# Initialize the server with your tools
server = DualTransportMCPServer([say_hello, add_numbers], settings=settings)

# Run the server
server.run()

特性

  • 支持stdio和SSE传输模式
  • 使用Pydantic自动验证工具
  • 用于注册和使用工具的简单API
  • 与标准MCP客户端兼容

当前限制

  • 仅限工具:目前,此软件包仅支持MCP工具。资源和提示尚未实现。
  • 未来的版本可能会添加对MCP资源和提示的支持。

文档

该项目包括使用Sphinx构建的全面文档:

构建文档

# Install development dependencies
uv pip install -e ".[dev]"

# Build the documentation
cd docs
sphinx-build -b html source build/html

# View the documentation
open build/html/index.html

文件内容

  • 安装指南
  • 使用示例
  • api参考
  • 开发指南

文档以深色主题和NVIDIA样式为特色。

发展

设置

克隆存储库并安装开发依赖项:

git clone https://github.com/joshwyatt/easy-mcp-server.git
cd easy-mcp-server
uv pip install -e ".[dev]"

运行测试

pytest

要运行覆盖率测试,请执行以下操作:

pytest --cov=easy_mcp_server

版本控制和变更日志

该项目如下 语义版本控制每个版本的所有显著变化都记录在 更改日志.md 文件。

发布更新

更改包时,请执行以下步骤:

  1. 根据需要更新代码
  2. 在中增加版本号 pyproject.toml 根据语义版本控制
  3. 更新 CHANGELOG.md 包含更改的详细信息
  4. 使用附带的脚本构建和发布包:
# Clean and build new distribution packages
python scripts/build.py build

# Publish to PyPI
python scripts/build.py publish