|
49 | 49 | * |
50 | 50 | * <p> |
51 | 51 | * This configuration class sets up the necessary beans for SSE-based HTTP client |
52 | | - * transport when WebFlux is not available. It provides HTTP client-based SSE transport |
53 | | - * implementation for MCP client communication. |
54 | | - * |
55 | | - * <p> |
56 | | - * The configuration is activated after the WebFlux SSE transport auto-configuration to |
57 | | - * ensure proper fallback behavior when WebFlux is not available. |
| 52 | + * transport. It provides HTTP client-based SSE transport implementation for MCP client |
| 53 | + * communication. |
58 | 54 | * |
59 | 55 | * <p> |
60 | 56 | * Key features: |
@@ -113,26 +109,38 @@ public List<NamedClientMcpTransport> sseHttpClientTransports(McpSseClientConnect |
113 | 109 | List<NamedClientMcpTransport> sseTransports = new ArrayList<>(); |
114 | 110 |
|
115 | 111 | for (Map.Entry<String, SseParameters> serverParameters : connectionDetails.getConnections().entrySet()) { |
116 | | - |
117 | | - String baseUrl = serverParameters.getValue().url(); |
118 | | - String sseEndpoint = serverParameters.getValue().sseEndpoint() != null |
119 | | - ? serverParameters.getValue().sseEndpoint() : "/sse"; |
120 | | - HttpClientSseClientTransport.Builder transportBuilder = HttpClientSseClientTransport.builder(baseUrl) |
121 | | - .sseEndpoint(sseEndpoint) |
122 | | - .clientBuilder(HttpClient.newBuilder()) |
123 | | - .jsonMapper(new JacksonMcpJsonMapper(objectMapper)); |
124 | | - |
125 | | - asyncHttpRequestCustomizer.ifUnique(transportBuilder::asyncHttpRequestCustomizer); |
126 | | - syncHttpRequestCustomizer.ifUnique(transportBuilder::httpRequestCustomizer); |
127 | | - if (asyncHttpRequestCustomizer.getIfUnique() != null && syncHttpRequestCustomizer.getIfUnique() != null) { |
128 | | - logger.warn("Found beans of type %s and %s. Using %s.".formatted( |
129 | | - McpAsyncHttpClientRequestCustomizer.class.getSimpleName(), |
130 | | - McpSyncHttpClientRequestCustomizer.class.getSimpleName(), |
131 | | - McpSyncHttpClientRequestCustomizer.class.getSimpleName())); |
| 112 | + String connectionName = serverParameters.getKey(); |
| 113 | + SseParameters params = serverParameters.getValue(); |
| 114 | + |
| 115 | + String baseUrl = params.url(); |
| 116 | + String sseEndpoint = params.sseEndpoint() != null ? params.sseEndpoint() : "/sse"; |
| 117 | + if (baseUrl == null || baseUrl.trim().isEmpty()) { |
| 118 | + throw new IllegalArgumentException("SSE connection '" + connectionName |
| 119 | + + "' requires a 'url' property. Example: url: http://localhost:3000"); |
132 | 120 | } |
133 | 121 |
|
134 | | - HttpClientSseClientTransport transport = transportBuilder.build(); |
135 | | - sseTransports.add(new NamedClientMcpTransport(serverParameters.getKey(), transport)); |
| 122 | + try { |
| 123 | + var transportBuilder = HttpClientSseClientTransport.builder(baseUrl) |
| 124 | + .sseEndpoint(sseEndpoint) |
| 125 | + .clientBuilder(HttpClient.newBuilder()) |
| 126 | + .jsonMapper(new JacksonMcpJsonMapper(objectMapper)); |
| 127 | + |
| 128 | + asyncHttpRequestCustomizer.ifUnique(transportBuilder::asyncHttpRequestCustomizer); |
| 129 | + syncHttpRequestCustomizer.ifUnique(transportBuilder::httpRequestCustomizer); |
| 130 | + if (asyncHttpRequestCustomizer.getIfUnique() != null |
| 131 | + && syncHttpRequestCustomizer.getIfUnique() != null) { |
| 132 | + logger.warn("Found beans of type %s and %s. Using %s.".formatted( |
| 133 | + McpAsyncHttpClientRequestCustomizer.class.getSimpleName(), |
| 134 | + McpSyncHttpClientRequestCustomizer.class.getSimpleName(), |
| 135 | + McpSyncHttpClientRequestCustomizer.class.getSimpleName())); |
| 136 | + } |
| 137 | + sseTransports.add(new NamedClientMcpTransport(connectionName, transportBuilder.build())); |
| 138 | + } |
| 139 | + catch (Exception e) { |
| 140 | + throw new IllegalArgumentException("Failed to create SSE transport for connection '" + connectionName |
| 141 | + + "'. Check URL splitting: url='" + baseUrl + "', sse-endpoint='" + sseEndpoint |
| 142 | + + "'. Full URL should be split as: url=http://host:port, sse-endpoint=/path/to/endpoint", e); |
| 143 | + } |
136 | 144 | } |
137 | 145 |
|
138 | 146 | return sseTransports; |
|
0 commit comments