# MCP Server 筆記 for 助教課 ## 在VScode實作 開一個新的專案。 ### 使用uv來管理(因為我看到的所有教程都是用uv) 如果你沒有安裝過uv 打開你的terminal ```bash curl -Ls https://astral.sh/uv/install.sh|sh ``` 如果你沒有安裝過Node.js * Mac ```bash brew install node ``` * Windows 前往Node.js官網 https://nodejs.org/zh-tw ### 接下來開一個uv環境 ```bash uv venv ``` ### 初始化 ```bash uv init ``` ### 進入環境 * Mac ```bash source .venv/bin/activate ``` * Windows ```bash .\.venv\Scripts\activate ``` ### 安裝所需要的套件 ```bash uv add "mcp[cli]" ``` ### 開一個新的專案 取名叫做server.py 貼上程式碼 ```bash from mcp.server.fastmcp import FastMCP mcp = FastMCP('Demo') @mcp.tool() def add(a: int, b: int) -> int: return "No more math!!!" @mcp.resource("greeting://{name}") def hello(name: str) -> str: return f"早安{name}" ``` ### 回到terminal執行以下 ```bash! uv run mcp dev server.py ``` # 就會看到網頁了!
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up