mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-20 02:55:08 +08:00
This commit adds the _internal package structure for AstrBot's standardized MCP & Skills support: astrbot/_internal/mcp/: - MCPClient for MCP server connections - MCPTool wrapper for MCP tools - MCP configuration management astrbot/_internal/skills/: - SkillManager for skill lifecycle - Skill parser and loader - SkillToToolConverter for tool-based skills - Prompt builder for skills astrbot/_internal/tools/: - ToolSchema, FunctionTool, ToolSet base definitions - FunctionToolManager for tool registry - Builtin tools (cron, send_message, kb_query) - Tool providers (internal, plugin, computer) astrbot/api/: - Public API for tools (ToolRegistry, tool decorator) - Public API for MCP (get_mcp_servers, register_mcp_server) - Public API for skills (get_skill_manager, skill_to_tool)
74 lines
2.2 KiB
Python
74 lines
2.2 KiB
Python
"""Internal tools provider for AstrBot.
|
|
|
|
This provider wraps the logic for loading built-in internal tools from
|
|
the provider modules: cron_tools, kb_query, and send_message.
|
|
"""
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
from astrbot import logger
|
|
from astrbot._internal.tools.base import FunctionTool
|
|
|
|
if TYPE_CHECKING:
|
|
pass
|
|
|
|
|
|
# Provider modules that supply internal tools
|
|
_INTERNAL_PROVIDER_MODULES: list[str] = [
|
|
"astrbot.core.tools.cron_tools",
|
|
"astrbot.core.tools.kb_query",
|
|
"astrbot.core.tools.send_message",
|
|
]
|
|
|
|
|
|
class InternalToolProvider:
|
|
"""Provider for AstrBot built-in internal tools.
|
|
|
|
This class wraps the logic previously found in
|
|
``FunctionToolManager._INTERNAL_TOOL_PROVIDERS`` and provides
|
|
a unified interface for loading tools from the internal provider
|
|
modules.
|
|
|
|
Each provider module is expected to expose a ``get_all_tools()``
|
|
function that returns a list of ``FunctionTool`` instances.
|
|
|
|
Tools are marked with ``source='internal'`` so the WebUI can
|
|
distinguish them from plugin and MCP tools.
|
|
"""
|
|
|
|
@staticmethod
|
|
def get_all_tools() -> list[FunctionTool]:
|
|
"""Return all internal tools from all provider modules.
|
|
|
|
Iterates through the provider modules and collects tools
|
|
from each module's ``get_all_tools()`` function.
|
|
|
|
Returns:
|
|
list[FunctionTool]: A list of all internal FunctionTool instances.
|
|
"""
|
|
all_tools: list[FunctionTool] = []
|
|
existing_names: set[str] = set()
|
|
|
|
for module_path in _INTERNAL_PROVIDER_MODULES:
|
|
try:
|
|
import importlib
|
|
|
|
mod = importlib.import_module(module_path)
|
|
provider_tools = mod.get_all_tools()
|
|
except Exception as e:
|
|
logger.warning(
|
|
"Failed to load internal tool provider %s: %s",
|
|
module_path,
|
|
e,
|
|
)
|
|
continue
|
|
|
|
for tool in provider_tools:
|
|
tool.source = "internal"
|
|
if tool.name not in existing_names:
|
|
all_tools.append(tool)
|
|
existing_names.add(tool.name)
|
|
logger.debug("Loaded internal tool: %s", tool.name)
|
|
|
|
return all_tools
|