53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
#!/usr/bin/env python
|
|
"""
|
|
启动 MCP 服务器的入口脚本
|
|
支持 stdio(本地)和 HTTP/SSE(远程)两种传输方式
|
|
"""
|
|
import sys
|
|
import os
|
|
import argparse
|
|
from pathlib import Path
|
|
|
|
# 添加项目根目录到 Python 路径
|
|
# 脚本在 facebook_agent/ 目录下,需要将父目录添加到路径
|
|
project_root = Path(__file__).parent.parent
|
|
sys.path.insert(0, str(project_root))
|
|
|
|
if __name__ == '__main__':
|
|
parser = argparse.ArgumentParser(description='启动 MCP 服务器')
|
|
parser.add_argument(
|
|
'--transport',
|
|
choices=['stdio', 'http', 'sse'],
|
|
default='stdio',
|
|
help='传输方式: stdio (本地), http (HTTP), sse (SSE)'
|
|
)
|
|
parser.add_argument('--host', default='0.0.0.0', help='HTTP/SSE 服务器地址')
|
|
parser.add_argument('--port', type=int, default=8001, help='HTTP/SSE 服务器端口')
|
|
|
|
args = parser.parse_args()
|
|
|
|
if args.transport == 'stdio':
|
|
# stdio 模式(本地)
|
|
from facebook_agent.mcp_server import server
|
|
print("🚀 MCP Server (stdio) 启动中...")
|
|
server.run()
|
|
else:
|
|
# HTTP/SSE 模式(远程)
|
|
from facebook_agent.mcp_http_server import app
|
|
import uvicorn
|
|
|
|
host = args.host
|
|
port = args.port
|
|
|
|
print(f"🚀 MCP HTTP/SSE Server 启动中...")
|
|
print(f"📡 HTTP 端点: http://{host}:{port}/mcp")
|
|
print(f"📡 SSE 端点: http://{host}:{port}/mcp/sse")
|
|
print(f"📚 健康检查: http://{host}:{port}/health")
|
|
print()
|
|
print("💡 Cursor 配置示例:")
|
|
print(f' "url": "http://{host}:{port}/mcp"')
|
|
print(f' "type": "{args.transport}"')
|
|
|
|
uvicorn.run(app, host=host, port=port)
|
|
|