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/*

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.0.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.0-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.0.tar.gz.

File metadata

File hashes

Hashes for mcp_http_streamable_ysx_test-0.1.0.tar.gz
Algorithm Hash digest
SHA256 93bc03a1d4957b68710ef192469e23d92eff326b4b88afebd2e4c6b8a8a6184b
MD5 16f1f88f739a8dd058aaef97186d86e9
BLAKE2b-256 7ebfafaffd6da686139cf4dafac80c317260d5b8f38fb0b3105dd085da37217e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for mcp_http_streamable_ysx_test-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fb444a0589a929672dd27261d8805f35d4767ad72151d0c67bd1de8325f0850f
MD5 31019cec1310d6af9d3a357a385c78ab
BLAKE2b-256 a13d2d98f39a4bdb9fbb50c7e0586158fad92455d79347c01ee691003ab045ab

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