Skip to content

Commit 248e0fc

Browse files
ivicacclaude
andcommitted
2447 Fix PR review comments for MCP client and cluster element execution
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b878743 commit 248e0fc

5 files changed

Lines changed: 48 additions & 34 deletions

File tree

server/libs/modules/components/mcp-client/src/main/java/com/bytechef/component/mcp/client/connection/McpClientConnection.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import static com.bytechef.component.definition.ComponentDsl.connection;
2828
import static com.bytechef.component.definition.ComponentDsl.option;
2929
import static com.bytechef.component.definition.ComponentDsl.string;
30+
import static com.bytechef.component.mcp.client.constant.McpClientConstants.HTTP_SSE;
3031
import static com.bytechef.component.mcp.client.constant.McpClientConstants.HTTP_STREAMABLE;
3132
import static com.bytechef.component.mcp.client.constant.McpClientConstants.TRANSPORT_TYPE;
3233
import static com.bytechef.component.mcp.client.constant.McpClientConstants.URL;
@@ -46,6 +47,14 @@ public class McpClientConnection {
4647
string(URL)
4748
.label("Server URL")
4849
.description("The URL of the MCP server to connect to.")
50+
.required(true),
51+
string(TRANSPORT_TYPE)
52+
.label("Transport Type")
53+
.description("The transport protocol to use for connecting to the MCP server.")
54+
.options(
55+
option("HTTP Streamable", HTTP_STREAMABLE),
56+
option("SSE", HTTP_SSE))
57+
.defaultValue(HTTP_STREAMABLE)
4958
.required(true))
5059
.authorizationRequired(false)
5160
.authorizations(
@@ -95,20 +104,7 @@ public class McpClientConnection {
95104
string(SCOPES)
96105
.label("Scopes")
97106
.description("Optional comma-delimited list of scopes")
98-
.controlType(ControlType.TEXT_AREA))
99-
.properties(
100-
string(URL)
101-
.label("Server URL")
102-
.description("The URL of the MCP server to connect to.")
103-
.required(true),
104-
string(TRANSPORT_TYPE)
105-
.label("Transport Type")
106-
.description("The transport protocol to use for connecting to the MCP server.")
107-
.options(
108-
option("HTTP Streamable", HTTP_STREAMABLE),
109-
option("SSE", "sse"))
110-
.defaultValue(HTTP_STREAMABLE)
111-
.required(true)));
107+
.controlType(ControlType.TEXT_AREA)));
112108

113109
private McpClientConnection() {
114110
}

