mirror of
https://github.com/AstrBotDevs/AstrBot
synced 2026-07-17 17:51:20 +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)
64 lines
1.5 KiB
Python
64 lines
1.5 KiB
Python
"""MCP module - Model Context Protocol client and tool implementations.
|
|
|
|
This module provides MCP client functionality and MCP tool wrappers.
|
|
"""
|
|
|
|
import asyncio
|
|
from dataclasses import dataclass
|
|
|
|
from .client import MCPClient
|
|
from .config import (
|
|
DEFAULT_MCP_CONFIG,
|
|
get_mcp_config_path,
|
|
load_mcp_config,
|
|
save_mcp_config,
|
|
)
|
|
from .tool import MCPTool
|
|
|
|
|
|
# Exceptions
|
|
class MCPInitError(Exception):
|
|
"""Base exception for MCP initialization failures."""
|
|
|
|
|
|
class MCPInitTimeoutError(asyncio.TimeoutError, MCPInitError):
|
|
"""Raised when MCP client initialization exceeds the configured timeout."""
|
|
|
|
|
|
class MCPAllServicesFailedError(MCPInitError):
|
|
"""Raised when all configured MCP services fail to initialize."""
|
|
|
|
|
|
class MCPShutdownTimeoutError(asyncio.TimeoutError):
|
|
"""Raised when MCP shutdown exceeds the configured timeout."""
|
|
|
|
def __init__(self, names: list[str], timeout: float) -> None:
|
|
self.names = names
|
|
self.timeout = timeout
|
|
message = f"MCP 服务关闭超时({timeout:g} 秒):{', '.join(names)}"
|
|
super().__init__(message)
|
|
|
|
|
|
@dataclass
|
|
class MCPInitSummary:
|
|
"""Summary of MCP initialization results."""
|
|
|
|
total: int
|
|
success: int
|
|
failed: list[str]
|
|
|
|
|
|
__all__ = [
|
|
"DEFAULT_MCP_CONFIG",
|
|
"MCPAllServicesFailedError",
|
|
"MCPClient",
|
|
"MCPInitError",
|
|
"MCPInitSummary",
|
|
"MCPInitTimeoutError",
|
|
"MCPShutdownTimeoutError",
|
|
"MCPTool",
|
|
"get_mcp_config_path",
|
|
"load_mcp_config",
|
|
"save_mcp_config",
|
|
]
|