mcpField
M
MCP Demo

MCP Demo

本地服务
github.com/guobinqiu开发工具175 周前更新

关于 MCP Demo

MCP Python Demo 是一个天气预报示例,展示如何用 DeepSeek 客户端连接 MCP 服务并调用天气工具,适合学习 Python MCP 客户端与工具调用。

主要功能

  1. 01连接天气 MCP 服务
  2. 02列出天气查询工具
  3. 03通过 DeepSeek 发起工具调用
  4. 04交互式输入天气问题

适用场景

  1. 01测试 MCP 客户端与服务的连接
  2. 02查询指定地点天气预报

MCP 相关

示例包含 MCP 客户端和天气 MCP 服务,客户端可发现并调用 get_alerts 与 get_forecast 工具。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

暂未收录安装方式

我们还没有获取到这个服务的安装包或远程地址,请按项目 README 中的说明安装。

代码仓库

工具

还没有获取到工具列表

本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。

README 原文English

来自项目 README

README 暂无中文译文,以下为英文原文;中文介绍见上方。

MCP Python Demo

LLM 使用的 deepseek-chat 因为只有v3有tools属性 (deepseek-reasoner是不行的)

chat_response = client.chat.completions.create(
    model="deepseek-chat", # 通过指定 model='deepseek-chat' 即可调用 DeepSeek-V3 V3有tools属性
    messages=messages,
    tools=available_tools,
    tool_choice="auto"
)

安装

pip install uv
# uv init mcp-demo-python
git clone [email protected]:guobinqiu/mcp-demo-python.git
cd mcp-demo-python
uv venv
source .venv/bin/activate
# uv add "mcp[cli]" httpx
# uv add mcp openai python-dotenv
# rm main.py

运行

运行前把.env文件里的OPENAI_API_KEY换成你自己的

source .venv/bin/activate
python client/main.py server/main.py

输出

[04/23/25 21:11:54] INFO     Processing request of type ListToolsRequest                                                                                 server.py:534

Connected to server with tools: ['get_alerts', 'get_forecast']

MCP Client Started!
Type your queries or 'quit' to exit.

Query: what's the weather in new york 
[04/23/25 21:12:09] INFO     Processing request of type ListToolsRequest                                                                                 server.py:534
[04/23/25 21:12:15] INFO     Processing request of type CallToolRequest                                                                                  server.py:534
                    INFO     HTTP Request: GET https://api.weather.gov/points/40.7128,-74.006 "HTTP/1.1 200 OK"                                        _client.py:1740
[04/23/25 21:12:16] INFO     HTTP Request: GET https://api.weather.gov/gridpoints/OKX/33,35/forecast "HTTP/1.1 200 OK"                                 _client.py:1740
[DEBUG] final_text[0] type: <class 'str'>, value: Here's the current weather forecast for New York:

### Today:  
- **Temperature:** 73°F  
- **Wind:** 7 mph NW  
- **Forecast:** Mostly sunny, with a high near 73.  

### Tonight:  
- **Temperature:** 57°F  
- **Wind:** 3 to 7 mph SE  
- **Forecast:** Mostly clear.  

### Thursday:  
- **Temperature:** 68°F (falling to 64°F in the afternoon)  
- **Wind:** 3 to 12 mph SE  
- **Forecast:** Sunny.  

### Thursday Night:  
- **Temperature:** 56°F  
- **Wind:** 6 to 12 mph S  
- **Forecast:** Mostly clear.  

### Friday:  
- **Temperature:** 70°F (falling to 66°F in the afternoon)  
- **Wind:** 5 to 14 mph S  
- **Forecast:** Partly sunny.  

Let me know if you'd like more details!

Here's the current weather forecast for New York:

### Today:  
- **Temperature:** 73°F  
- **Wind:** 7 mph NW  
- **Forecast:** Mostly sunny, with a high near 73.  

### Tonight:  
- **Temperature:** 57°F  
- **Wind:** 3 to 7 mph SE  
- **Forecast:** Mostly clear.  

### Thursday:  
- **Temperature:** 68°F (falling to 64°F in the afternoon)  
- **Wind:** 3 to 12 mph SE  
- **Forecast:** Sunny.  

### Thursday Night:  
- **Temperature:** 56°F  
- **Wind:** 6 to 12 mph S  
- **Forecast:** Mostly clear.  

### Friday:  
- **Temperature:** 70°F (falling to 66°F in the afternoon)  
- **Wind:** 5 to 14 mph S  
- **Forecast:** Partly sunny.  

Let me know if you'd like more details!

Query: 

Golang版

https://github.com/guobinqiu/mcp-demo-golang

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。