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

image

 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")
View Code
python server-sh.py  # 执行server程序

4、在Mcp-hub配置

image

 5、测试mcp-hub

image

 6、在DeepChat配置mcp-hub的mcp

image

 7、DeepChat测试一下

image

 8、Mcp-Hub Group使用

image

9、复制地址

image

 

方式一 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

image

 

image

 

posted @ 2025-07-30 21:50  小白啊小白,Fighting  阅读(75)  评论(0)    收藏  举报