py-mcp-服务器模板
此代码库是一个模板,可帮助您使用 Python 创建自己的 MCP(模型上下文协议)服务器。您可以 fork 此代码库来开始使用。
使用 uv 设置
本项目使用uv进行 Python 打包和管理虚拟环境。如果您尚未安装uv ,请参阅官方 uv 安装指南。
克隆你的分支存储库:
git clone https://github.com/YOUR_USERNAME/YOUR_REPOSITORY_NAME.git cd YOUR_REPOSITORY_NAME创建并激活虚拟环境:
uv通常会在项目根目录中创建一个.venv目录。uv venv source .venv/bin/activate # On macOS/Linux # .venv\Scripts\activate # On Windows**安装依赖项:**本项目使用
pyproject.toml来管理依赖项。uv pip install .如果添加了新的依赖项,请在
pyproject.toml文件中定义它们,然后再次运行此命令。如果出于某种原因使用了requirements.txt文件,可以使用uv pip install -r requirements.txt进行安装。
运行服务器
mcp_server.py脚本启动 MCP 服务器。
直接运行服务器:
与 Claude Desktop 或 Cursor 集成
要将此 MCP 服务器与 Claude Desktop 或 Cursor 等应用程序一起使用,您需要在应用程序的设置中进行配置。配置通常涉及指定运行服务器的命令。
以下是一个示例配置片段。您需要将/ABSOLUTE/PATH/TO/PARENT/FOLDER/YOUR_REPOSITORY_NAME替换为您系统上项目目录的实际绝对路径。
配置说明:
"my-custom-python-server":这是您为服务器配置指定的名称。"command": "uv":指定uv作为要执行的命令。"args":uv命令的参数列表:"run":告诉uv在其管理环境中执行命令。"--python":指定要使用的 Python 解释器。务必将其指向uv虚拟环境 (.venv/bin/python) 中的 Python 解释器。"/ABSOLUTE/PATH/TO/PARENT/FOLDER/YOUR_REPOSITORY_NAME/mcp_server.py":服务器脚本的绝对路径。
"workingDirectory":指定服务器进程的工作目录,该目录应该是项目的根目录。
重要的:
确保
args和workingDirectory中的路径对于您的系统来说是正确的。如果应用程序找不到
uv,您可能需要在"command"字段中指定其完整路径。通常,您可以在 macOS 或 Linux 的终端中运行which uv来找到此路径,或者在 Windows 上where uv来找到此路径。按照
mcp_server.py(mcp.run(transport='stdio')) 中的配置,服务器默认在stdio上监听,这通常是 Cursor 等应用程序所期望的。
配置完成后,应用程序应该能够与您的 Python MCP 服务器通信。
Related MCP Servers
- -securityAlicense-qualityA Python-based server that implements the Model Context Protocol to interface with Claude Desktop as an MCP client, supporting interaction through efficient memory management.Last updated -1MIT License
- -security-license-qualityA streamlined foundation for building Model Context Protocol servers in Python, designed to make AI-assisted development of MCP tools easier and more efficient.Last updated -13MIT License
- -securityFlicense-qualityA starter template for building Model Context Protocol (MCP) servers, enabling developers to create and add custom tools that can be integrated with Claude Desktop.Last updated -2
- -securityFlicense-qualityA Python template for building Model Context Protocol (MCP) servers that expose tools via JSON-RPC, enabling secure and scalable context and tool invocation for language models.Last updated -