From 9b5d9abf82f982733dd29cede91b562b6cf9aef3 Mon Sep 17 00:00:00 2001 From: stevessr Date: Mon, 12 Oct 2026 17:17:21 +0800 Subject: [PATCH 1/4] feat: add OAuth 2.0 support for MCP servers --- astrbot/core/agent/mcp_client.py | 22 +- astrbot/core/agent/mcp_oauth.py | 938 ++++++++++++++++++ astrbot/core/config/default.py | 32 +- astrbot/core/provider/func_tool_manager.py | 53 +- astrbot/dashboard/api/app.py | 2 + astrbot/dashboard/api/tools.py | 132 ++- astrbot/dashboard/server.py | 12 +- astrbot/dashboard/services/config_service.py | 6 + astrbot/dashboard/services/tools_service.py | 44 +- dashboard/src/api/v1.ts | 26 + .../extension/McpServersSection.vue | 303 +++++- .../en-US/features/config-metadata.json | 20 + .../i18n/locales/en-US/features/settings.json | 4 + .../i18n/locales/en-US/features/tool-use.json | 26 +- .../ru-RU/features/config-metadata.json | 4 +- .../i18n/locales/ru-RU/features/tool-use.json | 26 +- .../zh-CN/features/config-metadata.json | 20 + .../i18n/locales/zh-CN/features/settings.json | 4 + .../i18n/locales/zh-CN/features/tool-use.json | 98 +- dashboard/src/views/Settings.vue | 3 +- docs/en/use/mcp.md | 42 + docs/zh/use/mcp.md | 42 + 22 files changed, 1816 insertions(+), 43 deletions(-) create mode 100644 astrbot/core/agent/mcp_oauth.py diff --git a/astrbot/core/agent/mcp_client.py b/astrbot/core/agent/mcp_client.py index d71c5219d8b..68f0a8750ba 100644 --- a/astrbot/core/agent/mcp_client.py +++ b/astrbot/core/agent/mcp_client.py @@ -22,6 +22,11 @@ from astrbot.core.agent.run_context import ContextWrapper from astrbot.core.utils.log_pipe import LogPipe +from .mcp_oauth import ( + create_mcp_http_auth, + has_mcp_oauth_config, + probe_mcp_http_oauth_connection, +) from .run_context import TContext from .tool import FunctionTool @@ -129,6 +134,9 @@ def _prepare_config(config: dict) -> dict: else: config = dict(config) config.pop("active", None) + config.pop("oauth2_enabled", None) + config.pop("oauth2_authorized", None) + config.pop("oauth2_grant_type", None) return config @@ -533,9 +541,14 @@ def logging_callback( self.server_errlogs.append(log_msg) if "url" in cfg: - success, error_msg = await _quick_test_mcp_connection(cfg) - if not success: - raise Exception(error_msg) + auth = await create_mcp_http_auth(cfg) + + if not has_mcp_oauth_config(cfg): + success, error_msg = await _quick_test_mcp_connection(cfg) + if not success: + raise Exception(error_msg) + elif auth is not None: + await probe_mcp_http_oauth_connection(cfg, auth) if "transport" in cfg: transport_type = cfg["transport"] @@ -551,6 +564,7 @@ def logging_callback( headers=cfg.get("headers", {}), timeout=cfg.get("timeout", 5), sse_read_timeout=cfg.get("sse_read_timeout", 60 * 5), + auth=auth, ) streams = await self.exit_stack.enter_async_context( self._streams_context, @@ -577,6 +591,7 @@ def logging_callback( timeout=timeout, sse_read_timeout=sse_read_timeout, terminate_on_close=cfg.get("terminate_on_close", True), + auth=auth, ) elif streamable_http_client: http_client = await self.exit_stack.enter_async_context( @@ -587,6 +602,7 @@ def logging_callback( read=sse_read_timeout_seconds, ), follow_redirects=True, + auth=auth, ), ) self._streams_context = streamable_http_client( diff --git a/astrbot/core/agent/mcp_oauth.py b/astrbot/core/agent/mcp_oauth.py new file mode 100644 index 00000000000..f9292ae6b4b --- /dev/null +++ b/astrbot/core/agent/mcp_oauth.py @@ -0,0 +1,938 @@ +from __future__ import annotations + +import asyncio +import hashlib +import json +import os +import time +import uuid +from collections.abc import Mapping +from dataclasses import dataclass, field +from pathlib import Path +from typing import Any, Literal +from urllib.parse import parse_qs, urlparse + +import httpx +from mcp.client.auth import OAuthClientProvider, TokenStorage +from mcp.client.auth.extensions.client_credentials import ( + ClientCredentialsOAuthProvider, +) +from mcp.client.auth.oauth2 import ( + build_oauth_authorization_server_metadata_discovery_urls, + build_protected_resource_metadata_discovery_urls, + create_oauth_metadata_request, + handle_auth_metadata_response, + handle_protected_resource_response, +) +from mcp.shared.auth import ( + OAuthClientInformationFull, + OAuthClientMetadata, + OAuthMetadata, + OAuthToken, + ProtectedResourceMetadata, +) +from pydantic import BaseModel, ConfigDict + +from astrbot import logger +from astrbot.core.utils.astrbot_path import get_astrbot_data_path + + +class MCPOAuthError(Exception): + """Base exception for MCP OAuth flows.""" + + +class MCPOAuthAuthorizationRequiredError(MCPOAuthError): + """Raised when interactive OAuth authorization is required.""" + + +class MCPOAuthConfig(BaseModel): + model_config = ConfigDict(extra="ignore") + + grant_type: Literal["authorization_code", "client_credentials"] = ( + "authorization_code" + ) + client_id: str | None = None + client_secret: str | None = None + token_endpoint_auth_method: ( + Literal["none", "client_secret_post", "client_secret_basic"] | None + ) = None + scope: str | None = None + redirect_uri: str | None = None + timeout: float = 300.0 + client_name: str | None = "AstrBot MCP Client" + client_uri: str | None = None + logo_uri: str | None = None + contacts: list[str] | None = None + tos_uri: str | None = None + policy_uri: str | None = None + software_id: str | None = None + software_version: str | None = None + client_metadata_url: str | None = None + + +def _prepare_config(config: Mapping[str, Any]) -> dict[str, Any]: + prepared = dict(config) + mcp_servers = prepared.get("mcpServers") + if isinstance(mcp_servers, dict) and mcp_servers: + first_server = next(iter(mcp_servers.values())) + if isinstance(first_server, dict): + prepared = dict(first_server) + prepared.pop("active", None) + prepared.pop("oauth2_enabled", None) + prepared.pop("oauth2_authorized", None) + prepared.pop("oauth2_grant_type", None) + prepared.pop("_oauth_defaults_fingerprint", None) + return prepared + + +def get_mcp_oauth_config(config: Mapping[str, Any]) -> MCPOAuthConfig | None: + prepared = _prepare_config(config) + oauth_config = prepared.get("oauth2") or prepared.get("oauth") + if not isinstance(oauth_config, dict): + return None + return MCPOAuthConfig.model_validate(oauth_config) + + +def get_mcp_oauth_redirect_uri( + config: Mapping[str, Any], callback_base_url: str +) -> str: + oauth_config = get_mcp_oauth_config(config) + return ( + oauth_config.redirect_uri + if oauth_config and oauth_config.redirect_uri + else f"{callback_base_url.rstrip('/')}/mcp/oauth/callback" + ) + + +def sync_default_mcp_oauth_callback_base(config: dict[str, Any]) -> None: + callback_base = str(config.get("callback_api_base") or "").rstrip("/") + if not callback_base: + return + + default_redirect_uri = f"{callback_base}/mcp/oauth/callback" + mcp_callback_base = str(config.get("mcp_oauth_callback_base") or "").rstrip("/") + if not mcp_callback_base or mcp_callback_base == default_redirect_uri: + config["mcp_oauth_callback_base"] = callback_base + + +def get_mcp_oauth_callback_base( + config: Mapping[str, Any], callback_base_url: str +) -> str: + redirect_uri = get_mcp_oauth_redirect_uri(config, callback_base_url) + return redirect_uri.removesuffix("/mcp/oauth/callback") + + +def apply_mcp_oauth_defaults( + config: Mapping[str, Any], defaults: Mapping[str, Any] +) -> dict[str, Any]: + prepared = _prepare_config(config) + oauth_config = prepared.get("oauth2") or prepared.get("oauth") + if not isinstance(oauth_config, dict): + return prepared + prepared["_oauth_defaults_fingerprint"] = dict(defaults) + merged = {**defaults, **oauth_config} + if "oauth2" in prepared: + prepared["oauth2"] = merged + else: + prepared["oauth"] = merged + return prepared + + +def _get_oauth_defaults_fingerprint(config: Mapping[str, Any]) -> dict[str, Any]: + oauth_config = get_mcp_oauth_config(config) + if oauth_config is None: + return {} + return { + key: getattr(oauth_config, key) + for key in ( + "client_id", + "client_secret", + "scope", + "client_name", + "redirect_uri", + ) + } + + +def has_mcp_oauth_config(config: Mapping[str, Any]) -> bool: + return get_mcp_oauth_config(config) is not None + + +def _get_storage_fingerprint(config: Mapping[str, Any]) -> str: + prepared = _prepare_config(config) + oauth_config = get_mcp_oauth_config(prepared) + if oauth_config is None: + raise MCPOAuthError("OAuth 2.0 is not configured for this MCP server.") + + fingerprint_payload = { + "url": prepared.get("url"), + "transport": prepared.get("transport") or prepared.get("type"), + "grant_type": oauth_config.grant_type, + "client_id": oauth_config.client_id, + "client_secret": oauth_config.client_secret, + "token_endpoint_auth_method": oauth_config.token_endpoint_auth_method, + "scope": oauth_config.scope, + "redirect_uri": oauth_config.redirect_uri, + "client_metadata_url": oauth_config.client_metadata_url, + "oauth_defaults": _get_oauth_defaults_fingerprint(prepared), + } + canonical = json.dumps( + fingerprint_payload, + sort_keys=True, + ensure_ascii=False, + separators=(",", ":"), + ) + return hashlib.sha256(canonical.encode("utf-8")).hexdigest() + + +def get_mcp_oauth_storage_path(config: Mapping[str, Any]) -> Path: + data_dir = Path(get_astrbot_data_path()) / "mcp_oauth" + return data_dir / f"{_get_storage_fingerprint(config)}.json" + + +class MCPFileTokenStorage(TokenStorage): + def __init__(self, storage_path: Path) -> None: + self.storage_path = storage_path + self._lock = asyncio.Lock() + + @classmethod + def from_mcp_config(cls, config: Mapping[str, Any]) -> MCPFileTokenStorage: + return cls(get_mcp_oauth_storage_path(config)) + + def _load_unlocked(self) -> dict[str, Any]: + if not self.storage_path.exists(): + return {} + try: + return json.loads(self.storage_path.read_text(encoding="utf-8")) + except Exception as exc: # noqa: BLE001 + logger.warning( + "Failed to load MCP OAuth storage %s: %s", + self.storage_path, + exc, + ) + return {} + + def _save_unlocked(self, payload: dict[str, Any]) -> None: + self.storage_path.parent.mkdir(parents=True, exist_ok=True) + self.storage_path.write_text( + json.dumps(payload, ensure_ascii=False, indent=2), + encoding="utf-8", + ) + try: + os.chmod(self.storage_path, 0o600) + except Exception as exc: # noqa: BLE001 + logger.warning( + "Failed to set permissions on MCP OAuth storage %s: %s", + self.storage_path, + exc, + ) + + async def get_tokens(self) -> OAuthToken | None: + async with self._lock: + payload = self._load_unlocked() + token_payload = payload.get("tokens") + if not token_payload: + return None + return OAuthToken.model_validate(token_payload) + + async def set_tokens(self, tokens: OAuthToken) -> None: + async with self._lock: + payload = self._load_unlocked() + payload["tokens"] = tokens.model_dump(mode="json", exclude_none=True) + if tokens.expires_in is not None: + payload["token_expires_at"] = time.time() + float(tokens.expires_in) + else: + payload.pop("token_expires_at", None) + self._save_unlocked(payload) + + async def clear_tokens(self, *, include_client_info: bool = False) -> None: + async with self._lock: + payload = self._load_unlocked() + payload.pop("tokens", None) + payload.pop("token_expires_at", None) + if include_client_info: + payload.pop("client_info", None) + self._save_unlocked(payload) + + async def get_client_info(self) -> OAuthClientInformationFull | None: + async with self._lock: + payload = self._load_unlocked() + client_info_payload = payload.get("client_info") + if not client_info_payload: + return None + return OAuthClientInformationFull.model_validate(client_info_payload) + + async def set_client_info(self, client_info: OAuthClientInformationFull) -> None: + async with self._lock: + payload = self._load_unlocked() + payload["client_info"] = client_info.model_dump( + mode="json", + exclude_none=True, + ) + self._save_unlocked(payload) + + async def get_redirect_uri(self) -> str | None: + async with self._lock: + payload = self._load_unlocked() + redirect_uri = payload.get("redirect_uri") + return str(redirect_uri) if isinstance(redirect_uri, str) else None + + async def set_redirect_uri(self, redirect_uri: str) -> None: + async with self._lock: + payload = self._load_unlocked() + payload["redirect_uri"] = redirect_uri + self._save_unlocked(payload) + + async def get_token_expires_at(self) -> float | None: + async with self._lock: + payload = self._load_unlocked() + expires_at = payload.get("token_expires_at") + if isinstance(expires_at, (int, float)): + return float(expires_at) + return None + + async def get_protected_resource_metadata( + self, + ) -> ProtectedResourceMetadata | None: + async with self._lock: + payload = self._load_unlocked() + metadata = payload.get("protected_resource_metadata") + if not metadata: + return None + return ProtectedResourceMetadata.model_validate(metadata) + + async def set_protected_resource_metadata( + self, + metadata: ProtectedResourceMetadata, + ) -> None: + async with self._lock: + payload = self._load_unlocked() + payload["protected_resource_metadata"] = metadata.model_dump( + mode="json", + exclude_none=True, + ) + self._save_unlocked(payload) + + async def get_oauth_metadata(self) -> OAuthMetadata | None: + async with self._lock: + payload = self._load_unlocked() + metadata = payload.get("oauth_metadata") + if not metadata: + return None + return OAuthMetadata.model_validate(metadata) + + async def set_oauth_metadata(self, metadata: OAuthMetadata) -> None: + async with self._lock: + payload = self._load_unlocked() + payload["oauth_metadata"] = metadata.model_dump( + mode="json", + exclude_none=True, + ) + self._save_unlocked(payload) + + +def _get_token_endpoint_auth_method(oauth_config: MCPOAuthConfig) -> str: + if oauth_config.token_endpoint_auth_method: + return oauth_config.token_endpoint_auth_method + if oauth_config.client_secret: + return "client_secret_basic" + return "none" + + +async def _raise_interactive_redirect_required(_: str) -> None: + raise MCPOAuthAuthorizationRequiredError( + "OAuth 2.0 authorization is required. Complete authorization in the MCP server dialog first.", + ) + + +async def _raise_interactive_callback_required() -> tuple[str, str | None]: + raise MCPOAuthAuthorizationRequiredError( + "OAuth 2.0 authorization is required. Complete authorization in the MCP server dialog first.", + ) + + +if OAuthClientProvider is not None: + + class AstrBotOAuthClientProvider(OAuthClientProvider): + async def _ensure_oauth_metadata(self) -> None: + """Load or discover OAuth metadata before refreshing tokens. + + Raises: + MCPOAuthError: If OAuth metadata cannot be discovered. + """ + storage = self.context.storage + if not isinstance(storage, MCPFileTokenStorage): + return + + if self.context.protected_resource_metadata is None: + self.context.protected_resource_metadata = ( + await storage.get_protected_resource_metadata() + ) + if self.context.oauth_metadata is None: + self.context.oauth_metadata = await storage.get_oauth_metadata() + + if self.context.oauth_metadata is not None: + return + + async with httpx.AsyncClient( + follow_redirects=True, + timeout=self.context.timeout, + ) as client: + if self.context.protected_resource_metadata is None: + protected_resource_urls = ( + build_protected_resource_metadata_discovery_urls( + None, + self.context.server_url, + ) + ) + for url in protected_resource_urls: + response = await client.send(create_oauth_metadata_request(url)) + metadata = await handle_protected_resource_response(response) + if metadata is None: + continue + self.context.protected_resource_metadata = metadata + await storage.set_protected_resource_metadata(metadata) + if metadata.authorization_servers: + self.context.auth_server_url = str( + metadata.authorization_servers[0] + ) + break + + auth_server_url = ( + self.context.auth_server_url + or self.context.get_authorization_base_url( + self.context.server_url, + ) + ) + oauth_metadata_urls = ( + build_oauth_authorization_server_metadata_discovery_urls( + auth_server_url, + self.context.server_url, + ) + ) + for url in oauth_metadata_urls: + response = await client.send(create_oauth_metadata_request(url)) + ok, metadata = await handle_auth_metadata_response(response) + if not ok: + break + if metadata is None: + continue + self.context.oauth_metadata = metadata + await storage.set_oauth_metadata(metadata) + return + + raise MCPOAuthError("Failed to discover OAuth 2.0 metadata.") + + async def _initialize(self) -> None: + await super()._initialize() + + storage = self.context.storage + if not isinstance(storage, MCPFileTokenStorage): + return + + self.context.protected_resource_metadata = ( + await storage.get_protected_resource_metadata() + ) + self.context.oauth_metadata = await storage.get_oauth_metadata() + if self.context.protected_resource_metadata is not None: + authorization_servers = ( + self.context.protected_resource_metadata.authorization_servers + ) + if authorization_servers: + self.context.auth_server_url = str(authorization_servers[0]) + + expires_at = await storage.get_token_expires_at() + if expires_at is not None: + self.context.token_expiry_time = expires_at + + if ( + expires_at is not None + and time.time() > expires_at + and not self.context.can_refresh_token() + ): + raise MCPOAuthAuthorizationRequiredError( + "The stored OAuth 2.0 token has expired. Complete authorization in the MCP server dialog again.", + ) + + async def _refresh_token(self) -> httpx.Request: + await self._ensure_oauth_metadata() + return await super()._refresh_token() + + async def _handle_token_response(self, response: httpx.Response) -> None: + await super()._handle_token_response(response) + + storage = self.context.storage + if not isinstance(storage, MCPFileTokenStorage): + return + if self.context.protected_resource_metadata is not None: + await storage.set_protected_resource_metadata( + self.context.protected_resource_metadata, + ) + if self.context.oauth_metadata is not None: + await storage.set_oauth_metadata(self.context.oauth_metadata) + +else: + AstrBotOAuthClientProvider = None # type: ignore[assignment] + + +if ClientCredentialsOAuthProvider is not None: + + class AstrBotClientCredentialsOAuthProvider(ClientCredentialsOAuthProvider): + async def _initialize(self) -> None: + await super()._initialize() + + storage = self.context.storage + if not isinstance(storage, MCPFileTokenStorage): + return + + expires_at = await storage.get_token_expires_at() + if expires_at is not None: + self.context.token_expiry_time = expires_at + +else: + AstrBotClientCredentialsOAuthProvider = None # type: ignore[assignment] + + +def _build_client_metadata_fields( + oauth_config: MCPOAuthConfig, + redirect_uri: str, +) -> dict[str, Any]: + return { + "redirect_uris": [redirect_uri], + "token_endpoint_auth_method": _get_token_endpoint_auth_method(oauth_config), + "grant_types": ["authorization_code", "refresh_token"], + "response_types": ["code"], + "scope": oauth_config.scope, + "client_name": oauth_config.client_name, + "client_uri": oauth_config.client_uri, + "logo_uri": oauth_config.logo_uri, + "contacts": oauth_config.contacts, + "tos_uri": oauth_config.tos_uri, + "policy_uri": oauth_config.policy_uri, + "software_id": oauth_config.software_id, + "software_version": oauth_config.software_version, + } + + +async def _seed_client_info_if_needed( + storage: MCPFileTokenStorage, + oauth_config: MCPOAuthConfig, + *, + redirect_uri: str, +) -> None: + if oauth_config.client_id: + await storage.set_client_info( + OAuthClientInformationFull( + **_build_client_metadata_fields(oauth_config, redirect_uri), + client_id=oauth_config.client_id, + client_secret=oauth_config.client_secret, + ) + ) + + +@dataclass(slots=True) +class MCPOAuthPendingFlow: + flow_id: str + config: dict[str, Any] + redirect_uri: str + oauth_defaults: dict[str, Any] = field(default_factory=dict) + created_at: float = field(default_factory=time.time) + status: Literal[ + "initializing", + "awaiting_user", + "authorizing", + "completed", + "failed", + ] = "initializing" + authorization_url: str | None = None + error: str | None = None + callback_code: str | None = None + callback_state: str | None = None + callback_error: str | None = None + oauth_state: str | None = None + url_ready_event: asyncio.Event = field(default_factory=asyncio.Event) + callback_ready_event: asyncio.Event = field(default_factory=asyncio.Event) + done_event: asyncio.Event = field(default_factory=asyncio.Event) + task: asyncio.Task[None] | None = None + + async def handle_redirect(self, authorization_url: str) -> None: + self.authorization_url = authorization_url + parsed_url = urlparse(authorization_url) + self.oauth_state = parse_qs(parsed_url.query).get("state", [None])[0] + self.status = "awaiting_user" + self.url_ready_event.set() + + async def wait_for_callback(self) -> tuple[str, str | None]: + await self.callback_ready_event.wait() + if self.callback_error: + raise MCPOAuthError(self.callback_error) + self.status = "authorizing" + return self.callback_code or "", self.callback_state + + def submit_callback( + self, + *, + code: str | None, + state: str | None, + error: str | None, + ) -> None: + self.callback_code = code + self.callback_state = state + self.callback_error = error + self.callback_ready_event.set() + + +async def create_mcp_http_auth( + config: Mapping[str, Any], + *, + interactive_flow: MCPOAuthPendingFlow | None = None, + oauth_defaults: Mapping[str, Any] | None = None, +) -> httpx.Auth | None: + prepared = apply_mcp_oauth_defaults(config, oauth_defaults or {}) + if "url" not in prepared: + return None + + oauth_config = get_mcp_oauth_config(prepared) + if oauth_config is None: + return None + + if OAuthClientProvider is None or OAuthClientMetadata is None: + raise MCPOAuthError("The installed MCP dependency does not support OAuth 2.0.") + + storage = MCPFileTokenStorage.from_mcp_config(prepared) + + if oauth_config.grant_type == "client_credentials": + if not oauth_config.client_id or not oauth_config.client_secret: + raise MCPOAuthError( + "OAuth client_credentials requires both client_id and client_secret.", + ) + if AstrBotClientCredentialsOAuthProvider is None: + raise MCPOAuthError( + "The installed MCP dependency does not support OAuth 2.0 client_credentials.", + ) + return AstrBotClientCredentialsOAuthProvider( + server_url=str(prepared["url"]), + storage=storage, + client_id=oauth_config.client_id, + client_secret=oauth_config.client_secret, + token_endpoint_auth_method=_get_token_endpoint_auth_method(oauth_config), + scopes=oauth_config.scope, + ) + + if oauth_config.grant_type != "authorization_code": + raise MCPOAuthError( + f"Unsupported MCP OAuth grant_type: {oauth_config.grant_type}", + ) + + if interactive_flow is None: + stored_tokens = await storage.get_tokens() + if stored_tokens is None: + raise MCPOAuthAuthorizationRequiredError( + "OAuth 2.0 authorization is required. Complete authorization in the MCP server dialog first.", + ) + + expires_at = await storage.get_token_expires_at() + if ( + expires_at is not None + and time.time() > expires_at + and not stored_tokens.refresh_token + ): + raise MCPOAuthAuthorizationRequiredError( + "The stored OAuth 2.0 token has expired and no refresh token is available. Complete authorization in the MCP server dialog again.", + ) + + redirect_uri = ( + interactive_flow.redirect_uri + if interactive_flow + else ( + oauth_config.redirect_uri + or await storage.get_redirect_uri() + or "http://127.0.0.1/astrbot/mcp/oauth/callback/pending" + ) + ) + + await storage.set_redirect_uri(redirect_uri) + await _seed_client_info_if_needed(storage, oauth_config, redirect_uri=redirect_uri) + + redirect_handler = ( + interactive_flow.handle_redirect + if interactive_flow is not None + else _raise_interactive_redirect_required + ) + callback_handler = ( + interactive_flow.wait_for_callback + if interactive_flow is not None + else _raise_interactive_callback_required + ) + + if AstrBotOAuthClientProvider is None: + raise MCPOAuthError("The installed MCP dependency does not support OAuth 2.0.") + + return AstrBotOAuthClientProvider( + server_url=str(prepared["url"]), + client_metadata=OAuthClientMetadata( + **_build_client_metadata_fields(oauth_config, redirect_uri) + ), + storage=storage, + redirect_handler=redirect_handler, + callback_handler=callback_handler, + timeout=oauth_config.timeout, + client_metadata_url=oauth_config.client_metadata_url, + ) + + +async def get_mcp_oauth_state(config: Mapping[str, Any]) -> dict[str, Any]: + oauth_config = get_mcp_oauth_config(config) + authorized = ( + oauth_config is not None and oauth_config.grant_type == "client_credentials" + ) + if oauth_config is not None and not authorized: + storage = MCPFileTokenStorage.from_mcp_config(config) + tokens = await storage.get_tokens() + authorized = tokens is not None + if authorized and tokens is not None: + expires_at = await storage.get_token_expires_at() + authorized = not ( + expires_at is not None + and time.time() > expires_at + and not tokens.refresh_token + ) + + return { + "oauth2_enabled": oauth_config is not None, + "oauth2_authorized": authorized, + "oauth2_grant_type": oauth_config.grant_type if oauth_config else None, + } + + +async def probe_mcp_http_oauth_connection( + config: Mapping[str, Any], + auth: httpx.Auth, +) -> None: + """Validate OAuth-protected HTTP MCP connectivity before opening a session. + + Args: + config: MCP server config containing HTTP URL and transport type. + auth: Prepared HTTPX OAuth auth provider. + + Raises: + MCPOAuthError: If the server rejects the OAuth-authenticated probe. + """ + prepared = _prepare_config(config) + url = str(prepared["url"]) + headers = { + str(key): str(value) for key, value in dict(prepared.get("headers", {})).items() + } + timeout_value = float(prepared.get("timeout", 30)) + transport_type = prepared.get("transport") or prepared.get("type") or "sse" + + async with httpx.AsyncClient( + follow_redirects=True, + timeout=timeout_value, + ) as client: + probe_session_id = None + if transport_type == "streamable_http": + response = await client.post( + url, + headers={ + **headers, + "Content-Type": "application/json", + "Accept": "application/json, text/event-stream", + }, + json={ + "jsonrpc": "2.0", + "method": "initialize", + "id": 0, + "params": { + "protocolVersion": "2024-11-05", + "capabilities": {}, + "clientInfo": { + "name": "astrbot-oauth-probe", + "version": "1.0.0", + }, + }, + }, + auth=auth, + ) + probe_session_id = response.headers.get("mcp-session-id") + else: + response = await client.get( + url, + headers={ + **headers, + "Accept": "application/json, text/event-stream", + }, + auth=auth, + ) + + if response.status_code != 200: + raise MCPOAuthError( + f"OAuth authorization probe failed: HTTP {response.status_code} {response.reason_phrase}", + ) + + if probe_session_id: + try: + await client.delete( + url, + headers={**headers, "mcp-session-id": probe_session_id}, + auth=auth, + ) + except Exception as exc: # noqa: BLE001 + logger.debug(f"Failed to terminate MCP OAuth probe session: {exc}") + + +class MCPOAuthManager: + _FLOW_TTL_SECONDS = 900 + + def __init__(self) -> None: + self._flows: dict[str, MCPOAuthPendingFlow] = {} + self._state_to_flow_id: dict[str, str] = {} + self._lock = asyncio.Lock() + + async def _prune_flows(self) -> None: + threshold = time.time() - self._FLOW_TTL_SECONDS + async with self._lock: + expired_ids = [ + flow_id + for flow_id, flow in self._flows.items() + if flow.created_at < threshold + ] + for flow_id in expired_ids: + expired_states = [ + state + for state, state_flow_id in self._state_to_flow_id.items() + if state_flow_id == flow_id + ] + for state in expired_states: + self._state_to_flow_id.pop(state, None) + self._flows.pop(flow_id, None) + + async def _run_flow(self, flow: MCPOAuthPendingFlow) -> None: + try: + auth = await create_mcp_http_auth( + flow.config, + interactive_flow=flow, + oauth_defaults=flow.oauth_defaults, + ) + if auth is None: + raise MCPOAuthError("OAuth 2.0 is not configured for this MCP server.") + await probe_mcp_http_oauth_connection(flow.config, auth) + flow.status = "completed" + except Exception as exc: # noqa: BLE001 + error_message = str(exc).strip() or exc.__class__.__name__ + if isinstance(exc, httpx.TimeoutException): + request = getattr(exc, "request", None) + target = f" while requesting {request.url}" if request else "" + error_message = f"{exc.__class__.__name__}{target}" + flow.error = error_message + flow.status = "failed" + flow.url_ready_event.set() + finally: + flow.done_event.set() + + async def start_authorization( + self, + config: Mapping[str, Any], + *, + callback_base_url: str, + oauth_defaults: Mapping[str, Any] | None = None, + server_name: str | None = None, + force: bool = False, + ) -> MCPOAuthPendingFlow: + prepared = apply_mcp_oauth_defaults(config, oauth_defaults or {}) + oauth_config = get_mcp_oauth_config(prepared) + if oauth_config is None: + raise MCPOAuthError("OAuth 2.0 is not configured for this MCP server.") + if oauth_config.grant_type != "authorization_code": + raise MCPOAuthError( + "Interactive login is only available for authorization_code flows.", + ) + if "url" not in prepared: + raise MCPOAuthError("OAuth 2.0 is only supported for HTTP MCP transports.") + + await self._prune_flows() + + storage = MCPFileTokenStorage.from_mcp_config(prepared) + if force: + await storage.clear_tokens(include_client_info=True) + + flow_id = uuid.uuid4().hex + redirect_uri = get_mcp_oauth_redirect_uri(prepared, callback_base_url) + + flow = MCPOAuthPendingFlow( + flow_id=flow_id, + config=prepared, + redirect_uri=redirect_uri, + oauth_defaults=dict(oauth_defaults or {}), + ) + flow.task = asyncio.create_task( + self._run_flow(flow), + name=f"mcp-oauth:{flow_id}", + ) + + async with self._lock: + self._flows[flow_id] = flow + + wait_url_task = asyncio.create_task(flow.url_ready_event.wait()) + wait_done_task = asyncio.create_task(flow.done_event.wait()) + try: + done, pending = await asyncio.wait( + {wait_url_task, wait_done_task}, + timeout=15, + return_when=asyncio.FIRST_COMPLETED, + ) + for task in pending: + task.cancel() + await asyncio.gather(*pending, return_exceptions=True) + + if not done: + if flow.task is not None: + flow.task.cancel() + await asyncio.gather(flow.task, return_exceptions=True) + raise MCPOAuthError( + "Timed out while preparing the OAuth 2.0 authorization flow.", + ) + finally: + if not wait_url_task.done(): + wait_url_task.cancel() + if not wait_done_task.done(): + wait_done_task.cancel() + + if flow.status == "failed": + raise MCPOAuthError(flow.error or "Failed to start OAuth 2.0 flow.") + + if flow.oauth_state: + async with self._lock: + self._state_to_flow_id[flow.oauth_state] = flow.flow_id + + return flow + + async def submit_callback( + self, + flow_id: str | None = None, + *, + code: str | None, + state: str | None, + error: str | None, + ) -> None: + resolved_flow_id = flow_id + if resolved_flow_id is None and state: + resolved_flow_id = self._state_to_flow_id.get(state) + + async with self._lock: + flow = self._flows.get(resolved_flow_id or "") + if flow is None: + raise KeyError(flow_id or state or "") + flow.submit_callback(code=code, state=state, error=error) + + def get_flow_status(self, flow_id: str) -> dict[str, Any]: + flow = self._flows.get(flow_id) + if flow is None: + raise KeyError(flow_id) + return { + "flow_id": flow.flow_id, + "status": flow.status, + "authorization_url": flow.authorization_url, + "redirect_uri": flow.redirect_uri, + "error": flow.error, + } diff --git a/astrbot/core/config/default.py b/astrbot/core/config/default.py index 44872fd5090..eed3c140e45 100644 --- a/astrbot/core/config/default.py +++ b/astrbot/core/config/default.py @@ -307,6 +307,11 @@ def get_local_permission_defaults(system: str | None = None) -> dict: "persona": [], # deprecated "timezone": "Asia/Shanghai", "callback_api_base": "", + "mcp_oauth_callback_base": "", + "mcp_oauth_client_name": "AstrBot MCP Client", + "mcp_oauth_scope": "", + "mcp_oauth_client_id": "", + "mcp_oauth_client_secret": "", "default_kb_collection": "", # 默认知识库名称, 已经过时 "disabled_plugins": [], "plugin_set": ["*"], # "*" 表示使用所有可用的插件, 空列表表示不使用任何插件 @@ -5141,7 +5146,32 @@ def get_local_permission_defaults(system: str | None = None) -> dict: "callback_api_base": { "description": "对外可达的回调接口地址", "type": "string", - "hint": "外部服务可能会通过 AstrBot 生成的回调链接(如文件下载链接)访问 AstrBot 后端。由于 AstrBot 无法自动判断部署环境中对外可达的主机地址(host),因此需要通过此配置项显式指定 “外部服务如何访问 AstrBot” 的地址。如 http://localhost:6185,https://example.com 等。", + "hint": "外部服务可能会通过 AstrBot 生成的回调链接(如文件下载链接)访问 AstrBot 后端。由于 AstrBot 无法自动判断部署环境中对外可达的主机地址(host),因此需要通过此配置项显式指定“外部服务如何访问 AstrBot”的地址。如 http://localhost:6185,https://example.com 等。", + }, + "mcp_oauth_callback_base": { + "description": "MCP OAuth 回调地址", + "type": "string", + "hint": "对外可访问的 AstrBot 地址,用于 MCP OAuth 2.0 授权回调。留空或保持与“对外可达的回调接口地址”加上 /mcp/oauth/callback 一致时,将随通用回调地址自动更新。", + }, + "mcp_oauth_client_name": { + "description": "MCP OAuth 客户端名称", + "type": "string", + }, + "mcp_oauth_scope": { + "description": "MCP OAuth 默认 Scope", + "type": "string", + "hint": "不同 MCP 服务所需权限不同;单个服务器配置中的 oauth2.scope 可覆盖此默认值。", + }, + "mcp_oauth_client_id": { + "description": "MCP OAuth 默认 Client ID", + "type": "string", + "hint": "仅用于支持预注册客户端的 MCP 服务;单个服务器配置中的 oauth2.client_id 可覆盖此默认值。", + }, + "mcp_oauth_client_secret": { + "description": "MCP OAuth 默认 Client Secret", + "type": "string", + "secret": True, + "hint": "妥善保管客户端密钥;单个服务器配置中的 oauth2.client_secret 可覆盖此默认值。", }, "timezone": { "description": "时区", diff --git a/astrbot/core/provider/func_tool_manager.py b/astrbot/core/provider/func_tool_manager.py index df4f3207578..f321529b786 100644 --- a/astrbot/core/provider/func_tool_manager.py +++ b/astrbot/core/provider/func_tool_manager.py @@ -17,6 +17,12 @@ from astrbot import logger from astrbot.core import sp from astrbot.core.agent.mcp_client import MCPClient, MCPTool +from astrbot.core.agent.mcp_oauth import ( + MCPOAuthAuthorizationRequiredError, + MCPOAuthManager, + get_mcp_oauth_state, + has_mcp_oauth_config, +) from astrbot.core.agent.tool import FunctionTool, ToolSet from astrbot.core.utils.astrbot_path import get_astrbot_data_path @@ -291,6 +297,7 @@ def __init__(self) -> None: self._timeout_warn_lock = threading.Lock() self._runtime_lock = asyncio.Lock() self._mcp_starting: set[str] = set() + self._mcp_oauth_manager = MCPOAuthManager() self._init_timeout_default = _resolve_timeout( timeout=None, env_name=MCP_INIT_TIMEOUT_ENV, @@ -555,6 +562,11 @@ async def init_mcp_clients( logger.error( f"Connected to MCP server {name} timeout ({timeout_display} seconds)" ) + elif isinstance(result, MCPOAuthAuthorizationRequiredError): + logger.warning( + f"MCP server {name} requires OAuth 2.0 authorization. " + f"Please complete authorization in the dashboard. ({result})" + ) else: logger.error(f"Failed to initialize MCP server {name}: {result}") self._log_safe_mcp_debug_config(cfg) @@ -809,7 +821,7 @@ async def _terminate_mcp_client(self, name: str) -> None: @staticmethod async def test_mcp_server_connection(config: dict) -> list[str]: - if "url" in config: + if "url" in config and not has_mcp_oauth_config(config): success, error_msg = await _quick_test_mcp_connection(config) if not success: raise Exception(error_msg) @@ -825,6 +837,45 @@ async def test_mcp_server_connection(config: dict) -> list[str]: await mcp_client.cleanup() return tool_names + async def get_mcp_oauth_state(self, config: dict) -> dict[str, Any]: + return await get_mcp_oauth_state(config) + + async def start_mcp_oauth_authorization( + self, + config: dict, + *, + callback_base_url: str, + oauth_defaults: dict[str, Any] | None = None, + server_name: str | None = None, + force: bool = False, + ) -> dict[str, Any]: + flow = await self._mcp_oauth_manager.start_authorization( + config, + callback_base_url=callback_base_url, + oauth_defaults=oauth_defaults, + server_name=server_name, + force=force, + ) + return self._mcp_oauth_manager.get_flow_status(flow.flow_id) + + def get_mcp_oauth_flow_status(self, flow_id: str) -> dict[str, Any]: + return self._mcp_oauth_manager.get_flow_status(flow_id) + + async def submit_mcp_oauth_callback( + self, + flow_id: str | None, + *, + code: str | None, + state: str | None, + error: str | None, + ) -> None: + await self._mcp_oauth_manager.submit_callback( + flow_id, + code=code, + state=state, + error=error, + ) + async def enable_mcp_server( self, name: str, diff --git a/astrbot/dashboard/api/app.py b/astrbot/dashboard/api/app.py index 1bb15b0976b..7d6e5696a04 100644 --- a/astrbot/dashboard/api/app.py +++ b/astrbot/dashboard/api/app.py @@ -76,6 +76,7 @@ from .stats import legacy_router as legacy_stats_router from .t2i import legacy_router as legacy_t2i_router from .tools import legacy_router as legacy_tools_router +from .tools import oauth_callback_router as tools_oauth_callback_router from .updates import legacy_router as legacy_updates_router CLEAR_SITE_DATA_HEADERS = {"Clear-Site-Data": '"cache"'} @@ -224,6 +225,7 @@ async def catch_all_handler(_request: Request, exc: Exception): app.include_router(legacy_t2i_router) app.include_router(legacy_personas_router) app.include_router(legacy_updates_router) + app.include_router(tools_oauth_callback_router) app.include_router(build_api_router()) app.include_router(static_files_router) return app diff --git a/astrbot/dashboard/api/tools.py b/astrbot/dashboard/api/tools.py index 03ec432f7ce..d8c91c8034d 100644 --- a/astrbot/dashboard/api/tools.py +++ b/astrbot/dashboard/api/tools.py @@ -3,7 +3,9 @@ from typing import Any from fastapi import APIRouter, Depends, Query, Request +from fastapi.responses import HTMLResponse +from astrbot.core.agent.mcp_oauth import get_mcp_oauth_callback_base from astrbot.dashboard.async_utils import run_maybe_async from astrbot.dashboard.responses import ApiError, ok from astrbot.dashboard.schemas import ( @@ -13,7 +15,11 @@ ToolEnabledRequest, ToolPermissionRequest, ) -from astrbot.dashboard.services.tools_service import ToolsService, ToolsServiceError +from astrbot.dashboard.services.tools_service import ( + ToolsService, + ToolsServiceError, + extract_mcp_server_config, +) from .auth import AuthContext, ScopeDependency, require_dashboard_user, require_scope @@ -23,6 +29,10 @@ tags=["Dashboard Extension Components"], include_in_schema=False, ) +oauth_callback_router = APIRouter( + tags=["Dashboard Extension Components"], + include_in_schema=False, +) def get_service(request: Request) -> ToolsService: @@ -90,6 +100,20 @@ def _test_config_body( return {"name": server_name} +def _mcp_oauth_config_body(body: dict[str, Any]) -> dict[str, Any]: + config = body.get("mcp_server_config") or body.get("config") + if not isinstance(config, dict) or not config: + raise ApiError("Invalid MCP server configuration") + + if "mcpServers" in config: + try: + config = extract_mcp_server_config(config["mcpServers"]) + except ValueError as exc: + raise ApiError(f"{exc!s}") from exc + + return dict(config) + + def _raise_tools_error(exc: ToolsServiceError) -> None: raise ApiError(str(exc)) from exc @@ -176,6 +200,51 @@ async def _sync_modelscope_mcp_servers( ) +async def _start_mcp_oauth_authorization( + request: Request, + service: ToolsService, +): + body = await _json_or_empty(request) + config = _mcp_oauth_config_body(body) + + core_lifecycle = request.app.state.core_lifecycle + callback_api_base = core_lifecycle.astrbot_config.get("mcp_oauth_callback_base", "") + callback_base_value = ( + callback_api_base or body.get("callback_base_url") or str(request.base_url) + ) + callback_base_url = str(callback_base_value).rstrip("/") + callback_base_url = get_mcp_oauth_callback_base(config, callback_base_url) + oauth_defaults = { + key.removeprefix("mcp_oauth_"): core_lifecycle.astrbot_config.get(key) + for key in ( + "mcp_oauth_client_name", + "mcp_oauth_scope", + "mcp_oauth_client_id", + "mcp_oauth_client_secret", + ) + if core_lifecycle.astrbot_config.get(key) + } + server_name = request.query_params.get("name") + + return await _run( + lambda: service.start_mcp_oauth_authorization( + config, + callback_base_url=callback_base_url, + oauth_defaults=oauth_defaults, + server_name=server_name, + force=bool(body.get("force", False)), + ), + message="OAuth 2.0 authorization flow is ready.", + ) + + +async def _get_mcp_oauth_status(flow_id: str, service: ToolsService): + flow_id = flow_id.strip() + if not flow_id: + raise ApiError("Missing required parameter: flow_id") + return await _run(lambda: service.get_mcp_oauth_flow_status(flow_id)) + + @router.get("/tools") async def list_tools( _auth: AuthContext = Depends(require_tool_scope), @@ -412,6 +481,24 @@ async def test_dashboard_mcp_connection( ) +@legacy_router.post("/tools/mcp/oauth/start") +async def start_dashboard_mcp_oauth_authorization( + request: Request, + _username: str = Depends(require_dashboard_user), + service: ToolsService = Depends(get_service), +): + return await _start_mcp_oauth_authorization(request, service) + + +@legacy_router.get("/tools/mcp/oauth/status") +async def get_dashboard_mcp_oauth_status( + flow_id: str = Query(""), + _username: str = Depends(require_dashboard_user), + service: ToolsService = Depends(get_service), +): + return await _get_mcp_oauth_status(flow_id, service) + + @legacy_router.post("/tools/mcp/sync-provider") async def sync_dashboard_mcp_provider( request: Request, @@ -423,3 +510,46 @@ async def sync_dashboard_mcp_provider( lambda: service.sync_provider(body), result_as_message=True, ) + + +@oauth_callback_router.get("/mcp/oauth/callback", response_class=HTMLResponse) +async def handle_mcp_oauth_callback( + request: Request, + service: ToolsService = Depends(get_service), +): + error = request.query_params.get("error") + error_description = request.query_params.get("error_description") + if error_description: + error = f"{error or 'oauth_error'}: {error_description}" + + try: + await service.submit_mcp_oauth_callback( + None, + code=request.query_params.get("code"), + state=request.query_params.get("state"), + error=error, + ) + except KeyError: + return HTMLResponse( + "

OAuth flow not found or expired.

", + status_code=404, + ) + except ToolsServiceError as exc: + return HTMLResponse( + f"

OAuth callback failed: {exc!s}

", + status_code=500, + ) + + return HTMLResponse( + """ + + +

OAuth authorization completed.

+

You can return to AstrBot and wait for the status to update.

+ + + +""", + ) diff --git a/astrbot/dashboard/server.py b/astrbot/dashboard/server.py index e6645cbdbc7..138c6ee1783 100644 --- a/astrbot/dashboard/server.py +++ b/astrbot/dashboard/server.py @@ -10,7 +10,7 @@ import jwt import psutil from fastapi import Request -from fastapi.responses import JSONResponse +from fastapi.responses import JSONResponse, Response from hypercorn.asyncio import serve from hypercorn.config import Config as HyperConfig from hypercorn.logging import AccessLogAtoms @@ -298,7 +298,15 @@ async def dashboard_auth_middleware(request_, call_next): auth_response = await self.auth_middleware(request_) if auth_response is not None: return auth_response - return await call_next(request_) + try: + return await call_next(request_) + except RuntimeError as exc: + if ( + str(exc) == "No response returned." + and await request_.is_disconnected() + ): + return Response(status_code=204) + raise @self.asgi_app.middleware("http") async def dashboard_body_limit_middleware(request_, call_next): diff --git a/astrbot/dashboard/services/config_service.py b/astrbot/dashboard/services/config_service.py index e4514c224ff..51ae9fb1258 100644 --- a/astrbot/dashboard/services/config_service.py +++ b/astrbot/dashboard/services/config_service.py @@ -744,6 +744,12 @@ async def update_profile( config[key] = default_conf.get(key, []) current_config = self.acm.confs[config_id] + if config_id == "default": + from astrbot.core.agent.mcp_oauth import ( + sync_default_mcp_oauth_callback_base, + ) + + sync_default_mcp_oauth_callback_base(config) if ( not allow_admin_id_change and "admins_id" in config diff --git a/astrbot/dashboard/services/tools_service.py b/astrbot/dashboard/services/tools_service.py index 51497a068c5..80897b833a4 100644 --- a/astrbot/dashboard/services/tools_service.py +++ b/astrbot/dashboard/services/tools_service.py @@ -47,7 +47,7 @@ def rollback_mcp_server(self, name: str) -> bool: logger.error(traceback.format_exc()) return False - def get_mcp_servers(self) -> list[dict]: + async def get_mcp_servers(self) -> list[dict]: try: config = self.tool_mgr.load_mcp_config() servers = [] @@ -83,6 +83,10 @@ def get_mcp_servers(self) -> list[dict]: server_info["tools"] = [tool.name for tool in mcp_client.tools] server_info["errlogs"] = mcp_client.server_errlogs + get_oauth_state = getattr(self.tool_mgr, "get_mcp_oauth_state", None) + if get_oauth_state is not None: + server_info.update(await get_oauth_state(server_config)) + servers.append(server_info) return servers @@ -101,6 +105,41 @@ def get_mcp_server_config(self, name: str) -> dict | None: return None return dict(server_config) + async def start_mcp_oauth_authorization( + self, + config: dict, + *, + callback_base_url: str, + oauth_defaults: dict | None = None, + server_name: str | None = None, + force: bool = False, + ) -> dict: + return await self.tool_mgr.start_mcp_oauth_authorization( + config, + callback_base_url=callback_base_url, + oauth_defaults=oauth_defaults, + server_name=server_name, + force=force, + ) + + def get_mcp_oauth_flow_status(self, flow_id: str) -> dict: + return self.tool_mgr.get_mcp_oauth_flow_status(flow_id) + + async def submit_mcp_oauth_callback( + self, + flow_id: str | None, + *, + code: str | None, + state: str | None, + error: str | None, + ) -> None: + await self.tool_mgr.submit_mcp_oauth_callback( + flow_id, + code=code, + state=state, + error=error, + ) + async def add_mcp_server(self, server_data: Any) -> str: try: name = server_data.get("name", "") @@ -396,6 +435,9 @@ def _build_updated_server_config( "tools", "errlogs", "oldName", + "oauth2_enabled", + "oauth2_authorized", + "oauth2_grant_type", ]: continue if key == "mcpServers": diff --git a/dashboard/src/api/v1.ts b/dashboard/src/api/v1.ts index 8863c904009..79f16a70320 100644 --- a/dashboard/src/api/v1.ts +++ b/dashboard/src/api/v1.ts @@ -118,6 +118,19 @@ export interface ProviderEmbeddingDimensionData { [key: string]: unknown; } +export interface McpOAuthStartPayload { + mcp_server_config: DynamicConfig; + force?: boolean; +} + +export interface McpOAuthFlowData { + flow_id?: string; + authorization_url?: string; + status?: string; + error?: string | null; + [key: string]: unknown; +} + export interface VersionData { version?: string; dashboard_version?: string; @@ -1198,6 +1211,19 @@ export const mcpApi = { }), ); }, + startOAuth(payload: McpOAuthStartPayload, serverName: string) { + return httpClient.post>( + '/api/tools/mcp/oauth/start', + payload, + { params: { name: serverName } }, + ); + }, + getOAuthStatus(flowId: string, serverName: string) { + return httpClient.get>( + '/api/tools/mcp/oauth/status', + { params: { flow_id: flowId, name: serverName } }, + ); + }, syncModelScope(payload?: ModelScopeSyncRequest) { return typed( openApiV1.syncModelScopeMcpServers({ body: payload }), diff --git a/dashboard/src/components/extension/McpServersSection.vue b/dashboard/src/components/extension/McpServersSection.vue index 86c0fb77211..97672f57c7d 100644 --- a/dashboard/src/components/extension/McpServersSection.vue +++ b/dashboard/src/components/extension/McpServersSection.vue @@ -118,7 +118,7 @@
-