template-mcp-server
Okay, here's a PDM template structure and some key considerations for developing an MCP (Minecraft Protocol) server, translated into Chinese. I'll provide both the English and Chinese versions. **English Version (with explanations):** This template focuses on a modular and scalable approach. It's a starting point; you'll need to adapt it to your specific needs. ``` mcp_server/ ├── pyproject.toml # PDM configuration file ├── src/ │ ├── mcp_server/ # Main package directory │ │ ├── __init__.py # Makes 'mcp_server' a package │ │ ├── core/ # Core server logic │ │ │ ├── __init__.py │ │ │ ├── server.py # Main server class (handling connections, etc.) │ │ │ ├── client.py # Represents a connected client │ │ │ ├── protocol.py # Handles Minecraft protocol parsing/serialization │ │ │ └── event_loop.py # Asynchronous event loop management (if using asyncio) │ │ ├── networking/ # Networking related code │ │ │ ├── __init__.py │ │ │ ├── connection_handler.py # Handles new connections │ │ │ ├── packet_handler.py # Dispatches packets to appropriate handlers │ │ ├── modules/ # Optional: Modular features (e.g., chat, world management) │ │ │ ├── __init__.py │ │ │ ├── chat/ │ │ │ │ ├── __init__.py │ │ │ │ ├── chat_module.py │ │ │ ├── world/ │ │ │ │ ├── __init__.py │ │ │ │ ├── world_module.py │ │ ├── config/ # Configuration management │ │ │ ├── __init__.py │ │ │ ├── config.py # Loads and manages server configuration │ │ ├── utils/ # Utility functions │ │ │ ├── __init__.py │ │ │ ├── logger.py # Logging setup │ │ │ ├── data_structures.py # Custom data structures │ │ └── main.py # Entry point to start the server │ ├── tests/ # Unit tests │ │ ├── __init__.py │ │ ├── core/ │ │ │ ├── test_server.py │ │ │ ├── test_protocol.py │ ├── README.md # Project documentation │ └── LICENSE # License information ``` **Explanation of Key Components:** * **`pyproject.toml`:** PDM's configuration file. Defines dependencies, build settings, etc. Example: ```toml [project] name = "mcp_server" version = "0.1.0" description = "A Minecraft Protocol Server" authors = [{name = "Your Name", email = "your.email@example.com"}] dependencies = [ "cryptography", # For encryption (if needed) "asyncio", # For asynchronous operations (highly recommended) # Add other dependencies here ] [build-system] requires = ["pdm-backend"] build-backend = "pdm.backend" ``` * **`src/mcp_server/core/server.py`:** The heart of the server. Handles: * Socket creation and listening. * Accepting new client connections. * Managing client connections. * Server lifecycle (start, stop). * **`src/mcp_server/core/client.py`:** Represents a single connected Minecraft client. Handles: * Reading data from the client's socket. * Writing data to the client's socket. * Client authentication (login). * Client state (e.g., position, health). * **`src/mcp_server/core/protocol.py`:** Crucial for understanding and implementing the Minecraft protocol. Handles: * Packet parsing (converting raw bytes from the client into meaningful data). * Packet serialization (converting data into raw bytes to send to the client). * Protocol version handling (different Minecraft versions have different protocols). This is a *complex* area. You'll likely need to refer to the Minecraft protocol documentation (e.g., Wiki.vg). * **`src/mcp_server/networking/packet_handler.py`:** Receives parsed packets from `protocol.py` and dispatches them to the appropriate handlers (e.g., a chat handler for chat messages, a movement handler for player movement). * **`src/mcp_server/modules/`:** A place for optional features. This promotes modularity. For example, a chat module could handle chat messages, a world module could manage the game world. * **`src/mcp_server/config/config.py`:** Loads server configuration from a file (e.g., a JSON or YAML file). This allows you to easily change server settings without modifying the code. * **`src/mcp_server/utils/logger.py`:** Sets up logging for the server. Good logging is essential for debugging and monitoring. * **`src/mcp_server/main.py`:** The entry point of your server application. It typically: * Loads the server configuration. * Initializes the server. * Starts the server's main loop. **Key Considerations:** * **Asynchronous Programming (asyncio):** Minecraft servers need to handle many concurrent connections. Using `asyncio` is *highly* recommended for efficient handling of these connections. * **Minecraft Protocol:** The Minecraft protocol is complex and changes between versions. Refer to [https://wiki.vg/Protocol](https://wiki.vg/Protocol) for detailed information. Consider using a library that helps with protocol handling (though many are outdated). Be prepared to implement a significant portion of the protocol yourself. * **Security:** Implement proper security measures to prevent attacks (e.g., authentication, rate limiting, input validation). * **World Generation:** You'll need to implement world generation if you want a playable world. This is a complex topic in itself. * **Performance:** Optimize your code for performance. Profile your server to identify bottlenecks. * **Testing:** Write unit tests to ensure your code is working correctly. **Chinese Translation:** ``` mcp_server/ ├── pyproject.toml # PDM 配置文件 ├── src/ │ ├── mcp_server/ # 主包目录 │ │ ├── __init__.py # 使 'mcp_server' 成为一个包 │ │ ├── core/ # 核心服务器逻辑 │ │ │ ├── __init__.py │ │ │ ├── server.py # 主服务器类 (处理连接等) │ │ │ ├── client.py # 代表一个已连接的客户端 │ │ │ ├── protocol.py # 处理 Minecraft 协议的解析/序列化 │ │ │ └── event_loop.py # 异步事件循环管理 (如果使用 asyncio) │ │ ├── networking/ # 网络相关代码 │ │ │ ├── __init__.py │ │ │ ├── connection_handler.py # 处理新连接 │ │ │ ├── packet_handler.py # 将数据包分发到适当的处理程序 │ │ ├── modules/ # 可选: 模块化功能 (例如,聊天,世界管理) │ │ │ ├── __init__.py │ │ │ ├── chat/ │ │ │ │ ├── __init__.py │ │ │ │ ├── chat_module.py │ │ │ ├── world/ │ │ │ │ ├── __init__.py │ │ │ │ ├── world_module.py │ │ ├── config/ # 配置管理 │ │ │ ├── __init__.py │ │ │ ├── config.py # 加载和管理服务器配置 │ │ ├── utils/ # 实用函数 │ │ │ ├── __init__.py │ │ │ ├── logger.py # 日志设置 │ │ │ ├── data_structures.py # 自定义数据结构 │ │ └── main.py # 启动服务器的入口点 │ ├── tests/ # 单元测试 │ │ ├── __init__.py │ │ ├── core/ │ │ │ ├── test_server.py │ │ │ ├── test_protocol.py │ ├── README.md # 项目文档 │ └── LICENSE # 许可证信息 ``` **Chinese Explanation of Key Components (Simplified):** * **`pyproject.toml`:** PDM 的配置文件,定义依赖项、构建设置等。 * **`src/mcp_server/core/server.py`:** 服务器的核心,处理套接字创建、监听、客户端连接和服务器生命周期。 * **`src/mcp_server/core/client.py`:** 代表一个连接的 Minecraft 客户端,处理客户端数据的读取和写入、身份验证和客户端状态。 * **`src/mcp_server/core/protocol.py`:** 至关重要,用于理解和实现 Minecraft 协议。 处理数据包解析(将客户端的原始字节转换为有意义的数据)和数据包序列化(将数据转换为原始字节以发送到客户端)。 * **`src/mcp_server/networking/packet_handler.py`:** 接收来自 `protocol.py` 的已解析数据包,并将它们分发到适当的处理程序(例如,聊天消息的聊天处理程序,玩家移动的移动处理程序)。 * **`src/mcp_server/modules/`:** 可选功能的存放地,促进模块化。 * **`src/mcp_server/config/config.py`:** 从文件加载服务器配置,允许您轻松更改服务器设置,而无需修改代码。 * **`src/mcp_server/utils/logger.py`:** 设置服务器的日志记录。 良好的日志记录对于调试和监控至关重要。 * **`src/mcp_server/main.py`:** 服务器应用程序的入口点。 **Chinese Key Considerations:** * **异步编程 (asyncio):** Minecraft 服务器需要处理许多并发连接。 强烈建议使用 `asyncio` 来有效处理这些连接。 * **Minecraft 协议:** Minecraft 协议很复杂,并且在不同版本之间会发生变化。 请参阅 [https://wiki.vg/Protocol](https://wiki.vg/Protocol) 获取详细信息。 考虑使用一个帮助处理协议的库(尽管许多库已过时)。 准备好自己实现协议的很大一部分。 * **安全性:** 实施适当的安全措施以防止攻击(例如,身份验证、速率限制、输入验证)。 * **世界生成:** 如果您想要一个可玩的世界,您需要实现世界生成。 这本身就是一个复杂的话题。 * **性能:** 优化您的代码以提高性能。 分析您的服务器以识别瓶颈。 * **测试:** 编写单元测试以确保您的代码正常工作。 **Important Notes:** * This is a *template*. You'll need to fill in the details. * The Minecraft protocol is the most challenging part. Start with a simple version of the protocol and gradually add more features. * Consider using existing libraries for tasks like networking and data serialization, but be aware that many Minecraft-specific libraries are outdated. * Good luck! Developing an MCP server is a complex but rewarding project.
pdm-project
README
template-mcp-server
一个由 Python 和 PDM 开发的 MCP 服务器示例。
与 Claude Desktop 一起使用
将以下内容添加到 claude_desktop_config.json:
{
"mcpServers": {
"template-mcp-server": {
"command": "uvx",
"args": [
"template-mcp-server"
]
}
}
}
它需要您的机器上安装 uv。查看官方文档以获取安装指南。
可用工具
<!-- 在此处列出所有工具和描述 -->
开发
pdm install
pdm dev
推荐服务器
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
MCP Package Docs Server
促进大型语言模型高效访问和获取 Go、Python 和 NPM 包的结构化文档,通过多语言支持和性能优化来增强软件开发。
Claude Code MCP
一个实现了 Claude Code 作为模型上下文协议(Model Context Protocol, MCP)服务器的方案,它可以通过标准化的 MCP 接口来使用 Claude 的软件工程能力(代码生成、编辑、审查和文件操作)。
@kazuph/mcp-taskmanager
用于任务管理的模型上下文协议服务器。它允许 Claude Desktop(或任何 MCP 客户端)在基于队列的系统中管理和执行任务。
mermaid-mcp-server
一个模型上下文协议 (MCP) 服务器,用于将 Mermaid 图表转换为 PNG 图像。
Jira-Context-MCP
MCP 服务器向 AI 编码助手(如 Cursor)提供 Jira 工单信息。
Linear MCP Server
一个模型上下文协议(Model Context Protocol)服务器,它与 Linear 的问题跟踪系统集成,允许大型语言模型(LLM)通过自然语言交互来创建、更新、搜索和评论 Linear 问题。
Sequential Thinking MCP Server
这个服务器通过将复杂问题分解为顺序步骤来促进结构化的问题解决,支持修订,并通过完整的 MCP 集成来实现多条解决方案路径。
Curri MCP Server
通过管理文本笔记、提供笔记创建工具以及使用结构化提示生成摘要,从而实现与 Curri API 的交互。