MCP服务开发、测试、发布全流程
1、在某个conda环境中(比如llm-mcp),安装好uv:
pip install uv
2、PyCharm项目初始化为uv项目:
uv init .
3、创建、激活虚拟环境
uv venv source .venv/bin/activate
4、安装 MCP SDK
uv add openai dotenv mcp
5、创建项目源代码
创建src/weather 文件夹
添加 server.py 文件
6、本地测试(使用Inspector进行)
安装nodejs
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo bash - sudo apt install -y nodejs
运行Inspector
npx -y @modelcontextprotocol/inspector uv run ./src/weather/server.py --api_key apikey123abc
7、打包
添加__init__.py、main.py
修改pyproject.toml文件
填写内容,注意[project.scripts]中的rents-mcp-weather2名称:
[build-system] requires = ["setuptools>=61.0", "wheel"] build-backend = "setuptools.build_meta"
[project.scripts] rents-mcp-weather2 = "weather:main" [tool.setuptools] package-dir = {"" = "src"} [tool.setuptools.packages.find] where = ["src"]
安装打包/发布(上传)工具包
uv pip install build twine
打包(回到项⽬主⽬录)
cd /Users/rents/PycharmProjects/rents-mcp-weather python -m build
8、发布
python -m twine upload dist/*
Metadata
Release files for rents-weather-project 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| rents_weather_project-0.1.4.tar.gz | 5.1 kB | Without provenance | Details for rents_weather_project-0.1.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| rents_weather_project-0.1.4-py3-none-any.whl | Python 3 | none | any | Details for rents_weather_project-0.1.4-py3-none-any.whl |
Total release size: 11.5 kB
Release files / rents_weather_project-0.1.4.tar.gz
| Download URL | rents_weather_project-0.1.4.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
072f8d9eefa880888a30ddc8366ce0e6dc95d69388919e256ba8c428a90446c2
|
|
BLAKE2b-256 checksum How to use checksums |
a84d4a7b26b6f9f98bbef008acbb8539c3cbf61c95b20c2881c8faed9ffa4429
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.18
|
Release files / rents_weather_project-0.1.4-py3-none-any.whl
| Download URL | rents_weather_project-0.1.4-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1bce0d5e64de89d072f209a8eba7dcc84ec639edeb34c7f0086ba2dbdbced6b2
|
|
BLAKE2b-256 checksum How to use checksums |
09cf6f1baaef09962714a9220b38fbe88916087bbf9820529ed55dbeb84dc623
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.10.18
|
Security for rents-weather-project 0.1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.