server/libs/modules/components/mcp-client/src/main/java/com/bytechef/component/mcp/client/constant/McpClientConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class McpClientConstants {
2323

2424
public static final String ALL = "all";
2525
public static final String EXCLUDE = "exclude";
26+
public static final String HTTP_SSE = "sse";
2627
public static final String HTTP_STREAMABLE = "httpStreamable";
2728
public static final String INCLUDE = "include";
2829
public static final String MCP_CLIENT = "mcpClient";

server/libs/modules/components/mcp-client/src/main/java/com/bytechef/component/mcp/client/util/McpClientUtils.java

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import static com.bytechef.component.definition.ComponentDsl.string;
2929
import static com.bytechef.component.mcp.client.constant.McpClientConstants.ALL;
3030
import static com.bytechef.component.mcp.client.constant.McpClientConstants.EXCLUDE;
31+
import static com.bytechef.component.mcp.client.constant.McpClientConstants.HTTP_SSE;
3132
import static com.bytechef.component.mcp.client.constant.McpClientConstants.HTTP_STREAMABLE;
3233
import static com.bytechef.component.mcp.client.constant.McpClientConstants.INCLUDE;
3334
import static com.bytechef.component.mcp.client.constant.McpClientConstants.TOOLS_TO_EXCLUDE;
@@ -158,25 +159,30 @@ public static McpSyncClient createMcpSyncClient(
158159
Consumer<HttpRequest.Builder> requestCustomizer = getRequestCustomizer(
159160
connectionParameters, connectionDefinitionService, context);
160161

161-
McpClientTransport transport;
162+
McpClientTransport transport = switch (transportType) {
163+
case HTTP_STREAMABLE -> {
164+
HttpClientStreamableHttpTransport.Builder builder =
165+
HttpClientStreamableHttpTransport.builder(serverUrl);
162166

163-
if (HTTP_STREAMABLE.equals(transportType)) {
164-
HttpClientStreamableHttpTransport.Builder builder = HttpClientStreamableHttpTransport.builder(serverUrl);
167+
if (requestCustomizer != null) {
168+
builder.customizeRequest(requestCustomizer);
169+
}
165170

166-
if (requestCustomizer != null) {
167-
builder.customizeRequest(requestCustomizer);
171+
yield builder.build();
168172
}
173+
case HTTP_SSE -> {
174+
HttpClientSseClientTransport.Builder builder = HttpClientSseClientTransport.builder(serverUrl);
169175

170-
transport = builder.build();
171-
} else {
172-
HttpClientSseClientTransport.Builder builder = HttpClientSseClientTransport.builder(serverUrl);
176+
if (requestCustomizer != null) {
177+
builder.customizeRequest(requestCustomizer);
178+
}
173179

174-
if (requestCustomizer != null) {
175-
builder.customizeRequest(requestCustomizer);
180+
yield builder.build();
176181
}
177-
178-
transport = builder.build();
179-
}
182+
default -> throw new IllegalArgumentException(
183+
"Unsupported MCP transport type: " + transportType +
184+
". Supported values are: " + HTTP_STREAMABLE + ", " + HTTP_SSE);
185+
};
180186

181187
return McpClient.sync(transport)
182188
.build();
@@ -261,21 +267,27 @@ private static Consumer<HttpRequest.Builder> getRequestCustomizer(
261267
}
262268

263269
private static AuthorizationType getAuthorizationType(Parameters connectionParameters) {
264-
if (connectionParameters.getString(TOKEN) != null) {
270+
String token = connectionParameters.getString(TOKEN);
271+
272+
if (token != null && !token.isBlank()) {
265273
return AuthorizationType.BEARER_TOKEN;
266274
}
267275

268-
if (connectionParameters.getString(ACCESS_TOKEN) != null) {
276+
String accessToken = connectionParameters.getString(ACCESS_TOKEN);
277+
278+
if (accessToken != null && !accessToken.isBlank()) {
269279
String authorizationUrl = connectionParameters.getString(Authorization.AUTHORIZATION_URL);
270280

271-
if (authorizationUrl != null) {
281+
if (authorizationUrl != null && !authorizationUrl.isBlank()) {
272282
return AuthorizationType.OAUTH2_AUTHORIZATION_CODE;
273283
}
274284

275285
return AuthorizationType.OAUTH2_CLIENT_CREDENTIALS;
276286
}
277287

278-
if (connectionParameters.getString(KEY) != null) {
288+
String key = connectionParameters.getString(KEY);
289+
290+
if (key != null && !key.isBlank()) {
279291
return AuthorizationType.API_KEY;
280292
}
281293

server/libs/platform/platform-component/platform-component-api/src/main/java/com/bytechef/platform/component/definition/ParametersFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
public class ParametersFactory {
2727

2828
public static Parameters create(ComponentConnection componentConnection) {
29-
return new ParametersImpl(componentConnection == null ? Map.of() : componentConnection.getParameters());
29+
return create(componentConnection == null ? Map.of() : componentConnection.getParameters());
3030
}
3131

3232
public static Parameters create(Map<String, ?> map) {

server/libs/platform/platform-component/platform-component-service/src/main/java/com/bytechef/platform/component/service/ClusterElementDefinitionServiceImpl.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,14 @@ private Object doExecuteTool(
449449
return toolCallbackProviderFunction.apply(inputParams, connectionParams, context);
450450
}
451451

452-
ToolFunction toolFunction = (ToolFunction) clusterElement;
452+
if (clusterElement instanceof ToolFunction toolFunction) {
453+
return toolFunction.apply(inputParams, connectionParams, context);
454+
}
453455

454-
return toolFunction.apply(inputParams, connectionParams, context);
456+
throw new ExecutionException(
457+
"Unsupported cluster element type: " + clusterElement.getClass()
458+
.getName(),
459+
inputParameters, ClusterElementDefinitionErrorType.EXECUTE_PERFORM);
455460
} catch (Exception exception) {
456461
if (exception instanceof ProviderException) {
457462
throw (ProviderException) exception;

0 commit comments

Comments
 (0)