feat(plugin): 集成 MCP 协议支持并优化代码风格

- 新增 fastmcp 依赖,支持通过 Streamable HTTP 连接外部工具服务器
- 在 component_registry 与 tool_api 中实现 MCP 工具加载、注册及调用链路
- 补充 README 中的 MCP 特性说明
- 统一修复多处 import 顺序、空行、引号及类型注解,提升代码整洁度
- 在 pyproject.toml 中忽略 PERF203 规则,允许循环内异常处理
- 优化语音缓存与本地 ASR 调用逻辑,减少冗余代码
This commit is contained in:
明天好像没什么
2025-10-26 13:10:31 +08:00
parent 5e6857c8f7
commit 7b80d7c0b3
31 changed files with 1034 additions and 43 deletions

View File

@@ -6,4 +6,4 @@ __plugin_meta__ = PluginMetadata(
usage="在 bot_config.toml 中将 asr_provider 设置为 'local' 即可启用",
version="0.1.0",
author="Elysia",
)
)

View File

@@ -1,9 +1,4 @@
import asyncio
import os
import tempfile
from typing import Any
from pathlib import Path
import toml
import whisper
@@ -40,7 +35,7 @@ class LocalASRTool(BaseTool):
model_size = plugin_config.get("whisper", {}).get("model_size", "tiny")
device = plugin_config.get("whisper", {}).get("device", "cpu")
logger.info(f"正在预加载 Whisper ASR 模型: {model_size} ({device})")
loop = asyncio.get_running_loop()
_whisper_model = await loop.run_in_executor(
None, whisper.load_model, model_size, device
@@ -61,10 +56,10 @@ class LocalASRTool(BaseTool):
# 增强的等待逻辑:只要模型还没准备好,就一直等待后台加载任务完成
while _is_loading:
await asyncio.sleep(0.2)
if _whisper_model is None:
return "Whisper 模型加载失败,无法识别语音。"
try:
logger.info(f"开始使用 Whisper 识别音频: {audio_path}")
loop = asyncio.get_running_loop()
@@ -110,6 +105,6 @@ class STTWhisperPlugin(BasePlugin):
), LocalASRTool)]
except Exception as e:
logger.error(f"检查 ASR provider 配置时出错: {e}")
logger.debug("ASR provider is not 'local', whisper plugin's tool is disabled.")
return []

View File

@@ -6,9 +6,9 @@ from pathlib import Path
import toml
from src.chat.utils.self_voice_cache import register_self_voice
from src.common.logger import get_logger
from src.plugin_system.base.base_action import BaseAction, ChatMode
from src.chat.utils.self_voice_cache import register_self_voice
from ..services.manager import get_service

View File

@@ -15,7 +15,7 @@ __plugin_meta__ = PluginMetadata(
"is_built_in": True,
},
# Python包依赖列表
python_dependencies = [ # noqa: RUF012
python_dependencies = [
PythonDependency(package_name="asyncddgs", description="异步DuckDuckGo搜索库", optional=False),
PythonDependency(
package_name="exa_py",