Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions astrbot/core/agent/mcp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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)
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Resolved

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"]
Expand All @@ -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,
Expand All @@ -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(
Expand All @@ -587,6 +602,7 @@ def logging_callback(
read=sse_read_timeout_seconds,
),
follow_redirects=True,
auth=auth,
),
)
self._streams_context = streamable_http_client(
Expand Down
Loading
Loading