Skip to content
Closed
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
23 changes: 20 additions & 3 deletions backend/services/remote_mcp_service.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import logging
import os
import tempfile
import httpx

from fastmcp import Client
from fastmcp.client.transports import StreamableHttpTransport, SSETransport
from httpx import AsyncClient

from consts.const import CAN_EDIT_ALL_USER_ROLES, PERMISSION_EDIT, PERMISSION_READ
from consts.exceptions import MCPConnectionError, MCPNameIllegal
Expand All @@ -23,6 +25,18 @@

logger = logging.getLogger("remote_mcp_service")

def create_httpx_client(
headers: dict[str, str] | None = None,
timeout: httpx.Timeout | None = None,
auth: httpx.Auth | None = None,
) -> AsyncClient:
return AsyncClient(
headers=headers,
timeout=timeout,
auth=auth,
trust_env=False,
Comment on lines +33 to +37
verify=False,

Check failure on line 38 in backend/services/remote_mcp_service.py

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Enable server certificate validation on this SSL/TLS connection.

See more on https://sonarcloud.io/project/issues?id=ModelEngine-Group_nexent&issues=AZ5KTL-zCXIsTxTT8WFc&open=AZ5KTL-zCXIsTxTT8WFc&pullRequest=3014
)

async def mcp_server_health(remote_mcp_server: str, authorization_token: str | None = None) -> bool:
try:
Expand All @@ -33,18 +47,21 @@
if url_stripped.endswith("/sse"):
transport = SSETransport(
url=url_stripped,
headers=headers
headers=headers,
httpx_client_factory=create_httpx_client
)
elif url_stripped.endswith("/mcp"):
transport = StreamableHttpTransport(
url=url_stripped,
headers=headers
headers=headers,
httpx_client_factory=create_httpx_client
)
else:
# Default to StreamableHttpTransport for unrecognized formats
transport = StreamableHttpTransport(
url=url_stripped,
headers=headers
headers=headers,
httpx_client_factory=create_httpx_client
)

client = Client(transport=transport)
Expand Down
7 changes: 4 additions & 3 deletions backend/services/tool_configuration_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from mcpadapt.smolagents_adapter import _sanitize_function_name
from services.file_management_service import get_llm_model, validate_urls_access
from services.vectordatabase_service import get_embedding_model_by_index_name, get_rerank_model
from services.remote_mcp_service import create_httpx_client
from database.client import minio_client
from services.image_service import get_vlm_model
from nexent.monitor import set_monitoring_context, set_monitoring_operation
Expand All @@ -62,12 +63,12 @@ def _create_mcp_transport(url: str, authorization_token: Optional[str] = None):
headers = {"Authorization": authorization_token} if authorization_token else {}

if url_stripped.endswith("/sse"):
return SSETransport(url=url_stripped, headers=headers)
return SSETransport(url=url_stripped, headers=headers, httpx_client_factory=create_httpx_client)
elif url_stripped.endswith("/mcp"):
return StreamableHttpTransport(url=url_stripped, headers=headers)
return StreamableHttpTransport(url=url_stripped, headers=headers, httpx_client_factory=create_httpx_client)
else:
# Default to StreamableHttpTransport for unrecognized formats
return StreamableHttpTransport(url=url_stripped, headers=headers)
return StreamableHttpTransport(url=url_stripped, headers=headers, httpx_client_factory=create_httpx_client)


def python_type_to_json_schema(annotation: Any) -> str:
Expand Down
1 change: 1 addition & 0 deletions sdk/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ dependencies = [
"pymysql>=1.1.0",
"psycopg2-binary>=2.9.9",
"pymssql>=2.2.11",
"pandas>=2.2.0",
"openpyxl>=3.1.5",
"orjson==3.10",
"pypdf==6.9.1",
Expand Down