Fast Mcp & Higress 案例十 (Higress安装)

前提:FastMcp 案例四(Streamable-http) - 小白啊小白,Fighting - 博客园

mcp运行

1、首先安装python环境

conda create -n mcp python=3.10

2、安装依赖

pip install fastmcp

3、编写一个server-sh.py

复制代码
# -*- coding: utf-8 -*-
# @Time : 2025/7/28 17:10
# @Author : yangwenjie
# @Email : 邮箱
# @File : server-sh.py
# @Project : fastmcp

from fastmcp import FastMCP
from datetime import datetime

mcp = FastMCP()

@mcp.tool
def get_current_time():
    """Get current time"""
    return datetime.now()

@mcp.resource("resource://cities")
def get_cities():
    """返回支持查询天气的城市列表"""
    cities = ["北京", "上海", "广州", "深圳"]
    return f"Cities: {', '.join(cities)}"

@mcp.resource("resource://{city}/weather")
def get_city_weather(city: str) -> str:
    return f"Weather for {city}"

@mcp.tool()
def greet(name: str) -> str:
    """向用户打招呼"""
    return f"Hello, {name}!"

@mcp.prompt
def ask_about_topic(topic: str) -> str:
    """Generates a user message asking for an explanation of a topic."""
    return f"Can you please explain the concept of '{topic}'?"


if __name__ == "__main__":
    mcp.run(transport="streamable-http", host="0.0.0.0", port=3003, path="/mcp")
复制代码

 

4、运行

