VOOZH about

URL: https://glama.ai/mcp/servers/nictuku/py-mcp-server-template?locale=zh-CN

⇱ Python MCP 服务器模板 by nictuku | Glama


py-mcp-服务器模板

此代码库是一个模板,可帮助您使用 Python 创建自己的 MCP(模型上下文协议)服务器。您可以 fork 此代码库来开始使用。

使用 uv 设置

本项目使用uv进行 Python 打包和管理虚拟环境。如果您尚未安装uv ,请参阅官方 uv 安装指南

  1. 克隆你的分支存储库:

    git clone https://github.com/YOUR_USERNAME/YOUR_REPOSITORY_NAME.git
    cd YOUR_REPOSITORY_NAME
  2. 创建并激活虚拟环境: uv通常会在项目根目录中创建一个.venv目录。

    uv venv
    source .venv/bin/activate # On macOS/Linux
    # .venv\Scripts\activate # On Windows
  3. **安装依赖项:**本项目使用pyproject.toml来管理依赖项。

    uv pip install .

    如果添加了新的依赖项,请在pyproject.toml文件中定义它们,然后再次运行此命令。如果出于某种原因使用了requirements.txt文件,可以使用uv pip install -r requirements.txt进行安装。

Related MCP server: mcp-framework-starter

运行服务器

mcp_server.py脚本启动 MCP 服务器。

直接运行服务器:

uv run python mcp_server.py

与 Claude Desktop 或 Cursor 集成

要将此 MCP 服务器与 Claude Desktop 或 Cursor 等应用程序一起使用,您需要在应用程序的设置中进行配置。配置通常涉及指定运行服务器的命令。

以下是一个示例配置片段。您需要将/ABSOLUTE/PATH/TO/PARENT/FOLDER/YOUR_REPOSITORY_NAME替换为您系统上项目目录的实际绝对路径。

{
 "mcpServers": {
 "my-custom-python-server": {
 "command": "uv",
 "args": [
 "run",
 "--python",
 "/ABSOLUTE/PATH/TO/PARENT/FOLDER/YOUR_REPOSITORY_NAME/.venv/bin/python",
 "/ABSOLUTE/PATH/TO/PARENT/FOLDER/YOUR_REPOSITORY_NAME/mcp_server.py"
 ],
 "workingDirectory": "/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" :指定服务器进程的工作目录,该目录应该是项目的根目录。

重要的:

  • 确保argsworkingDirectory中的路径对于您的系统来说是正确的。

  • 如果应用程序找不到uv ,您可能需要在"command"字段中指定其完整路径。通常,您可以在 macOS 或 Linux 的终端中运行which uv来找到此路径,或者在 Windows 上where uv来找到此路径。

  • 按照mcp_server.py ( mcp.run(transport='stdio') ) 中的配置,服务器默认在stdio上监听,这通常是 Cursor 等应用程序所期望的。

配置完成后,应用程序应该能够与您的 Python MCP 服务器通信。

A
license - permissive license
D
quality
D
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/nictuku/py-mcp-server-template'

If you have feedback or need assistance with the MCP directory API, please join our Discord server