7575import java .time .Duration ;
7676import java .util .*;
7777import java .util .List ;
78+ import java .util .concurrent .atomic .AtomicReference ;
7879
7980/**
8081 * Web 设置控制器 —— SolonCode Web UI 的设置管理 HTTP 入口。
@@ -782,9 +783,9 @@ public Result mcpServersToggle(@Param("name") String name, @Param("enabled") boo
782783 */
783784 @ Post
784785 @ Mapping ("/web/settings/mcp/servers/check" )
785- public Result mcpServersCheck (Context ctx ) {
786+ public Result mcpServersCheck (String json ) {
786787 try {
787- ONode root = ONode .ofJson (ctx . body () );
788+ ONode root = ONode .ofJson (json );
788789 String type = root .get ("type" ).getString ();
789790 if (type == null || type .isEmpty ()) type = "stdio" ;
790791
@@ -842,10 +843,22 @@ public Result mcpServersCheck(Context ctx) {
842843 }
843844
844845 McpClientProvider client = builder .build ();
846+ AtomicReference <Throwable > errorRef = new AtomicReference <>();
845847 try {
846848 // 通过 getTools() 触发 MCP 初始化握手,验证连接有效性
847- client .getTools ();
849+ client .getClient ().listTools ()
850+ .doOnError (err -> {
851+ errorRef .set (err );
852+ })
853+ .block ();
854+
848855 return Result .succeed ("连接成功:MCP 初始化握手完成(" + type + ")" );
856+ } catch (Exception e ) {
857+ if (errorRef .get () != null ) {
858+ throw errorRef .get ();
859+ } else {
860+ throw e ;
861+ }
849862 } finally {
850863 client .close ();
851864 }
@@ -858,7 +871,7 @@ public Result mcpServersCheck(Context ctx) {
858871 return Result .failure ("连接超时,请检查地址是否可达" );
859872 } catch (java .io .IOException e ) {
860873 return Result .failure ("连接失败: " + e .getMessage ());
861- } catch (Exception e ) {
874+ } catch (Throwable e ) {
862875 return Result .failure ("检测失败: " + e .getMessage ());
863876 }
864877 }
@@ -1170,8 +1183,8 @@ public Result<List<Map>> openapiServers() throws Exception {
11701183 */
11711184 @ Post
11721185 @ Mapping ("/web/settings/openapi/servers/add" )
1173- public Result openapiServersAdd (Context ctx ) throws Exception {
1174- ONode root = ONode .ofJson (ctx . body () );
1186+ public Result openapiServersAdd (@ Body String json ) throws Exception {
1187+ ONode root = ONode .ofJson (json );
11751188 String name = root .get ("name" ).getString ();
11761189 String apiBaseUrl = root .get ("apiBaseUrl" ).getString ();
11771190
@@ -1226,8 +1239,8 @@ public Result openapiServersAdd(Context ctx) throws Exception {
12261239 */
12271240 @ Post
12281241 @ Mapping ("/web/settings/openapi/servers/update" )
1229- public Result openapiServersUpdate (Context ctx ) throws Exception {
1230- ONode root = ONode .ofJson (ctx . body () );
1242+ public Result openapiServersUpdate (@ Body String json ) throws Exception {
1243+ ONode root = ONode .ofJson (json );
12311244 String name = root .get ("name" ).getString ();
12321245 String originalName = root .get ("originalName" ).getString ();
12331246
0 commit comments