使用说明
🧠 MCP服务器-Python设置
此存储库包含使用Python和 fastmcp 包裹。
📁 项目结构
mcp服务器/ ├── 服务器.py ├── 需求.txt └── README.md
格式 复制 编辑
🚀 入门指南
✅ 先决条件
- Python 3.8或更高版本
- pip(Python包管理器)
📦 安装
- 克隆存储库:
git clone https://github.com/your-username/mcp-server.git
cd mcp-server
Install dependencies:
bash
Copy
Edit
pip install fastmcp
Or, if using a requirements.txt:
bash
Copy
Edit
pip install -r requirements.txt
🛠️ Usage
Example server.py:
python
Copy
Edit
from mcp.server.fastmcp import FastMCP
# Create MCP server instance
mcp = FastMCP("Demo")
# Define a tool
@mcp.tool()
def add(a: int, b: int) -> int:
"""Add two numbers"""
return a + b
# Define a resource
@mcp.resource("greeting://{name}")
def get_greeting(name: str) -> str:
"""Returns a greeting message"""
return f"Hello, {name}!"
# Run the server
if __name__ == "__main__":
mcp.run()
▶️ Run the Server
To start the MCP server:
bash
Copy
Edit
python server.py
🌐 Access
Once the server is running:
Call the tool via MCP interface or API: add(a=5, b=7) → returns 12
Access resource like: greeting://Alice → returns "Hello, Alice!"
💡 Future Ideas
Add multiple tools (math, string utils, etc.)
Connect to a frontend
Add authentication or logging
👤 Author
Yash Surve
