Skip to content

Commit 93d1958

Browse files
committed
fix: validate transport type in MCP server configuration
--bug=1056812 --user=刘瑞斌 【github##3232】【应用编排】mcp节点的transport配置填写http,错误提示不对 https://www.tapd.cn/57709429/s/1736690
1 parent 90ee3c4 commit 93d1958

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

apps/application/serializers/application_serializers.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import uuid
1717
from functools import reduce
1818
from typing import Dict, List
19+
1920
from django.contrib.postgres.fields import ArrayField
2021
from django.core import cache, validators
2122
from django.core import signing
@@ -24,8 +25,8 @@
2425
from django.db.models.expressions import RawSQL
2526
from django.http import HttpResponse
2627
from django.template import Template, Context
28+
from django.utils.translation import gettext_lazy as _, get_language, to_locale
2729
from langchain_mcp_adapters.client import MultiServerMCPClient
28-
from mcp.client.sse import sse_client
2930
from rest_framework import serializers, status
3031
from rest_framework.utils.formatting import lazy_format
3132

@@ -38,7 +39,7 @@
3839
from common.constants.authentication_type import AuthenticationType
3940
from common.db.search import get_dynamics_model, native_search, native_page_search
4041
from common.db.sql_execute import select_list
41-
from common.exception.app_exception import AppApiException, NotFound404, AppUnauthorizedFailed, ChatException
42+
from common.exception.app_exception import AppApiException, NotFound404, AppUnauthorizedFailed
4243
from common.field.common import UploadedImageField, UploadedFileField
4344
from common.models.db_model_manage import DBModelManage
4445
from common.response import result
@@ -57,7 +58,6 @@
5758
from setting.serializers.provider_serializers import ModelSerializer
5859
from smartdoc.conf import PROJECT_DIR
5960
from users.models import User
60-
from django.utils.translation import gettext_lazy as _, get_language, to_locale
6161

6262
chat_cache = cache.caches['chat_cache']
6363

@@ -1328,6 +1328,9 @@ def get_mcp_servers(self, with_valid=True):
13281328
if '"stdio"' in self.data.get('mcp_servers'):
13291329
raise AppApiException(500, _('stdio is not supported'))
13301330
servers = json.loads(self.data.get('mcp_servers'))
1331+
for server, config in servers.items():
1332+
if config.get('transport') not in ['sse', 'streamable_http']:
1333+
raise AppApiException(500, _('Only support transport=sse or transport=streamable_http'))
13311334

13321335
async def get_mcp_tools(servers):
13331336
async with MultiServerMCPClient(servers) as client:

0 commit comments

Comments
 (0)