Skip to content

Commit 0cf3681

Browse files
refactor(mcp): 删除冗余tools
1 parent 375c476 commit 0cf3681

File tree

4 files changed

+17
-185
lines changed

4 files changed

+17
-185
lines changed

src/mcp/tools/system/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@
33
提供完整的系统管理功能,包括设备状态查询、音频控制等操作。
44
"""
55

6-
from .device_status import get_device_status
76
from .manager import SystemToolsManager, get_system_tools_manager
8-
from .tools import get_system_status, set_volume
7+
from .tools import set_volume
98

109
__all__ = [
1110
"SystemToolsManager",
1211
"get_system_tools_manager",
13-
"get_device_status",
14-
"get_system_status",
1512
"set_volume",
1613
]

src/mcp/tools/system/device_status.py

Lines changed: 0 additions & 97 deletions
This file was deleted.

src/mcp/tools/system/manager.py

Lines changed: 16 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from .app_management.killer import kill_application, list_running_applications
1111
from .app_management.launcher import launch_application
1212
from .app_management.scanner import scan_installed_applications
13-
from .tools import get_system_status, set_volume
13+
from .tools import set_volume
1414

1515
logger = get_logger(__name__)
1616

@@ -34,9 +34,6 @@ def init_tools(self, add_tool, PropertyList, Property, PropertyType):
3434
try:
3535
logger.info("[SystemManager] 开始注册系统工具")
3636

37-
# 注册获取设备状态工具
38-
self._register_device_status_tool(add_tool, PropertyList)
39-
4037
# 注册音量控制工具
4138
self._register_volume_control_tool(
4239
add_tool, PropertyList, Property, PropertyType
@@ -64,27 +61,6 @@ def init_tools(self, add_tool, PropertyList, Property, PropertyType):
6461
logger.error(f"[SystemManager] 系统工具注册失败: {e}", exc_info=True)
6562
raise
6663

67-
def _register_device_status_tool(self, add_tool, PropertyList):
68-
"""
69-
注册设备状态查询工具.
70-
"""
71-
add_tool(
72-
(
73-
"self.get_device_status",
74-
"Provides comprehensive real-time system information including "
75-
"OS details, CPU usage, memory status, disk usage, battery info, "
76-
"audio speaker volume and settings, and application state.\n"
77-
"Use this tool for: \n"
78-
"1. Answering questions about current system condition\n"
79-
"2. Getting detailed hardware and software status\n"
80-
"3. Checking current audio volume level and mute status\n"
81-
"4. As the first step before controlling device settings",
82-
PropertyList(),
83-
get_system_status,
84-
)
85-
)
86-
logger.debug("[SystemManager] 注册设备状态工具成功")
87-
8864
def _register_volume_control_tool(
8965
self, add_tool, PropertyList, Property, PropertyType
9066
):
@@ -97,22 +73,12 @@ def _register_volume_control_tool(
9773
add_tool(
9874
(
9975
"self.audio_speaker.set_volume",
100-
"【音量控制】当用户提到:调音量、声音大小、音量设为、调大声音、调小声音、声音太大/太小、"
101-
"静音、取消静音、增大音量、降低音量、把声音、音量调整、声音调节 时调用本工具。\n"
102-
"功能:设置系统扬声器音量到绝对值(0-100)。\n"
103-
"使用场景:\n"
104-
"1. 用户要求设置音量到具体数值 (例如: '音量设为50', '把声音调到80', 'volume to 30')\n"
105-
"2. 用户要求相对调整音量 ('调大一点', '声音小一点', '再大声点'): 必须先调用 "
106-
"`self.get_device_status` 获取当前 audio_speaker.volume, 计算目标值(保持在0-100内), 然后调用本工具\n"
107-
"3. 静音/取消静音: 静音设volume=0, 取消静音可设为之前的值或默认值(如30-50)\n\n"
108-
"参数说明:\n"
109-
"- volume: 整数类型,范围[0, 100],表示目标音量的绝对值\n\n"
110-
"重要提示:如果当前音量未知,切勿猜测 —— 必须先调用 `self.get_device_status` 获取。"
111-
"本工具不支持切换静音状态,要静音请设置volume=0。\n"
112-
"English: Set the volume of the audio speaker. If the current volume is unknown, "
113-
"you must call `self.get_device_status` tool first and then call this tool. "
114-
"Use when user mentions: volume, sound, louder, quieter, mute, unmute, adjust volume. "
115-
"Examples: '音量设为50', '调大声音', '声音小一点', 'set volume to 80', 'turn it up'.",
76+
"Set the system speaker volume to an absolute value (0-100).\n"
77+
"Use when user mentions: volume, sound, louder, quieter, mute, unmute, adjust volume.\n"
78+
"Examples: 'set volume to 50', 'turn volume up', 'make it louder', 'mute', "
79+
"'音量设为50', '调大声音', '声音小一点', '静音'.\n"
80+
"Parameter:\n"
81+
"- volume: Integer (0-100) representing the target volume level. Set to 0 for mute.",
11682
volume_props,
11783
set_volume,
11884
)
@@ -255,17 +221,17 @@ def get_status(self) -> Dict[str, Any]:
255221
"""
256222
获取管理器状态.
257223
"""
224+
available_tools = [
225+
"set_volume",
226+
"launch_application",
227+
"scan_installed_applications",
228+
"kill_application",
229+
"list_running_applications",
230+
]
258231
return {
259232
"initialized": self._initialized,
260-
"tools_count": 6, # 当前注册的工具数量
261-
"available_tools": [
262-
"get_device_status",
263-
"set_volume",
264-
"launch_application",
265-
"scan_installed_applications",
266-
"kill_application",
267-
"list_running_applications",
268-
],
233+
"tools_count": len(available_tools),
234+
"available_tools": available_tools,
269235
}
270236

271237

src/mcp/tools/system/tools.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,43 +9,9 @@
99

1010
from src.utils.logging_config import get_logger
1111

12-
from .device_status import get_device_status
13-
1412
logger = get_logger(__name__)
1513

1614

17-
async def get_system_status(args: Dict[str, Any]) -> str:
18-
"""
19-
获取完整的系统状态.
20-
"""
21-
try:
22-
logger.info("[SystemTools] 开始获取系统状态")
23-
24-
# 使用线程池执行同步的设备状态获取,避免阻塞事件循环
25-
status = await asyncio.to_thread(get_device_status)
26-
27-
# 添加音频/音量状态信息
28-
audio_status = await _get_audio_status()
29-
status["audio_speaker"] = audio_status
30-
31-
# 添加应用状态信息
32-
app_status = _get_application_status()
33-
status["application"] = app_status
34-
35-
logger.info("[SystemTools] 系统状态获取成功")
36-
return json.dumps(status, ensure_ascii=False, indent=2)
37-
38-
except Exception as e:
39-
logger.error(f"[SystemTools] 获取系统状态失败: {e}", exc_info=True)
40-
# 返回默认状态
41-
fallback_status = {
42-
"error": str(e),
43-
"audio_speaker": {"volume": 50, "muted": False, "available": False},
44-
"application": {"device_state": "unknown", "iot_devices": 0},
45-
}
46-
return json.dumps(fallback_status, ensure_ascii=False)
47-
48-
4915
async def set_volume(args: Dict[str, Any]) -> bool:
5016
"""
5117
设置音量.

0 commit comments

Comments
 (0)