Skip to main content

输入OpenWeather-API-KEY,获取天气信息。

Project description

一、基于HTTP流式传输的MCP服务器开发流程

  • 创建项目文件:
# cd /root/autodl-tmp/MCP
uv init mcp-weather-http
cd mcp-weather-http
# 创建虚拟环境
uv venv
# 激活虚拟环境
source .venv/bin/activate
uv add mcp httpx

代码解释

如果你传的是 --port 3000,访问路径就是 http://localhost:3000/mcp

修改配置文件pyproject.toml:

  • 参考:
[build-system]
requires = ["setuptools>=61.0", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "mcp-weather-http"
version = "1.1.0"
description = "输入OpenWeather-API-KEY,获取天气信息。"
readme = "README.md"
requires-python = ">=3.9"
dependencies = [
    "httpx>=0.28.1",
    "mcp>=1.8.0",
]

[project.scripts]
mcp-weather-http = "mcp_weather_http:main"

[tool.setuptools]
package-dir = {"" = "src"}

[tool.setuptools.packages.find]
where = ["src"]

二、HTTP流式传输MCP服务器开启与测试

  • 在创建完server.py后,我们可以开启服务并进行测试。需要注意的是,我们需要先开启流式HTTP MCP服务器,然后再开启Inspector:

开启流式HTTP MCP服务器

# 回到项目主目录
# cd /root/autodl-tmp/MCP/mcp-weather-http

uv run ./src/mcp_weather_http/server.py --port 3001 --api-key YOUR_KEY

开启Inspector

# 回到项目主目录
# cd /root/autodl-tmp/MCP/mcp-weather-http
# source .venv/bin/activate

npx -y @modelcontextprotocol/inspector

访问: MCP Inspector is up and running at http://127.0.0.1:6274 进入inspector界面:

三、流式HTTP MCP服务器异地调用

  • 接下来即可在异地环境(也可以是本地)通过HTTP方式调用MCP服务了。
  • 这里以本地安装的Cherry Studio为例,进行调用演示。
  • 此处需要保持远程流式HTTP MCP服务器处于开启状态,然后配置即可。

四、流式HTTP MCP服务器发布流程

  • 测试完成后,即可上线发布。这里仍然考虑发布到pypi平台,并使用cherry studio进行本地调用测试。

打包上传:

# 回到项目主目录
# cd xx/MCP/mcp-http-streamable

uv pip install build twine
python -m build
python -m twine upload dist/*

# View at: https://pypi.org/project/mcp-http-streamable-ysx-test/0.1.0/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_http_streamable_ysx_test-0.1.1.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_http_streamable_ysx_test-0.1.1-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file mcp_http_streamable_ysx_test-0.1.1.tar.gz.

File metadata

File hashes

Hashes for mcp_http_streamable_ysx_test-0.1.1.tar.gz
Algorithm Hash digest
SHA256 de1504ebedeba2089c854b836d4613f11ac96b4a9b47159184fb2b0b9bedf214
MD5 13815f9092f83d420089448e8d5cb0ec
BLAKE2b-256 61193fc644233bbef53e6e70c37de9688068f5f559c2a23beb0294a0f057f93d

See more details on using hashes here.

File details

Details for the file mcp_http_streamable_ysx_test-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mcp_http_streamable_ysx_test-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4ee90fb1a3dd902b4102031f727b6e7b06557c4c8d4e965da802618cb475b3a8
MD5 b97645dffd883d904a4c1286ed7079e5
BLAKE2b-256 8c2b1cbc08e414796a2208567010b7965077e4622452580c43205ee2eec84412

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page