模块化命令平台服务器

一个基于Python和fastmcp包的模块化命令平台服务器,用于创建和运行自定义工具和资源。

  • by Yash404007
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 yash404007/mcp-server

使用说明

🧠 MCP服务器-Python设置

此存储库包含使用Python和 fastmcp 包裹。


📁 项目结构

mcp服务器/ ├── 服务器.py ├── 需求.txt └── README.md

格式 复制 编辑


🚀 入门指南

✅ 先决条件

  • Python 3.8或更高版本
  • pip(Python包管理器)

📦 安装

  1. 克隆存储库:
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