模型上下文协议服务器

Sufy MCP Server是一个基于Sufy产品的模型上下文协议服务器,允许用户在AI大模型客户端中访问Sufy服务。

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

使用说明

Sufy MCP服务器

中文文档 | 英文文档

概述

基于Sufy产品构建的模型上下文协议(MCP)服务器允许用户在AI大型模型客户端的上下文中通过此MCP服务器访问Sufy服务。

环境要求

  • Python 3.12或更高版本
  • uv包管理器

如果您还没有安装uv,可以使用以下命令进行安装:

以下是所提供文本的英文翻译:

# Mac, recommended to install using brew
brew install uv


# Linux & Mac
# 1. Installation
curl -LsSf https://astral.sh/uv/install.sh | sh
# 2. After installation, make sure to add the package installation directory (the directory containing uv and uvx executables) to your system's PATH environment variable.
# Assuming the installation path is /Users/xxx/.local/bin (see installation output)
### Temporary effect (current session), execute the following command in your current terminal:
export PATH="/Users/xxx/.local/bin:$PATH"
### Permanent effect (recommended), execute the following command in your current terminal:
echo 'export PATH="/Users/xxx/.local/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile


# Windows
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

具体安装方法请参考 紫外线装置.

临床应用

步骤:

  1. 在VSCode中安装Cline插件(安装后Cline图标将出现在侧边栏中)
  2. 配置大型模型
  3. 配置Sufy MCP
    1. 点击Cline图标进入插件界面,选择MCP Server模块
    2. 选择“已安装”,单击“高级MCP设置”,并使用以下模板进行配置:
    {
      "mcpServers": {
        "Sufy": {
          "command": "uvx",
          "args": [
            "sufy-mcp-server"
          ],
          "env": {
            "SUFY_ACCESS_KEY": "YOUR_ACCESS_KEY",
            "SUFY_SECRET_KEY": "YOUR_SECRET_KEY",
            "SUFY_REGION_NAME": "YOUR_REGION_NAME",
            "SUFY_ENDPOINT_URL": "YOUR_ENDPOINT_URL",
            "SUFY_BUCKETS": "YOUR_BUCKET_A,YOUR_BUCKET_B"
         },
          "disabled": false
        }
      }
    }
    
    1. 切换Sufy MCP服务器的连接开关以建立连接
  4. 在Cline中创建一个聊天窗口,使用sufy mcp服务器与AI进行交互。示例提示: ◦ 列出Sufy资源信息 ◦ 列出Sufy中的所有Buckets ◦ 列出Sufy xxx存储桶中的文件 ◦ 读取Sufy xxx Bucket中yyy文件的内容 ◦ 将Sufy的xxx Bucket中的图像yyy大小调整20%

注意:在Cline中创建MCP服务器时,可以直接使用上述配置。

发展

  1. 克隆存储库:
git clone git@github.com:sufy/sufy-mcp-server.git
cd sufy-mcp-server
  1. 创建并激活虚拟环境:
uv venv
source .venv/bin/activate  # Linux/macOS
# or
.venv\Scripts\activate  # Windows
  1. 安装依赖项:
uv pip install -e .
  1. 配置

复制环境模板:

cp .env.example .env

编辑 .env 具有以下参数的文件:

# S3/Sufy credentials
SUFY_ACCESS_KEY=your_access_key
SUFY_SECRET_KEY=your_secret_key

# Region info
SUFY_REGION_NAME=your_region
SUFY_ENDPOINT_URL=endpoint_url # eg:https://s3.your_region.sufycs.com

# Configure buckets (comma-separated, max 20 recommended)
SUFY_BUCKETS=bucket1,bucket2,bucket3

对于功能扩展:

  1. 在下创建新的业务包目录 core (例如,存储)
  2. 在包目录中实现功能
  3. 通过注册工具/资源 load() 包中的函数 __init__.py
  4. 在中调用加载函数 core/__init__.py 完成注册

目录结构:

core
├── __init__.py # Load business tools/resources
└── storage # Storage service
    ├── __init__.py # Load storage tools/resources
    ├── resource.py # Storage resources
    ├── storage.py # Storage utilities
    └── tools.py # Storage tools

测试

使用模型控制协议检查器

推荐工具: 模型控制协议检查器

# Requires node v22.4.0
npx @modelcontextprotocol/inspector uv --directory . run sufy-mcp-server

本地MCP服务器示例

  1. 以stdio模式启动(默认):
uv --directory . run sufy-mcp-server
  1. 以SSE模式启动(适用于web应用程序):
uv --directory . run sufy-mcp-server --transport sse --port 8000