MCP-工厂平台服务器
MCP工厂平台服务器 - 用于平台管理功能的AI代理接口层
将mcp-factory-platform后端REST API转换为MCP工具,使AI代理(如Claude)能够通过自然语言对话管理用户、钱包、账单及其他平台功能。
🌟 特点
🔐 认证管理(6种工具)
get_oauth_login_url()- 获取OAuth登录URLexplain_authentication()- 详细的认证配置说明create_api_key()创建新的API密钥 ⭐ 新功能list_api_keys()列出所有API密钥 ⭐ 新增delete_api_key()- 删除API密钥 ⭐ 新增get_api_key_stats()- 获取API密钥使用统计信息 ⭐ 新增
👤 用户管理(4种工具)
get_user_profile()- 获取用户资料update_user_profile()- 更新用户资料get_user_account()- 获取账户摘要get_user_analytics()- 用户收入分析
🖥️ MCP 服务管理(5种工具)⭐ 新功能
register_mcp_service()- 注册新的MCP服务 ⭐ 新增list_my_services()- 列出我的所有服务 ⭐ 新增update_mcp_service()- 更新服务信息 ⭐ 新增delete_mcp_service()- 删除服务 ⭐ 新功能get_service_revenue()- 查看服务收入统计 ⭐ 新增
💰 钱包管理(5种工具)
get_consumer_wallet()- 获取消费者钱包详情get_provider_wallet()- 获取提供商钱包详情create_charge()- 创建收费订单transfer_credits()- 在用户之间转移积分get_transactions()- 获取交易记录
💸 提现管理(3种工具)⭐ 新增
request_withdrawal()- 请求提现 ⭐ 新功能list_withdrawals()- 列出退订记录 ⭐ 新增get_withdrawal_detail()- 查看提现详情 ⭐ 新增功能
📊 账单管理(5种工具)
consume_service()- 消耗服务并开具账单list_services()- 列出可用的MCP服务get_service_endpoint()- 获取服务端点详细信息check_server_balance()- 检查服务器负载均衡get_server_analytics()- 获取服务器使用分析数据
🔧 平台工具(1个工具)
test_platform_connection()- 测试平台连接
总计:28个MCP工具 ✨(星星眼表情,常用来表示兴奋、喜爱或赞叹) 完全的双边市场闭环!
🚀 快速入门
先决条件
- Python 版本大于等于 3.10
mcp-factory-platform后端服务(生产环境:https://mcp-factory-beta.up.railway.app)
步骤1:使用OAuth登录并获取API密钥
- 访问登录页面
https://mcp-factory-beta.up.railway.app/auth/login- 使用GitHub帐户授权
- 授权后自动获得1000个Beta积分
- 生成API密钥
- 访问:https://mcp-factory-beta.up.railway.app/auth/api-keys - 点击“创建API密钥” - 配置示例: - 名称:“我的MCP服务器” - 范围:\["读取", "写入"\] - 过期时间:30天
- 复制生成的API密钥
- 格式: mcp_key_xxxxxxxxxxxxxxxxx
步骤2:配置环境变量
# 1. Copy environment configuration template
cp env.example .env
# 2. Edit .env file
nano .env添加以下内容:
# Platform backend address (production)
PLATFORM_API_BASE=https://mcp-factory-beta.up.railway.app
# API authentication key (obtained from platform)
PLATFORM_API_KEY=mcp_key_your_api_key_here
# API timeout
API_TIMEOUT=30.0步骤3:安装依赖项并启动
# Install dependencies
uv sync
# Test server
uv run python server.py📋 Cursor/Claude 桌面配置
光标配置
添加到 .cursor/mcp.json:
{
"mcpServers": {
"mcp-factory-platform-server": {
"command": "/absolute/path/to/project/.venv/bin/python",
"args": ["/absolute/path/to/project/server.py"],
"cwd": "/absolute/path/to/mcp-factory-platform-server"
}
}
}Claude桌面配置
添加到 claude_desktop_config.json:
{
"mcpServers": {
"mcp-factory-platform-server": {
"command": "uv",
"args": ["run", "python", "server.py"],
"cwd": "/path/to/mcp-factory-platform-server"
}
}
}💡 使用示例
身份验证和连接测试
You: "Test platform connection"
Claude:
✅ Platform connection test successful
Health status: healthy
Service: mcp-factory-platform-foundation-early-access
Version: 0.9.0用户配置文件查询
You: "Get my user profile"
Claude: Calling get_user_profile() ...钱包余额查询
You: "Check my wallet balance"
Claude: Calling get_consumer_wallet() and get_provider_wallet() ...服务列表
You: "What MCP services are available"
Claude: Calling list_services() ...🏗️ 项目结构
mcp-factory-platform-server/
├── Dockerfile # Docker image configuration
├── .dockerignore # Docker build exclusions
├── docker-compose.yml # Docker Compose orchestration
├── config.yaml # Server configuration
├── pyproject.toml # Python project configuration
├── server.py # Server entry file
├── .env # Environment configuration (need to create)
├── env.example # Environment configuration example
├── README.md # This document
├── CHANGELOG.md # Version changelog
├── tools/ # Tools implementation directory
│ ├── auth_management.py # Authentication management tools (2)
│ ├── api_key_management.py # API Key management tools (4)
│ ├── user_management.py # User management tools (4)
│ ├── service_management.py # MCP service management tools (5)
│ ├── wallet_management.py # Wallet management tools (5)
│ ├── withdrawal_management.py # Withdrawal management tools (3)
│ ├── billing_management.py # Billing management tools (5)
│ └── platform_api_adapter.py # Platform API adapter
├── resources/ # Resources implementation directory
└── prompts/ # Prompt template directory🔧 开发
添加新工具
- 创建一个新文件或编辑现有文件
tools/目录 - 使用(某种方法或系统)来定义工具
@server.tool()装饰器 - 使用平台API进行调用
httpx - 添加
Authorization用于身份验证的头部信息
示例:
import httpx
import os
PLATFORM_API_BASE = os.getenv("PLATFORM_API_BASE", "http://localhost:8001")
PLATFORM_API_KEY = os.getenv("PLATFORM_API_KEY", "")
def _get_headers() -> dict:
headers = {"Content-Type": "application/json"}
if PLATFORM_API_KEY:
headers["Authorization"] = PLATFORM_API_KEY
return headers
async def my_new_tool(param: str) -> str:
"""Tool description"""
async with httpx.AsyncClient(timeout=30.0) as client:
response = await client.get(
f"{PLATFORM_API_BASE}/api/endpoint",
headers=_get_headers()
)
if response.status_code == 200:
return f"Success: {response.json()}"
return f"Failed: HTTP {response.status_code}"代码质量检查
# Ruff check
uv run ruff check .
# Auto-fix
uv run ruff check --fix .
# Format
uv run ruff format .🐳 Docker 部署
Docker Compose(推荐)
# Build and start
docker-compose up -d
# View logs
docker-compose logs -f
# Stop
docker-compose downDocker 直接运行
# Build image
docker build -t mcp-factory-platform-server .
# Run container
docker run -d \
--name mcp-platform-server \
--env-file .env \
mcp-factory-platform-server🔐 认证指南
OAuth 流程
- 用户访问
/auth/login在浏览器中 - 重定向到GitHub OAuth授权页面
- 用户授权后,平台将创建账户并授予1000个Beta积分
- 用户在平台管理页面生成API密钥
API密钥使用
所有MCP工具都需要API密钥认证:
- 配置
PLATFORM_API_KEY在.env文件 - API密钥格式:
mcp_key_xxx - 重启MCP服务器以使更改生效
测试版限制
- ✅ 可用:所有查询和读取功能
- ✅ 可用:使用平台提供的1000个免费积分
- ⚠️ 限制:充值功能(Beta版中不可用)
- ⚠️ 限制:提现功能(Beta版中不可用)
📚 相关资源
- 平台后端: MCP工厂平台
- 工厂框架: mcp-factory 翻译成中文是“MCP工厂”或“MCP制造厂”,具体取决于上下文和“MCP”在此处的具体含义(MCP可能代表某个特定的项目、产品或技术名称)。如果“MCP”没有特定含义,那么“MCP工厂”或“MCP制造厂”就是通用的翻译
- API 文档https://mcp-factory-beta.up.railway.app/docs 翻译为中文是:“https://mcp工厂测试版.up.railway.app/文档”
- Beta版指南https://mcp-factory-beta.up.railway.app/beta-guide 翻译为中文是:“https://mcp-factory-beta.up.railway.app/测试版指南”
🆘 故障排除
问题:工具显示“API密钥未配置”
解决方案:
- 确保
.env文件已创建 - 检查是否
PLATFORM_API_KEY填写正确 - 重启MCP服务器
问题:连接失败,HTTP 502
解决方案:
- 检查是否
PLATFORM_API_BASE是正确的 - 确认平台后端正在运行
- 检查网络连接
问题:所有请求均返回403错误
解决方案:
- API密钥可能已过期或已被撤销
- 重新生成API密钥
- 更新
.env文件并重新启动
寻求帮助
使用MCP工具查看帮助:
explain_authentication()- 详细的认证说明test_platform_connection()- 测试连接platform_status()- 查看平台状态
📄 许可证
麻省理工学院许可证(MIT License)
📝 更新日志
看 CHANGELOG.md 翻译为中文是:“变更日志文件(Markdown 格式)” 用于版本历史。
______________________________________________________________________
版本1.3.0\ 最后更新时间2025年10月18日\ 作者MCP工厂团队
✨ v1.3.0 版本亮点功能
全面双边市场支持
现在 mcp-factory-platform-server 支持完整的双边市场业务流程:
服务提供商工作流程:
Register Service → Set Pricing → Earn Revenue → Request Withdrawal服务消费者工作流程:
Browse Services → Recharge Wallet → Consume Services → View Transactions核心新功能
- 自助式API密钥管理 - 无需依赖网页,AI代理可以直接创建和管理API密钥
- 🖥️ MCP服务注册 - 服务提供商可以通过AI代理注册和管理自己的MCP服务
- 💸 提现功能 服务提供商可以将收入提现至银行账户/支付宝/微信
这些功能完善了平台的核心业务循环,使得 mcp-factory-platform 一个真正的双边市场平台!
