Skip to content

Commit 4f8b302

Browse files
committed
update:输出单模块部署的mcp接入点
1 parent e77cf83 commit 4f8b302

File tree

3 files changed

+14
-20
lines changed

3 files changed

+14
-20
lines changed

src/core/connection_manager.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import json
88
import time
99
import uuid
10-
import re
1110
from typing import Dict, Any, List, Optional, Tuple
1211
from websockets.server import WebSocketServerProtocol
1312
from websockets.exceptions import ConnectionClosed

src/handlers/websocket_handler.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
"""
55

66
import json
7-
from typing import Optional, Any
8-
from urllib.parse import parse_qs, urlparse
9-
from websockets.server import WebSocketServerProtocol
10-
from websockets.exceptions import ConnectionClosed
117
from ..core.connection_manager import connection_manager
128
from ..utils.logger import get_logger
139
from ..utils.jsonrpc import (
@@ -116,17 +112,6 @@ async def _handle_robot_message(
116112
except Exception as e:
117113
logger.error(f"处理小智端消息时发生错误: {e}")
118114

119-
def _extract_agent_id(self, path: str) -> Optional[str]:
120-
"""从路径中提取agentId参数"""
121-
try:
122-
parsed_url = urlparse(f"ws://localhost{path}")
123-
query_params = parse_qs(parsed_url.query)
124-
agent_ids = query_params.get("agentId", [])
125-
return agent_ids[0] if agent_ids else None
126-
except Exception as e:
127-
logger.error(f"提取agentId参数失败: {e}")
128-
return None
129-
130115

131116
# 全局WebSocket处理器实例
132117
websocket_handler = WebSocketHandler()

src/server.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
import json
88
import signal
99
import uvicorn
10+
from urllib.parse import quote
1011
from .utils.config import config
1112
from .utils.logger import get_logger
12-
from .utils.aes_utils import decrypt
13+
from .utils.aes_utils import decrypt, encrypt
1314
from .utils.jsonrpc import (
1415
JSONRPCProtocol,
1516
)
@@ -65,12 +66,21 @@ async def lifespan(app: FastAPI):
6566
"""应用生命周期管理"""
6667
# 启动时
6768
logger.info("MCP Endpoint Server 正在启动...")
68-
logger.info(f"======================================================")
69+
logger.info(f"=====下面的地址分别是智控台/单模块MCP接入点地址====")
6970
local_ip = get_local_ip()
7071
logger.info(
71-
f"接口地址: http://{local_ip}:{config.getint('server', 'port', 8004)}/mcp_endpoint/health?key={config.get('server', 'key', '')}"
72+
f"智控台MCP参数配置: http://{local_ip}:{config.getint('server', 'port', 8004)}/mcp_endpoint/health?key={config.get('server', 'key', '')}"
73+
)
74+
encrypted_token = encrypt(
75+
config.get("server", "key", ""), '{"agentId":"single_module"}'
76+
)
77+
token = quote(encrypted_token)
78+
logger.info(
79+
f"单模块部署MCP接入点: ws://{local_ip}:{config.getint('server', 'port', 8004)}/mcp_endpoint/mcp/?token={token}"
80+
)
81+
logger.info(
82+
"=====请根据具体部署选择使用,请勿泄露给任何人======",
7283
)
73-
logger.info("=======上面的地址是MCP接入点地址,请勿泄露给任何人============")
7484
yield
7585
# 关闭时
7686
logger.info("MCP Endpoint Server 已关闭")

0 commit comments

Comments
 (0)