python server-sh.py 
复制代码
╭─ FastMCP 2.0 ──────────────────────────────────────────────────────────────╮
│                                                                            │
│        _ __ ___ ______           __  __  _____________    ____    ____     │
│       _ __ ___ / ____/___ ______/ /_/  |/  / ____/ __ \  |___ \  / __ \    │
│      _ __ ___ / /_  / __ `/ ___/ __/ /|_/ / /   / /_/ /  ___/ / / / / /    │
│     _ __ ___ / __/ / /_/ (__  ) /_/ /  / / /___/ ____/  /  __/_/ /_/ /     │
│    _ __ ___ /_/    \__,_/____/\__/_/  /_/\____/_/      /_____(_)____/      │
│                                                                            │
│                                                                            │
│                                                                            │
│    🖥️  Server name:     FastMCP                                             │
│    📦 Transport:       Streamable-HTTP                                     │
│    🔗 Server URL:      http://0.0.0.0:3003/mcp                             │
│                                                                            │
│    📚 Docs:            https://gofastmcp.com                               │
│    🚀 Deploy:          https://fastmcp.cloud                               │
│                                                                            │
│    🏎️  FastMCP version: 2.10.6                                              │
│    🤝 MCP version:     1.12.2                                              │
│                                                                            │
╰────────────────────────────────────────────────────────────────────────────╯


[07/29/25 10:14:24] INFO     Starting MCP server 'FastMCP' with transport 'streamable-http' on http://0.0.0.0:3003/mcp                                                                                         server.py:1448
INFO:     Started server process [1545763]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:3003 (Press CTRL+C to quit)
复制代码

 

Higress运行

mcp测试:MCP Server 快速开始(对接现存 SSE Server)_AI-Higress官网

官网:https://higress.ai/

部署文档:https://higress.cn/ai/quick-start/?spm=36971b57.7beea2de.0.0.d85f20a99Ah0M1

1、一键安装

curl -sS https://higress.cn/ai-gateway/install.sh | bash
Provide a key for each LLM provider you want to enable, then press Enter.
If no key is provided and Enter is pressed, configuration for that provider will be skipped.

1. OpenAI
2. Aliyun Dashscope
3. Moonshot
4. Azure OpenAI
5. 360 Zhinao
6. Baichuan AI
7. 01.AI
8. DeepSeek
9. Zhipu AI
10. Ollama
11. Claude
12. Baidu AI Cloud
13. Stepfun
14. Minimax
15. Google Gemini
16. Mistral AI
17. Cohere
18. Doubao
Please choose an LLM service provider to configure (1~18, press Enter alone to break): 1
→ Enter API Key for OpenAI: sk-17baz5G3457aA2BeB0E971AfC8A6
1. [Configured] OpenAI
2. Aliyun Dashscope
3. Moonshot
4. Azure OpenAI
5. 360 Zhinao
6. Baichuan AI
7. 01.AI
8. DeepSeek
9. Zhipu AI
10. Ollama
11. Claude
12. Baidu AI Cloud
13. Stepfun
14. Minimax
15. Google Gemini
16. Mistral AI
17. Cohere
18. Doubao
Please choose an LLM service provider to configure (1~18, press Enter alone to break): 2
→ Enter API Key for Aliyun Dashscope: sk-75da872786de217b8
1. [Configured] OpenAI
2. [Configured] Aliyun Dashscope
3. Moonshot
4. Azure OpenAI
5. 360 Zhinao
6. Baichuan AI
7. 01.AI
8. DeepSeek
9. Zhipu AI
10. Ollama
11. Claude
12. Baidu AI Cloud
13. Stepfun
14. Minimax
15. Google Gemini
16. Mistral AI
17. Cohere
18. Doubao
Please choose an LLM service provider to configure (1~18, press Enter alone to break): 

Starting Higress AI Gateway...

Unable to find image 'higress-registry.cn-hangzhou.cr.aliyuncs.com/higress/all-in-one:latest' locally
latest: Pulling from higress/all-in-one
3153aa388d02: Pulling fs layer 
e64ee0e4a075: Pulling fs layer 
5ad776fa7a05: Pulling fs layer 
d6343124ba05: Pulling fs layer 
d6343124ba05: Waiting 
38dbdc8f7981: Waiting 
d2708ccd1f1e: Pulling fs layer 
2d433de3d80d: Waiting 
d2708ccd1f1e: Waiting 
dee766fc18cd: Pull complete 
07a9e4218996: Pull complete 
91038e63856a: Pull complete 
1d9b0bb48aaf: Pull complete 
3ffe1f68d061: Pull complete 
b60c29c7ef37: Pull complete 
c2db41f5e40f: Pull complete 
d14dfd8257cc: Pull complete 
ac03dfc9d9ea: Pull complete 
7577b8821476: Pull complete 
d773e423a2a2: Pull complete 
bcbff4dfc4ef: Pull complete 
8454d64a8534: Pull complete 
499f60c03143: Pull complete 
51702a9e5aa6: Pull complete 
b92cd97fe40c: Pull complete 
ce442c60d8a7: Pull complete 
2995ad802411: Pull complete 
d3cc1105ceea: Pull complete 
7433fc8f22b4: Pull complete 
9db521ec25ab: Pull complete 
aa83981dbcca: Pull complete 
191682481c03: Pull complete 
Digest: sha256:9cad52dc73c81e7a2daf2c22076c691055f4953269de4b71170df4c26fe89e72
Status: Downloaded newer image for higress-registry.cn-hangzhou.cr.aliyuncs.com/higress/all-in-one:latest

 ___  ___  ___  ________  ________  _______   ________   ________
|\  \|\  \|\  \|\   ____\|\   __  \|\  ___ \ |\   ____\ |\   ____\
\ \  \\\  \ \  \ \  \___|\ \  \|\  \ \   __/|\ \  \___|_\ \  \___|_
 \ \   __  \ \  \ \  \  __\ \   _  _\ \  \_|/_\ \_____  \\ \_____  \
  \ \  \ \  \ \  \ \  \|\  \ \  \\  \\ \  \_|\ \|____|\  \\|____|\  \
   \ \__\ \__\ \__\ \_______\ \__\\ _\\ \_______\____\_\  \ ____\_\  \
    \|__|\|__|\|__|\|_______|\|__|\|__|\|_______|\_________\\_________\
                                                \|_________\|_________|

Higress AI Gateway is now running.

=======================================================
               Using Higress AI Gateway                
=======================================================

Higress AI Gateway Data Plane endpoints:
    HTTP  = http://localhost:8080
    HTTPS = https://localhost:8443

Higress AI Gateway chat completion endpoint:
    http://localhost:8080/v1/chat/completions

You can try it with cURL directly:

    curl 'http://localhost:8080/v1/chat/completions' \
      -H 'Content-Type: application/json' \
      -d '{
        "model": "qwen-turbo",
        "messages": [
          {
            "role": "user",
            "content": "Hello!"
          }
        ]
      }'

=======================================================
             Administer Higress AI Gateway             
=======================================================

Higress Console URL (open with browser):
   http://localhost:8001

To stop the gateway run:

  docker stop higress-ai-gateway

Happy Higressing!

2、访问地址

http://localhost:8001/

image

 3、登录密码

admin/admin

 4、配置服务来源

image

 5、查看服务列表是否有

image

 6、点击路由配置,创建路由、配置策略

image

image

7、点击系统配置,编辑全局配置

修改 higress 配置项中的 mcpServer 配置
  1、将 enable 改为 true
  2、移除 redis 配置项
  3、在 match_list 中添加一个新元素:
    - match_rule_domain: "*"
     match_rule_path: /   # 这里使用 / 是 mcp-server请求为:localhost:3002/see
     match_rule_type: prefix
     upstream_type: sse
     enable_path_rewrite: true
     path_rewrite_prefix: /  # 这里使用 / 是 mcp-server请求为:localhost:3002/see

 

image

 8、访问测试

 localhost:8080/see
posted @ 2025-07-30 17:24  小白啊小白,Fighting  阅读(65)  评论(0)    收藏  举报