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 : fastmcpfrom fastmcp import FastMCP from datetime import datetimemcp = FastMCP()@mcp.tool def get_current_time():"""Get current time"""return datetime.now()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)
5、修改端口为3002 ,运行文件
fastmcp dev server-sh.py
Starting MCP inspector... ⚙️ Proxy server listening on localhost:6277 🔑 Session token: 1e1e09283bb43d35e11c95e03669efc9e296cf9197620c59d2119db5bd4f2c74Use this token to authenticate requests or set DANGEROUSLY_OMIT_AUTH=true to disable auth🚀 MCP Inspector is up and running at:http://localhost:6274/?MCP_PROXY_AUTH_TOKEN=1e1e09283bb43d35e11c95e03669efc9e296cf9197620c59d2119db5bd4f2c74🌐 Opening browser... New StreamableHttp connection request Query parameters: {"url":"http://0.0.0.0:3003/mcp","transportType":"streamable-http"} Created StreamableHttp server transport Created StreamableHttp client transport Client <-> Proxy sessionId: 3c5d3289-e1b1-45f2-a19f-1bb0728beaf7 Proxy <-> Server sessionId: 9781d4c316c24277b635ce8e6f6484a7 Received POST message for sessionId 3c5d3289-e1b1-45f2-a19f-1bb0728beaf7 Received GET message for sessionId 3c5d3289-e1b1-45f2-a19f-1bb0728beaf7
6、测试验证