DeepChat使用MCP-Hub 案例六 (结合FastMcp案例四)
1、安装Mcp-hub
https://github.com/samanhappy/mcphub
# 端口结合自己机器配置 docker run -p 3001:3000 samanhappy/mcphub
2、打开网站
http://localhost:3001/ # 账号密码: admin/admin123

3、根据 《FastMcp案例四》 启动程序
import json from datetime import datetime import requests from fastmcp import FastMCP mcp = FastMCP("Demo 🚀") @mcp.tool() def get_public_ip_address() -> str: """ 获取服务器公网 IP 地址 返回: str: 当前网络的公网 IP 地址 """ try: response = requests.get("http://ip-api.com/json") response.raise_for_status() # 检查 HTTP 请求是否成功 content = json.loads(response.text) return content.get("query", "Unknown IP") # 提供默认值以防字段缺失 except requests.RequestException as e: print(f"请求错误: {e}") return "Request Failed" except json.JSONDecodeError as e: print(f"JSON 解码错误: {e}") return "Invalid Response" @mcp.tool() def greet(name: str) -> str: """向用户打招呼""" return f"Hello, {name}!" @mcp.tool def get_current_time(): """Get current time""" return datetime.now() if __name__ == "__main__": # mcp.run() mcp.run(transport="streamable-http", host="0.0.0.0", port=9000, path="/mcp")
python server-sh.py # 执行server程序
4、在Mcp-hub配置

5、测试mcp-hub

6、在DeepChat配置mcp-hub的mcp

7、DeepChat测试一下

8、Mcp-Hub Group使用

9、复制地址

方式一 Url: http://localhost:3000/mcp/83b39d5a-72f4-4e6b-9172-ca089c858419 方式二Json: { "mcpServers": { "mcphub": { "url": "http://localhost:3000/mcp/83b39d5a-72f4-4e6b-9172-ca089c858419", "headers": { "Authorization": "Bearer <your-access-token>" } } } }
10、配置DeepChat


本文来自博客园,作者:小白啊小白,Fighting,转载请注明原文链接:https://www.cnblogs.com/ywjfx/p/19014156

浙公网安备 33010602011771号