KICCO_AI_IMAGE/mcp_server/flux_starter.py

63 lines
2.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
FLUX风格塑形MCP服务器启动脚本
--------------------------
启动带有FLUX风格塑形功能的MCP服务器
"""
import logging
import argparse
import sys
import asyncio
# 设置日志
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
# 导入MCP服务器
from mcp_server import MCPServer
from flux_style_resource import register_flux_resources
async def main_async():
"""异步主函数"""
# 解析命令行参数
parser = argparse.ArgumentParser(description='启动带有FLUX风格塑形功能的MCP服务器')
parser.add_argument('--host', type=str, default='127.0.0.1', help='服务器监听地址')
parser.add_argument('--port', type=int, default=8189, help='服务器监听端口')
parser.add_argument('--name', type=str, default='FLUX-MCP', help='服务器名称')
args = parser.parse_args()
try:
# 创建MCP服务器实例
logger.info(f"正在初始化MCP服务器: {args.name}...")
server = MCPServer(server_name=args.name)
# 注册FLUX风格塑形资源和工具
logger.info("正在注册FLUX风格塑形资源...")
register_flux_resources(server)
# 启动服务器
logger.info(f"正在启动MCP服务器监听地址: {args.host}:{args.port}")
await server.start(host=args.host, port=args.port)
except KeyboardInterrupt:
logger.info("收到中断信号,服务器关闭")
except Exception as e:
logger.error(f"服务器启动失败: {e}")
return 1
return 0
def main():
"""主函数"""
try:
return asyncio.run(main_async())
except KeyboardInterrupt:
logger.info("收到中断信号,服务器关闭")
return 0
except Exception as e:
logger.error(f"服务器运行出错: {e}")
return 1
if __name__ == "__main__":
sys.exit(main())